Skip to content

Commit 2227562

Browse files
committed
Keep ExtractAnnotations cacheable
1 parent f89b98c commit 2227562

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/main/groovy/org/gradle/android/AndroidCacheFixPlugin.groovy

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import groovy.transform.CompileStatic
1313
import groovy.transform.TypeCheckingMode
1414
import org.gradle.api.Plugin
1515
import org.gradle.api.Project
16-
import org.gradle.api.specs.Specs
1716
import org.gradle.api.tasks.CacheableTask
1817
import org.gradle.api.tasks.PathSensitivity
1918
import org.gradle.internal.Factory
@@ -33,7 +32,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
3332
new AndroidJavaCompile_BootClasspath_Workaround(),
3433
new AndroidJavaCompile_AnnotationProcessorSource_Workaround(),
3534
new AndroidJavaCompile_ProcessorListFile_Workaround(),
36-
new ExtractAnnotations_Disable_Workaround(),
35+
new ExtractAnnotations_Source_Workaround(),
3736
new IncrementalTask_CombinedInput_Workaround(),
3837
new StreamBasedTask_CombinedInput_Workaround(),
3938
new ProcessAndroidResources_MergeBlameLogFolder_Workaround(),
@@ -169,14 +168,23 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
169168
}
170169

171170
/**
172-
* Disables caching for {@link ExtractAnnotations#getSource()} as the path sensitivity of {@code source} cannot be overridden.
171+
* Override path sensitivity for {@link ExtractAnnotations#getSource()} to {@link PathSensitivity#RELATIVE}.
173172
*/
174-
static class ExtractAnnotations_Disable_Workaround implements Workaround {
173+
static class ExtractAnnotations_Source_Workaround implements Workaround {
175174
@CompileStatic(TypeCheckingMode.SKIP)
176175
@Override
177176
void apply(Project project) {
178177
project.tasks.withType(ExtractAnnotations) { ExtractAnnotations task ->
179-
task.outputs.doNotCacheIf("Has absolute source", Specs.SATISFIES_ALL)
178+
def originalValue = task.source
179+
task.source = []
180+
task.inputs.files(originalValue)
181+
.withPathSensitivity(PathSensitivity.RELATIVE)
182+
.withPropertyName("source.workaround")
183+
.skipWhenEmpty(true)
184+
185+
task.doFirst {
186+
task.source = originalValue
187+
}
180188
}
181189
}
182190
}

src/test/groovy/org/gradle/android/VersionCheckTest.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class VersionCheckTest extends Specification {
108108
result.task(":library:compileReleaseRenderscript").outcome == FROM_CACHE
109109
result.task(":library:compileReleaseShaders").outcome == FROM_CACHE
110110
result.task(":library:compileReleaseShaders").outcome == FROM_CACHE
111+
result.task(":library:extractDebugAnnotations").outcome == FROM_CACHE
112+
// TODO This produces overlapping outputs in build/intermediates/typedefs.txt
113+
// result.task(":library:extractReleaseAnnotations").outcome == FROM_CACHE
111114
result.task(":library:generateDebugBuildConfig").outcome == FROM_CACHE
112115
result.task(":library:generateDebugResValues").outcome == FROM_CACHE
113116
result.task(":library:generateDebugResValues").outcome == FROM_CACHE
@@ -140,7 +143,7 @@ class VersionCheckTest extends Specification {
140143

141144
where:
142145
// [gradleVersion, androidVersion] << GroovyCollections.combinations(Versions.SUPPORTED_GRADLE_VERSIONS, Versions.SUPPORTED_ANDROID_VERSIONS)
143-
gradleVersion = GradleVersion.version("4.1")
146+
gradleVersion = GradleVersion.version("4.3")
144147
androidVersion = VersionNumber.parse("3.0.0")
145148
}
146149

0 commit comments

Comments
 (0)