Skip to content

Commit

Permalink
Fix a bug where kotlin classes are ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
ogolberg authored Feb 24, 2024
1 parent 08e04dd commit c144fbc
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 20 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ tasks {
dependencies {
testImplementation(libs.junit)
testImplementation(libs.strikt.core)
}
}
7 changes: 7 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ dependencies {
testImplementation(libs.testkit.junit5)
}

testkitTests {
replaceToken("TESTKIT_PLUGIN_VERSION", libs.versions.testkit.plugin.get())
replaceToken("KOTLIN_VERSION", libs.versions.kotlin.get())
replaceToken("PROTOKT_VERSION", libs.versions.protokt.get())
replaceToken("PROTOBUF_VERSION", libs.versions.protobuf.get())
}

gradlePlugin {
plugins {
create("expediter") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.gradle.api.GradleException
import org.gradle.api.artifacts.ArtifactCollection
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
Expand All @@ -43,6 +42,7 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskAction
import protokt.v1.toasttab.expediter.v1.TypeDescriptors
import java.io.File
Expand All @@ -52,7 +52,7 @@ import java.util.zip.GZIPInputStream
abstract class ExpediterTask : DefaultTask() {
private val applicationConfigurationArtifacts = mutableListOf<ArtifactCollection>()
private val platformConfigurationArtifacts = mutableListOf<ArtifactCollection>()
private val applicationSourceSets: MutableSet<SourceDirectorySet> = mutableSetOf()
private val applicationSourceSets: MutableSet<SourceSet> = mutableSetOf()

@get:Internal
abstract val cache: Property<ApplicationTypeCache>
Expand All @@ -71,7 +71,7 @@ abstract class ExpediterTask : DefaultTask() {
@get:PathSensitive(PathSensitivity.RELATIVE)
@Suppress("UNUSED")
val sourceSets: FileCollection get() = project.objects.fileCollection().apply {
setFrom(applicationSourceSets.map { it.classesDirectory })
setFrom(applicationSourceSets.flatMap { it.output })
}

private fun Collection<ArtifactCollection>.asFileCollection() = if (isEmpty()) {
Expand All @@ -92,7 +92,7 @@ abstract class ExpediterTask : DefaultTask() {
platformConfigurationArtifacts.add(artifactCollection)
}

fun sourceSet(sourceDirectorySet: SourceDirectorySet) {
fun sourceSet(sourceDirectorySet: SourceSet) {
applicationSourceSets.add(sourceDirectorySet)
}

Expand Down Expand Up @@ -166,6 +166,8 @@ abstract class ExpediterTask : DefaultTask() {

val typeSources = applicationConfigurationArtifacts.sources() + files.sources() + applicationSourceSets.sources()

logger.info("type sources = {}", typeSources)

val issues = Expediter(
ignore,
cache.get().resolve(typeSources),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.tasks.SourceSet
import java.io.File

fun ResolvedArtifactResult.source() =
Expand All @@ -19,12 +19,12 @@ fun ResolvedArtifactResult.source() =

fun File.source() = ClassfileSource(this, ClassfileSourceType.UNKNOWN, name)

fun SourceDirectorySet.source() = ClassfileSource(classesDirectory.get().asFile, ClassfileSourceType.SOURCE_SET, name)
fun SourceSet.sources() = output.map { ClassfileSource(it, ClassfileSourceType.SOURCE_SET, name) }

fun ArtifactCollection.sources() = artifacts.map { it.source() }

fun ConfigurableFileCollection.sources() = map { it.source() }

fun Collection<ArtifactCollection>.sources() = flatMapTo(LinkedHashSet(), ArtifactCollection::sources)

fun Set<SourceDirectorySet>.sources() = map { it.source() }
fun Set<SourceSet>.sources() = flatMap { it.sources() }
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ abstract class ExpediterExtension(
files.from(file)
}

for (sourceSet in spec.sourceSets) {
sourceSet(project.sourceSet(sourceSet).java)
for (sourceSetName in spec.sourceSets) {
val sourceSet = project.sourceSet(sourceSetName)
sourceSet(sourceSet)
dependsOn(sourceSet.classesTaskName)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,54 @@ class ExpediterPluginIntegrationTest {
)
}

@Test
fun `kotlin jvm compat`(project: TestProject) {
project.createRunner()
.withArguments("check")
.buildAndFail()

val report = IssueReport.fromJson(project.dir.resolve("build/expediter.json").readText())

expectThat(report.issues).contains(
Issue.MissingMember(
"test/Caller",
MemberAccess.MethodAccess(
"java/lang/String",
null,
MemberSymbolicReference(
"isBlank",
"()Z"
),
MethodAccessType.VIRTUAL
)
)
)
}

@Test
fun `protokt android compat`(project: TestProject) {
project.createRunner()
.withArguments("check")
.buildAndFail()

val report = IssueReport.fromJson(project.dir.resolve("build/expediter.json").readText())

expectThat(report.issues).contains(
Issue.MissingMember(
"com/google/protobuf/UnsafeUtil\$JvmMemoryAccessor",
MemberAccess.MethodAccess(
"sun/misc/Unsafe",
null,
MemberSymbolicReference(
"getLong",
"(J)J"
),
MethodAccessType.VIRTUAL
)
)
)
}

@Test
fun `multi check`(project: TestProject) {
project.createRunner().withArguments("check").build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.library") version "8.1.2"
id("org.jetbrains.kotlin.android") version "1.9.0"
id("org.jetbrains.kotlin.android") version "@KOTLIN_VERSION@"
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

expediter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'com.toasttab.expediter'
id 'com.toasttab.testkit.coverage' version '0.0.2'
id 'com.toasttab.testkit.coverage' version '@TESTKIT_PLUGIN_VERSION@'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
kotlin("jvm") version "@KOTLIN_VERSION@"
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
mavenCentral()
}

expediter {
failOnIssues = true

platform {
jvmVersion = 8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 Toast Inc.
*
* 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 test
class Caller {
fun f(s: java.lang.String) {
s.isBlank()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("com.toasttab.testkit.coverage") version "0.0.4"
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
kotlin("jvm") version "@KOTLIN_VERSION@"
id("com.toasttab.protokt") version "@PROTOKT_VERSION@"
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "@TESTKIT_PLUGIN_VERSION@"
}

dependencies {
implementation("com.google.protobuf:protobuf-java:@PROTOBUF_VERSION@")
}

repositories {
mavenCentral()
}

expediter {
failOnIssues = true

platform {
android {
sdk = 21
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package test.v1;

message Foo {
string name = 1;
}

0 comments on commit c144fbc

Please sign in to comment.