Skip to content

Commit ed29753

Browse files
committed
Revise LuceneLockName as enum per review
1 parent 736e80e commit ed29753

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.configuration;
2525

@@ -179,7 +179,7 @@ public final class Configuration {
179179
*/
180180
@Deprecated
181181
private boolean usingLuceneLocking;
182-
private String luceneLocking = LuceneLockName.OFF;
182+
private LuceneLockName luceneLocking = LuceneLockName.OFF;
183183
private boolean compressXref;
184184
private boolean indexVersionedFilesOnly;
185185
private int indexingParallelism;
@@ -407,6 +407,7 @@ public Configuration() {
407407
setIncludedNames(new Filter());
408408
setIndexVersionedFilesOnly(false);
409409
setLastEditedDisplayMode(true);
410+
//luceneLocking default is OFF
410411
setMandoc(System.getProperty("org.opensolaris.opengrok.analysis.Mandoc", null));
411412
setMaxSearchThreadCount(2 * Runtime.getRuntime().availableProcessors());
412413
setMessageLimit(500);
@@ -942,15 +943,15 @@ public void setUsingLuceneLocking(boolean useLuceneLocking) {
942943
LuceneLockName.OFF);
943944
}
944945

945-
public String getLuceneLocking() {
946+
public LuceneLockName getLuceneLocking() {
946947
return luceneLocking;
947948
}
948949

949950
/**
950951
* @param value off|on|simple|native where "on" is an alias for "simple".
951952
* Any other value is a fallback alias for "off" (with a logged warning).
952953
*/
953-
public void setLuceneLocking(String value) {
954+
public void setLuceneLocking(LuceneLockName value) {
954955
this.luceneLocking = value;
955956
// Set the following to default(boolean) regardless of `value'.
956957
this.usingLuceneLocking = false;

src/org/opensolaris/opengrok/configuration/LuceneLockName.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,20 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, Chris Fraire <[email protected]>.
21+
* Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2222
*/
2323

2424
package org.opensolaris.opengrok.configuration;
2525

2626
/**
2727
* Represents a container for OpenGrok's names of Lucene lock modes.
2828
*/
29-
public class LuceneLockName {
30-
public static final String OFF = "off";
29+
public enum LuceneLockName {
30+
OFF,
3131
/**
3232
* An alias for {@link #SIMPLE}
3333
*/
34-
public static final String ON = "on";
35-
public static final String SIMPLE = "simple";
36-
public static final String NATIVE = "native";
37-
38-
/** private to enforce static */
39-
private LuceneLockName() {
40-
}
34+
ON,
35+
SIMPLE,
36+
NATIVE
4137
}

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.configuration;
2525

@@ -1047,7 +1047,7 @@ public void setOptimizeDatabase(boolean optimizeDatabase) {
10471047
threadConfig.get().setOptimizeDatabase(optimizeDatabase);
10481048
}
10491049

1050-
public String getLuceneLocking() {
1050+
public LuceneLockName getLuceneLocking() {
10511051
return threadConfig.get().getLuceneLocking();
10521052
}
10531053

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.index;
2525

@@ -1417,18 +1417,14 @@ private Writer getXrefWriter(FileAnalyzer fa, String path) throws IOException {
14171417
}
14181418

14191419
LockFactory pickLockFactory(RuntimeEnvironment env) {
1420-
String luceneLocking = env.getLuceneLocking();
1421-
switch (luceneLocking) {
1422-
case LuceneLockName.OFF:
1423-
return NoLockFactory.INSTANCE;
1424-
case LuceneLockName.ON:
1425-
case LuceneLockName.SIMPLE:
1420+
switch (env.getLuceneLocking()) {
1421+
case ON:
1422+
case SIMPLE:
14261423
return SimpleFSLockFactory.INSTANCE;
1427-
case LuceneLockName.NATIVE:
1424+
case NATIVE:
14281425
return NativeFSLockFactory.INSTANCE;
1426+
case OFF:
14291427
default:
1430-
LOGGER.log(Level.WARNING, "Unknown Lucene locking mode: {0}",
1431-
luceneLocking);
14321428
return NoLockFactory.INSTANCE;
14331429
}
14341430
}

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright 2011 Jens Elkner.
23-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2424
*/
2525
package org.opensolaris.opengrok.index;
2626

@@ -34,6 +34,7 @@
3434
import java.util.HashMap;
3535
import java.util.HashSet;
3636
import java.util.List;
37+
import java.util.Locale;
3738
import java.util.Map;
3839
import java.util.Map.Entry;
3940
import java.util.Set;
@@ -341,9 +342,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
341342
String program = "opengrok.jar";
342343
final String[] ON_OFF = {ON, OFF};
343344
final String[] REMOTE_REPO_CHOICES = {ON, OFF, DIRBASED, UIONLY};
344-
final String[] LUCENE_LOCKS = {LuceneLockName.ON,
345-
LuceneLockName.OFF, LuceneLockName.SIMPLE,
346-
LuceneLockName.NATIVE};
345+
final String[] LUCENE_LOCKS = {ON, OFF, "simple", "native"};
347346

348347
if (argv.length == 0) {
349348
argv = usage; // will force usage output
@@ -474,7 +473,15 @@ public static String[] parseOptions(String[] argv) throws ParseException {
474473
"Set OpenGrok/Lucene locking mode of the Lucene database",
475474
"during index generation. \"on\" is an alias for \"simple\".",
476475
"Default is off.").Do( v -> {
477-
cfg.setLuceneLocking((String)v);
476+
try {
477+
if (v != null) {
478+
String vuc = v.toString().toUpperCase(Locale.ROOT);
479+
cfg.setLuceneLocking(LuceneLockName.valueOf(vuc));
480+
}
481+
} catch (IllegalArgumentException e) {
482+
System.err.println(String.format(
483+
"`--lock %s' is invalid and ignored", v));
484+
}
478485
});
479486

480487
parser.on("--leadingWildCards", "=on|off", ON_OFF, Boolean.class,

test/org/opensolaris/opengrok/configuration/RuntimeEnvironmentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.configuration;
2525

@@ -439,7 +439,7 @@ public void testOptimizeDatabase() {
439439
@Test
440440
public void testUsingLuceneLocking() {
441441
RuntimeEnvironment instance = RuntimeEnvironment.getInstance();
442-
assertEquals("off", instance.getLuceneLocking());
442+
assertEquals(LuceneLockName.OFF, instance.getLuceneLocking());
443443
}
444444

445445
@Test

0 commit comments

Comments
 (0)