Skip to content

Commit afe982b

Browse files
authored
Schedule compileJava after the internal task if it affects source files (apache#13282)
1 parent df0384c commit afe982b

File tree

10 files changed

+98
-48
lines changed

10 files changed

+98
-48
lines changed

gradle/generation/antlr.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ configure(project(":lucene:expressions")) {
8282
}
8383

8484
def generateAntlr = wrapWithPersistentChecksums(
85-
generateAntlrInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
85+
generateAntlrInternal, [
86+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
87+
mustRunBefore: [ "compileJava" ]
88+
])
8689

8790
regenerate.dependsOn generateAntlr
8891
}

gradle/generation/forUtil.gradle

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ configure(project(":lucene:core")) {
3939
}
4040
}
4141

42-
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtilInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
42+
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtilInternal, [
43+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
44+
mustRunBefore: [ "compileJava" ]
45+
])
4346
}
4447

4548
configure(project(":lucene:backward-codecs")) {
@@ -64,7 +67,10 @@ configure(project(":lucene:backward-codecs")) {
6467
}
6568
}
6669

67-
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil84Internal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
70+
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil84Internal, [
71+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
72+
mustRunBefore: [ "compileJava" ]
73+
])
6874

6975
task generateForUtil90Internal() {
7076
description "Regenerate gen_ForUtil.py"
@@ -86,6 +92,9 @@ configure(project(":lucene:backward-codecs")) {
8692
}
8793
}
8894

89-
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil90Internal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
95+
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil90Internal, [
96+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
97+
mustRunBefore: [ "compileJava" ]
98+
])
9099
}
91100

gradle/generation/icu.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,13 @@ configure(project(":lucene:analysis:icu")) {
159159
}
160160
}
161161

162-
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [ ignoreWithSource: icuCompileTask ])
163-
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal)
162+
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [
163+
ignoreWithSource: icuCompileTask,
164+
mustRunBefore: [ "compileJava" ]
165+
])
166+
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal, [
167+
mustRunBefore: [ "compileJava" ]
168+
])
164169

165170
task compileIcuWindows() {
166171
doFirst {
@@ -281,5 +286,8 @@ configure(project(":lucene:analysis:common")) {
281286
}
282287
}
283288

284-
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
289+
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [
290+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
291+
mustRunBefore: [ "compileJava" ]
292+
])
285293
}

gradle/generation/javacc.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,14 @@ configure(project(":lucene:queryparser")) {
232232
description "Regenerate query parsers (javacc syntax definitions)."
233233
group "generation"
234234

235-
dependsOn wrapWithPersistentChecksums(javaccParserClassicInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
236-
wrapWithPersistentChecksums(javaccParserSurroundInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
237-
wrapWithPersistentChecksums(javaccParserFlexibleInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
235+
def extraConfig = [
236+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
237+
mustRunBefore: [ "compileJava" ]
238+
]
239+
240+
dependsOn wrapWithPersistentChecksums(javaccParserClassicInternal, extraConfig),
241+
wrapWithPersistentChecksums(javaccParserSurroundInternal, extraConfig),
242+
wrapWithPersistentChecksums(javaccParserFlexibleInternal, extraConfig)
238243
}
239244

240245
regenerate.dependsOn javacc

gradle/generation/jflex.gradle

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ configure(project(":lucene:core")) {
5151
}
5252
}
5353

54-
def generateStandardTokenizer = wrapWithPersistentChecksums(generateStandardTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
54+
def generateStandardTokenizer = wrapWithPersistentChecksums(generateStandardTokenizerInternal, [
55+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
56+
mustRunBefore: [ "compileJava" ]
57+
])
5558

5659
regenerate.dependsOn generateStandardTokenizer
5760
}
@@ -149,7 +152,11 @@ configure(project(":lucene:analysis:common")) {
149152
}
150153
}
151154

152-
def generateUAX29URLEmailTokenizer = wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
155+
def generateUAX29URLEmailTokenizer = wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [
156+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
157+
mustRunBefore: [ "compileJava" ]
158+
])
159+
153160
// UAX29URLEmailTokenizerImpl.jflex includes: ASCIITLD.jflex
154161
// so we make sure it is up to date. Also, make sure the ordering of internal
155162
// tasks is enforced (just scheduling top-level wrappers doesn't mean their subtask graphs cannot be reordered).
@@ -197,7 +204,12 @@ configure(project(":lucene:analysis:common")) {
197204
skeleton = skeletonDefault
198205
}
199206

200-
def generateHTMLStripCharFilter = wrapWithPersistentChecksums(generateHTMLStripCharFilterInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
207+
def extraConfig = [
208+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
209+
mustRunBefore: [ "compileJava" ]
210+
]
211+
212+
def generateHTMLStripCharFilter = wrapWithPersistentChecksums(generateHTMLStripCharFilterInternal, extraConfig)
201213
// HTMLStripCharFilter.jflex includes HTMLCharacterEntities.jflex so we make sure it's up to date.
202214
configure(generateHTMLStripCharFilter) {
203215
dependsOn "generateHTMLCharacterEntities"
@@ -206,12 +218,12 @@ configure(project(":lucene:analysis:common")) {
206218
dependsOn "generateHTMLCharacterEntitiesInternal"
207219
}
208220

209-
regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
210-
wrapWithPersistentChecksums(generateClassicTokenizerInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ]),
221+
regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizerInternal, extraConfig),
222+
wrapWithPersistentChecksums(generateClassicTokenizerInternal, extraConfig),
211223
generateUAX29URLEmailTokenizer,
212-
wrapWithPersistentChecksums(generateHTMLCharacterEntitiesInternal),
224+
wrapWithPersistentChecksums(generateHTMLCharacterEntitiesInternal, extraConfig),
213225
generateHTMLStripCharFilter,
214-
wrapWithPersistentChecksums(generateTldsInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
226+
wrapWithPersistentChecksums(generateTldsInternal, extraConfig)
215227
}
216228

217229
class JFlexTask extends DefaultTask {

gradle/generation/moman.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ configure(project(":lucene:core")) {
105105
description "Regenerate Moman-based sources."
106106
group "generation"
107107

108-
dependsOn wrapWithPersistentChecksums(utilGenPackedInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
109-
dependsOn wrapWithPersistentChecksums(utilGenLevInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
108+
def extraConfig = [
109+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
110+
mustRunBefore: [ "compileJava" ]
111+
]
112+
113+
dependsOn wrapWithPersistentChecksums(utilGenPackedInternal, extraConfig)
114+
dependsOn wrapWithPersistentChecksums(utilGenLevInternal, extraConfig)
110115
}
111116

112117
regenerate.dependsOn moman

gradle/generation/regenerate.gradle

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,33 @@ configure([
105105
//
106106
// The idea is that, given source-generating task "sourceTaskInternal" (note the suffix),
107107
// we create a bunch of other tasks that perform checksum generation, validation and
108-
// source task skipping; example (sourceTask has Internal suffix stripped)
108+
// source task skipping. For example, let's say we have a task 'genFooInternal";
109+
// the following tasks would be created
109110
//
110-
// ${sourceTask}ChecksumLoad
111-
// ${sourceTask}ChecksumSave
112-
// ${sourceTask}ChecksumCheck (fails if checksums are inconsistent)
113-
// ${sourceTask} dependsOn [checksum-load, ${sourceTask}Internal, checksum-save]
111+
// genFooChecksumLoad
112+
// genFooChecksumSave
113+
// genFooChecksumCheck (fails if checksums are inconsistent)
114+
//
115+
// and the following set of dependencies would be created (with additional
116+
// constraints to run them in this particular order!).
117+
//
118+
// genFoo.dependsOn [genFooChecksumLoad, genFooInternal, genFooChecksumSave]
114119
//
115120
// Checksums are persisted and computed from sourceTask's inputs/outputs. If the
116-
// persisted checksums are identical to current checksums, source task
117-
// is skipped (via sourceTaskInternal.onlyIf { false }).
121+
// persisted checksums are identical to the now-current checksums, the "internal" task
122+
// is skipped (using onlyIf { false }).
118123
//
119124
// Implementation-wise things get complicated because gradle doesn't have the notion
120125
// of "ordered" task execution with respect to task AND its dependencies (we can add
121126
// constraints to each node in the execution graph but not node-and-dependencies).
122127
//
123128
// sourceTask - the task to wrap
124129
// extraConfig - a map with extra (optional) configuration options.
125-
// andThenTasks: other tasks that should be scheduled to run after source task and
126-
// before checksum calculation.
130+
// andThenTasks: any other tasks that should be scheduled to run after the internal task and
131+
// before checksum calculation/ saving. spotless is a good example of this.
132+
// ignoreWithSource: any other tasks that should be ignored if the internal task is ignored
133+
// (checksums are identical)
134+
// mustRunBefore: any tasks which should be scheduled to run after the internal task.
127135
wrapWithPersistentChecksums = { Task sourceTask, Map<String, Object> extraConfig = [:] ->
128136
if (!sourceTask.name.endsWith("Internal")) {
129137
throw new GradleException("Wrapped task must follow the convention name of *Internal: ${sourceTask.name}")
@@ -144,6 +152,13 @@ configure([
144152
List<Object> andThenTasks = toList(extraConfig.get("andThenTasks"))
145153
List<Object> ignoreWithSource = toList(extraConfig.get("ignoreWithSource"))
146154

155+
// Schedule must-run-afters
156+
List<Object> mustRunBefore = toList(extraConfig.get("mustRunBefore"))
157+
// TODO: maybe ensure all task refs here are strings?
158+
tasks.matching { it.name in mustRunBefore }.configureEach {
159+
mustRunAfter sourceTask
160+
}
161+
147162
// Create checksum-loader task.
148163
Task checksumLoadTask = tasks.create("${sourceTaskName}ChecksumLoad", {
149164
ext {

gradle/generation/snowball.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,9 @@ configure(project(":lucene:analysis:common")) {
109109
}
110110
}
111111

112-
regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"], ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite] ])
112+
regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [
113+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
114+
ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite],
115+
mustRunBefore: [ "compileJava" ]
116+
])
113117
}

gradle/generation/unicode-test-classes.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ configure(project(":lucene:test-framework")) {
4343
}
4444
}
4545
}
46-
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiTokenizationTestInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
46+
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiTokenizationTestInternal, [
47+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
48+
mustRunBefore: [ "compileJava" ]
49+
])
4750

4851
task generateJavaUnicodeWordBreakTestInternal() {
4952
def unicodeVersion = "12.1"
@@ -71,6 +74,8 @@ configure(project(":lucene:test-framework")) {
7174
}
7275
}
7376

74-
regenerate.dependsOn wrapWithPersistentChecksums(generateJavaUnicodeWordBreakTestInternal, [ andThenTasks: ["spotlessJava", "spotlessJavaApply"] ])
75-
77+
regenerate.dependsOn wrapWithPersistentChecksums(generateJavaUnicodeWordBreakTestInternal, [
78+
andThenTasks: ["spotlessJava", "spotlessJavaApply"],
79+
mustRunBefore: [ "compileJava" ]
80+
])
7681
}

help/regeneration.txt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,6 @@ In many cases hitting (1) means you'll have to do (2) so let's discuss
1616
these in order.
1717

1818

19-
SPECIAL NOTE
20-
------------
21-
22-
Regeneration tasks currently don't play well with the current gradle version.
23-
To workaround the issue, compile everything first:
24-
25-
gradlew compileJava
26-
27-
Then run the commands as described in this document, excluding compileJava.
28-
For example to run "regenerate":
29-
30-
gradlew regenerate -x compileJava
31-
32-
More information: https://github.com/apache/lucene/issues/13240
33-
34-
3519
Checksum validation errors
3620
--------------------------
3721

0 commit comments

Comments
 (0)