Skip to content

Commit ee305c2

Browse files
authored
Add markdown support for javadocs and modernize highlighting a bit. (#15568)
1 parent ccf5b59 commit ee305c2

10 files changed

Lines changed: 100 additions & 78 deletions

File tree

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/java/RenderJavadocPlugin.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,17 @@ public void render() throws IOException {
566566
getTaskResources(),
567567
"table_padding.css",
568568
"custom_styles.css",
569-
"prettify/prettify.css");
569+
"prettify/prettify.css",
570+
"prettify/prism.css");
570571

571572
// append prettify to scripts
572573
Provider<RegularFile> customScript = getOutputDir().file("script-files/lucene-script.js");
573574
concat(
574-
customScript, getTaskResources().dir("prettify"), "prettify.js", "inject-javadocs.js");
575+
customScript,
576+
getTaskResources().dir("prettify"),
577+
"prettify.js",
578+
"inject-javadocs.js",
579+
"prism.js");
575580

576581
opts.add(List.of("--add-script", customScript.get().getAsFile().toString()));
577582
opts.add(List.of("--add-stylesheet", customCss.get().getAsFile().toString()));

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class ParentGoogleJavaFormatTask extends DefaultTask {
7676
@Internal
7777
protected abstract RegularFileProperty getFileStateCache();
7878

79-
private Function<File, String> fileToKey;
79+
private final Function<File, String> fileToKey;
8080

8181
public ParentGoogleJavaFormatTask(ProjectLayout layout, String gjfTask) {
8282
getOutputChangeListFile()

gradle/documentation/render-javadoc/prettify/prism.css

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/documentation/render-javadoc/prettify/prism.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ errorprone = "2.45.0"
1515
# markdown documentation generation
1616
flexmark = "0.64.8"
1717
# @keep This is GJF version for java source code formatting
18-
googleJavaFormat = "1.33.0"
18+
googleJavaFormat = "1.33.0-markdown"
1919
# gradle build support
2020
groovy = "5.0.3"
2121
# test assertions
@@ -72,7 +72,7 @@ flexmark-ext-abbreviation = { module = "com.vladsch.flexmark:flexmark-ext-abbrev
7272
flexmark-ext-attributes = { module = "com.vladsch.flexmark:flexmark-ext-attributes", version.ref = "flexmark" }
7373
flexmark-ext-autolink = { module = "com.vladsch.flexmark:flexmark-ext-autolink", version.ref = "flexmark" }
7474
flexmark-ext-tables = { module = "com.vladsch.flexmark:flexmark-ext-tables", version.ref = "flexmark" }
75-
gjf = { module = "com.google.googlejavaformat:google-java-format", version.ref = "googleJavaFormat" }
75+
gjf = { module = "com.carrotsearch.googlejavaformat:google-java-format", version.ref = "googleJavaFormat" }
7676
groovy = { module = "org.apache.groovy:groovy-all", version.ref = "groovy" }
7777
hamcrest = { module = "org.hamcrest:hamcrest", version.ref = "hamcrest" }
7878
icu4j = { module = "com.ibm.icu:icu4j", version.ref = "icu4j" }

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ New Features
7171
Improvements
7272
---------------------
7373

74+
* GITHUB#15568: Add markdown support for javadocs and modernize highlighting a bit. (Dawid Weiss)
75+
7476
* GITHUB#14972: Require named thread factory in ThreadPoolExecutor constructors. (Dawid Weiss)
7577

7678
* GITHUB#14597: Rewrite expressions compiler to use Java 24+ Classfile library instead of ASM.

lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapaneseBaseFormFilterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
/**
2424
* Factory for {@link org.apache.lucene.analysis.ja.JapaneseBaseFormFilter}.
2525
*
26-
* <pre class="prettyprint">
26+
* <pre><code class="language-xml">
2727
* &lt;fieldType name="text_ja" class="solr.TextField"&gt;
2828
* &lt;analyzer&gt;
2929
* &lt;tokenizer class="solr.JapaneseTokenizerFactory"/&gt;
3030
* &lt;filter class="solr.JapaneseBaseFormFilterFactory"/&gt;
3131
* &lt;/analyzer&gt;
3232
* &lt;/fieldType&gt;
33-
* </pre>
33+
* </code></pre>
3434
*
3535
* @since 3.6.0
3636
* @lucene.spi {@value #NAME}

lucene/core/src/java/org/apache/lucene/document/FeatureField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
* example, assuming that documents have a {@link FeatureField} called 'features' with values for
8989
* the 'pagerank' feature.
9090
*
91-
* <pre class="prettyprint">
91+
* <pre><code class="language-java">
9292
* Query query = new BooleanQuery.Builder()
9393
* .add(new TermQuery(new Term("body", "apache")), Occur.SHOULD)
9494
* .add(new TermQuery(new Term("body", "lucene")), Occur.SHOULD)
@@ -99,7 +99,7 @@
9999
* .add(boost, Occur.SHOULD)
100100
* .build();
101101
* TopDocs topDocs = searcher.search(boostedQuery, 10);
102-
* </pre>
102+
* </code></pre>
103103
*
104104
* @lucene.experimental
105105
*/

lucene/core/src/java/overview.html

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,37 @@
3030
code comes from org.apache.lucene.TestDemo.
3131
See LUCENE-8481 for reasons why it's out of sync with the code.
3232
-->
33-
<pre class="prettyprint">
34-
Analyzer analyzer = new StandardAnalyzer();
35-
36-
Path indexPath = Files.createTempDirectory("tempIndex");
37-
try (Directory directory = FSDirectory.open(indexPath)) {
38-
IndexWriterConfig config = new IndexWriterConfig(analyzer);
39-
try (IndexWriter iwriter = new IndexWriter(directory, config)) {
40-
Document doc = new Document();
41-
String text = "This is the text to be indexed.";
42-
doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
43-
iwriter.addDocument(doc);
44-
}
45-
46-
// Now search the index:
47-
try (DirectoryReader ireader = DirectoryReader.open(directory)) {
48-
IndexSearcher isearcher = new IndexSearcher(ireader);
49-
// Parse a simple query that searches for "text":
50-
QueryParser parser = new QueryParser("fieldname", analyzer);
51-
Query query = parser.parse("text");
52-
ScoreDoc[] hits = isearcher.search(query, 10).scoreDocs;
53-
assertEquals(1, hits.length);
54-
// Iterate through the results:
55-
StoredFields storedFields = isearcher.storedFields();
56-
for (int i = 0; i &lt; hits.length; i++) {
57-
Document hitDoc = storedFields.document(hits[i].doc);
58-
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
59-
}
60-
}
61-
} finally {
62-
IOUtils.rm(indexPath);
63-
}</pre>
33+
<pre><code class="language-java">
34+
Analyzer analyzer = new StandardAnalyzer();
35+
36+
Path indexPath = Files.createTempDirectory("tempIndex");
37+
try (Directory directory = FSDirectory.open(indexPath)) {
38+
IndexWriterConfig config = new IndexWriterConfig(analyzer);
39+
try (IndexWriter iwriter = new IndexWriter(directory, config)) {
40+
Document doc = new Document();
41+
String text = "This is the text to be indexed.";
42+
doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
43+
iwriter.addDocument(doc);
44+
}
45+
46+
// Now search the index:
47+
try (DirectoryReader ireader = DirectoryReader.open(directory)) {
48+
IndexSearcher isearcher = new IndexSearcher(ireader);
49+
// Parse a simple query that searches for "text":
50+
QueryParser parser = new QueryParser("fieldname", analyzer);
51+
Query query = parser.parse("text");
52+
ScoreDoc[] hits = isearcher.search(query, 10).scoreDocs;
53+
assertEquals(1, hits.length);
54+
// Iterate through the results:
55+
StoredFields storedFields = isearcher.storedFields();
56+
for (int i = 0; i &lt; hits.length; i++) {
57+
Document hitDoc = storedFields.document(hits[i].doc);
58+
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
59+
}
60+
}
61+
} finally {
62+
IOUtils.rm(indexPath);
63+
}</code></pre>
6464
<!-- ======================================================== -->
6565

6666

lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -210,49 +210,53 @@
210210
import org.junit.BeforeClass;
211211
import org.junit.ClassRule;
212212
import org.junit.Rule;
213-
import org.junit.Test;
214213
import org.junit.internal.AssumptionViolatedException;
215214
import org.junit.rules.RuleChain;
216215
import org.junit.rules.TestRule;
217216
import org.junit.runner.RunWith;
218217

219-
/**
220-
* Base class for all Lucene unit tests, Junit3 or Junit4 variant.
221-
*
222-
* <h2>Class and instance setup.</h2>
223-
*
224-
* <p>The preferred way to specify class (suite-level) setup/cleanup is to use static methods
225-
* annotated with {@link BeforeClass} and {@link AfterClass}. Any code in these methods is executed
226-
* within the test framework's control and ensure proper setup has been made. <b>Try not to use
227-
* static initializers (including complex final field initializers).</b> Static initializers are
228-
* executed before any setup rules are fired and may cause you (or somebody else) headaches.
229-
*
230-
* <p>For instance-level setup, use {@link Before} and {@link After} annotated methods. If you
231-
* override either {@link #setUp()} or {@link #tearDown()} in your subclass, make sure you call
232-
* <code>super.setUp()</code> and <code>super.tearDown()</code>. This is detected and enforced.
233-
*
234-
* <h2>Specifying test cases</h2>
235-
*
236-
* <p>Any test method with a <code>testXXX</code> prefix is considered a test case. Any test method
237-
* annotated with {@link Test} is considered a test case.
238-
*
239-
* <h2>Randomized execution and test facilities</h2>
240-
*
241-
* <p>{@link LuceneTestCase} uses {@link RandomizedRunner} to execute test cases. {@link
242-
* RandomizedRunner} has built-in support for tests randomization including access to a repeatable
243-
* {@link Random} instance. See {@link #random()} method. Any test using {@link Random} acquired
244-
* from {@link #random()} should be fully reproducible (assuming no race conditions between threads
245-
* etc.). The initial seed for a test case is reported in many ways:
246-
*
247-
* <ul>
248-
* <li>as part of any exception thrown from its body (inserted as a dummy stack trace entry),
249-
* <li>as part of the main thread executing the test case (if your test hangs, just dump the stack
250-
* trace of all threads and you'll see the seed),
251-
* <li>the master seed can also be accessed manually by getting the current context ({@link
252-
* RandomizedContext#current()}) and then calling {@link
253-
* RandomizedContext#getRunnerSeedAsString()}.
254-
* </ul>
255-
*/
218+
/// Base class for all Lucene unit tests (JUnit4 variant).
219+
///
220+
/// ## Class and instance setup
221+
///
222+
/// The preferred way to specify class (suite-level) setup/cleanup is to use static methods
223+
/// annotated with [BeforeClass] and [AfterClass]. Any code in these methods is executed
224+
/// within the test framework's control and ensure proper setup has been made. **Try not to use
225+
/// static initializers (including complex final field initializers).** Static initializers are
226+
/// executed before any setup rules are fired and may cause you (or somebody else) headaches.
227+
///
228+
/// For instance-level setup, use [Before] and [After] annotated methods. If you
229+
/// override either [#setUp()] or [#tearDown()] in your subclass, make sure you call
230+
/// `super.setUp()` and `super.tearDown()`. This is detected and enforced.
231+
///
232+
/// ## Specifying test cases
233+
///
234+
/// Any test method with a `testXXX` prefix is considered a test case. Any test method
235+
/// annotated with [org.junit.Test] is considered a test case. For example, these are equivalent
236+
/// declarations:
237+
///
238+
/// ```java
239+
/// public void testPrefixIsSufficient() {}
240+
///
241+
/// @Test
242+
/// public void annotationIsRequiredHere() {}
243+
/// ```
244+
///
245+
/// ## Randomized execution and test facilities
246+
///
247+
/// [LuceneTestCase] uses [RandomizedRunner] to execute test cases.
248+
/// [RandomizedRunner] has built-in support for tests randomization including access to a repeatable
249+
/// [Random] instance. See [#random()] method. Any test using [Random] acquired
250+
/// from [#random()] should be fully reproducible (assuming no race conditions between threads
251+
/// etc.). The initial seed for a test case is reported in many ways:
252+
///
253+
/// - as part of any exception thrown from its body (inserted as a dummy stack trace entry),
254+
/// - as part of the main thread executing the test case (if your test hangs, just dump the stack
255+
/// trace of all threads, and you'll see the seed),
256+
/// - the master seed can also be accessed manually by getting the current context (
257+
/// [RandomizedContext#current()]) and then calling
258+
/// [RandomizedContext#getRunnerSeedAsString()].
259+
///
256260
@RunWith(RandomizedRunner.class)
257261
@TestMethodProviders({LuceneJUnit3MethodProvider.class, JUnit4MethodProvider.class})
258262
@Listeners({RunListenerPrintReproduceInfo.class, FailureMarker.class})

0 commit comments

Comments
 (0)