Skip to content

Commit 202e6da

Browse files
committed
do not consider history vs. history based reindex as configuration problem
1 parent ea354d5 commit 202e6da

File tree

1 file changed

+40
-25
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/index

1 file changed

+40
-25
lines changed

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

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

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

195199
if (awaitProfiler) {
196200
pauseToAwaitProfiler();
@@ -573,7 +577,20 @@ public static String[] parseOptions(String[] argv) throws ParseException {
573577
"Assign commit tags to all entries in history for all repositories.").execute(v ->
574578
cfg.setTagsEnabled(true));
575579

576-
parser.on("-H", "--history", "Enable history.").execute(v -> cfg.setHistoryEnabled(true));
580+
// for backward compatibility
581+
parser.on("-H", "Enable history.").execute(v -> cfg.setHistoryEnabled(true));
582+
583+
parser.on("--historyBased", "=on|off", ON_OFF, Boolean.class,
584+
"If history based reindex is in effect, the set of files ",
585+
"changed/deleted since the last reindex is determined from history ",
586+
"of the repositories. This needs history, history cache and ",
587+
"projects to be enabled. This should be much faster than the ",
588+
"classic way of traversing the directory structure. ",
589+
"The default is on. If you need to e.g. index files untracked by ",
590+
"SCM, set this to off. Currently works only for Git.",
591+
"All repositories in a project need to support this in order ",
592+
"to be indexed using history.").
593+
execute(v -> cfg.setHistoryBasedReindex((Boolean) v));
577594

578595
parser.on("--historyThreads", "=number", Integer.class,
579596
"The number of threads to use for history cache generation on repository level. " +
@@ -801,18 +818,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
801818
}
802819
});
803820

804-
parser.on("--historyBased", "=on|off", ON_OFF, Boolean.class,
805-
"If history based reindex is in effect, the set of files ",
806-
"changed/deleted since the last reindex is determined from history ",
807-
"of the repositories. This needs history, history cache and ",
808-
"projects to be enabled. This should be much faster than the ",
809-
"classic way of traversing the directory structure. ",
810-
"The default is on. If you need to e.g. index files untracked by ",
811-
"SCM, set this to off. Currently works only for Git.",
812-
"All repositories in a project need to support this in order ",
813-
"to be indexed using history.").
814-
execute(v -> cfg.setHistoryBasedReindex((Boolean) v));
815-
816821
parser.on("-U", "--uri", "=SCHEME://webappURI:port/contextPath",
817822
"Send the current configuration to the specified web application.").execute(webAddr -> {
818823
webappURI = (String) webAddr;
@@ -866,8 +871,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
866871
execute(v -> cfg.setWebappCtags((Boolean) v));
867872
});
868873

869-
// Need to read the configuration file first
870-
// so that options may be overwritten later.
874+
// Need to read the configuration file first, so that options may be overwritten later.
871875
configure.parse(argv);
872876

873877
LOGGER.log(Level.INFO, "Indexer options: {0}", Arrays.toString(argv));
@@ -883,38 +887,49 @@ public static String[] parseOptions(String[] argv) throws ParseException {
883887
return argv;
884888
}
885889

886-
private static void checkConfiguration() {
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 {
887900
env = RuntimeEnvironment.getInstance();
888901

889902
if (bareConfig && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
890-
die("Missing webappURI setting");
903+
throw new ConfigurationException("Missing webappURI setting");
891904
}
892905

893906
if (!repositories.isEmpty() && !cfg.isHistoryEnabled()) {
894-
die("Repositories were specified; history is off however");
907+
throw new ConfigurationException("Repositories were specified; history is off however");
895908
}
896909

897910
if (cfg.getSourceRoot() == null) {
898-
die("Please specify a SRC_ROOT with option -s !");
911+
throw new ConfigurationException("Please specify a SRC_ROOT with option -s !");
899912
}
900913
if (cfg.getDataRoot() == null) {
901-
die("Please specify a DATA ROOT path");
914+
throw new ConfigurationException("Please specify a DATA ROOT path");
902915
}
903916

904917
if (!new File(cfg.getSourceRoot()).canRead()) {
905-
die("Source root '" + cfg.getSourceRoot() + "' must be readable");
918+
throw new ConfigurationException("Source root '" + cfg.getSourceRoot() + "' must be readable");
906919
}
907920

908921
if (!new File(cfg.getDataRoot()).canWrite()) {
909-
die("Data root '" + cfg.getDataRoot() + "' must be writable");
922+
throw new ConfigurationException("Data root '" + cfg.getDataRoot() + "' must be writable");
910923
}
911924

912925
if (!cfg.isHistoryEnabled() && cfg.isHistoryBasedReindex()) {
913-
die("History has to be enabled for history based reindex");
926+
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " +
927+
"History has to be enabled for history based reindex.");
914928
}
915929

916930
if (!cfg.isHistoryCache() && cfg.isHistoryBasedReindex()) {
917-
die("History cache has to be enabled for history based reindex");
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.");
918933
}
919934
}
920935

0 commit comments

Comments
 (0)