Skip to content

Commit 61dce4c

Browse files
committed
move configuration check to Configuration class
1 parent 202e6da commit 61dce4c

File tree

2 files changed

+58
-51
lines changed

2 files changed

+58
-51
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,4 +1535,45 @@ private static Configuration decodeObject(InputStream in) throws IOException {
15351535

15361536
return conf;
15371537
}
1538+
1539+
public static class ConfigurationException extends Exception {
1540+
static final long serialVersionUID = -1;
1541+
1542+
public ConfigurationException(String message) {
1543+
super(message);
1544+
}
1545+
}
1546+
1547+
/**
1548+
* Check if configuration is populated and self-consistent.
1549+
* @throws ConfigurationException on error
1550+
*/
1551+
public void checkConfiguration() throws ConfigurationException {
1552+
1553+
if (getSourceRoot() == null) {
1554+
throw new ConfigurationException("Source root is not specified.");
1555+
}
1556+
1557+
if (getDataRoot() == null) {
1558+
throw new ConfigurationException("Data root is not specified.");
1559+
}
1560+
1561+
if (!new File(getSourceRoot()).canRead()) {
1562+
throw new ConfigurationException("Source root directory '" + getSourceRoot() + "' must be readable.");
1563+
}
1564+
1565+
if (!new File(getDataRoot()).canWrite()) {
1566+
throw new ConfigurationException("Data root directory '" + getDataRoot() + "' must be writable.");
1567+
}
1568+
1569+
if (!isHistoryEnabled() && isHistoryBasedReindex()) {
1570+
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " +
1571+
"History has to be enabled for history based reindex.");
1572+
}
1573+
1574+
if (!isHistoryCache() && isHistoryBasedReindex()) {
1575+
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " +
1576+
"History cache has to be enabled for history based reindex.");
1577+
}
1578+
}
15381579
}

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

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ public static void main(String[] argv) {
190190
exitWithHelp();
191191
}
192192

193-
try {
194-
checkConfiguration();
195-
} catch (ConfigurationException e) {
196-
die(e.getMessage());
197-
}
193+
checkConfiguration();
198194

199195
if (awaitProfiler) {
200196
pauseToAwaitProfiler();
@@ -419,6 +415,22 @@ public static void main(String[] argv) {
419415
}
420416
}
421417

418+
private static void checkConfiguration() {
419+
if (bareConfig && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
420+
die("Missing webappURI setting");
421+
}
422+
423+
if (!repositories.isEmpty() && !cfg.isHistoryEnabled()) {
424+
die("Repositories were specified; history is off however");
425+
}
426+
427+
try {
428+
cfg.checkConfiguration();
429+
} catch (Configuration.ConfigurationException e) {
430+
die(e.getMessage());
431+
}
432+
}
433+
422434
/**
423435
* Parse OpenGrok Indexer options
424436
* This method was created so that it would be easier to write unit
@@ -887,52 +899,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
887899
return argv;
888900
}
889901

890-
static class ConfigurationException extends Exception {
891-
static final long serialVersionUID = -1;
892-
893-
public ConfigurationException(String message) {
894-
super(message);
895-
}
896-
}
897-
898-
// TODO: move this Configuration
899-
private static void checkConfiguration() throws ConfigurationException {
900-
env = RuntimeEnvironment.getInstance();
901-
902-
if (bareConfig && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
903-
throw new ConfigurationException("Missing webappURI setting");
904-
}
905-
906-
if (!repositories.isEmpty() && !cfg.isHistoryEnabled()) {
907-
throw new ConfigurationException("Repositories were specified; history is off however");
908-
}
909-
910-
if (cfg.getSourceRoot() == null) {
911-
throw new ConfigurationException("Please specify a SRC_ROOT with option -s !");
912-
}
913-
if (cfg.getDataRoot() == null) {
914-
throw new ConfigurationException("Please specify a DATA ROOT path");
915-
}
916-
917-
if (!new File(cfg.getSourceRoot()).canRead()) {
918-
throw new ConfigurationException("Source root '" + cfg.getSourceRoot() + "' must be readable");
919-
}
920-
921-
if (!new File(cfg.getDataRoot()).canWrite()) {
922-
throw new ConfigurationException("Data root '" + cfg.getDataRoot() + "' must be writable");
923-
}
924-
925-
if (!cfg.isHistoryEnabled() && cfg.isHistoryBasedReindex()) {
926-
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " +
927-
"History has to be enabled for history based reindex.");
928-
}
929-
930-
if (!cfg.isHistoryCache() && cfg.isHistoryBasedReindex()) {
931-
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " +
932-
"History cache has to be enabled for history based reindex.");
933-
}
934-
}
935-
936902
private static void die(String message) {
937903
System.err.println("ERROR: " + message);
938904
System.exit(1);

0 commit comments

Comments
 (0)