@@ -12,14 +12,19 @@ import groovy.transform.CompileStatic
12
12
import groovy.transform.TypeCheckingMode
13
13
import org.gradle.api.Plugin
14
14
import org.gradle.api.Project
15
+ import org.gradle.api.Task
15
16
import org.gradle.api.tasks.PathSensitivity
17
+ import org.gradle.api.tasks.util.PatternFilterable
16
18
import org.gradle.internal.Factory
17
19
import org.gradle.util.DeprecationLogger
18
20
import org.gradle.util.GradleVersion
19
21
import org.gradle.util.VersionNumber
20
22
import org.slf4j.Logger
21
23
import org.slf4j.LoggerFactory
22
24
25
+ import static org.gradle.android.CompilerArgsProcessor.AnnotationProcessorOverride
26
+ import static org.gradle.android.CompilerArgsProcessor.Skip
27
+ import static org.gradle.android.CompilerArgsProcessor.SkipNext
23
28
import static org.gradle.android.Versions.android
24
29
25
30
@CompileStatic
@@ -32,6 +37,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
32
37
new AndroidJavaCompile_BootClasspath_Workaround (),
33
38
new AndroidJavaCompile_AnnotationProcessorSource_Workaround (),
34
39
new AndroidJavaCompile_ProcessorListFile_Workaround (),
40
+ new DataBindingDependencyArtifacts_Workaround (),
35
41
new ExtractAnnotations_Source_Workaround (),
36
42
new CombinedInput_Workaround (),
37
43
new ProcessAndroidResources_MergeBlameLogFolder_Workaround (),
@@ -52,9 +58,11 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
52
58
}
53
59
}
54
60
61
+ def context = new WorkaroundContext (project, new CompilerArgsProcessor (project))
62
+
55
63
getWorkaroundsToApply(currentAndroidVersion). each { Workaround workaround ->
56
64
LOGGER . debug(" Applying Android workaround {} to {}" , workaround. getClass(). simpleName, project)
57
- workaround. apply(project )
65
+ workaround. apply(context )
58
66
}
59
67
}
60
68
@@ -82,11 +90,14 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
82
90
*/
83
91
@AndroidIssue (introducedIn = " 3.0.0" , link = " https://issuetracker.google.com/issues/68392933" )
84
92
static class AndroidJavaCompile_BootClasspath_Workaround implements Workaround {
85
- @Override
86
93
@CompileStatic (TypeCheckingMode .SKIP )
87
- void apply (Project project ) {
94
+ @Override
95
+ void apply (WorkaroundContext context ) {
96
+ def project = context. project
88
97
project. tasks. withType(AndroidJavaCompile ) { AndroidJavaCompile task ->
89
98
task. inputs. property " options.bootClasspath" , " "
99
+ // Override workaround introduced in 3.1.0-alpha02
100
+ task. inputs. property " options.bootClasspath.filtered" , " "
90
101
task. inputs. files({
91
102
DeprecationLogger . whileDisabled({
92
103
// noinspection GrDeprecatedAPIUsage
@@ -105,27 +116,9 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
105
116
*/
106
117
@AndroidIssue (introducedIn = " 3.0.0" , link = " https://issuetracker.google.com/issues/68391973" )
107
118
static class AndroidJavaCompile_AnnotationProcessorSource_Workaround implements Workaround {
108
- @CompileStatic (TypeCheckingMode .SKIP )
109
119
@Override
110
- void apply (Project project ) {
111
- project. tasks. withType(AndroidJavaCompile ) { AndroidJavaCompile task ->
112
- task. inputs. property " options.compilerArgs" , " "
113
- task. inputs. property " options.compilerArgs.workaround" , {
114
- def filteredArgs = []
115
- def iCompilerArgs = task. options. compilerArgs. iterator()
116
- while (iCompilerArgs. hasNext()) {
117
- def compilerArg = iCompilerArgs. next()
118
- if (compilerArg == " -s" ) {
119
- if (iCompilerArgs. hasNext()) {
120
- iCompilerArgs. next()
121
- }
122
- } else {
123
- filteredArgs + = compilerArg
124
- }
125
- }
126
- return filteredArgs
127
- }
128
- }
120
+ void apply (WorkaroundContext context ) {
121
+ context. compilerArgsProcessor. addRule(SkipNext . matching(" -s" ))
129
122
}
130
123
}
131
124
@@ -136,7 +129,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
136
129
static class AndroidJavaCompile_ProcessorListFile_Workaround implements Workaround {
137
130
@CompileStatic (TypeCheckingMode .SKIP )
138
131
@Override
139
- void apply (Project project ) {
132
+ void apply (WorkaroundContext context ) {
133
+ def project = context. project
140
134
project. tasks. withType(AndroidJavaCompile ) { AndroidJavaCompile task ->
141
135
def originalValue
142
136
@@ -157,14 +151,110 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
157
151
}
158
152
}
159
153
154
+ /**
155
+ * Override path sensitivity for {@link AndroidJavaCompile#getDataBindingDependencyArtifacts()} to {@link PathSensitivity#RELATIVE}.
156
+ */
157
+ @AndroidIssue (introducedIn = " 3.0.0" , link = " https://issuetracker.google.com/issues/68759178" )
158
+ static class DataBindingDependencyArtifacts_Workaround implements Workaround {
159
+ @Override
160
+ void apply (WorkaroundContext context ) {
161
+ def project = context. project
162
+ def compilerArgsProcessor = context. compilerArgsProcessor
163
+ compilerArgsProcessor. addRule(Skip . matching(" -Aandroid.databinding.sdkDir=.*" ))
164
+ compilerArgsProcessor. addRule(Skip . matching(" -Aandroid.databinding.bindingBuildFolder=.*" ))
165
+ compilerArgsProcessor. addRule(Skip . matching(" -Aandroid.databinding.xmlOutDir=.*" ))
166
+
167
+ def outputRules = [
168
+ AnnotationProcessorOverride . of(" android.databinding.generationalFileOutDir" ) { Task task , String path ->
169
+ task. outputs. dir(path)
170
+ .withPropertyName(" android.databinding.generationalFileOutDir.workaround" )
171
+ },
172
+ AnnotationProcessorOverride . of(" android.databinding.exportClassListTo" ) { Task task , String path ->
173
+ task. outputs. file(path)
174
+ .withPropertyName(" android.databinding.exportClassListTo" )
175
+ }
176
+ ]
177
+ outputRules. each {
178
+ compilerArgsProcessor. addRule it
179
+ }
180
+
181
+ project. tasks. withType(AndroidJavaCompile ) { AndroidJavaCompile task ->
182
+ reconfigurePathSensitivityForDataBindingDependencyArtifacts(project, task)
183
+ filterDataBindingInfoFromSource(project, task)
184
+ configureAdditionalOutputs(project, task, outputRules)
185
+ }
186
+ }
187
+
188
+ @CompileStatic (TypeCheckingMode .SKIP )
189
+ private
190
+ static void reconfigurePathSensitivityForDataBindingDependencyArtifacts (Project project , AndroidJavaCompile task ) {
191
+ def originalValue
192
+
193
+ project. gradle. taskGraph. beforeTask {
194
+ if (task == it) {
195
+ originalValue = task. dataBindingDependencyArtifacts
196
+ if (originalValue != null ) {
197
+ task. dataBindingDependencyArtifacts = project. files()
198
+ task. inputs. files(originalValue)
199
+ .withPathSensitivity(PathSensitivity . RELATIVE )
200
+ .withPropertyName(" dataBindingDependencyArtifacts.workaround" )
201
+ }
202
+ }
203
+ }
204
+
205
+ task. doFirst {
206
+ task. dataBindingDependencyArtifacts = originalValue
207
+ }
208
+ }
209
+
210
+ @CompileStatic (TypeCheckingMode .SKIP )
211
+ private static void filterDataBindingInfoFromSource (Project project , AndroidJavaCompile task ) {
212
+ def originalValue
213
+
214
+ project. gradle. taskGraph. beforeTask {
215
+ if (task == it) {
216
+ originalValue = task. source
217
+ if (originalValue != null ) {
218
+ task. source = project. files()
219
+ def filteredSources = originalValue. matching { PatternFilterable filter ->
220
+ filter. exclude(" android/databinding/layouts/DataBindingInfo.java" )
221
+ }
222
+ task. inputs. files(filteredSources)
223
+ .withPathSensitivity(PathSensitivity . RELATIVE )
224
+ .withPropertyName(" source.workaround" )
225
+ .skipWhenEmpty()
226
+ }
227
+ }
228
+ }
229
+
230
+ task. doFirst {
231
+ task. source = originalValue
232
+ }
233
+ }
234
+
235
+
236
+ @CompileStatic (TypeCheckingMode .SKIP )
237
+ private static void configureAdditionalOutputs (Project project , AndroidJavaCompile task , List<AnnotationProcessorOverride > overrides ) {
238
+ def configTask = project. tasks. create(" configure" + task. name. capitalize()) { configTask ->
239
+ configTask. doFirst {
240
+ overrides. each {
241
+ it. configureAndroidJavaCompile(task)
242
+ }
243
+ }
244
+ }
245
+ task. dependsOn configTask
246
+ }
247
+ }
248
+
160
249
/**
161
250
* Override path sensitivity for {@link ExtractAnnotations#getSource()} to {@link PathSensitivity#RELATIVE}.
162
251
*/
163
252
@AndroidIssue (introducedIn = " 3.0.0" , fixedIn = " 3.1.0-alpha01" , link = " https://issuetracker.google.com/issues/68759476" )
164
253
static class ExtractAnnotations_Source_Workaround implements Workaround {
165
254
@CompileStatic (TypeCheckingMode .SKIP )
166
255
@Override
167
- void apply (Project project ) {
256
+ void apply (WorkaroundContext context ) {
257
+ def project = context. project
168
258
project. tasks. withType(ExtractAnnotations ) { ExtractAnnotations task ->
169
259
def originalValue
170
260
@@ -193,7 +283,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
193
283
static class CombinedInput_Workaround implements Workaround {
194
284
@CompileStatic (TypeCheckingMode .SKIP )
195
285
@Override
196
- void apply (Project project ) {
286
+ void apply (WorkaroundContext context ) {
287
+ def project = context. project
197
288
project. tasks. withType(IncrementalTask ) { IncrementalTask task ->
198
289
task. inputs. property " combinedInput" , " "
199
290
task. inputs. property " combinedInput.workaround" , {
@@ -224,7 +315,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
224
315
static class ProcessAndroidResources_MergeBlameLogFolder_Workaround implements Workaround {
225
316
@CompileStatic (TypeCheckingMode .SKIP )
226
317
@Override
227
- void apply (Project project ) {
318
+ void apply (WorkaroundContext context ) {
319
+ def project = context. project
228
320
project. tasks. withType(ProcessAndroidResources ) { ProcessAndroidResources task ->
229
321
task. inputs. property " mergeBlameLogFolder" , " "
230
322
}
@@ -238,7 +330,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
238
330
static class CheckManifest_Manifest_Workaround implements Workaround {
239
331
@CompileStatic (TypeCheckingMode .SKIP )
240
332
@Override
241
- void apply (Project project ) {
333
+ void apply (WorkaroundContext context ) {
334
+ def project = context. project
242
335
project. tasks. withType(CheckManifest ) { CheckManifest task ->
243
336
task. inputs. property " manifest" , " "
244
337
}
0 commit comments