From 7d087ba1fa9bfba9b53c5a2d24814c4bc0ca13f8 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 26 Jun 2023 18:37:03 -0400 Subject: [PATCH] Split the Zipline API validator into its own module (#1060) After implementation there isn't much code shared with the Kotlin compiler plugin. Lets keep these separate for simplicity, and to avoid dragging compiler plugin dependencies into the CLI. --- settings.gradle.kts | 5 ++- zipline-api-validator/build.gradle.kts | 45 +++++++++++++++++++ .../validator}/ApiCompatibilityDecision.kt | 10 ++--- .../cash/zipline/api/validator}/fir/Fir.kt | 2 +- .../api/validator/fir/FirZiplineApi.kt | 12 ++++- .../api/validator}/fir/FirZiplineApiReader.kt | 12 ++--- .../api/validator}/fir/KotlinFirLoader.kt | 2 +- .../zipline/api/validator/fir/ZiplineApis.kt | 14 ++++-- .../api/validator}/toml/TomlZiplineApi.kt | 2 +- .../validator}/toml/ZiplineApiTomlReader.kt | 4 +- .../validator}/toml/ZiplineApiTomlWriter.kt | 4 +- .../ApiCompatibilityDecisionTest.kt | 16 +++---- .../validator}/fir/FirZiplineApiReaderTest.kt | 2 +- .../toml/TomlZiplineApiReaderTest.kt | 10 ++--- .../toml/TomlZiplineApiWriterTest.kt | 8 ++-- zipline-cli/build.gradle.kts | 1 + zipline-gradle-plugin/build.gradle.kts | 2 + ...tionTask.kt => ZiplineApiValidatorTask.kt} | 22 ++++----- .../app/cash/zipline/gradle/ZiplinePlugin.kt | 4 +- zipline-kotlin-plugin/build.gradle.kts | 22 --------- .../cash/zipline/api/fir/FirZiplineService.kt | 22 --------- 21 files changed, 121 insertions(+), 100 deletions(-) create mode 100644 zipline-api-validator/build.gradle.kts rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/compatibility => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/ApiCompatibilityDecision.kt (91%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/fir/Fir.kt (97%) rename zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineFunction.kt => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApi.kt (74%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/fir/FirZiplineApiReader.kt (94%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/fir/KotlinFirLoader.kt (99%) rename zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApi.kt => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/ZiplineApis.kt (63%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/toml/TomlZiplineApi.kt (95%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/toml/ZiplineApiTomlReader.kt (98%) rename {zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api => zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator}/toml/ZiplineApiTomlWriter.kt (94%) rename {zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/compatibility => zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator}/ApiCompatibilityDecisionTest.kt (95%) rename {zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api => zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator}/fir/FirZiplineApiReaderTest.kt (98%) rename zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReaderTest.kt => zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiReaderTest.kt (93%) rename zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriterTest.kt => zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiWriterTest.kt (94%) rename zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/{ZiplineApiValidationTask.kt => ZiplineApiValidatorTask.kt} (84%) delete mode 100644 zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineService.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index bc607f9cd4..2853817104 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,14 +1,15 @@ rootProject.name = "zipline-root" include(":zipline") -include(":zipline-testing") +include(":zipline-api-validator") +include(":zipline-bytecode") include(":zipline-cli") include(":zipline-gradle-plugin") include(":zipline-kotlin-plugin") include(":zipline-kotlin-plugin-tests") -include(":zipline-bytecode") include(":zipline-loader") include(":zipline-loader-testing") include(":zipline-profiler") +include(":zipline-testing") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") diff --git a/zipline-api-validator/build.gradle.kts b/zipline-api-validator/build.gradle.kts new file mode 100644 index 0000000000..7d624eac5b --- /dev/null +++ b/zipline-api-validator/build.gradle.kts @@ -0,0 +1,45 @@ +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.KotlinJvm +import com.vanniktech.maven.publish.MavenPublishBaseExtension +import org.gradle.api.plugins.JavaPlugin.TEST_TASK_NAME +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME + +plugins { + kotlin("jvm") + kotlin("kapt") + id("com.vanniktech.maven.publish.base") +} + +dependencies { + api(kotlin("compiler-embeddable")) + api(libs.okio.core) + + kapt(libs.auto.service.compiler) + compileOnly(libs.auto.service.annotations) + + testImplementation(projects.zipline) + testImplementation(libs.assertk) + testImplementation(libs.junit) + testImplementation(libs.kotlin.test) +} + +// In order to simplify writing test schemas, inject the test sources and +// test classpath as properties into the test runtime. This allows testing +// the FIR-based parser on sources written inside the test case. Cool! +tasks.named(TEST_TASK_NAME).configure { + val compilation = kotlin.target.compilations.getByName(TEST_COMPILATION_NAME) + + val sources = compilation.defaultSourceSet.kotlin.sourceDirectories.files + systemProperty("zipline.internal.sources", sources.joinToString(separator = File.pathSeparator)) + + val classpath = project.configurations.getByName(compilation.compileDependencyConfigurationName).files + systemProperty("zipline.internal.classpath", classpath.joinToString(separator = File.pathSeparator)) +} + +configure { + configure( + KotlinJvm( + javadocJar = JavadocJar.Empty() + ) + ) +} diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecision.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecision.kt similarity index 91% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecision.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecision.kt index 4b70c185b9..9d88e44fb2 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecision.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecision.kt @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.compatibility +package app.cash.zipline.api.validator -import app.cash.zipline.api.fir.FirZiplineApi -import app.cash.zipline.api.toml.TomlZiplineApi -import app.cash.zipline.api.toml.TomlZiplineFunction -import app.cash.zipline.api.toml.TomlZiplineService +import app.cash.zipline.api.validator.fir.FirZiplineApi +import app.cash.zipline.api.validator.toml.TomlZiplineApi +import app.cash.zipline.api.validator.toml.TomlZiplineFunction +import app.cash.zipline.api.validator.toml.TomlZiplineService sealed interface ApiCompatibilityDecision diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/Fir.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/Fir.kt similarity index 97% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/Fir.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/Fir.kt index 0d5f7e3356..af37a32d53 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/Fir.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/Fir.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirClass diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineFunction.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApi.kt similarity index 74% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineFunction.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApi.kt index 26d2a8745f..eeb8a3c443 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineFunction.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApi.kt @@ -13,9 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir -import app.cash.zipline.kotlin.signatureHash +data class FirZiplineApi( + val services: List, +) + +/** An interface that extends from ZiplineService. */ +data class FirZiplineService( + val name: String, + val functions: List, +) data class FirZiplineFunction( val id: String, diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApiReader.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReader.kt similarity index 94% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApiReader.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReader.kt index 46ee728f96..80fd4fa8eb 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApiReader.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReader.kt @@ -13,11 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir -import app.cash.zipline.kotlin.BridgedInterface.Companion.NON_INTERFACE_FUNCTION_NAMES -import app.cash.zipline.kotlin.FqPackageName -import app.cash.zipline.kotlin.classId import java.io.File import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.checkers.isSupertypeOf @@ -38,6 +35,9 @@ import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.FirTypeProjectionWithVariance import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirUserTypeRef +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.Variance fun readFirZiplineApi( @@ -50,8 +50,8 @@ fun readFirZiplineApi( } } -private val ziplineFqPackage = FqPackageName("app.cash.zipline") -private val ziplineServiceClassId = ziplineFqPackage.classId("ZiplineService") +private val ziplineServiceClassId = + ClassId(FqName("app.cash.zipline"), Name.identifier("ZiplineService")) /** * Read the frontend intermediate representation of a program and emit its ZiplineService diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/KotlinFirLoader.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/KotlinFirLoader.kt similarity index 99% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/KotlinFirLoader.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/KotlinFirLoader.kt index 2404ce7041..96721e4bc1 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/KotlinFirLoader.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/KotlinFirLoader.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir import java.io.File import org.jetbrains.kotlin.KtVirtualFileSourceFile diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApi.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/ZiplineApis.kt similarity index 63% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApi.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/ZiplineApis.kt index 858e6a9b79..ab513b0b3f 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineApi.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/fir/ZiplineApis.kt @@ -13,8 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir -data class FirZiplineApi( - val services: List, +import okio.ByteString.Companion.encodeUtf8 + +internal fun String.signatureHash(): String = + encodeUtf8().sha256().substring(0, 6).base64() // In base64, 6 bytes takes 8 chars. + +/** Don't bridge these. */ +internal val NON_INTERFACE_FUNCTION_NAMES = setOf( + "equals", + "hashCode", + "toString", ) diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/TomlZiplineApi.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApi.kt similarity index 95% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/TomlZiplineApi.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApi.kt index cfa44ad6d9..1cf301467f 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/TomlZiplineApi.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApi.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.toml +package app.cash.zipline.api.validator.toml data class TomlZiplineApi( val services: List, diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReader.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlReader.kt similarity index 98% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReader.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlReader.kt index 6ed735068d..f033f5a1b3 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReader.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlReader.kt @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.toml +package app.cash.zipline.api.validator.toml import okio.BufferedSource import okio.ByteString.Companion.encodeUtf8 import okio.IOException import okio.Options -fun BufferedSource.readZiplineApi(): TomlZiplineApi { +fun BufferedSource.readTomlZiplineApi(): TomlZiplineApi { return TomlZiplineApiReader(this).readServices() } diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriter.kt b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlWriter.kt similarity index 94% rename from zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriter.kt rename to zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlWriter.kt index 1d46e31bc5..c8a9e26359 100644 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriter.kt +++ b/zipline-api-validator/src/main/kotlin/app/cash/zipline/api/validator/toml/ZiplineApiTomlWriter.kt @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.toml +package app.cash.zipline.api.validator.toml import okio.BufferedSink -fun BufferedSink.writeZiplineApi(api: TomlZiplineApi) { +fun BufferedSink.writeTomlZiplineApi(api: TomlZiplineApi) { TomlZiplineApiWriter(this).writeApi(api) } diff --git a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecisionTest.kt b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecisionTest.kt similarity index 95% rename from zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecisionTest.kt rename to zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecisionTest.kt index 311f03be0d..141aba9aa7 100644 --- a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/compatibility/ApiCompatibilityDecisionTest.kt +++ b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/ApiCompatibilityDecisionTest.kt @@ -13,15 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.compatibility +package app.cash.zipline.api.validator -import app.cash.zipline.api.fir.FirZiplineApi -import app.cash.zipline.api.fir.FirZiplineFunction -import app.cash.zipline.api.fir.FirZiplineService -import app.cash.zipline.api.toml.TomlZiplineApi -import app.cash.zipline.api.toml.TomlZiplineFunction -import app.cash.zipline.api.toml.TomlZiplineService -import app.cash.zipline.kotlin.signatureHash +import app.cash.zipline.api.validator.fir.FirZiplineApi +import app.cash.zipline.api.validator.fir.FirZiplineFunction +import app.cash.zipline.api.validator.fir.FirZiplineService +import app.cash.zipline.api.validator.fir.signatureHash +import app.cash.zipline.api.validator.toml.TomlZiplineApi +import app.cash.zipline.api.validator.toml.TomlZiplineFunction +import app.cash.zipline.api.validator.toml.TomlZiplineService import assertk.assertThat import assertk.assertions.containsExactly import assertk.assertions.isEqualTo diff --git a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/fir/FirZiplineApiReaderTest.kt b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReaderTest.kt similarity index 98% rename from zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/fir/FirZiplineApiReaderTest.kt rename to zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReaderTest.kt index 408968a624..cc4476af53 100644 --- a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/fir/FirZiplineApiReaderTest.kt +++ b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/fir/FirZiplineApiReaderTest.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.fir +package app.cash.zipline.api.validator.fir import app.cash.zipline.ZiplineService import assertk.assertThat diff --git a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReaderTest.kt b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiReaderTest.kt similarity index 93% rename from zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReaderTest.kt rename to zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiReaderTest.kt index e10f024995..7a3a9aed8b 100644 --- a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlReaderTest.kt +++ b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiReaderTest.kt @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.toml +package app.cash.zipline.api.validator.toml import assertk.assertThat import assertk.assertions.isEqualTo import okio.Buffer import org.junit.Test -internal class ZiplineApiTomlReaderTest { +internal class TomlZiplineApiReaderTest { @Test fun happyPath() { val toml = Buffer().writeUtf8( @@ -37,7 +37,7 @@ internal class ZiplineApiTomlReaderTest { """.trimMargin(), ) - val ziplineApi = toml.readZiplineApi() + val ziplineApi = toml.readTomlZiplineApi() assertThat(ziplineApi).isEqualTo( TomlZiplineApi( services = listOf( @@ -70,7 +70,7 @@ internal class ZiplineApiTomlReaderTest { """.trimMargin(), ) - val ziplineApi = toml.readZiplineApi() + val ziplineApi = toml.readTomlZiplineApi() assertThat(ziplineApi).isEqualTo( TomlZiplineApi( services = listOf( @@ -108,7 +108,7 @@ internal class ZiplineApiTomlReaderTest { """.trimMargin(), ) - val ziplineApi = toml.readZiplineApi() + val ziplineApi = toml.readTomlZiplineApi() assertThat(ziplineApi).isEqualTo( TomlZiplineApi( services = listOf( diff --git a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriterTest.kt b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiWriterTest.kt similarity index 94% rename from zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriterTest.kt rename to zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiWriterTest.kt index 8a0d4c6c34..87dcbeaa7f 100644 --- a/zipline-kotlin-plugin/src/test/kotlin/app/cash/zipline/api/toml/ZiplineApiTomlWriterTest.kt +++ b/zipline-api-validator/src/test/kotlin/app/cash/zipline/api/validator/toml/TomlZiplineApiWriterTest.kt @@ -13,18 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package app.cash.zipline.api.toml +package app.cash.zipline.api.validator.toml import assertk.assertThat import assertk.assertions.isEqualTo import okio.Buffer import org.junit.Test -internal class ZiplineApiTomlWriterTest { +internal class TomlZiplineApiWriterTest { @Test fun happyPath() { val buffer = Buffer().apply { - writeZiplineApi( + writeTomlZiplineApi( TomlZiplineApi( services = listOf( TomlZiplineService( @@ -64,7 +64,7 @@ internal class ZiplineApiTomlWriterTest { @Test fun multipleServices() { val buffer = Buffer().apply { - writeZiplineApi( + writeTomlZiplineApi( TomlZiplineApi( services = listOf( TomlZiplineService( diff --git a/zipline-cli/build.gradle.kts b/zipline-cli/build.gradle.kts index 26037626d1..f63ce36fcf 100644 --- a/zipline-cli/build.gradle.kts +++ b/zipline-cli/build.gradle.kts @@ -45,6 +45,7 @@ kotlin { } dependencies { + api(projects.ziplineApiValidator) api(projects.ziplineLoader) implementation(libs.okHttp.core) implementation(libs.picocli) diff --git a/zipline-gradle-plugin/build.gradle.kts b/zipline-gradle-plugin/build.gradle.kts index 58fbb12871..09d4eacc5c 100644 --- a/zipline-gradle-plugin/build.gradle.kts +++ b/zipline-gradle-plugin/build.gradle.kts @@ -21,6 +21,7 @@ kotlin { dependencies { implementation(kotlin("gradle-plugin-api")) implementation(projects.zipline) + implementation(projects.ziplineApiValidator) implementation(projects.ziplineBytecode) implementation(projects.ziplineKotlinPlugin) implementation(projects.ziplineLoader) @@ -71,6 +72,7 @@ tasks { } ) systemProperty("ziplineVersion", project.version) + dependsOn(":zipline-api-validator:publishAllPublicationsToTestMavenRepository") dependsOn(":zipline-bytecode:publishAllPublicationsToTestMavenRepository") dependsOn(":zipline-gradle-plugin:publishAllPublicationsToTestMavenRepository") dependsOn(":zipline-kotlin-plugin:publishAllPublicationsToTestMavenRepository") diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidationTask.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidatorTask.kt similarity index 84% rename from zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidationTask.kt rename to zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidatorTask.kt index c08925d83e..059ad71a9f 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidationTask.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplineApiValidatorTask.kt @@ -16,14 +16,14 @@ package app.cash.zipline.gradle -import app.cash.zipline.api.compatibility.ActualApiHasProblems -import app.cash.zipline.api.compatibility.ExpectedApiIsUpToDate -import app.cash.zipline.api.compatibility.ExpectedApiRequiresUpdates -import app.cash.zipline.api.compatibility.makeApiCompatibilityDecision -import app.cash.zipline.api.fir.readFirZiplineApi -import app.cash.zipline.api.toml.TomlZiplineApi -import app.cash.zipline.api.toml.readZiplineApi -import app.cash.zipline.api.toml.writeZiplineApi +import app.cash.zipline.api.validator.ActualApiHasProblems +import app.cash.zipline.api.validator.ExpectedApiIsUpToDate +import app.cash.zipline.api.validator.ExpectedApiRequiresUpdates +import app.cash.zipline.api.validator.fir.readFirZiplineApi +import app.cash.zipline.api.validator.makeApiCompatibilityDecision +import app.cash.zipline.api.validator.toml.TomlZiplineApi +import app.cash.zipline.api.validator.toml.readTomlZiplineApi +import app.cash.zipline.api.validator.toml.writeTomlZiplineApi import javax.inject.Inject import okio.buffer import okio.sink @@ -38,7 +38,7 @@ import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction @Suppress("unused") // Public API for Gradle plugin users. -abstract class ZiplineApiValidationTask @Inject constructor( +abstract class ZiplineApiValidatorTask @Inject constructor( fileCollectionFactory: FileCollectionFactory, @Input val mode: Mode, ) : DefaultTask() { @@ -69,7 +69,7 @@ abstract class ZiplineApiValidationTask @Inject constructor( val tomlFile = ziplineApiFile.get().asFile val expectedZiplineApi = when { - tomlFile.exists() -> tomlFile.source().buffer().use { it.readZiplineApi() } + tomlFile.exists() -> tomlFile.source().buffer().use { it.readTomlZiplineApi() } else -> TomlZiplineApi(listOf()) } @@ -99,7 +99,7 @@ abstract class ZiplineApiValidationTask @Inject constructor( Mode.Dump -> { logger.info("Updated $tomlFileRelative because Zipline API has changed") - tomlFile.sink().buffer().use { it.writeZiplineApi(decision.updatedApi) } + tomlFile.sink().buffer().use { it.writeTomlZiplineApi(decision.updatedApi) } } } } diff --git a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt index 1e86671fb2..829460967e 100644 --- a/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt +++ b/zipline-gradle-plugin/src/main/kotlin/app/cash/zipline/gradle/ZiplinePlugin.kt @@ -15,7 +15,7 @@ */ package app.cash.zipline.gradle -import app.cash.zipline.gradle.ZiplineApiValidationTask.Mode +import app.cash.zipline.gradle.ZiplineApiValidatorTask.Mode import app.cash.zipline.loader.SignatureAlgorithmId import org.gradle.api.Project import org.gradle.api.Task @@ -128,7 +128,7 @@ class ZiplinePlugin : KotlinCompilerPluginSupportPlugin { ) { val task = project.tasks.register( "${compileTask.name}ZiplineApi$mode", // Like 'compileKotlinJvmZiplineApiCheck' - ZiplineApiValidationTask::class.java, + ZiplineApiValidatorTask::class.java, mode, ) diff --git a/zipline-kotlin-plugin/build.gradle.kts b/zipline-kotlin-plugin/build.gradle.kts index 0254f70016..5759c40ae9 100644 --- a/zipline-kotlin-plugin/build.gradle.kts +++ b/zipline-kotlin-plugin/build.gradle.kts @@ -1,8 +1,6 @@ import com.vanniktech.maven.publish.JavadocJar import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.MavenPublishBaseExtension -import org.gradle.api.plugins.JavaPlugin.TEST_TASK_NAME -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME plugins { kotlin("jvm") @@ -17,26 +15,6 @@ dependencies { kapt(libs.auto.service.compiler) compileOnly(libs.auto.service.annotations) - api(libs.okio.core) - - testImplementation(projects.zipline) - testImplementation(libs.assertk) - testImplementation(libs.junit) - testImplementation(libs.kotlin.test) - testImplementation(kotlin("compiler-embeddable")) -} - -// In order to simplify writing test schemas, inject the test sources and -// test classpath as properties into the test runtime. This allows testing -// the FIR-based parser on sources written inside the test case. Cool! -tasks.named(TEST_TASK_NAME).configure { - val compilation = kotlin.target.compilations.getByName(TEST_COMPILATION_NAME) - - val sources = compilation.defaultSourceSet.kotlin.sourceDirectories.files - systemProperty("zipline.internal.sources", sources.joinToString(separator = File.pathSeparator)) - - val classpath = project.configurations.getByName(compilation.compileDependencyConfigurationName).files - systemProperty("zipline.internal.classpath", classpath.joinToString(separator = File.pathSeparator)) } buildConfig { diff --git a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineService.kt b/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineService.kt deleted file mode 100644 index bf5a3d6154..0000000000 --- a/zipline-kotlin-plugin/src/main/kotlin/app/cash/zipline/api/fir/FirZiplineService.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2023 Cash App - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package app.cash.zipline.api.fir - -/** An interface that extends from ZiplineService. */ -data class FirZiplineService( - val name: String, - val functions: List, -)