Skip to content

Apache Lucene open-source search software

Custom google java format tasks to replace spotless (#14824)

Dawid Weiss13904b512338
diff --git a/build-tools/build-infra-shadow/build.gradle b/build-tools/build-infra-shadow/build.gradle
index cc348fccf9c..7d8043837f9 100644
--- a/build-tools/build-infra-shadow/build.gradle
+++ b/build-tools/build-infra-shadow/build.gradle
@@ -1,5 +1,3 @@
-import com.diffplug.gradle.spotless.SpotlessTask
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -37,7 +35,6 @@ static Provider<String> plugin(Provider<PluginDependency> plugin) {
} else {
// maven artifact pattern for gradle's plugin repositories.
return "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}".toString()
- // return "${it.pluginId}:${it.pluginId.replaceFirst(".*\\.", "")}-plugin-gradle:${it.version}".toString()
}
}
}
@@ -47,11 +44,12 @@ dependencies {
implementation localGroovy()
implementation deps.commons.codec
implementation deps.randomizedtesting.runner
+ implementation deps.gjf
+ implementation deps.jgit
implementation plugin(deps.plugins.carrotsearch.buildopts)
implementation plugin(deps.plugins.carrotsearch.dependencychecks)
implementation plugin(deps.plugins.forbiddenapis)
- implementation plugin(deps.plugins.spotless)
}
tasks.matching {
@@ -69,16 +67,10 @@ tasks.matching {
enabled = false
}
-// check spotless and other tasks into thinking their sources
-// are from build-infra.
+// make certain tasks think their sources are from build-infra.
if (!isIdea) {
plugins.withType(JavaPlugin).configureEach {
SourceSet main = sourceSets.main
main.java.srcDirs = rootProject.files("build-tools/build-infra/src/main/java")
}
-
- tasks.withType(SpotlessTask).configureEach {
- it.projectDir.set(rootProject.file("build-tools/build-infra"))
- it.target
- }
}
diff --git a/build-tools/build-infra/build.gradle b/build-tools/build-infra/build.gradle
index 3b1ba01ebf0..84ed5c64b37 100644
--- a/build-tools/build-infra/build.gradle
+++ b/build-tools/build-infra/build.gradle
@@ -19,7 +19,6 @@ plugins {
id "java-gradle-plugin"
id "groovy-gradle-plugin"
- alias(deps.plugins.spotless) apply false
alias(deps.plugins.forbiddenapis) apply false
}
@@ -50,7 +49,6 @@ static Provider<String> plugin(Provider<PluginDependency> plugin) {
} else {
// maven artifact pattern for gradle's plugin repositories.
return "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}".toString()
- // return "${it.pluginId}:${it.pluginId.replaceFirst(".*\\.", "")}-plugin-gradle:${it.version}".toString()
}
}
}
@@ -68,6 +66,8 @@ dependencies {
implementation deps.flexmark.ext.attributes
implementation deps.flexmark.ext.autolink
implementation deps.flexmark.ext.tables
+ implementation deps.gjf
+ implementation deps.jgit
implementation plugin(deps.plugins.carrotsearch.buildopts)
implementation plugin(deps.plugins.carrotsearch.dependencychecks)
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
index c3d55ba7ec9..c5ed226b2f8 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.antlr.gradle
@@ -85,8 +85,7 @@ configure(project(":lucene:expressions")) {
def generateAntlr = wrapWithPersistentChecksums(
generateAntlrInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.forUtil.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.forUtil.gradle
index 0d6057536b2..f4358284a4a 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.forUtil.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.forUtil.gradle
@@ -41,8 +41,7 @@ configure(project(":lucene:core")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtilInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -69,8 +68,7 @@ configure(project(":lucene:core")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForDeltaUtilInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -100,8 +98,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil84Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -128,8 +125,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil90Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -156,8 +152,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil99Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -184,8 +179,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil912Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -212,8 +206,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForDeltaUtil912Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -240,8 +233,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForUtil101Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -268,8 +260,7 @@ configure(project(":lucene:backward-codecs")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateForDeltaUtil101Internal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.gradle
index ccbde3a46f0..3f71d330885 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.gradle
@@ -131,7 +131,7 @@ configure([
// sourceTask - the task to wrap
// extraConfig - a map with extra (optional) configuration options.
// andThenTasks: any other tasks that should be scheduled to run after the internal task and
- // before checksum calculation/ saving. spotless is a good example of this.
+ // before checksum calculation/ saving. code formatting is a good example of this.
// ignoreWithSource: any other tasks that should be ignored if the internal task is ignored
// (checksums are identical)
// mustRunBefore: any tasks which should be scheduled to run after the internal task.
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
index 2d7af52ff83..65bb2cafe84 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.icu.gradle
@@ -285,8 +285,7 @@ configure(project(":lucene:analysis:common")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -325,8 +324,7 @@ configure(project(":lucene:core")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateUnicodePropsInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
index c08ffeb1c2c..0b0700b0dd0 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.javacc.gradle
@@ -235,8 +235,7 @@ configure(project(":lucene:queryparser")) {
def extraConfig = [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
]
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
index cd68535221d..934e08e5bea 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.jflex.gradle
@@ -53,8 +53,7 @@ configure(project(":lucene:core")) {
def generateStandardTokenizer = wrapWithPersistentChecksums(generateStandardTokenizerInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -157,8 +156,7 @@ configure(project(":lucene:analysis:common")) {
def generateUAX29URLEmailTokenizer = wrapWithPersistentChecksums(generateUAX29URLEmailTokenizerInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -213,8 +211,7 @@ configure(project(":lucene:analysis:common")) {
def extraConfig = [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
]
@@ -307,11 +304,12 @@ class JFlexTask extends DefaultTask {
value: 'SuppressWarnings({"fallthrough","unused"})'
)
- // Correct line endings for Windows.
- project.ant.fixcrlf(
+ // Seems like a bug in gjf. https://github.com/google/google-java-format/issues/1260
+ project.ant.replace(
file: target,
encoding: "UTF-8",
- eol: "lf"
+ token: '/* Break so we don\'t hit fall-through warning: */',
+ value: ''
)
}
}
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.moman.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.moman.gradle
index 0c6fd998bf2..ede74cee631 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.moman.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.moman.gradle
@@ -112,8 +112,7 @@ configure(project(":lucene:core")) {
def extraConfig = [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
]
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.snowball.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.snowball.gradle
index acbf8bcf700..c27599bb875 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.snowball.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.snowball.gradle
@@ -114,8 +114,7 @@ configure(project(":lucene:analysis:common")) {
regenerate.dependsOn wrapWithPersistentChecksums(snowballInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
ignoreWithSource: [
downloadSnowballStemmers,
diff --git a/build-tools/build-infra/src/main/groovy/lucene.regenerate.unicode-test-classes.gradle b/build-tools/build-infra/src/main/groovy/lucene.regenerate.unicode-test-classes.gradle
index ef8e5b51437..d76d6b77121 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.regenerate.unicode-test-classes.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.regenerate.unicode-test-classes.gradle
@@ -46,8 +46,7 @@ configure(project(":lucene:test-framework")) {
}
regenerate.dependsOn wrapWithPersistentChecksums(generateEmojiTokenizationTestInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
@@ -81,8 +80,7 @@ configure(project(":lucene:test-framework")) {
regenerate.dependsOn wrapWithPersistentChecksums(generateJavaUnicodeWordBreakTestInternal, [
andThenTasks: [
- "spotlessJava",
- "spotlessJavaApply"
+ "applyGoogleJavaFormat"
],
mustRunBefore: ["compileJava"]
])
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.ecj-lint.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.ecj-lint.gradle
index 204cc5d9fa2..9f6bec29a64 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.ecj-lint.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.ecj-lint.gradle
@@ -1,4 +1,4 @@
-import com.diffplug.gradle.spotless.SpotlessApply
+import org.apache.lucene.gradle.plugins.spotless.ApplyGoogleJavaFormatTask
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -76,7 +76,7 @@ def lintTasks = sourceSets.collect { SourceSet sourceSet ->
dependsOn sourceSet.compileClasspath
dependsOn ecjConfiguration
- mustRunAfter tasks.withType(SpotlessApply)
+ mustRunAfter tasks.withType(ApplyGoogleJavaFormatTask)
// The inputs are all source files from the sourceSet.
inputs.files sourceSet.allSource.asFileTree
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.google-java-format.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.google-java-format.gradle
new file mode 100644
index 00000000000..655d2e2b90a
--- /dev/null
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.google-java-format.gradle
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.gradle.plugins.spotless.ApplyGoogleJavaFormatTask
+import org.apache.lucene.gradle.plugins.spotless.CheckGoogleJavaFormatTask
+
+/*
+ * This adds automatic (and enforced) code formatting using
+ * google-java-format (LUCENE-9564, GITHUB-14824).
+ */
+configure(allprojects) {prj ->
+ Provider<Integer> batchSizeOption = buildOptions.addIntOption(
+ "lucene.gjf.batchSize", "Sets the batch size for google-java-format tasks.", 5)
+
+ plugins.withType(JavaPlugin).configureEach {
+ def applyGoogleJavaFormat = tasks.register("applyGoogleJavaFormat", ApplyGoogleJavaFormatTask)
+
+ def checkGoogleJavaFormat = tasks.register("checkGoogleJavaFormat", CheckGoogleJavaFormatTask, {
+ colorizedOutput = !rootProject.ext.isCIBuild
+ mustRunAfter applyGoogleJavaFormat
+ })
+
+ [
+ checkGoogleJavaFormat,
+ applyGoogleJavaFormat
+ ].each {
+ it.configure {
+ batchSize.set(batchSizeOption)
+
+ if (project.path == ":lucene:build-tools:build-infra-shadow") {
+ sourceFiles = rootProject.fileTree("build-tools/build-infra/src", {
+ include "**/*.java"
+ })
+ } else {
+ sourceFiles = project.fileTree("src", {
+ include "**/*.java"
+
+ switch (prj.path) {
+ case ":lucene:core":
+ exclude("**/StandardTokenizerImpl.java")
+ break
+
+ case ":lucene:analysis:common":
+ exclude("**/HTMLStripCharFilter.java",
+ "**/UAX29URLEmailTokenizerImpl.java")
+ break
+
+ case ":lucene:test-framework":
+ exclude("**/EmojiTokenizationTestUnicode_11_0.java",
+ "**/WordBreakTestUnicode_9_0_0.java")
+ break
+
+ case ":lucene:queryparser":
+ exclude("**/classic/ParseException.java",
+ "**/classic/QueryParser.java",
+ "**/classic/QueryParserConstants.java",
+ "**/classic/QueryParserTokenManager.java",
+ "**/classic/Token.java",
+ "**/classic/TokenMgrError.java",
+ "**/standard/parser/ParseException.java",
+ "**/standard/parser/StandardSyntaxParser.java",
+ "**/standard/parser/StandardSyntaxParserConstants.java",
+ "**/standard/parser/StandardSyntaxParserTokenManager.java",
+ "**/standard/parser/Token.java",
+ "**/standard/parser/TokenMgrError.java",
+ "**/surround/parser/ParseException.java",
+ "**/surround/parser/QueryParser.java",
+ "**/surround/parser/QueryParserConstants.java",
+ "**/surround/parser/QueryParserTokenManager.java",
+ "**/surround/parser/Token.java",
+ "**/surround/parser/TokenMgrError.java")
+ break
+ }
+ })
+ }
+ }
+ }
+
+ // Connect to check and tidy tasks.
+ tasks.named("tidy").configure {v ->
+ v.dependsOn applyGoogleJavaFormat
+ }
+
+ tasks.named("check").configure {v ->
+ v.dependsOn checkGoogleJavaFormat
+ }
+ }
+}
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.rat-sources.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.rat-sources.gradle
index 3ac9e2eac00..28d63c16c52 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.rat-sources.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.rat-sources.gradle
@@ -48,6 +48,7 @@ allprojects {
if (project.path == ":") {
exclude "lucene"
exclude "**/build"
+ include "build-tools/build-infra/**"
} else {
exclude subprojects.collect { it.projectDir.name }
}
@@ -61,6 +62,9 @@ allprojects {
include "**/*.sh"
include "**/*.bat"
+ // Any .gradle folder in composite or top-level project.
+ exclude "**/.gradle/**"
+
// Include selected patterns from any source folders. We could make this
// relative to source sets but it seems to be of little value - all our source sets
// live under 'src' anyway.
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
index 1aa501beb60..346ef48fea5 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
@@ -63,9 +63,9 @@ if (!spotlessGradleScriptsOption.get()) {
}
tasks.named("spotlessGradleScripts").configure {
- mustRunAfter ":lucene:build-tools:missing-doclet:spotlessJava"
+ mustRunAfter ":lucene:build-tools:missing-doclet:applyGoogleJavaFormat"
mustRunAfter ":lucene:build-tools:missing-doclet:renderJavadoc"
- mustRunAfter ":lucene:build-tools:build-infra-shadow:spotlessJava"
+ mustRunAfter ":lucene:build-tools:build-infra-shadow:applyGoogleJavaFormat"
mustRunAfter ":lucene:build-tools:build-infra-shadow:pluginUnderTestMetadata"
mustRunAfter ":lucene:build-tools:build-infra-shadow:pluginDescriptors"
}
diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-java.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-java.gradle
deleted file mode 100644
index 4c7ef644529..00000000000
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-java.gradle
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import com.diffplug.gradle.spotless.SpotlessPlugin
-import com.diffplug.spotless.LineEnding
-
-/*
- * LUCENE-9564: This adds automatic (and enforced) code formatting using
- * spotless and Google Java Format.
- */
-
-configure(allprojects) { prj ->
- plugins.apply(SpotlessPlugin)
-
- plugins.withType(JavaPlugin).configureEach {
- spotless {
- java {
- lineEndings = LineEnding.UNIX
- endWithNewline()
- googleJavaFormat(deps.versions.googleJavaFormat.get())
- removeUnusedImports()
-
- // Apply to all Java sources
- target("src/**/*.java")
-
- // Exclude certain files (generated ones, mostly).
- switch (prj.path) {
- case ":lucene:build-tools:build-infra-shadow":
- target = sourceSets.main.allJava.sourceDirectories
- break
-
- case ":lucene:core":
- targetExclude("**/StandardTokenizerImpl.java")
- break
-
- case ":lucene:analysis:common":
- targetExclude("**/HTMLStripCharFilter.java",
- "**/UAX29URLEmailTokenizerImpl.java")
- break
-
- case ":lucene:test-framework":
- targetExclude("**/EmojiTokenizationTestUnicode_11_0.java",
- "**/WordBreakTestUnicode_9_0_0.java")
- break
-
- case ":lucene:expressions":
- break
-
- case ":lucene:queryparser":
- targetExclude("**/classic/ParseException.java",
- "**/classic/QueryParser.java",
- "**/classic/QueryParserConstants.java",
- "**/classic/QueryParserTokenManager.java",
- "**/classic/Token.java",
- "**/classic/TokenMgrError.java",
- "**/standard/parser/ParseException.java",
- "**/standard/parser/StandardSyntaxParser.java",
- "**/standard/parser/StandardSyntaxParserConstants.java",
- "**/standard/parser/StandardSyntaxParserTokenManager.java",
- "**/standard/parser/Token.java",
- "**/standard/parser/TokenMgrError.java",
- "**/surround/parser/ParseException.java",
- "**/surround/parser/QueryParser.java",
- "**/surround/parser/QueryParserConstants.java",
- "**/surround/parser/QueryParserTokenManager.java",
- "**/surround/parser/Token.java",
- "**/surround/parser/TokenMgrError.java")
- break
- }
- }
- }
-
- // Schedule the core formatting task to run after Java compilation (GH-12012)
- spotlessJava {
- mustRunAfter tasks.withType(JavaCompile)
- }
- }
-
- // Emit a custom message about how to fix formatting errors.
- tasks.matching { task -> task.name == "spotlessJavaCheck" }.configureEach {
- it.runToFixMessage.set("\nIMPORTANT: run the top-level './gradlew tidy' to " +
- "format the code automatically (see help/formatting.txt for more info).")
- }
-
- // Hook up spotless to tidy and check tasks.
- tasks.named("tidy").configure { v ->
- v.dependsOn tasks.matching { it.name == "spotlessApply" }
- v.dependsOn ":checkJdkInternalsExportedToGradle"
- }
-
- tasks.named("check").configure { v ->
- v.dependsOn tasks.matching { it.name == "spotlessCheck" }
- v.dependsOn ":checkJdkInternalsExportedToGradle"
- }
-}
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/astgrep/AstGrepPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/astgrep/AstGrepPlugin.java
index 0744e68cfc6..315210d0428 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/astgrep/AstGrepPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/astgrep/AstGrepPlugin.java
@@ -62,7 +62,8 @@ public class AstGrepPlugin implements Plugin<Project> {
if (!astToolOption.isPresent()) {
task.getLogger()
.warn(
- "The ast-grep tool location is not set ('{}' option), will not apply ast-grep rules.",
+ "The ast-grep tool location is not set ('{}' option), will not apply"
+ + " ast-grep rules.",
optionName);
}
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
index c607c8a5787..3621ce9df5b 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
@@ -75,6 +75,7 @@ public class BuildOptionGroupsPlugin implements Plugin<Project> {
"Build control and information",
explicitList(
"lucene.spotlessGradleScripts",
+ "lucene.gjf.batchSize",
"task.times",
"javac.failOnWarnings",
"tests.slowestSuites",
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ApplyGoogleJavaFormatTask.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ApplyGoogleJavaFormatTask.java
new file mode 100644
index 00000000000..c7a8434afd0
--- /dev/null
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ApplyGoogleJavaFormatTask.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gradle.plugins.spotless;
+
+import com.google.googlejavaformat.java.FormatterException;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+import javax.inject.Inject;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.tasks.TaskAction;
+import org.gradle.work.DisableCachingByDefault;
+import org.gradle.work.InputChanges;
+import org.gradle.workers.WorkAction;
+import org.gradle.workers.WorkParameters;
+import org.gradle.workers.WorkQueue;
+
+@DisableCachingByDefault
+public abstract class ApplyGoogleJavaFormatTask extends ParentGoogleJavaFormatTask {
+ @Inject
+ public ApplyGoogleJavaFormatTask(ProjectLayout layout) {
+ super(layout, "apply");
+ }
+
+ @TaskAction
+ public void formatSources(InputChanges inputChanges) throws IOException {
+ WorkQueue workQueue = getWorkQueue();
+ List<File> sourceFiles = getIncrementalBatch(inputChanges);
+ if (sourceFiles.isEmpty()) {
+ return;
+ }
+
+ getLogger()
+ .info(
+ "Will apply formatting to {} source {} in this run.",
+ sourceFiles.size(),
+ sourceFiles.size() == 1 ? "file" : "files");
+
+ for (var batch : batchSourceFiles(sourceFiles)) {
+ workQueue.submit(
+ ApplyGoogleJavaFormatAction.class,
+ params -> {
+ params.getTargetFiles().setFrom(batch);
+ });
+ }
+
+ Path taskOutput = getOutputChangeListFile().get().getAsFile().toPath();
+ Files.writeString(
+ taskOutput, sourceFiles.stream().map(File::getPath).collect(Collectors.joining("\n")));
+
+ workQueue.await();
+ }
+
+ public abstract static class ApplyGoogleJavaFormatAction
+ implements WorkAction<ApplyGoogleJavaFormatAction.Parameters> {
+ public interface Parameters extends WorkParameters {
+ ConfigurableFileCollection getTargetFiles();
+ }
+
+ @Override
+ public void execute() {
+ var formatter = getFormatter();
+
+ for (File inputFile : getParameters().getTargetFiles().getFiles()) {
+ var inputPath = inputFile.toPath();
+ try {
+ String input = Files.readString(inputPath);
+ String output = applyFormatter(formatter, input);
+
+ if (!input.equals(output)) {
+ Files.writeString(inputPath, output);
+ }
+ } catch (FormatterException | IOException e) {
+ throw new RuntimeException("Could not format file: " + inputPath, e);
+ }
+ }
+ }
+ }
+}
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/CheckGoogleJavaFormatTask.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/CheckGoogleJavaFormatTask.java
new file mode 100644
index 00000000000..70f2de3030a
--- /dev/null
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/CheckGoogleJavaFormatTask.java
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gradle.plugins.spotless;
+
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Splitter;
+import com.google.googlejavaformat.java.FormatterException;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import javax.inject.Inject;
+import org.eclipse.jgit.diff.DiffFormatter;
+import org.eclipse.jgit.diff.EditList;
+import org.eclipse.jgit.diff.MyersDiff;
+import org.eclipse.jgit.diff.RawText;
+import org.eclipse.jgit.diff.RawTextComparator;
+import org.gradle.api.GradleException;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.FileSystemOperations;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.file.RegularFileProperty;
+import org.gradle.api.provider.Property;
+import org.gradle.api.tasks.Input;
+import org.gradle.api.tasks.TaskAction;
+import org.gradle.internal.logging.text.StyledTextOutput;
+import org.gradle.internal.logging.text.StyledTextOutput.Style;
+import org.gradle.internal.logging.text.StyledTextOutputFactory;
+import org.gradle.work.DisableCachingByDefault;
+import org.gradle.work.InputChanges;
+import org.gradle.workers.WorkAction;
+import org.gradle.workers.WorkParameters;
+import org.gradle.workers.WorkQueue;
+
+/**
+ * Verifies formatting against google java format.
+ *
+ * <p>Diffing code is borrowed from <a
+ * href="https://github.com/diffplug/spotless/blob/main/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java#L46">spotless</a>.
+ */
+@DisableCachingByDefault
+public abstract class CheckGoogleJavaFormatTask extends ParentGoogleJavaFormatTask {
+ @Input
+ public abstract Property<Boolean> getColorizedOutput();
+
+ @Input
+ public abstract Property<Integer> getOutputLimit();
+
+ @Inject
+ protected abstract FileSystemOperations getFilesystemOperations();
+
+ @Inject
+ protected abstract StyledTextOutputFactory getStyledOutput();
+
+ @Inject
+ public CheckGoogleJavaFormatTask(ProjectLayout layout) {
+ super(layout, "check");
+ getColorizedOutput().convention(true);
+ getOutputLimit().convention(1024 * 1024 * 2);
+ }
+
+ @TaskAction
+ public void formatSources(InputChanges inputChanges) throws IOException {
+ WorkQueue workQueue = getWorkQueue();
+ List<File> sourceFiles = getIncrementalBatch(inputChanges);
+ if (sourceFiles.isEmpty()) {
+ return;
+ }
+
+ getLogger()
+ .info(
+ "Will check the formatting of {} source {} in this run.",
+ sourceFiles.size(),
+ sourceFiles.size() == 1 ? "file" : "files");
+
+ int outputSeq = 0;
+ File tempDir = new File(getTemporaryDir(), "changes");
+ if (Files.exists(tempDir.toPath())) {
+ getFilesystemOperations().delete(spec -> spec.delete(tempDir));
+ }
+ Files.createDirectory(tempDir.toPath());
+
+ for (List<File> batch : batchSourceFiles(sourceFiles)) {
+ final int seq = outputSeq;
+ workQueue.submit(
+ CheckGoogleJavaFormatAction.class,
+ params -> {
+ params.getTargetFiles().setFrom(batch);
+ params.getOutputFile().set(new File(tempDir, "gjf-check-" + seq + ".txt"));
+ });
+ outputSeq++;
+ }
+ workQueue.await();
+
+ // Check if there are any changes.
+ try (Stream<Path> stream = Files.list(tempDir.toPath()).sorted()) {
+ var allChanges = stream.toList();
+
+ if (!allChanges.isEmpty()) {
+ var errorMsg =
+ "java file(s) have google-java-format violations (run './gradlew tidy' to fix).";
+
+ if (getColorizedOutput().getOrElse(false)) {
+ printChangesToColorizedTerminal(allChanges, errorMsg);
+ } else {
+ printChangesToLogger(allChanges, errorMsg);
+ }
+
+ throw new GradleException(errorMsg);
+ }
+ }
+
+ Path taskOutput = getOutputChangeListFile().get().getAsFile().toPath();
+ Files.writeString(
+ taskOutput, sourceFiles.stream().map(File::getPath).collect(Collectors.joining("\n")));
+ }
+
+ private void printChangesToColorizedTerminal(List<Path> allChanges, String errorMsg)
+ throws IOException {
+ var out = getStyledOutput().create(this.getClass());
+
+ out.withStyle(Style.Failure).append(errorMsg).append(" An overview diff of changes:\n");
+
+ var normalLineStyle = Style.Normal;
+ var removedLineStyle = Style.Failure;
+ var addedLineStyle = Style.Success;
+ var fileNameLineStyle = Style.Description;
+
+ int limit = getOutputLimit().get();
+ int writtenChars = 0;
+ for (Path changeset : allChanges) {
+ if (writtenChars > limit) {
+ out.append("\n(...and more, omitted)");
+ break;
+ }
+
+ String diff = Files.readString(changeset);
+ for (var line : Splitter.on('\n').split(diff)) {
+ StyledTextOutput currentStyle;
+ if (line.startsWith("@@") || line.startsWith("==")) {
+ currentStyle = out.style(fileNameLineStyle);
+ } else if (line.startsWith("-")) {
+ currentStyle = out.style(removedLineStyle);
+ } else if (line.startsWith("+")) {
+ currentStyle = out.style(addedLineStyle);
+ } else {
+ currentStyle = out.style(normalLineStyle);
+ }
+
+ currentStyle.append(line).append("\n");
+ }
+
+ writtenChars += diff.length();
+ }
+ out.println();
+ }
+
+ private void printChangesToLogger(List<Path> allChanges, String errorMsg) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ int limit = getOutputLimit().get();
+ for (Path changeset : allChanges) {
+ if (sb.length() > limit) {
+ sb.append("\n(...and more, omitted)");
+ break;
+ }
+
+ sb.append(Files.readString(changeset));
+ sb.append("\n");
+ }
+
+ getLogger().error(errorMsg + " An overview diff of changes:\n" + sb);
+ }
+
+ public abstract static class CheckGoogleJavaFormatAction
+ implements WorkAction<CheckGoogleJavaFormatAction.Parameters> {
+ public interface Parameters extends WorkParameters {
+ ConfigurableFileCollection getTargetFiles();
+
+ RegularFileProperty getOutputFile();
+ }
+
+ @Override
+ public void execute() {
+ var formatter = getFormatter();
+ var outputFile = getParameters().getOutputFile().get().getAsFile().toPath();
+ Writer diffOutput = null;
+ for (File inputFile : getParameters().getTargetFiles().getFiles()) {
+ var inputPath = inputFile.toPath();
+ try {
+ String input = Files.readString(inputPath);
+ String expected = applyFormatter(formatter, input);
+
+ if (!input.equals(expected)) {
+ if (diffOutput == null) {
+ diffOutput = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8);
+ }
+
+ diffOutput.write("== " + inputPath + "\n");
+ writeDiff(diffOutput, input, expected);
+ }
+ } catch (FormatterException | IOException e) {
+ throw new RuntimeException("Could not format file: " + inputPath, e);
+ }
+ }
+
+ try {
+ if (diffOutput != null) {
+ diffOutput.close();
+ }
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ /**
+ * Let's try to display a short diff of what's changed. This is informational only, really -
+ * nobody should care (or try to fix those manually).
+ */
+ private static void writeDiff(Writer diffOutput, String input, String expected)
+ throws IOException {
+ var difference = diffWhitespaceLineEndings(input, expected, true, true);
+ diffOutput.write(difference);
+ diffOutput.write("\n");
+ }
+
+ /** Returns a git-style diff between the two unix strings. */
+ private static String diffWhitespaceLineEndings(
+ String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
+ dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings);
+ clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings);
+
+ RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8));
+ RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8));
+ EditList edits = new EditList();
+ edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try (DiffFormatter formatter = new DiffFormatter(out)) {
+ formatter.format(edits, a, b);
+ }
+ String formatted = out.toString(StandardCharsets.UTF_8);
+
+ // we don't need the diff to show this, since we display newlines ourselves
+ formatted = formatted.replace("\\ No newline at end of file\n", "");
+
+ CharMatcher NEWLINE_MATCHER = CharMatcher.is('\n');
+ return NEWLINE_MATCHER.trimTrailingFrom(formatted);
+ }
+
+ /**
+ * Makes the whitespace and/or the lineEndings visible.
+ *
+ * <p>MyersDiff wants inputs with only unix line endings. So this ensures that that is the case.
+ */
+ private static String visibleWhitespaceLineEndings(
+ String input, boolean whitespace, boolean lineEndings) {
+ final char MIDDLE_DOT = '·';
+
+ if (whitespace) {
+ input = input.replace(' ', MIDDLE_DOT).replace("\t", "\\t");
+ }
+ if (lineEndings) {
+ input = input.replace("\r", "\\r");
+ } else {
+ // we want only \n, so if we didn't replace them above, we'll replace them here.
+ input = input.replace("\r", "");
+ }
+ return input;
+ }
+ }
+}
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java
new file mode 100644
index 00000000000..1049111037e
--- /dev/null
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gradle.plugins.spotless;
+
+import com.google.common.collect.Iterables;
+import com.google.googlejavaformat.java.Formatter;
+import com.google.googlejavaformat.java.FormatterException;
+import com.google.googlejavaformat.java.ImportOrderer;
+import com.google.googlejavaformat.java.JavaFormatterOptions;
+import com.google.googlejavaformat.java.RemoveUnusedImports;
+import java.io.File;
+import java.util.List;
+import java.util.stream.StreamSupport;
+import javax.inject.Inject;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.FileType;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.file.RegularFileProperty;
+import org.gradle.api.provider.Property;
+import org.gradle.api.tasks.Input;
+import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.Internal;
+import org.gradle.api.tasks.OutputFile;
+import org.gradle.api.tasks.PathSensitive;
+import org.gradle.api.tasks.PathSensitivity;
+import org.gradle.work.ChangeType;
+import org.gradle.work.FileChange;
+import org.gradle.work.Incremental;
+import org.gradle.work.InputChanges;
+import org.gradle.workers.WorkQueue;
+import org.gradle.workers.WorkerExecutor;
+
+abstract class ParentGoogleJavaFormatTask extends DefaultTask {
+ /***
+ * The number of files to pass to a work action in a single batch.
+ */
+ @Input
+ public abstract Property<Integer> getBatchSize();
+
+ @Incremental
+ @InputFiles
+ @PathSensitive(PathSensitivity.RELATIVE)
+ public abstract ConfigurableFileCollection getSourceFiles();
+
+ @OutputFile
+ public abstract RegularFileProperty getOutputChangeListFile();
+
+ @Inject
+ protected abstract WorkerExecutor getWorkerExecutor();
+
+ public ParentGoogleJavaFormatTask(ProjectLayout layout, String gjfTask) {
+ getOutputChangeListFile()
+ .convention(layout.getBuildDirectory().file("gjf-" + gjfTask + ".txt"));
+ getBatchSize().convention(1);
+ }
+
+ protected Iterable<List<File>> batchSourceFiles(List<File> sourceFiles) {
+ return Iterables.partition(sourceFiles, getBatchSize().get());
+ }
+
+ protected static Formatter getFormatter() {
+ JavaFormatterOptions options =
+ JavaFormatterOptions.builder()
+ .style(JavaFormatterOptions.Style.GOOGLE)
+ .formatJavadoc(true)
+ .reorderModifiers(true)
+ .build();
+ return new Formatter(options);
+ }
+
+ protected List<File> getIncrementalBatch(InputChanges inputChanges) {
+ return StreamSupport.stream(inputChanges.getFileChanges(getSourceFiles()).spliterator(), false)
+ .filter(
+ fileChange -> {
+ return fileChange.getFileType() == FileType.FILE
+ && (fileChange.getChangeType() == ChangeType.ADDED
+ || fileChange.getChangeType() == ChangeType.MODIFIED);
+ })
+ .map(FileChange::getFile)
+ .toList();
+ }
+
+ protected static String applyFormatter(Formatter formatter, String input)
+ throws FormatterException {
+ // Correct line endings, if there are any oddities.
+ if (input.indexOf('\r') >= 0) {
+ // replace windows sequences first,
+ input = input.replace("\r\n", "\n");
+ // then just remove any CRs
+ input = input.replaceAll("\\r", "");
+ }
+
+ // Add trailing LF if the last character isn't an LF already. We don't
+ // care about blanks because we'll reformat everything anyway.
+ if (!input.isEmpty() && input.charAt(input.length() - 1) != '\n') {
+ input = input + "\n";
+ }
+
+ input = ImportOrderer.reorderImports(input, JavaFormatterOptions.Style.GOOGLE);
+ input = RemoveUnusedImports.removeUnusedImports(input);
+ input = formatter.formatSource(input);
+ return input;
+ }
+
+ @Internal
+ protected WorkQueue getWorkQueue() {
+ // TODO: maybe fork a separate jvm so that we can pass open-module settings there and fine-tune
+ // the jvm for the task?
+ return getWorkerExecutor().noIsolation();
+ }
+}
diff --git a/build.gradle b/build.gradle
index ce7e5fba413..38103a6ad4e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -38,7 +38,7 @@ plugins {
id "lucene.java.modules"
id "lucene.validation.spotless-groovy"
- id "lucene.validation.spotless-java"
+ id "lucene.validation.google-java-format"
id "lucene.validation.lockfile"
id "lucene.validation.gradle-versions-cleanup"
id "lucene.validation.gradlew-scripts-customizations"
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index b9cff8c627b..1a79c7ac683 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -14,7 +14,7 @@ ecj = "4.36M1"
errorprone = "2.38.0"
# markdown documentation generation
flexmark = "0.64.8"
-# @keep This is GJF version for spotless/ tidy source code formatting
+# @keep This is GJF version for java source code formatting
googleJavaFormat = "1.23.0"
# gradle build support
groovy = "4.0.27"
@@ -26,6 +26,8 @@ icu4j = "77.1"
javacc = "7.0.13"
# analysis/ tokenizer grammars
jflex = "1.9.1"
+# build infra only (diff of changes from google java format tasks)
+jgit = "7.3.0.202506031305-r"
# benchmark-jmh/ microbenchmarks
jmh = "1.37"
# spatial-extras/ support
@@ -72,11 +74,13 @@ flexmark-ext-abbreviation = { module = "com.vladsch.flexmark:flexmark-ext-abbrev
flexmark-ext-attributes = { module = "com.vladsch.flexmark:flexmark-ext-attributes", version.ref = "flexmark" }
flexmark-ext-autolink = { module = "com.vladsch.flexmark:flexmark-ext-autolink", version.ref = "flexmark" }
flexmark-ext-tables = { module = "com.vladsch.flexmark:flexmark-ext-tables", version.ref = "flexmark" }
+gjf = { module = "com.google.googlejavaformat:google-java-format", version.ref = "googleJavaFormat" }
groovy = { module = "org.apache.groovy:groovy-all", version.ref = "groovy" }
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" }
icu4j = { module = "com.ibm.icu:icu4j", version.ref = "icu4j" }
javacc = { module = "net.java.dev.javacc:javacc", version.ref = "javacc" }
jflex = { module = "de.jflex:jflex", version.ref = "jflex" }
+jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "jgit" }
jmh-annprocess = { module = "org.openjdk.jmh:jmh-generator-annprocess", version.ref = "jmh" }
jmh-core = { module = "org.openjdk.jmh:jmh-core", version.ref = "jmh" }
jts = { module = "org.locationtech.jts:jts-core", version.ref = "jts" }
diff --git a/gradle/template.gradle.properties b/gradle/template.gradle.properties
index a5ffcb5da63..ee6f5ffa2df 100644
--- a/gradle/template.gradle.properties
+++ b/gradle/template.gradle.properties
@@ -4,7 +4,7 @@
#
# The first invocation of any task in Lucene gradlew will generate and save this project-local 'gradle.properties' file.
# This file contains the defaults you may (but don't have to) tweak for your particular hardware (or taste). Note there
-# are certain settings in that file that may be _required_ at runtime for certain plugins (an example is the spotless/
+# are certain settings in that file that may be _required_ at runtime for certain plugins (an example is the
# google java format plugin, which requires adding custom exports to JVM modules). gradlew only generates this file
# if it's not already present (it never overwrites the defaults) -- occasionally you may have to manually delete (or move)
# this file and regenerate from scratch.
@@ -70,7 +70,7 @@ systemProp.file.encoding=UTF-8
# Set up gradle JVM defaults.
#
-# We also open up internal compiler modules for spotless/ google java format.
+# We also open up internal compiler modules for google java format.
org.gradle.jvmargs=-Xmx1g -XX:ReservedCodeCacheSize=256m -XX:TieredStopAtLevel=1 -XX:+UseParallelGC \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
diff --git a/lucene/analysis/common/src/generated/checksums/generateClassicTokenizer.json b/lucene/analysis/common/src/generated/checksums/generateClassicTokenizer.json
index 0acde0adb0e..6e10924b54a 100644
--- a/lucene/analysis/common/src/generated/checksums/generateClassicTokenizer.json
+++ b/lucene/analysis/common/src/generated/checksums/generateClassicTokenizer.json
@@ -1,5 +1,5 @@
{
"gradle/regenerate/jflex/skeleton.default.txt": "58944f66c9113a940dfaf6a17210ec8219024390",
- "lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java": "db0247e6c18327d1e21eb8f37495d81488655ff6",
+ "lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java": "edf60483d07543dad3167dab6dd6f000980c13d8",
"lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.jflex": "db33fb08d340110cfa1d71299898b8082a0091d8"
}
diff --git a/lucene/analysis/common/src/generated/checksums/generateWikipediaTokenizer.json b/lucene/analysis/common/src/generated/checksums/generateWikipediaTokenizer.json
index 586735f9792..d1148adba68 100644
--- a/lucene/analysis/common/src/generated/checksums/generateWikipediaTokenizer.json
+++ b/lucene/analysis/common/src/generated/checksums/generateWikipediaTokenizer.json
@@ -1,5 +1,5 @@
{
"gradle/regenerate/jflex/skeleton.default.txt": "58944f66c9113a940dfaf6a17210ec8219024390",
- "lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java": "288850d5a05c0428e7bd3aaf8d1204fdd5043746",
+ "lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java": "8288c966869ed17b7f1cc271513012b7fef707fb",
"lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.jflex": "0b8c7774b98e8237702013e82c352d4711509bd0"
}
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java
index c58db919ac1..a67e6a120f0 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/classic/ClassicTokenizerImpl.java
@@ -752,7 +752,6 @@ class ClassicTokenizerImpl {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
{
- /* Break so we don't hit fall-through warning: */
break; /* ignore */
}
// fall through
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java
index 301dc709dab..f3d85558d60 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/wikipedia/WikipediaTokenizerImpl.java
@@ -906,7 +906,7 @@ class WikipediaTokenizerImpl {
case 1:
{
numWikiTokensSeen = 0;
- positionInc = 1; /* Break so we don't hit fall-through warning: */
+ positionInc = 1;
break;
}
// fall through
@@ -925,7 +925,7 @@ class WikipediaTokenizerImpl {
numWikiTokensSeen = 0;
positionInc = 1;
currentTokType = EXTERNAL_LINK_URL;
- yybegin(EXTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(EXTERNAL_LINK_STATE);
break;
}
// fall through
@@ -941,7 +941,7 @@ class WikipediaTokenizerImpl {
break;
case 5:
{
- positionInc = 1; /* Break so we don't hit fall-through warning: */
+ positionInc = 1;
break;
}
// fall through
@@ -967,7 +967,6 @@ class WikipediaTokenizerImpl {
break;
case 8:
{
- /* Break so we don't hit fall-through warning: */
break; /* ignore */
}
// fall through
@@ -993,7 +992,7 @@ class WikipediaTokenizerImpl {
{
numLinkToks = 0;
positionInc = 0;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break;
}
// fall through
@@ -1002,7 +1001,7 @@ class WikipediaTokenizerImpl {
case 11:
{
currentTokType = BOLD;
- yybegin(THREE_SINGLE_QUOTES_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(THREE_SINGLE_QUOTES_STATE);
break;
}
// fall through
@@ -1022,7 +1021,7 @@ class WikipediaTokenizerImpl {
{
currentTokType = EXTERNAL_LINK;
numWikiTokensSeen = 0;
- yybegin(EXTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(EXTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1051,7 +1050,7 @@ class WikipediaTokenizerImpl {
{
currentTokType = SUB_HEADING;
numWikiTokensSeen = 0;
- yybegin(STRING); /* Break so we don't hit fall-through warning: */
+ yybegin(STRING);
break;
}
// fall through
@@ -1068,7 +1067,6 @@ class WikipediaTokenizerImpl {
break;
case 18:
{
- /* Break so we don't hit fall-through warning: */
break; /* ignore STRING */
}
// fall through
@@ -1088,7 +1086,7 @@ class WikipediaTokenizerImpl {
numBalanced = 0;
numWikiTokensSeen = 0;
currentTokType = EXTERNAL_LINK;
- yybegin(EXTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(EXTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1111,7 +1109,7 @@ class WikipediaTokenizerImpl {
yybegin(TWO_SINGLE_QUOTES_STATE);
} else {
numBalanced = 0;
- } /* Break so we don't hit fall-through warning: */
+ }
break;
}
// fall through
@@ -1121,7 +1119,7 @@ class WikipediaTokenizerImpl {
{
numWikiTokensSeen = 0;
positionInc = 1;
- yybegin(DOUBLE_EQUALS_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(DOUBLE_EQUALS_STATE);
break;
}
// fall through
@@ -1132,7 +1130,7 @@ class WikipediaTokenizerImpl {
numWikiTokensSeen = 0;
positionInc = 1;
currentTokType = INTERNAL_LINK;
- yybegin(INTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(INTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1143,7 +1141,7 @@ class WikipediaTokenizerImpl {
numWikiTokensSeen = 0;
positionInc = 1;
currentTokType = CITATION;
- yybegin(DOUBLE_BRACE_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(DOUBLE_BRACE_STATE);
break;
}
// fall through
@@ -1151,7 +1149,7 @@ class WikipediaTokenizerImpl {
break;
case 26:
{
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break;
}
// fall through
@@ -1160,7 +1158,7 @@ class WikipediaTokenizerImpl {
case 27:
{
numLinkToks = 0;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break;
}
// fall through
@@ -1170,7 +1168,7 @@ class WikipediaTokenizerImpl {
{
currentTokType = INTERNAL_LINK;
numWikiTokensSeen = 0;
- yybegin(INTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(INTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1180,7 +1178,7 @@ class WikipediaTokenizerImpl {
{
currentTokType = INTERNAL_LINK;
numWikiTokensSeen = 0;
- yybegin(INTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(INTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1188,7 +1186,7 @@ class WikipediaTokenizerImpl {
break;
case 30:
{
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break;
}
// fall through
@@ -1198,7 +1196,7 @@ class WikipediaTokenizerImpl {
{
numBalanced = 0;
currentTokType = ALPHANUM;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break; /*end italics*/
}
// fall through
@@ -1209,7 +1207,7 @@ class WikipediaTokenizerImpl {
numBalanced = 0;
numWikiTokensSeen = 0;
currentTokType = INTERNAL_LINK;
- yybegin(INTERNAL_LINK_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(INTERNAL_LINK_STATE);
break;
}
// fall through
@@ -1250,7 +1248,7 @@ class WikipediaTokenizerImpl {
case 37:
{
currentTokType = BOLD_ITALICS;
- yybegin(FIVE_SINGLE_QUOTES_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(FIVE_SINGLE_QUOTES_STATE);
break;
}
// fall through
@@ -1260,7 +1258,7 @@ class WikipediaTokenizerImpl {
{
numBalanced = 0;
currentTokType = ALPHANUM;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break; /*end bold*/
}
// fall through
@@ -1270,7 +1268,7 @@ class WikipediaTokenizerImpl {
{
numBalanced = 0;
currentTokType = ALPHANUM;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break; /*end sub header*/
}
// fall through
@@ -1296,7 +1294,7 @@ class WikipediaTokenizerImpl {
{
numBalanced = 0;
currentTokType = ALPHANUM;
- yybegin(YYINITIAL); /* Break so we don't hit fall-through warning: */
+ yybegin(YYINITIAL);
break; /*end bold italics*/
}
// fall through
@@ -1317,7 +1315,7 @@ class WikipediaTokenizerImpl {
numWikiTokensSeen = 0;
positionInc = 1;
currentTokType = CATEGORY;
- yybegin(CATEGORY_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(CATEGORY_STATE);
break;
}
// fall through
@@ -1327,7 +1325,7 @@ class WikipediaTokenizerImpl {
{
currentTokType = CATEGORY;
numWikiTokensSeen = 0;
- yybegin(CATEGORY_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(CATEGORY_STATE);
break;
}
// fall through
@@ -1338,7 +1336,7 @@ class WikipediaTokenizerImpl {
numBalanced = 0;
numWikiTokensSeen = 0;
currentTokType = CATEGORY;
- yybegin(CATEGORY_STATE); /* Break so we don't hit fall-through warning: */
+ yybegin(CATEGORY_STATE);
break;
}
// fall through
diff --git a/lucene/core/src/generated/checksums/generateStandardTokenizer.json b/lucene/core/src/generated/checksums/generateStandardTokenizer.json
index 74455660c18..bf532d0abb8 100644
--- a/lucene/core/src/generated/checksums/generateStandardTokenizer.json
+++ b/lucene/core/src/generated/checksums/generateStandardTokenizer.json
@@ -1,5 +1,5 @@
{
"gradle/regenerate/jflex/skeleton.disable.buffer.expansion.txt": "6e43a3a64a9b5eb82ec5b4bc21f95aff5a2a061e",
- "lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java": "58d4856f55dda7cecfb7bd938b90614aee566cb4",
+ "lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java": "f4d6311e03a97cb55301cfa55fab3338b1fdb725",
"lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.jflex": "6dd5ea9741b13281378be5680fdcc2bc2aef3aec"
}
diff --git a/lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java b/lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java
index c79aea42949..24bbcf1274e 100644
--- a/lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java
+++ b/lucene/core/src/java/org/apache/lucene/analysis/standard/StandardTokenizerImpl.java
@@ -1082,7 +1082,7 @@ public final class StandardTokenizerImpl {
else {
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 1:
- { /* Break so we don't hit fall-through warning: */ break; /* Not numeric, word, ideographic, hiragana, emoji or SE Asian -- ignore it. */
+ { break; /* Not numeric, word, ideographic, hiragana, emoji or SE Asian -- ignore it. */
}
// fall through
case 10: break;