Skip to content

Apache Lucene open-source search software

Go back to the official google-java-format distribution (#16713)

Dawid Weissdf6f71a3729a
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/GoogleJavaFormatPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/GoogleJavaFormatPlugin.java
index ae5cefbffe4..aa4c2fef48b 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/GoogleJavaFormatPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/GoogleJavaFormatPlugin.java
@@ -68,10 +68,16 @@ public class GoogleJavaFormatPlugin extends LuceneGradlePlugin {
tasks.named("check", check -> check.dependsOn(checkTask));
var fileStates = project.getLayout().getBuildDirectory().file("gjf-file-states.json");
+ var formatterVersion =
+ getVersionCatalog(project)
+ .findLibrary("gjf")
+ .orElseThrow()
+ .map(dep -> dep.getModule() + ":" + dep.getVersionConstraint().getRequiredVersion());
for (var t : List.of(applyTask, checkTask)) {
t.configure(
task -> {
task.getBatchSize().set(batchSizeOption);
+ task.getFormatterVersion().set(formatterVersion);
task.dependsOn(":" + CheckEnvironmentPlugin.TASK_CHECK_JDK_INTERNALS_EXPOSED_TO_GRADLE);
task.getFileStateCache().set(fileStates);
});
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
index f8d7c047bd0..d2d96419812 100644
--- 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
@@ -67,6 +67,13 @@ abstract class ParentGoogleJavaFormatTask extends DefaultTask {
@PathSensitive(PathSensitivity.RELATIVE)
public abstract ConfigurableFileCollection getSourceFiles();
+ /**
+ * The formatter's coordinates (module and version). Any change invalidates all cached file states
+ * so that every source file is processed again with the new formatter.
+ */
+ @Input
+ public abstract Property<String> getFormatterVersion();
+
@OutputFile
public abstract RegularFileProperty getOutputChangeListFile();
@@ -143,7 +150,9 @@ abstract class ParentGoogleJavaFormatTask extends DefaultTask {
if (pathProvider.isPresent()) {
Files.writeString(
pathProvider.get().getAsFile().toPath(),
- JsonOutput.prettyPrint(JsonOutput.toJson(fileStates)));
+ JsonOutput.prettyPrint(
+ JsonOutput.toJson(
+ Map.of("formatter", getFormatterVersion().get(), "files", fileStates))));
}
}
@@ -154,7 +163,13 @@ abstract class ParentGoogleJavaFormatTask extends DefaultTask {
if (Files.exists(path)) {
try {
@SuppressWarnings("unchecked")
- var saved = (Map<String, Map<String, Object>>) new JsonSlurper().parse(path);
+ var root = (Map<String, Object>) new JsonSlurper().parse(path);
+ if (!getFormatterVersion().get().equals(root.get("formatter"))) {
+ // The formatter changed, ignore all stored file states.
+ return checksums;
+ }
+ @SuppressWarnings("unchecked")
+ var saved = (Map<String, Map<String, Object>>) root.get("files");
var restored =
saved.entrySet().stream()
.collect(
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 38bff1e9f21..ee875dc2985 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -15,7 +15,7 @@ errorprone = "2.50.0"
# markdown documentation generation
flexmark = "0.64.8"
# @keep This is GJF version for java source code formatting
-googleJavaFormat = "1.33.0-markdown"
+googleJavaFormat = "1.36.1"
# gradle build support
groovy = "6.0.0"
# test assertions
@@ -74,7 +74,7 @@ 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.carrotsearch.googlejavaformat:google-java-format", version.ref = "googleJavaFormat" }
+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" }
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
index 29df5b1bc8d..0c8950ebca0 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/hyphenation/TernaryTree.java
@@ -22,8 +22,6 @@ import java.util.Deque;
import java.util.Enumeration;
/**
- *
- *
* <h2>Ternary Search Tree.</h2>
*
* <p>A ternary search tree is a hybrid between a binary tree and a digital search tree (trie). Keys
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java
index c1232197ed2..461ad518603 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/PerFieldAnalyzerWrapper.java
@@ -22,10 +22,11 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
/// This analyzer is used to facilitate scenarios where different fields require different analysis
-/// techniques. Use the Map argument in [#PerFieldAnalyzerWrapper(Analyzer, java.util.Map)] to
-/// add non-default analyzers for fields.
+/// techniques. Use the Map argument in [#PerFieldAnalyzerWrapper(Analyzer, java.util.Map)] to add
+/// non-default analyzers for fields.
///
/// Example usage:
+///
/// ```java
/// Map<String,Analyzer> analyzerPerField = new HashMap<>();
/// analyzerPerField.put("firstname", new KeywordAnalyzer());
@@ -35,8 +36,8 @@ import org.apache.lucene.analysis.DelegatingAnalyzerWrapper;
/// new PerFieldAnalyzerWrapper(new StandardAnalyzer(version), analyzerPerField);
/// ```
///
-/// In this example, StandardAnalyzer will be used for all fields except "firstname" and
-/// "lastname", for which KeywordAnalyzer will be used.
+/// In this example, StandardAnalyzer will be used for all fields except "firstname" and "lastname",
+/// for which KeywordAnalyzer will be used.
///
/// A PerFieldAnalyzerWrapper can be used like any other analyzer, for both indexing and query
/// parsing.
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java
index 02e19dd994b..d9752d4b428 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/pt/RSLPStemmerBase.java
@@ -46,9 +46,7 @@ import org.apache.lucene.analysis.CharArraySet;
* <p>The general rule format is:
*
* <blockquote>
- *
* { "suffix", N, "replacement", { "exception1", "exception2", ...}}
- *
* </blockquote>
*
* where:
@@ -67,9 +65,7 @@ import org.apache.lucene.analysis.CharArraySet;
* <p>A step is an ordered list of rules, with a structure in this format:
*
* <blockquote>
- *
* { "name", N, B, { "cond1", "cond2", ... } ... rules ... };
- *
* </blockquote>
*
* where:
diff --git a/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/ICUTransformFilter.java b/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/ICUTransformFilter.java
index afc54fcb6eb..17d4c484071 100644
--- a/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/ICUTransformFilter.java
+++ b/lucene/analysis/icu/src/java/org/apache/lucene/analysis/icu/ICUTransformFilter.java
@@ -46,9 +46,7 @@ import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
* <p>Example usage:
*
* <blockquote>
- *
* stream = new ICUTransformFilter(stream, Transliterator.getInstance("Traditional-Simplified"));
- *
* </blockquote>
*
* <br>
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/package-info.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/package-info.java
index 91088f43b27..64148750dd4 100644
--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/package-info.java
+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/package-info.java
@@ -99,13 +99,11 @@
* DocMaker and implementing QueryMaker.
*
* <blockquote>
- *
* <b>Note:</b> since 2.9, DocMaker is a concrete class which accepts a ContentSource. In most
* cases, you can use the DocMaker class to create Documents, while providing your own ContentSource
* implementation. For example, the current Benchmark package includes ContentSource implementations
* for TREC, Enwiki and Reuters collections, as well as others like LineDocSource which reads a
* 'line' file produced by WriteLineDocTask.
- *
* </blockquote>
*
* <p>Benchmark .alg file contains the benchmark "algorithm". The syntax is described below. Within
diff --git a/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java b/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java
index 3ddba160b44..4c475bd4e8a 100644
--- a/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java
+++ b/lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborArray.java
@@ -88,7 +88,8 @@ public class NeighborArray {
++sortedNodeSize;
}
- /// Grow the [#scores] and [#nodes] fields if they are full, up to [#maxSize]. Grow in larger steps.
+ /// Grow the [#scores] and [#nodes] fields if they are full, up to [#maxSize]. Grow in larger
+ /// steps.
private void growArrays() {
if (size == maxSize) {
throw new IllegalStateException("Cannot grow beyond maxSize: " + maxSize);
diff --git a/lucene/monitor/src/java/org/apache/lucene/monitor/package-info.java b/lucene/monitor/src/java/org/apache/lucene/monitor/package-info.java
index 9ee06fed075..c919d9789e0 100644
--- a/lucene/monitor/src/java/org/apache/lucene/monitor/package-info.java
+++ b/lucene/monitor/src/java/org/apache/lucene/monitor/package-info.java
@@ -16,8 +16,6 @@
*/
/**
- *
- *
* <h2>Monitoring framework</h2>
*
* This package contains classes to allow the monitoring of a stream of documents with a set of
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ModifierQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ModifierQueryNode.java
index e367b70e8c9..53877080c22 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ModifierQueryNode.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/core/nodes/ModifierQueryNode.java
@@ -28,11 +28,9 @@ import org.apache.lucene.queryparser.flexible.messages.MessageImpl;
* string. For example "+t1 -t2 t3" will have a tree of:
*
* <blockquote>
- *
* &lt;BooleanQueryNode&gt; &lt;ModifierQueryNode modifier="MOD_REQ"&gt; &lt;t1/&gt;
* &lt;/ModifierQueryNode&gt; &lt;ModifierQueryNode modifier="MOD_NOT"&gt; &lt;t2/&gt;
* &lt;/ModifierQueryNode&gt; &lt;t3/&gt; &lt;/BooleanQueryNode&gt;
- *
* </blockquote>
*/
public class ModifierQueryNode extends QueryNodeImpl {
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/package-info.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/package-info.java
index dba0de2e406..fcbe8cb47ea 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/package-info.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/parser/package-info.java
@@ -16,8 +16,6 @@
*/
/**
- *
- *
* <h2>Lucene Query Parser</h2>
*
* <p>The package org.apache.lucene.queryparser.flexible.standard.parser contains the query parser.
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
index e16b2ede269..171d832d5aa 100644
--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/simple/SimpleQueryParser.java
@@ -65,9 +65,7 @@ import org.apache.lucene.util.automaton.LevenshteinAutomata;
* will evaluate {@code token1 OR token2} first, then {@code AND} with {@code token3}:
*
* <blockquote>
- *
* token1 | token2 + token3
- *
* </blockquote>
*
* <b>Escaping</b>
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
index 18bbecd1725..dbe21490e5f 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
@@ -75,21 +75,19 @@ import org.junit.runner.RunWith;
/// ## Class and instance setup
///
/// The preferred way to specify class (suite-level) setup/cleanup is to use static methods
-/// annotated with [org.junit.BeforeClass] and [org.junit.AfterClass]. Any code in these methods
-/// is executed
-/// within the test framework's control and ensure proper setup has been made. **Try not to use
-/// static initializers (including complex final field initializers).** Static initializers are
+/// annotated with [org.junit.BeforeClass] and [org.junit.AfterClass]. Any code in these methods is
+/// executed within the test framework's control and ensure proper setup has been made. **Try not to
+/// use static initializers (including complex final field initializers).** Static initializers are
/// executed before any setup rules are fired and may cause you (or somebody else) headaches.
///
-/// For instance-level setup, use [Before] and [After] annotated methods. If you
-/// override either [#setUp()] or [#tearDown()] in your subclass, make sure you call
-/// `super.setUp()` and `super.tearDown()`. This is detected and enforced.
+/// For instance-level setup, use [Before] and [After] annotated methods. If you override either
+/// [#setUp()] or [#tearDown()] in your subclass, make sure you call `super.setUp()` and
+/// `super.tearDown()`. This is detected and enforced.
///
/// ## Specifying test cases
///
-/// Any test method with a `testXXX` prefix is considered a test case. Any test method
-/// annotated with [org.junit.Test] is considered a test case. For example, these are equivalent
-/// declarations:
+/// Any test method with a `testXXX` prefix is considered a test case. Any test method annotated
+/// with [org.junit.Test] is considered a test case. For example, these are equivalent declarations:
///
/// ```java
/// public void testPrefixIsSufficient() {}
@@ -100,19 +98,17 @@ import org.junit.runner.RunWith;
///
/// ## Randomized execution and test facilities
///
-/// [LuceneTestCase] uses [RandomizedRunner] to execute test cases.
-/// [RandomizedRunner] has built-in support for tests randomization including access to a repeatable
-/// [Random] instance. See [#random()] method. Any test using [Random] acquired
-/// from [#random()] should be fully reproducible (assuming no race conditions between threads
-/// etc.). The initial seed for a test case is reported in many ways:
-///
-/// - as part of any exception thrown from its body (inserted as a dummy stack trace entry),
-/// - as part of the main thread executing the test case (if your test hangs, just dump the stack
-/// trace of all threads, and you'll see the seed),
-/// - the master seed can also be accessed manually by getting the current context (
-/// [RandomizedContext#current()]) and then callingd
-/// [RandomizedContext#getRunnerSeedAsString()].
+/// [LuceneTestCase] uses [RandomizedRunner] to execute test cases. [RandomizedRunner] has built-in
+/// support for tests randomization including access to a repeatable [Random] instance. See
+/// [#random()] method. Any test using [Random] acquired from [#random()] should be fully
+/// reproducible (assuming no race conditions between threads etc.). The initial seed for a test
+/// case is reported in many ways:
///
+/// - as part of any exception thrown from its body (inserted as a dummy stack trace entry),
+/// - as part of the main thread executing the test case (if your test hangs, just dump the stack
+/// trace of all threads, and you'll see the seed),
+/// - the master seed can also be accessed manually by getting the current context (
+/// [RandomizedContext#current()]) and then callingd [RandomizedContext#getRunnerSeedAsString()].
@RunWith(RandomizedRunner.class)
@TestMethodProviders({LuceneJUnit3MethodProvider.class, JUnit4MethodProvider.class})
@Listeners({RunListenerPrintReproduceInfo.class, FailureMarker.class})
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseJupiter.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseJupiter.java
index e0be5b494d9..ebd6865444d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseJupiter.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCaseJupiter.java
@@ -68,8 +68,8 @@ import org.opentest4j.TestAbortedException;
/// ## Class and instance setup
///
/// The preferred way to specify class (suite-level) setup/cleanup is to use static methods
-/// annotated with [org.junit.jupiter.api.BeforeAll] and [org.junit.jupiter.api.AfterAll].
-/// **Do not use static initializers (including complex final field initializers).**
+/// annotated with [org.junit.jupiter.api.BeforeAll] and [org.junit.jupiter.api.AfterAll]. **Do not
+/// use static initializers (including complex final field initializers).**
///
/// For instance-level setup, use [org.junit.jupiter.api.BeforeEach] and
/// [org.junit.jupiter.api.AfterEach] annotated methods.
@@ -77,6 +77,7 @@ import org.opentest4j.TestAbortedException;
/// ## Specifying test cases
///
/// Any method of specifying JUnit jupiter tests will work. The most common way would therefore be:
+///
/// ```java
/// @Test
/// public void testMethod(Random random) {}
@@ -86,15 +87,13 @@ import org.opentest4j.TestAbortedException;
///
/// ## Randomized execution and test facilities
///
-/// [LuceneTestCaseJupiter] uses the [Randomized] extension to support component randomization.
-/// A [Random] can be automatically injected in the test (or any junit5 callback) as a parameter.
-/// Tests should be fully reproducible for the same initial seed
-/// (assuming no race conditions between threads
-/// etc.). The initial seed for a test case is reported in many ways:
-///
-/// - logged from the gradle build,
-/// - inserted as a synthetic stack frame in any exceptions.
+/// [LuceneTestCaseJupiter] uses the [Randomized] extension to support component randomization. A
+/// [Random] can be automatically injected in the test (or any junit5 callback) as a parameter.
+/// Tests should be fully reproducible for the same initial seed (assuming no race conditions
+/// between threads etc.). The initial seed for a test case is reported in many ways:
///
+/// - logged from the gradle build,
+/// - inserted as a synthetic stack frame in any exceptions.
/*
TODO: port the remaining infrastructure bits from LuceneTestCase:
- there are class rules and test rules that are still only on junit4 side
@@ -182,9 +181,9 @@ public abstract non-sealed class LuceneTestCaseJupiter extends LuceneTestCasePar
}
}
- /// Tracks whether any test in the current suite had a failure.
- /// Registered before [ClassLevelCallbackChain] so its state is available during suite teardown.
- /// We plug into multiple jupiter extensions, hoping they will be sufficient to detect failure
+ /// Tracks whether any test in the current suite had a failure. Registered before
+ /// [ClassLevelCallbackChain] so its state is available during suite teardown. We plug into
+ /// multiple jupiter extensions, hoping they will be sufficient to detect failure
// state.
static final class SuiteFailureTracker
implements AfterAllCallback,
@@ -264,11 +263,11 @@ public abstract non-sealed class LuceneTestCaseJupiter extends LuceneTestCasePar
}
}
- /// This extension sets up junit-jupiter implementations of the
- /// test framework-dependent infrastructure in [LuceneTestCaseParent].
+ /// This extension sets up junit-jupiter implementations of the test framework-dependent
+ /// infrastructure in [LuceneTestCaseParent].
///
- /// It tries to simulate before-after rules as they are implemented in junit4
- /// (call order, unwinding in case of failures, etc.).
+ /// It tries to simulate before-after rules as they are implemented in junit4 (call order,
+ /// unwinding in case of failures, etc.).
static class ClassLevelCallbackChain
implements BeforeAllCallback, AfterAllCallback, AfterEachCallback {
private final SuiteFailureTracker suiteFailureTracker;
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestLuceneTestCaseJupiter.java b/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestLuceneTestCaseJupiter.java
index a1333834c4a..f37241e99a4 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestLuceneTestCaseJupiter.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/util/TestLuceneTestCaseJupiter.java
@@ -125,8 +125,8 @@ public class TestLuceneTestCaseJupiter {
}
}
- /// Test cases should use parameter-injected [java.util.Random] or a supplier
- /// of [java.util.Random]. Avoid using static methods.
+ /// Test cases should use parameter-injected [java.util.Random] or a supplier of
+ /// [java.util.Random]. Avoid using static methods.
@Nested
class RandomInjection {
@Test
@@ -298,8 +298,8 @@ public class TestLuceneTestCaseJupiter {
}
}
- /// Verifies that failing to close a [org.apache.lucene.store.Directory] created during
- /// a test causes a test failure, mirroring the behavior of [TestFailIfDirectoryNotClosed]
+ /// Verifies that failing to close a [org.apache.lucene.store.Directory] created during a test
+ /// causes a test failure, mirroring the behavior of [TestFailIfDirectoryNotClosed]
@Nested
class UnclosedDirectoryTracking {
@Test