Skip to content

Commit 46414f5

Browse files
author
Vladimir Kotal
authored
Opt parser private (#2265)
1 parent ba599c9 commit 46414f5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public final class Indexer {
104104
private static RuntimeEnvironment env = null;
105105
private static String host = null;
106106

107-
public static OptionParser openGrok = null;
107+
private static OptionParser optParser = null;
108108

109109
public static Indexer getInstance() {
110110
return index;
@@ -319,7 +319,7 @@ public static void main(String argv[]) {
319319
System.exit(1);
320320
} catch (IndexerException ex) {
321321
LOGGER.log(Level.SEVERE, "Exception running indexer", ex);
322-
System.err.println(openGrok.getUsage());
322+
System.err.println(optParser.getUsage());
323323
System.exit(1);
324324
} catch (Throwable e) {
325325
LOGGER.log(Level.SEVERE, "Unexpected Exception", e);
@@ -402,7 +402,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
402402
// An example of how to add a data type for option parsing
403403
OptionParser.accept(WebAddress.class, s -> { return parseWebAddress(s); });
404404

405-
openGrok = OptionParser.Do(parser -> {
405+
optParser = OptionParser.Do(parser -> {
406406
parser.setPrologue(
407407
String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program));
408408

@@ -779,7 +779,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
779779

780780
cfg.setHistoryEnabled(false); // force user to turn on history capture
781781

782-
argv = openGrok.parse(argv);
782+
argv = optParser.parse(argv);
783783

784784
return argv;
785785
}

opengrok-indexer/src/test/java/org/opengrok/indexer/util/OptionParserTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.Test;
3030
import static org.junit.Assert.*;
3131

32+
import java.lang.reflect.Field;
3233
import java.text.ParseException;
3334
import org.opengrok.indexer.index.Indexer;
3435

@@ -524,12 +525,16 @@ public void catchNamelessOption() {
524525

525526
// Fail options put into Indexer.java that do not have a description.
526527
@Test
527-
public void catchIndexerOptionsWithoutDescription() {
528+
public void catchIndexerOptionsWithoutDescription() throws NoSuchFieldException, IllegalAccessException {
528529
String[] argv = {"---unitTest"};
529530
try {
530531
Indexer.parseOptions(argv);
531-
OptionParser op = Indexer.openGrok;
532-
532+
533+
// Use reflection to get the option parser from Indexer.
534+
Field f = Indexer.class.getDeclaredField("optParser");
535+
f.setAccessible(true);
536+
OptionParser op = (OptionParser) f.get(Indexer.class);
537+
533538
for (OptionParser.Option o : op.getOptionList()) {
534539
if (o.description == null) {
535540
fail("'"+o.names.get(0) + "' option needs description");

0 commit comments

Comments
 (0)