From df9019c031cc512a4a249dd54ee2a944b5367b7b Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 29 Jul 2022 16:04:28 -0400 Subject: [PATCH] Test for new plugin behavior - transitive deps for free --- gradle/libs.versions.toml | 2 +- .../squareup/wire/gradle/WirePluginTest.kt | 49 +++++++++++++++--- .../wire/dinosaur/caveman/1.0/caveman-1.0.jar | Bin 0 -> 532 bytes .../wire/dinosaur/caveman/1.0/caveman-1.0.pom | 18 +++++++ .../wire/dinosaur/caveman/maven-metadata.xml | 12 +++++ .../build.gradle | 25 +++++++++ 6 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar create mode 100644 wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom create mode 100644 wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml create mode 100644 wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 79808cbba2..a5cfdd8b3a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ jimfs = "1.0" jmh = "1.34" jsr305 = "3.0.2" junit = "4.13.2" -kotlin = "1.6.10" +kotlin = "1.6.21" kotlinpoet = "1.12.0" ktlint = "0.42.1" moshi = "1.13.0" diff --git a/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt b/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt index 87f95a6b10..7e18c65907 100644 --- a/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt +++ b/wire-library/wire-gradle-plugin/src/test/kotlin/com/squareup/wire/gradle/WirePluginTest.kt @@ -4,6 +4,11 @@ package com.squareup.wire.gradle import com.squareup.wire.VERSION import com.squareup.wire.testing.withPlatformSlashes +import java.io.File +import java.io.IOException +import java.util.zip.ZipFile +import kotlin.text.RegexOption.DOT_MATCHES_ALL +import kotlin.text.RegexOption.MULTILINE import org.assertj.core.api.Assertions.assertThat import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner @@ -14,11 +19,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder -import java.io.File -import java.io.IOException -import java.util.zip.ZipFile -import kotlin.text.RegexOption.DOT_MATCHES_ALL -import kotlin.text.RegexOption.MULTILINE class WirePluginTest { @@ -34,14 +34,14 @@ class WirePluginTest { .withPluginClasspath() // Ensure individual tests are isolated and not reusing each other's previous outputs // by setting project dir and gradle home directly. - .withProjectDir(tmpFolder.newFolder("project-dir")) +// .withProjectDir(tmpFolder.newFolder("project-dir")) .withArguments( "-g", tmpFolder.newFolder("gradle-home").absolutePath, "generateProtos", "--stacktrace", "--info", - "--configuration-cache", +// "--configuration-cache", ) .withDebug(true) } @@ -1307,6 +1307,41 @@ class WirePluginTest { buildCacheDir.deleteRecursively() } + /** + * This project has a protoSource .jar + * caveman.jar + * + * It depends on another .jar, + * all-protos.jar + * + * We expect sources to be generated from cavemen.jar, but not all-protos.jar. + */ + @Test + fun sourcePathTransitiveDependenciesPulledAsProtoPathDependencies() { + val fixtureRoot = File("src/test/projects/sourcepath-dependencies-not-generated") + + val result = gradleRunner.runFixture(fixtureRoot) { build() } + + assertThat(result.task(":generateProtos")).isNotNull + assertThat(result.output) + .contains("Writing com.squareup.caveman.Caveman") + .doesNotContain("Writing com.squareup.dinosaurs.Dinosaur") + .doesNotContain("Writing com.squareup.geology.Period") + + assertThat( + File( + fixtureRoot, + "dinosaurs/build/generated/source/wire/com/squareup/caveman/Caveman.java" + ) + ).exists() + assertThat( + File( + fixtureRoot, + "dinosaurs/build/generated/source/wire/com/squareup/dinosaurs/Dinosaur.java" + ) + ).doesNotExist() + } + private fun GradleRunner.runFixture( root: File, action: GradleRunner.() -> BuildResult diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..60bbba784feffabfb55135fd50fe2feeeb538199 GIT binary patch literal 532 zcmWIWW@h1HVBlb2V5<8Y!hi%g8CV#K3riD=QcDZ;|D9rB2!Jc)MpG&X)CO0YoLH8c zo0z8$QZB;4!NI|Ru3QeAa;P@Ff};GA{Mf#OT!#zr=+ z?q+V_k$Uru+nTmF&NMgv<%M>Xv9p~-&as_+l>2K!MB$lTTK{jZedw`j>wAOGA4(WL%f&hBwwpK{ieTTK z`_YJVVc`GYJGcFQ9Nst~ld)`V^-l8uZ+4F8uc1#T0p0!vhy%PCnYb8mha6A|5`YH| zBpeZ1(SrsQk_ey;WWu!~!j+LpgaHw<$gTo~ECNIUnHbtp!a2a3l?|kx83>O7X$wXW F4*>4^m0bV; literal 0 HcmV?d00001 diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom new file mode 100644 index 0000000000..f83794c1af --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/1.0/caveman-1.0.pom @@ -0,0 +1,18 @@ + + + 4.0.0 + com.squareup.wire.dinosaur + caveman + 1.0 + POM was created from install:install-file + + + + com.squareup.wire.dinosaur + all-protos + 1.0 + + + + diff --git a/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml new file mode 100644 index 0000000000..353887a45e --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/libs/com/squareup/wire/dinosaur/caveman/maven-metadata.xml @@ -0,0 +1,12 @@ + + + com.squareup.wire.dinosaur + caveman + + 1.0 + + 1.0 + + 20220729023530 + + diff --git a/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle b/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle new file mode 100644 index 0000000000..bd46431742 --- /dev/null +++ b/wire-library/wire-gradle-plugin/src/test/projects/sourcepath-dependencies-not-generated/build.gradle @@ -0,0 +1,25 @@ +plugins { + id 'application' + id 'com.squareup.wire' +} + +// See installProtoJars task in wire-gradle-plugin/build.gradle.kts +repositories { + maven { + url "file://${projectDir.absolutePath}/../../../../../build/localMaven" + } +} + +wire { + sourcePath { + srcJar 'com.squareup.wire.dinosaur:caveman:+' + } + + // TODO(jwilson/enelson): make this dependency free by making the Gradle plugin smarter. + // protoPath { + // srcJar 'com.squareup.wire.dinosaur:all-protos:+' + // } + + java { + } +}