Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for new plugin behavior - transitive deps for free #2311

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.squareup.wire.dinosaur</groupId>
<artifactId>caveman</artifactId>
<version>1.0</version>
<description>POM was created from install:install-file</description>

<dependencies>
<dependency>
<groupId>com.squareup.wire.dinosaur</groupId>
<artifactId>all-protos</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<groupId>com.squareup.wire.dinosaur</groupId>
<artifactId>caveman</artifactId>
<versioning>
<release>1.0</release>
<versions>
<version>1.0</version>
</versions>
<lastUpdated>20220729023530</lastUpdated>
</versioning>
</metadata>
Original file line number Diff line number Diff line change
@@ -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 {
}
}