Skip to content

Commit

Permalink
Fix ToolsLocator to work with Gradle 6.1 Instant Execution (#381)
Browse files Browse the repository at this point in the history
This PR fixes ToolsLocator to comply with Gradle's Instant Execution constraints (see https://gradle.github.io/instant-execution/). It also enables test coverage for Gradle 6.1 and adds more coverage for using Instant Execution on a Java project. The Android support for Instant Execution is pending todo.
  • Loading branch information
eskatos authored and voidzcy committed Jan 23, 2020
1 parent 8d421ce commit ac76dd5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
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

0 comments on commit ac76dd5

Please sign in to comment.