Skip to content

Commit beafd11

Browse files
authored
LUCENE-9931: Rename checksummed regen. tasks FooInternal and generated wrappers Foo (#88)
1 parent 52e2abc commit beafd11

File tree

9 files changed

+71
-65
lines changed

9 files changed

+71
-65
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ ext {
5858
baseVersion = {
5959
def m = (version =~ /^(\d+\.\d+\.\d+)(-(.+))?/)
6060
if (!m) {
61-
throw GradleException("Can't strip version to just x.y.z: " + rootProject.version)
61+
throw new GradleException("Can't strip version to just x.y.z: " + rootProject.version)
6262
}
6363
return m[0][1]
6464
}()
6565
// "majorVersion" is an integer with just the major version. Compute it.
6666
majorVersion = {
6767
def m = (version =~ /^(\d+)\.\d+\.\d+(-(.+))?/)
6868
if (!m) {
69-
throw GradleException("Can't strip version to just major version: " + rootProject.version)
69+
throw new GradleException("Can't strip version to just major version: " + rootProject.version)
7070
}
7171
return m[0][1] as int
7272
}

gradle/documentation/markdown.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ configure(project(':lucene:documentation')) {
7878
def regex = ~/\bdefaultCodec\s*=\s*LOADER\s*\.\s*lookup\s*\(\s*"([^"]+)"\s*\)\s*;/
7979
def matcher = regex.matcher(defaultCodecFile.getText('UTF-8'))
8080
if (!matcher.find()) {
81-
throw GradleException("Cannot determine default codec from file ${defaultCodecFile}")
81+
throw new GradleException("Cannot determine default codec from file ${defaultCodecFile}")
8282
}
8383
return matcher.group(1).toLowerCase(Locale.ROOT)
8484
})

gradle/generation/icu.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ configure(project(":lucene:analysis:icu")) {
6969

7070
def icuCompileTask = Os.isFamily(Os.FAMILY_WINDOWS) ? "compileIcuWindows" : "compileIcuLinux"
7171

72-
task genUtr30DataFiles() {
72+
task genUtr30DataFilesInternal() {
7373
dependsOn icuCompileTask
7474

7575
// May be undefined yet, so use a provider.
@@ -119,7 +119,7 @@ configure(project(":lucene:analysis:icu")) {
119119
}
120120
}
121121

122-
task genRbbi() {
122+
task genRbbiInternal() {
123123
// May be undefined yet, so use a provider.
124124
dependsOn { sourceSets.tools.runtimeClasspath }
125125

@@ -141,8 +141,8 @@ configure(project(":lucene:analysis:icu")) {
141141
}
142142
}
143143

144-
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFiles, [ ignoreWithSource: icuCompileTask ])
145-
regenerate.dependsOn wrapWithPersistentChecksums(genRbbi)
144+
regenerate.dependsOn wrapWithPersistentChecksums(genUtr30DataFilesInternal, [ ignoreWithSource: icuCompileTask ])
145+
regenerate.dependsOn wrapWithPersistentChecksums(genRbbiInternal)
146146

147147
task compileIcuWindows() {
148148
doFirst {
@@ -236,7 +236,7 @@ configure(project(":lucene:analysis:icu")) {
236236

237237
// Regenerates UnicodeProps.java
238238
configure(project(":lucene:analysis:common")) {
239-
task generateUnicodeProps() {
239+
task generateUnicodePropsInternal() {
240240
def icuConfig = rootProject.configurations.icu_68
241241
def outputFile = file("src/java/org/apache/lucene/analysis/util/UnicodeProps.java")
242242

@@ -260,13 +260,13 @@ configure(project(":lucene:analysis:common")) {
260260
}
261261
}
262262

263-
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodeProps, [ andThenTasks: "spotlessApply" ])
263+
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [ andThenTasks: "spotlessApply" ])
264264
}
265265

266266

267267
// UnicodeEmojiProperties.jflex
268268
configure(project(":lucene:core")) {
269-
task generateEmojiProperties() {
269+
task generateEmojiPropertiesInternal() {
270270
def icuConfig = rootProject.configurations.icu_62
271271
def outputFile = file("src/data/jflex/UnicodeEmojiProperties.jflex")
272272

@@ -290,5 +290,5 @@ configure(project(":lucene:core")) {
290290
}
291291
}
292292

293-
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiProperties)
293+
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiPropertiesInternal)
294294
}

gradle/generation/javacc.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def commonCleanups = { FileTree generatedFiles ->
107107
}
108108

109109
configure(project(":lucene:queryparser")) {
110-
task javaccParserClassic(type: JavaCCTask) {
110+
task javaccParserClassicInternal(type: JavaCCTask) {
111111
description "Regenerate classic query parser from lucene/queryparser/classic/QueryParser.jj"
112112
group "generation"
113113

@@ -144,7 +144,7 @@ configure(project(":lucene:queryparser")) {
144144
}
145145
}
146146

147-
task javaccParserSurround(type: JavaCCTask) {
147+
task javaccParserSurroundInternal(type: JavaCCTask) {
148148
description "Regenerate surround query parser from lucene/queryparser/surround/parser/QueryParser.jj"
149149
group "generation"
150150

@@ -169,7 +169,7 @@ configure(project(":lucene:queryparser")) {
169169
}
170170
}
171171

172-
task javaccParserFlexible(type: JavaCCTask) {
172+
task javaccParserFlexibleInternal(type: JavaCCTask) {
173173
description "Regenerate flexible query parser from queryparser/flexible/standard/parser/StandardSyntaxParser.jj"
174174
group "generation"
175175

@@ -252,9 +252,9 @@ configure(project(":lucene:queryparser")) {
252252
description "Regenerate query parsers (javacc syntax definitions)."
253253
group "generation"
254254

255-
dependsOn wrapWithPersistentChecksums(javaccParserClassic, [ andThenTasks: "spotlessApply" ]),
256-
wrapWithPersistentChecksums(javaccParserSurround, [ andThenTasks: "spotlessApply" ]),
257-
wrapWithPersistentChecksums(javaccParserFlexible, [ andThenTasks: "spotlessApply" ])
255+
dependsOn wrapWithPersistentChecksums(javaccParserClassicInternal, [ andThenTasks: "spotlessApply" ]),
256+
wrapWithPersistentChecksums(javaccParserSurroundInternal, [ andThenTasks: "spotlessApply" ]),
257+
wrapWithPersistentChecksums(javaccParserFlexibleInternal, [ andThenTasks: "spotlessApply" ])
258258
}
259259

260260
regenerate.dependsOn javacc

gradle/generation/jflex.gradle

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def skeletonDefault = file("${resources}/skeleton.default.txt")
3232
def skeletonNoBufferExpansion = file("${resources}/skeleton.disable.buffer.expansion.txt")
3333

3434
configure(project(":lucene:core")) {
35-
task generateStandardTokenizer(type: JFlexTask) {
35+
task generateStandardTokenizerInternal(type: JFlexTask) {
3636
description "Regenerate StandardTokenizerImpl.java"
3737
group "generation"
3838

@@ -49,11 +49,11 @@ configure(project(":lucene:core")) {
4949
}
5050
}
5151

52-
regenerate.dependsOn wrapWithPersistentChecksums(generateStandardTokenizer, [ andThenTasks: "spotlessApply" ])
52+
regenerate.dependsOn wrapWithPersistentChecksums(generateStandardTokenizerInternal, [ andThenTasks: "spotlessApply" ])
5353
}
5454

5555
configure(project(":lucene:analysis:common")) {
56-
task generateTlds() {
56+
task generateTldsInternal() {
5757
def tldZones = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"
5858
def jflexMacro = file("src/java/org/apache/lucene/analysis/email/ASCIITLD.jflex")
5959
def tldList = file("src/test/org/apache/lucene/analysis/email/TLDs.txt")
@@ -82,23 +82,23 @@ configure(project(":lucene:analysis:common")) {
8282
}
8383
}
8484

85-
task generateWikipediaTokenizer(type: JFlexTask) {
85+
task generateWikipediaTokenizerInternal(type: JFlexTask) {
8686
description "Regenerate WikipediaTokenizerImpl.java"
8787
group "generation"
8888

8989
jflexFile = file('src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.jflex')
9090
skeleton = skeletonDefault
9191
}
9292

93-
task generateClassicTokenizer(type: JFlexTask) {
93+
task generateClassicTokenizerInternal(type: JFlexTask) {
9494
description "Regenerate ClassicTokenizerImpl.java"
9595
group "generation"
9696

9797
jflexFile = file('src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.jflex')
9898
skeleton = skeletonDefault
9999
}
100100

101-
task generateUAX29URLEmailTokenizer(type: JFlexTask) {
101+
task generateUAX29URLEmailTokenizerInternal(type: JFlexTask) {
102102
description "Regenerate UAX29URLEmailTokenizerImpl.java"
103103
group "generation"
104104

@@ -108,7 +108,7 @@ configure(project(":lucene:analysis:common")) {
108108

109109
// Don't enforce strict dependency (although it would make sense to regenerate both).
110110
// Just ensure we run after TLD regeneration, if it runs too.
111-
mustRunAfter generateTlds
111+
mustRunAfter generateTldsInternal
112112

113113
// Additional input (included by the source jflex file)
114114
inputs.file file('src/java/org/apache/lucene/analysis/email/ASCIITLD.jflex')
@@ -127,7 +127,7 @@ configure(project(":lucene:analysis:common")) {
127127
}
128128
}
129129

130-
task generateHTMLStripCharFilter(type: JFlexTask) {
130+
task generateHTMLStripCharFilterInternal(type: JFlexTask) {
131131
description "Regenerate HTMLStripCharFilter.java"
132132
group "generation"
133133

@@ -154,11 +154,11 @@ configure(project(":lucene:analysis:common")) {
154154
}
155155
}
156156

157-
regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizer, [ andThenTasks: "spotlessApply" ]),
158-
wrapWithPersistentChecksums(generateClassicTokenizer, [ andThenTasks: "spotlessApply" ]),
159-
wrapWithPersistentChecksums(generateUAX29URLEmailTokenizer, [ andThenTasks: "spotlessApply" ]),
160-
wrapWithPersistentChecksums(generateHTMLStripCharFilter, [ andThenTasks: "spotlessApply" ]),
161-
wrapWithPersistentChecksums(generateTlds, [ andThenTasks: "spotlessApply" ])
157+
regenerate.dependsOn wrapWithPersistentChecksums(generateWikipediaTokenizerInternal, [ andThenTasks: "spotlessApply" ]),
158+
wrapWithPersistentChecksums(generateClassicTokenizerInternal, [ andThenTasks: "spotlessApply" ]),
159+
wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [ andThenTasks: "spotlessApply" ]),
160+
wrapWithPersistentChecksums(generateHTMLStripCharFilterInternal, [ andThenTasks: "spotlessApply" ]),
161+
wrapWithPersistentChecksums(generateTldsInternal, [ andThenTasks: "spotlessApply" ])
162162
}
163163

164164
class JFlexTask extends DefaultTask {

gradle/generation/moman.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ configure(project(":lucene:core")) {
3838
}
3939
}
4040

41-
task utilGenPacked(dependsOn: installMoman) {
41+
task utilGenPackedInternal(dependsOn: installMoman) {
4242
def targetDir = file("src/java/org/apache/lucene/util/packed")
4343

4444
inputs.property("source", momanSource)
@@ -66,7 +66,7 @@ configure(project(":lucene:core")) {
6666
}
6767
}
6868

69-
task utilGenLev(dependsOn: installMoman) {
69+
task utilGenLevInternal(dependsOn: installMoman) {
7070
def targetDir = file("src/java/org/apache/lucene/util/automaton")
7171

7272
inputs.property("source", momanSource)
@@ -99,8 +99,8 @@ configure(project(":lucene:core")) {
9999
description "Regenerate Moman-based sources."
100100
group "generation"
101101

102-
dependsOn wrapWithPersistentChecksums(utilGenPacked, [ andThenTasks: "spotlessApply" ])
103-
dependsOn wrapWithPersistentChecksums(utilGenLev, [ andThenTasks: "spotlessApply" ])
102+
dependsOn wrapWithPersistentChecksums(utilGenPackedInternal, [ andThenTasks: "spotlessApply" ])
103+
dependsOn wrapWithPersistentChecksums(utilGenLevInternal, [ andThenTasks: "spotlessApply" ])
104104
}
105105

106106
regenerate.dependsOn moman

gradle/generation/regenerate.gradle

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,18 @@ configure([
3838
// This utility method implements the logic required for "persistent" incremental
3939
// source-generating tasks. The idea is simple, the implementation quite complex.
4040
//
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)
4444
//
4545
// ${sourceTask}ChecksumLoad
4646
// ${sourceTask}ChecksumSave
4747
// ${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]
4949
//
5050
// 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 }).
5353
//
5454
// Implementation-wise things get complicated because gradle doesn't have the notion
5555
// of "ordered" task execution with respect to task AND its dependencies (we can add
@@ -60,6 +60,12 @@ configure([
6060
// andThenTasks: other tasks that should be scheduled to run after source task and
6161
// before checksum calculation.
6262
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+
6369
def toList = { value ->
6470
if (value instanceof List) {
6571
return value
@@ -74,7 +80,7 @@ configure([
7480
List<Object> ignoreWithSource = toList(extraConfig.get("ignoreWithSource"))
7581

7682
// Create checksum-loader task.
77-
Task checksumLoadTask = tasks.create("${sourceTask.name}ChecksumLoad", {
83+
Task checksumLoadTask = tasks.create("${sourceTaskName}ChecksumLoad", {
7884
ext {
7985
checksumMatch = true
8086
}
@@ -94,7 +100,7 @@ configure([
94100
ext.actualChecksums = actualChecksums
95101

96102
// 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")
98104
Map<String, String> savedChecksums = [:]
99105
if (checksumsFile.exists()) {
100106
savedChecksums = new JsonSlurper().parse(checksumsFile) as Map
@@ -105,7 +111,7 @@ configure([
105111
}
106112
})
107113

108-
Task checksumCheckTask = tasks.create("${sourceTask.name}ChecksumCheck", {
114+
Task checksumCheckTask = tasks.create("${sourceTaskName}ChecksumCheck", {
109115
dependsOn checksumLoadTask
110116

111117
doFirst {
@@ -119,7 +125,7 @@ configure([
119125
expected = expected - same
120126

121127
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" +
123129
"Actual:\n ${actual.entrySet().join('\n ')}\n\n" +
124130
"Expected:\n ${expected.entrySet().join('\n ')}"
125131
)
@@ -128,7 +134,7 @@ configure([
128134
})
129135
check.dependsOn checksumCheckTask
130136

131-
Task checksumSaveTask = tasks.create("${sourceTask.name}ChecksumSave", {
137+
Task checksumSaveTask = tasks.create("${sourceTaskName}ChecksumSave", {
132138
dependsOn checksumLoadTask
133139

134140
doFirst {
@@ -150,7 +156,7 @@ configure([
150156
}
151157
})
152158

153-
Task conditionalTask = tasks.create("${sourceTask.name}IfChanged", {
159+
Task conditionalTask = tasks.create("${sourceTaskName}", {
154160
def deps = [
155161
checksumLoadTask,
156162
sourceTask,
@@ -162,7 +168,7 @@ configure([
162168
mustRunInOrder deps
163169

164170
doFirst {
165-
if (checksumLoadTask.checksumMatch) {
171+
if (checksumLoadTask.checksumMatch && !sourceTask.didWork) {
166172
logger.lifecycle("Checksums consistent with sources, skipping task: ${sourceTask.path}")
167173
}
168174
}

gradle/generation/snowball.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ configure(project(":lucene:analysis:common")) {
9292
}
9393

9494
// runs shell script to regenerate stemmers, base stemming subclasses, test data, and stopwords.
95-
task snowball() {
95+
task snowballInternal() {
9696
description "Regenerate snowball stemmers."
9797
group "generation"
9898

@@ -117,7 +117,7 @@ configure(project(":lucene:analysis:common")) {
117117
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
118118
doFirst {
119119
// Just emit a big fat error message. Fail the build so that checksums are not regenerated.
120-
throw GradleException("Snowball generation does not work on Windows (patch and bash must be available).")
120+
throw new GradleException("Snowball generation does not work on Windows (patch and bash must be available).")
121121
}
122122
} else {
123123
dependsOn downloadSnowballStemmers
@@ -133,5 +133,5 @@ configure(project(":lucene:analysis:common")) {
133133
}
134134
}
135135

136-
regenerate.dependsOn wrapWithPersistentChecksums(snowball, [ andThenTasks: "spotlessApply", ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite, downloadSnowballData] ])
136+
regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [ andThenTasks: "spotlessApply", ignoreWithSource: [downloadSnowballStemmers, downloadSnowballWebsite, downloadSnowballData] ])
137137
}

0 commit comments

Comments
 (0)