Skip to content

Commit cd560f8

Browse files
author
Vladimir Kotal
authored
print list of analyzers with -h guru (#3495)
fixes #3494
1 parent 8e5e103 commit cd560f8

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public static Map<String, String> getfileTypeDescriptions() {
391391
return Collections.unmodifiableMap(fileTypeDescriptions);
392392
}
393393

394-
public List<AnalyzerFactory> getAnalyzerFactories() {
394+
public static List<AnalyzerFactory> getAnalyzerFactories() {
395395
return Collections.unmodifiableList(factories);
396396
}
397397

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuruHelp.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/*
21+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2122
* Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.analysis;
@@ -48,26 +49,38 @@ private AnalyzerGuruHelp() {
4849
*/
4950
public static String getUsage() {
5051
StringBuilder b = new StringBuilder();
51-
b.append("AnalyzerGuru prefixes:\n");
52+
53+
b.append("List of analyzers:" + System.lineSeparator());
54+
b.append("The names of the analyzers (left column) can be used for the -A indexer option:" +
55+
System.lineSeparator() + System.lineSeparator());
56+
byFactory(AnalyzerGuru.getAnalyzerFactories().stream().
57+
collect(Collectors.toMap(f -> f.getClass().getSimpleName(), f -> f))).
58+
forEach((factory) -> {
59+
b.append(String.format("%-10s : %s%n",
60+
factory.fac.getClass().getSimpleName().replace("AnalyzerFactory", ""),
61+
factory.fac.getName() != null ? factory.fac.getName() : "N/A"));
62+
});
63+
64+
b.append(System.lineSeparator() + "AnalyzerGuru prefixes:" + System.lineSeparator());
5265
byKey(AnalyzerGuru.getPrefixesMap()).forEach((kv) -> {
53-
b.append(String.format("%-10s : %s\n", reportable(kv.key + '*'),
66+
b.append(String.format("%-10s : %s%n", reportable(kv.key + '*'),
5467
reportable(kv.fac)));
5568
});
5669

57-
b.append("\nAnalyzerGuru extensions:\n");
70+
b.append(System.lineSeparator() + "AnalyzerGuru extensions:" + System.lineSeparator());
5871
byKey(AnalyzerGuru.getExtensionsMap()).forEach((kv) -> {
59-
b.append(String.format("*.%-7s : %s\n",
72+
b.append(String.format("*.%-7s : %s%n",
6073
reportable(kv.key.toLowerCase(Locale.ROOT)),
6174
reportable(kv.fac)));
6275
});
6376

64-
b.append("\nAnalyzerGuru magic strings:\n");
77+
b.append(System.lineSeparator() + "AnalyzerGuru magic strings:" + System.lineSeparator());
6578
byFactory(AnalyzerGuru.getMagicsMap()).forEach((kv) -> {
66-
b.append(String.format("%-23s : %s\n", reportable(kv.key),
79+
b.append(String.format("%-23s : %s%n", reportable(kv.key),
6780
reportable(kv.fac)));
6881
});
6982

70-
b.append("\nAnalyzerGuru magic matchers:\n");
83+
b.append(System.lineSeparator() + "AnalyzerGuru magic matchers:" + System.lineSeparator());
7184
AnalyzerGuru.getAnalyzerFactoryMatchers().forEach((m) -> {
7285
if (m.getIsPreciseMagic()) {
7386
b.append(reportable(m));
@@ -121,7 +134,7 @@ private static String reportable(String value) {
121134
}
122135

123136
private static String reportable(FileAnalyzerFactory.Matcher m) {
124-
final String MATCHER_FMT = "%-11s %-1s %s\n";
137+
final String MATCHER_FMT = "%-11s %-1s %s%n";
125138
StringBuilder b = new StringBuilder();
126139
String[] lines = splitLines(m.description(), 66);
127140
for (int i = 0; i < lines.length; ++i) {
@@ -172,8 +185,7 @@ private static String[] splitLines(String str, int width) {
172185
return res.stream().toArray(String[]::new);
173186
}
174187

175-
private static List<MappedFactory> byKey(
176-
Map<String, AnalyzerFactory> mapped) {
188+
private static List<MappedFactory> byKey(Map<String, AnalyzerFactory> mapped) {
177189

178190
List<MappedFactory> res = mapped.entrySet().stream().map((t) -> {
179191
return new MappedFactory(t.getKey(), t.getValue());
@@ -186,8 +198,7 @@ private static List<MappedFactory> byKey(
186198
return res;
187199
}
188200

189-
private static List<MappedFactory> byFactory(
190-
Map<String, AnalyzerFactory> mapped) {
201+
private static List<MappedFactory> byFactory(Map<String, AnalyzerFactory> mapped) {
191202

192203
List<MappedFactory> res = mapped.entrySet().stream().map((t) -> {
193204
return new MappedFactory(t.getKey(), t.getValue());

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/MandocAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.document;

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/document/MandocAnalyzerFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Copyright (c) 2017, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis.document;
@@ -32,7 +32,7 @@
3232

3333
public class MandocAnalyzerFactory extends FileAnalyzerFactory {
3434

35-
private static final String NAME = "Mandoc";
35+
private static final String NAME = "Manual pages";
3636

3737
public static final Matcher MATCHER = new Matcher() {
3838
@Override

opengrok-indexer/src/test/java/org/opengrok/indexer/analysis/LuceneCompatibilityTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.analysis;
@@ -89,7 +89,7 @@ protected void setUp() throws Exception {
8989
}
9090

9191
public void testCompatibility() throws Exception {
92-
for (AnalyzerFactory fa : guru.getAnalyzerFactories()) {
92+
for (AnalyzerFactory fa : AnalyzerGuru.getAnalyzerFactories()) {
9393
String input = "Hello world";
9494
String[] output = new String[]{"Hello", "world"};
9595
testA = fa.getAnalyzer();

0 commit comments

Comments
 (0)