diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8449f6f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI + +on: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: validation-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + validate: + runs-on: ubuntu-latest + timeout-minutes: 90 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Run tests and assemble + run: ./gradlew --no-daemon --stacktrace build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1373154 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,93 @@ +name: Release Library + +on: + push: + tags: + - 'v*' + +permissions: + contents: read + packages: write + +jobs: + publish-library: + runs-on: ubuntu-latest + environment: release + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Run tests + run: | + ./gradlew --no-daemon --stacktrace \ + build + + - name: Validate tag matches version + run: | + TAG="${GITHUB_REF#refs/tags/}" + VERSION=$(grep '^versionName=' gradle.properties | cut -d'=' -f2) + if [ "v${VERSION}" != "${TAG}" ] && [ "${VERSION}" != "${TAG}" ]; then + echo "Tag '${TAG}' does not match versionName '${VERSION}' in gradle.properties" + exit 1 + fi + + - name: Prepare publishing credentials + env: + NEXUS_USERTOKEN_NAME: ${{ secrets.NEXUS_USERTOKEN_NAME }} + NEXUS_USERTOKEN_PASSWORD: ${{ secrets.NEXUS_USERTOKEN_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_SECRET_KEY_RING_FILE_BASE64: ${{ secrets.SIGNING_SECRET_KEY_RING_FILE_BASE64 }} + run: | + required_vars=( + NEXUS_USERTOKEN_NAME + NEXUS_USERTOKEN_PASSWORD + SIGNING_KEY_ID + SIGNING_PASSWORD + SIGNING_SECRET_KEY_RING_FILE_BASE64 + ) + + for var in "${required_vars[@]}"; do + if [ -z "${!var}" ]; then + echo "Missing required secret: ${var}" + exit 1 + fi + done + + keyring_file="${RUNNER_TEMP}/signing-secring.gpg" + echo "${SIGNING_SECRET_KEY_RING_FILE_BASE64}" | base64 --decode > "${keyring_file}" + chmod 600 "${keyring_file}" + + mkdir -p "${HOME}/.gradle" + { + echo "mavenCentralUsername=${NEXUS_USERTOKEN_NAME}" + echo "mavenCentralPassword=${NEXUS_USERTOKEN_PASSWORD}" + echo "NEXUS_USERTOKEN_NAME=${NEXUS_USERTOKEN_NAME}" + echo "NEXUS_USERTOKEN_PASSWORD=${NEXUS_USERTOKEN_PASSWORD}" + echo "signing.keyId=${SIGNING_KEY_ID}" + echo "signing.password=${SIGNING_PASSWORD}" + echo "signing.secretKeyRingFile=${keyring_file}" + } >> "${HOME}/.gradle/gradle.properties" + + - name: Publish library + run: | + ./gradlew --no-daemon --stacktrace \ + publishAndReleaseToMavenCentral + + gh-release: + needs: publish-library + uses: appKODE/.github/.github/workflows/gh-release.yml@main + permissions: + contents: write diff --git a/CHANGELOG.md b/CHANGELOG.md index ec83112..8959dc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.15.0 + +* Support KSP2: validators are now generated per processing round instead of in `finish()` + (fixes `KaInvalidLifetimeOwnerAccessException`, google/ksp#2113) +* Artifacts moved to the `ru.kode` group: `ru.kode:vanilla` and `ru.kode:vanilla-processor` (Java packages are unchanged) +* Publish to Maven Central via the Central Portal +* Update Kotlin to 2.3.20, KSP to 2.3.9, kotlinpoet to 2.2.0, Gradle to 9.4.1 +* Remove the `kotlinpoet-metadata` dependency from the processor + ## 0.14.1 - 2023-09-01 * Update kotlin to 1.9.10 and ksp to 1.9.10-1.0.13 diff --git a/README.md b/README.md index e0e215e..ad2e885 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ > Migrated from [github.com/dimsuz/vanilla](https://github.com/dimsuz/vanilla) (original author: Dmitry Suzdalev, MIT). -> Published versions up to now: `ru.dimsuz:vanilla`. New releases will be published by appKODE under the `ru.kode` group. +> Published versions up to 0.14.1: `ru.dimsuz:vanilla`. Starting from 0.15.0 releases are published by appKODE to Maven Central under the `ru.kode` group (`ru.kode:vanilla`, `ru.kode:vanilla-processor`). Java packages are unchanged. # Vanilla @@ -198,8 +198,8 @@ will be any. ## Download ``` -implementation "ru.dimsuz:vanilla:0.14.1" -ksp "ru.dimsuz:vanilla-processor:0.14.1" +implementation "ru.kode:vanilla:0.15.0" +ksp "ru.kode:vanilla-processor:0.15.0" ``` ## License diff --git a/build.gradle.kts b/build.gradle.kts index dacdc62..ad6f422 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,7 @@ plugins { - kotlin("jvm") version "1.9.10" - `maven-publish` - signing - id("org.jetbrains.dokka") version "1.9.0" - id("com.google.devtools.ksp") version "1.9.10-1.0.13" apply false + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.ksp) apply false + alias(libs.plugins.vanniktech.mavenPublish) apply false } allprojects { @@ -18,7 +16,7 @@ dependencies { ktlint("com.pinterest:ktlint:0.42.0") } -val outputDir = "${project.buildDir}/reports/ktlint/" +val outputDir = layout.buildDirectory.dir("reports/ktlint") val inputFiles = project.fileTree(mapOf("dir" to ".", "include" to "**/*.kt")) val ktlintCheck by tasks.creating(JavaExec::class) { @@ -44,101 +42,60 @@ val ktlintFormat by tasks.creating(JavaExec::class) { } subprojects { - apply(plugin = "kotlin") - apply(plugin = "maven-publish") - apply(plugin = "org.jetbrains.dokka") - apply(plugin = "signing") - - tasks { - compileKotlin { - kotlinOptions.jvmTarget = "11" - } - compileTestKotlin { - kotlinOptions.jvmTarget = "11" - } - } + apply(plugin = "org.jetbrains.kotlin.jvm") - kotlin { - jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(11)) + // Consumers are Android apps: keep the JVM 11 bytecode floor, build on any JDK >= 11 (CI uses 17) + extensions.configure { + compilerOptions { + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11) } } - - val dokkaJar by tasks.creating(org.gradle.jvm.tasks.Jar::class) { - group = JavaBasePlugin.DOCUMENTATION_GROUP - archiveClassifier.set("javadoc") - from(tasks.dokkaHtml) + extensions.configure { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } +} - val sourcesJar by tasks.creating(org.gradle.jvm.tasks.Jar::class) { - archiveClassifier.set("sources") - from(sourceSets.main.get().allSource) - } +configure(listOf(project(":library"), project(":processor"))) { + apply(plugin = "com.vanniktech.maven.publish") - val pomArtifactId: String? by project - if (pomArtifactId != null) { - publishing { - publications { - create("maven") { - val versionName: String by project - val pomGroupId: String by project - groupId = pomGroupId - artifactId = pomArtifactId - version = versionName - from(components["java"]) - - artifact(dokkaJar) - artifact(sourcesJar) - - pom { - val pomDescription: String by project - val pomUrl: String by project - val pomName: String by project - description.set(pomDescription) - url.set(pomUrl) - name.set(pomName) - scm { - val pomScmUrl: String by project - val pomScmConnection: String by project - val pomScmDevConnection: String by project - url.set(pomScmUrl) - connection.set(pomScmConnection) - developerConnection.set(pomScmDevConnection) - } - licenses { - license { - val pomLicenseName: String by project - val pomLicenseUrl: String by project - val pomLicenseDist: String by project - name.set(pomLicenseName) - url.set(pomLicenseUrl) - distribution.set(pomLicenseDist) - } - } - developers { - developer { - val pomDeveloperId: String by project - val pomDeveloperName: String by project - id.set(pomDeveloperId) - name.set(pomDeveloperName) - } - } - } - } + group = providers.gradleProperty("pomGroupId").get() + version = providers.gradleProperty("versionName").get() + + extensions.configure { + coordinates(artifactId = property("pomArtifactId").toString()) + + publishToMavenCentral() + signAllPublications() + + pom { + name.set(property("pomName").toString()) + description.set(providers.gradleProperty("pomDescription")) + url.set(providers.gradleProperty("pomUrl")) + + scm { + url.set(providers.gradleProperty("pomScmUrl")) + connection.set(providers.gradleProperty("pomScmConnection")) + developerConnection.set(providers.gradleProperty("pomScmDevConnection")) } - signing { - sign(publishing.publications["maven"]) + + licenses { + license { + name.set(providers.gradleProperty("pomLicenseName")) + url.set(providers.gradleProperty("pomLicenseUrl")) + distribution.set(providers.gradleProperty("pomLicenseDist")) + } } - repositories { - maven { - val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/") - val versionName: String by project - url = if (versionName.endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl - credentials { - username = project.property("NEXUS_USERNAME")?.toString() - password = project.property("NEXUS_PASSWORD")?.toString() - } + + developers { + developer { + id.set("dimsuz") + name.set("Dmitry Suzdalev") + } + developer { + id.set("appKODE") + name.set("appKODE") + url.set("https://github.com/appKODE") } } } diff --git a/gradle.properties b/gradle.properties index 684b78b..8dc0d5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,13 @@ kotlin.code.style=official +org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 -versionName=0.14.1 -pomGroupId=ru.dimsuz +versionName=0.15.0 +pomGroupId=ru.kode pomDescription=Validation library with a clear distinction between source and validated models -pomUrl=https://github.com/dimsuz/vanilla -pomScmUrl=https://github.com/dimsuz/vanilla -pomScmConnection=scm:git@github.com:dimsuz/vanilla.git -pomScmDevConnection=scm:git@github.com:dimsuz/vanilla.git +pomUrl=https://github.com/appKODE/vanilla +pomScmUrl=https://github.com/appKODE/vanilla +pomScmConnection=scm:git:git://github.com/appKODE/vanilla.git +pomScmDevConnection=scm:git:ssh://git@github.com/appKODE/vanilla.git pomLicenseName=MIT License -pomLicenseUrl=https://github.com/dimsuz/way/blob/master/LICENSE +pomLicenseUrl=https://github.com/appKODE/vanilla/blob/master/LICENSE pomLicenseDist=repo -pomDeveloperId=dimsuz -pomDeveloperName=Dmitry Suzdalev diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..46f84e5 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,22 @@ +[versions] +kotlin = "2.3.20" +ksp = "2.3.9" +kotlinpoet = "2.2.0" +kotlinResult = "1.1.16" +truth = "1.4.4" +kctfork = "0.13.0" +vanniktechMavenPublish = "0.37.0" + +[libraries] +kotlin-result = { module = "com.michael-bull.kotlin-result:kotlin-result", version.ref = "kotlinResult" } +kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } +kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" } +kotlin-metadata = { module = "org.jetbrains.kotlin:kotlin-metadata-jvm", version.ref = "kotlin" } +ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } +truth = { module = "com.google.truth:truth", version.ref = "truth" } +kctfork-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref = "kctfork" } + +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "vanniktechMavenPublish" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae0804..221c4f9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/library/build.gradle.kts b/library/build.gradle.kts index 520a5db..d430bd2 100644 --- a/library/build.gradle.kts +++ b/library/build.gradle.kts @@ -1,12 +1,11 @@ dependencies { - implementation(kotlin("stdlib-jdk8")) - api("com.michael-bull.kotlin-result:kotlin-result:1.1.16") + api(libs.kotlin.result) - testImplementation("com.google.truth:truth:1.0.1") + testImplementation(libs.truth) } -tasks { - compileKotlin { - kotlinOptions.moduleName = "vanilla-library" +kotlin { + compilerOptions { + moduleName.set("vanilla-library") } } diff --git a/processor/build.gradle.kts b/processor/build.gradle.kts index f37722d..250e272 100644 --- a/processor/build.gradle.kts +++ b/processor/build.gradle.kts @@ -1,22 +1,22 @@ dependencies { - implementation(kotlin("stdlib-jdk8")) implementation(project(":library")) - implementation("com.squareup:kotlinpoet:1.14.2") - implementation("com.squareup:kotlinpoet-metadata:1.14.2") - implementation("com.squareup:kotlinpoet-ksp:1.14.2") - implementation("com.google.devtools.ksp:symbol-processing-api:1.9.10-1.0.13") + implementation(libs.kotlinpoet) + implementation(libs.kotlinpoet.ksp) + compileOnly(libs.ksp.api) - testImplementation("com.google.truth:truth:1.0.1") - testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.5.0") + testImplementation(libs.ksp.api) + testImplementation(libs.kotlin.metadata) + testImplementation(libs.truth) + testImplementation(libs.kctfork.ksp) } -tasks { - compileKotlin { - kotlinOptions.moduleName = "vanilla-processor" - kotlinOptions.freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview" - kotlinOptions.freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.metadata.DelicateKotlinPoetApi" - } - compileTestKotlin { - kotlinOptions.freeCompilerArgs += "-Xopt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview" +kotlin { + compilerOptions { + moduleName.set("vanilla-processor") + optIn.add("com.squareup.kotlinpoet.DelicateKotlinPoetApi") } } + +tasks.compileTestKotlin { + compilerOptions.optIn.add("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi") +} diff --git a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessor.kt b/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessor.kt index 4737432..6547383 100644 --- a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessor.kt +++ b/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessor.kt @@ -16,27 +16,25 @@ internal class VanillaProcessor( private val processingEnv: SymbolProcessorEnvironment, ) : SymbolProcessor { - private val modelPairs = mutableListOf>() - override fun process(resolver: Resolver): List { val validatedAsSymbols = resolver .getSymbolsWithAnnotation(ValidatedAs::class.qualifiedName.orEmpty()) .filterIsInstance() + .toList() - val hasNext = validatedAsSymbols.iterator().hasNext() - - if (!hasNext) return emptyList() + // Symbols are analyzed and generated within the round they are received in: KSP2 invalidates + // them between rounds. Symbols with unresolved types are deferred to the next round. + val (ready, deferred) = validatedAsSymbols.partition { it.validate() } + if (ready.isEmpty()) return deferred - validatedAsSymbols.forEach { ksClassDeclaration -> + val modelPairs = mutableListOf>() + ready.forEach { ksClassDeclaration -> ksClassDeclaration.accept( ValidateAsVisitor { modelPairs += it }, Unit ) } - return validatedAsSymbols.filterNot { it.validate() }.toList() - } - override fun finish() { val result = modelPairs .combine() .flatMap { modelPairList -> @@ -49,5 +47,6 @@ internal class VanillaProcessor( if (result is Err) { processingEnv.logger.error(result.error) } + return deferred } } diff --git a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/ElementExtensions.kt b/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/ElementExtensions.kt deleted file mode 100644 index e7262f8..0000000 --- a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/ElementExtensions.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.dimsuz.vanilla.processor.extension - -import javax.lang.model.element.Element -import javax.lang.model.element.ElementKind -import javax.lang.model.element.PackageElement - -internal val Element.enclosingPackage: PackageElement - get() { - var enclosing: Element? = this - while (enclosing != null && enclosing.kind != ElementKind.PACKAGE) { - enclosing = enclosing.enclosingElement - } - return (enclosing as? PackageElement) ?: throw IllegalStateException("no package element found") - } - -internal val Element.enclosingPackageName get() = enclosingPackage.qualifiedName.toString() diff --git a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/KotlinMetadataExtensions.kt b/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/KotlinMetadataExtensions.kt deleted file mode 100644 index 1249494..0000000 --- a/processor/src/main/kotlin/ru/dimsuz/vanilla/processor/extension/KotlinMetadataExtensions.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.dimsuz.vanilla.processor.extension - -import com.squareup.kotlinpoet.ClassName -import kotlinx.metadata.KmClass - -val KmClass.simpleName: String get() { - return this.name.substringAfterLast('/') -} - -val KmClass.packageName: String get() { - return this.name.substringBeforeLast('/', missingDelimiterValue = "").replace('/', '.') -} - -fun KmClass.toClassName(): ClassName { - return ClassName(this.packageName, this.simpleName) -} diff --git a/processor/src/test/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessorTest.kt b/processor/src/test/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessorTest.kt index ccdc7b3..941cfe7 100644 --- a/processor/src/test/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessorTest.kt +++ b/processor/src/test/kotlin/ru/dimsuz/vanilla/processor/VanillaProcessorTest.kt @@ -1,23 +1,24 @@ package ru.dimsuz.vanilla.processor import com.google.common.truth.Truth.assertThat -import com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview -import com.squareup.kotlinpoet.metadata.isInternal -import com.squareup.kotlinpoet.metadata.isNullable -import com.squareup.kotlinpoet.metadata.isPrivate -import com.squareup.kotlinpoet.metadata.toKmClass import com.tschuchort.compiletesting.KotlinCompilation +import com.tschuchort.compiletesting.JvmCompilationResult import com.tschuchort.compiletesting.SourceFile import com.tschuchort.compiletesting.SourceFile.Companion.kotlin +import com.tschuchort.compiletesting.useKsp2 import com.tschuchort.compiletesting.kspWithCompilation import com.tschuchort.compiletesting.symbolProcessorProviders -import kotlinx.metadata.KmClassifier -import kotlinx.metadata.KmType +import kotlin.metadata.KmClass +import kotlin.metadata.KmClassifier +import kotlin.metadata.KmType +import kotlin.metadata.Visibility +import kotlin.metadata.isNullable +import kotlin.metadata.jvm.KotlinClassMetadata +import kotlin.metadata.visibility import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -@KotlinPoetMetadataPreview class VanillaProcessorTest { @Rule @JvmField @@ -380,7 +381,7 @@ class VanillaProcessorTest { } val createValidateFunction = companionClass?.functions?.find { it.name == "createValidateFunction" } assertThat(createValidateFunction).isNotNull() - assertThat(createValidateFunction?.flags?.isPrivate).isTrue() + assertThat(createValidateFunction?.visibility == Visibility.PRIVATE).isTrue() assertThat(createValidateFunction?.returnType?.classifier) .isEqualTo(KmClassifier.Class("kotlin/Function1")) assertThat(createValidateFunction?.returnType?.arguments?.get(0)?.type?.classifier) @@ -408,7 +409,7 @@ class VanillaProcessorTest { assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val builderClass = result.classLoader.loadClass("DraftValidatorBuilder").toKmClass() - assertThat(builderClass.flags.isInternal) + assertThat(builderClass.visibility == Visibility.INTERNAL) .isTrue() } @@ -431,7 +432,7 @@ class VanillaProcessorTest { assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val builderClass = result.classLoader.loadClass("DraftValidatorBuilder").toKmClass() - assertThat(builderClass.flags.isInternal) + assertThat(builderClass.visibility == Visibility.INTERNAL) .isTrue() } @@ -456,7 +457,7 @@ class VanillaProcessorTest { assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val builderClass = result.classLoader.loadClass("HelloDraftValidatorBuilder").toKmClass() - assertThat(builderClass.flags.isInternal) + assertThat(builderClass.visibility == Visibility.INTERNAL) .isTrue() } @@ -481,7 +482,7 @@ class VanillaProcessorTest { assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val builderClass = result.classLoader.loadClass("HelloDraftValidatorBuilder").toKmClass() - assertThat(builderClass.flags.isInternal) + assertThat(builderClass.visibility == Visibility.INTERNAL) .isTrue() } @@ -510,7 +511,7 @@ class VanillaProcessorTest { assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) val builderClass = result.classLoader.loadClass("HelloWorldFooDraftValidatorBuilder").toKmClass() - assertThat(builderClass.flags.isInternal) + assertThat(builderClass.visibility == Visibility.INTERNAL) .isTrue() } @@ -612,6 +613,11 @@ class VanillaProcessorTest { // TODO generates property validator signature which has target field type if it differs from source // TODO gives an error if source or target is private,must be public/internal + private fun Class<*>.toKmClass(): KmClass { + val metadata = getAnnotation(Metadata::class.java) + return (KotlinClassMetadata.readStrict(metadata) as KotlinClassMetadata.Class).kmClass + } + private fun assertIsValidatorType(type: KmType?) { assertThat(type?.classifier).isEqualTo(KmClassifier.Class("ru/dimsuz/vanilla/Validator")) } @@ -628,7 +634,8 @@ class VanillaProcessorTest { return KotlinCompilation() .apply { workingDir = temporaryFolder.root - symbolProcessorProviders = listOf(VanillaProcessorProvider()) + useKsp2() + symbolProcessorProviders = mutableListOf(VanillaProcessorProvider()) inheritClassPath = true sources = sourceFiles.asList() verbose = false @@ -636,7 +643,7 @@ class VanillaProcessorTest { } } - private fun compile(vararg sourceFiles: SourceFile): KotlinCompilation.Result { + private fun compile(vararg sourceFiles: SourceFile): JvmCompilationResult { return prepareCompilation(*sourceFiles).compile() } } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index e045f9d..9edbbf2 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,10 +1,6 @@ plugins { application - id("com.google.devtools.ksp") -} - -repositories { - mavenCentral() + alias(libs.plugins.ksp) } application { @@ -12,9 +8,8 @@ application { } dependencies { - implementation(kotlin("stdlib-jdk8")) implementation(project(":library")) ksp(project(":processor")) - testImplementation("com.google.truth:truth:1.0.1") + testImplementation(libs.truth) }