@@ -38,18 +38,18 @@ configure([
38
38
// This utility method implements the logic required for "persistent" incremental
39
39
// source-generating tasks. The idea is simple, the implementation quite complex.
40
40
//
41
- // The idea is that, given source-generating task "sourceTask" we create
42
- // a bunch of other tasks that perform checksum generation, validation and sourceTask
43
- // skipping; example:
41
+ // The idea is that, given source-generating task "sourceTaskInternal" (note the suffix),
42
+ // we create a bunch of other tasks that perform checksum generation, validation and
43
+ // source task skipping; example (sourceTask has Internal suffix stripped)
44
44
//
45
45
// ${sourceTask}ChecksumLoad
46
46
// ${sourceTask}ChecksumSave
47
47
// ${sourceTask}ChecksumCheck (fails if checksums are inconsistent)
48
- // maybe ${sourceTask} dependsOn [checksum-load, sourceTask, checksum-save]
48
+ // ${sourceTask} dependsOn [checksum-load, ${ sourceTask}Internal , checksum-save]
49
49
//
50
50
// Checksums are persisted and computed from sourceTask's inputs/outputs. If the
51
- // persisted checksums are identical to current checksums, sourceTask
52
- // is skipped (via sourceTask .onlyIf { false }).
51
+ // persisted checksums are identical to current checksums, source task
52
+ // is skipped (via sourceTaskInternal .onlyIf { false }).
53
53
//
54
54
// Implementation-wise things get complicated because gradle doesn't have the notion
55
55
// of "ordered" task execution with respect to task AND its dependencies (we can add
@@ -60,6 +60,12 @@ configure([
60
60
// andThenTasks: other tasks that should be scheduled to run after source task and
61
61
// before checksum calculation.
62
62
wrapWithPersistentChecksums = { Task sourceTask , Map<String , Object > extraConfig = [:] ->
63
+ if (! sourceTask. name. endsWith(" Internal" )) {
64
+ throw new GradleException (" Wrapped task must follow the convention name of *Internal: ${ sourceTask.name} " )
65
+ }
66
+
67
+ String sourceTaskName = sourceTask. name. replaceAll(' Internal$' , ' ' )
68
+
63
69
def toList = { value ->
64
70
if (value instanceof List ) {
65
71
return value
@@ -74,7 +80,7 @@ configure([
74
80
List<Object > ignoreWithSource = toList(extraConfig. get(" ignoreWithSource" ))
75
81
76
82
// Create checksum-loader task.
77
- Task checksumLoadTask = tasks. create(" ${ sourceTask.name } ChecksumLoad" , {
83
+ Task checksumLoadTask = tasks. create(" ${ sourceTaskName } ChecksumLoad" , {
78
84
ext {
79
85
checksumMatch = true
80
86
}
@@ -94,7 +100,7 @@ configure([
94
100
ext. actualChecksums = actualChecksums
95
101
96
102
// Load any previously written checksums
97
- ext. checksumsFile = project. file(" src/generated/checksums/${ sourceTask.name } .json" )
103
+ ext. checksumsFile = project. file(" src/generated/checksums/${ sourceTaskName } .json" )
98
104
Map<String , String > savedChecksums = [:]
99
105
if (checksumsFile. exists()) {
100
106
savedChecksums = new JsonSlurper (). parse(checksumsFile) as Map
@@ -105,7 +111,7 @@ configure([
105
111
}
106
112
})
107
113
108
- Task checksumCheckTask = tasks. create(" ${ sourceTask.name } ChecksumCheck" , {
114
+ Task checksumCheckTask = tasks. create(" ${ sourceTaskName } ChecksumCheck" , {
109
115
dependsOn checksumLoadTask
110
116
111
117
doFirst {
@@ -119,7 +125,7 @@ configure([
119
125
expected = expected - same
120
126
121
127
throw new GradleException (" Checksums mismatch for derived resources; you might have" +
122
- " modified a generated resource (regenerate task: ${ sourceTask.path } IfChanged ):\n " +
128
+ " modified a generated resource (regenerate task: ${ sourceTask.name } ):\n " +
123
129
" Actual:\n ${ actual.entrySet().join('\n ')} \n\n " +
124
130
" Expected:\n ${ expected.entrySet().join('\n ')} "
125
131
)
@@ -128,7 +134,7 @@ configure([
128
134
})
129
135
check. dependsOn checksumCheckTask
130
136
131
- Task checksumSaveTask = tasks. create(" ${ sourceTask.name } ChecksumSave" , {
137
+ Task checksumSaveTask = tasks. create(" ${ sourceTaskName } ChecksumSave" , {
132
138
dependsOn checksumLoadTask
133
139
134
140
doFirst {
@@ -150,7 +156,7 @@ configure([
150
156
}
151
157
})
152
158
153
- Task conditionalTask = tasks. create(" ${ sourceTask.name } IfChanged " , {
159
+ Task conditionalTask = tasks. create(" ${ sourceTaskName } " , {
154
160
def deps = [
155
161
checksumLoadTask,
156
162
sourceTask,
@@ -162,7 +168,7 @@ configure([
162
168
mustRunInOrder deps
163
169
164
170
doFirst {
165
- if (checksumLoadTask. checksumMatch) {
171
+ if (checksumLoadTask. checksumMatch && ! sourceTask . didWork ) {
166
172
logger. lifecycle(" Checksums consistent with sources, skipping task: ${ sourceTask.path} " )
167
173
}
168
174
}
0 commit comments