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

Fix ToolsLocator to work with Gradle 6.1 Instant Execution #381

Merged
merged 2 commits into from
Jan 23, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.PathSensitivity

/**
Expand Down Expand Up @@ -106,18 +107,19 @@ class ToolsLocator {
ext:extension ?: 'exe',
]
Dependency dep = project.dependencies.add(config.name, notation)
FileCollection artifactFiles = config.fileCollection(dep)

for (GenerateProtoTask protoTask in protoTasks) {
if (protoc.is(locator) || protoTask.hasPlugin(locator.name)) {
// register the configuration dependency as a task input
protoTask.inputs.files(config)
// register the tool artifact files as a task input
protoTask.inputs.files(artifactFiles)
.withPathSensitivity(PathSensitivity.NONE)
.withPropertyName("config.${locator.name}")

protoTask.doFirst {
if (locator.path == null) {
project.logger.info("Resolving artifact: ${notation}")
File file = config.fileCollection(dep).singleFile
File file = artifactFiles.singleFile
if (!file.canExecute() && !file.setExecutable(true)) {
throw new GradleException("Cannot set ${file} as executable")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import spock.lang.Unroll
*/
class ProtobufJavaPluginTest extends Specification {
// Current supported version is Gradle 5+.
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.1"]
private static final List<String> KOTLIN_VERSIONS = ["1.3.20", "1.3.30"]

void "testApplying java and com.google.protobuf adds corresponding task to project"() {
Expand Down Expand Up @@ -77,6 +77,50 @@ class ProtobufJavaPluginTest extends Specification {
gradleVersion << GRADLE_VERSIONS
}

@Unroll
void "testProject should be successfully executed (instant-execution) [gradle #gradleVersion]"() {
given: "project from testProject"
File projectDir = ProtobufPluginTestHelper.projectBuilder('testProject')
.copyDirs('testProjectBase', 'testProject')
.build()

and:
GradleRunner runner = GradleRunner.create()
.withProjectDir(projectDir)
.withArguments(
'build', '--stacktrace',
'-Dorg.gradle.unsafe.instant-execution=true',
'-Dorg.gradle.unsafe.instant-execution.fail-on-problems=true'
)
.withPluginClasspath()
.withGradleVersion(gradleVersion)
.forwardStdOutput(new OutputStreamWriter(System.out))
.forwardStdError(new OutputStreamWriter(System.err))

when: "build is invoked"
BuildResult result = runner.build()

then: "it caches the task graph"
result.output.contains("Calculating task graph")

and: "it succeeds"
result.task(":build").outcome == TaskOutcome.SUCCESS
ProtobufPluginTestHelper.verifyProjectDir(projectDir)

when: "build is invoked again"
result = runner.build()

then: "it reuses the task graph"
result.output.contains("Reusing instant execution cache")

and: "it succeeds"
result.task(":build").outcome == TaskOutcome.SUCCESS
ProtobufPluginTestHelper.verifyProjectDir(projectDir)

where:
gradleVersion << GRADLE_VERSIONS.takeRight(1)
}

@Unroll
void "testProjectBuildTimeProto should be successfully executed [gradle #gradleVersion]"() {
given: "project from testProjectGeneratedProto"
Expand Down Expand Up @@ -124,8 +168,7 @@ class ProtobufJavaPluginTest extends Specification {
ProtobufPluginTestHelper.verifyProjectDir(projectDir)

where:
gradleVersion << GRADLE_VERSIONS
kotlinVersion << KOTLIN_VERSIONS
[gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations()
}

@Unroll
Expand All @@ -150,8 +193,7 @@ class ProtobufJavaPluginTest extends Specification {
ProtobufPluginTestHelper.verifyProjectDir(projectDir)

where:
gradleVersion << GRADLE_VERSIONS
kotlinVersion << KOTLIN_VERSIONS
[gradleVersion, kotlinVersion] << [GRADLE_VERSIONS, KOTLIN_VERSIONS].combinations()
}

@Unroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import spock.lang.Unroll
*/
class ProtobufKotlinDslPluginTest extends Specification {
// Current supported version is Gradle 5+.
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0"]
private static final List<String> GRADLE_VERSIONS = ["5.6", "6.0", "6.1"]

@Unroll
void "testProjectKotlinDsl should be successfully executed (java-only project) [gradle #gradleVersion]"() {
Expand Down