Skip to content

Commit 8ea3083

Browse files
author
Vladimir Kotal
committed
--noindex should suppress history cache generation
1 parent 40e6c66 commit 8ea3083

File tree

1 file changed

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

1 file changed

+62
-25
lines changed

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

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public final class Indexer {
101101
private static boolean optimizedChanged = false;
102102
private static boolean addProjects = false;
103103
private static boolean searchRepositories = false;
104-
private static boolean noindex = false;
104+
private static boolean bareConfig = false;
105105
private static boolean awaitProfiler;
106106

107107
private static boolean help;
@@ -252,7 +252,7 @@ public static void main(String argv[]) {
252252
// call above.
253253
RepositoryFactory.initializeIgnoredNames(env);
254254

255-
if (noindex) {
255+
if (bareConfig) {
256256
getInstance().sendToConfigHost(env, webappURI);
257257
writeConfigToFile(env, configFilename);
258258
System.exit(0);
@@ -314,12 +314,13 @@ public static void main(String argv[]) {
314314

315315
LOGGER.log(Level.INFO, "Indexer version {0} ({1})",
316316
new Object[]{Info.getVersion(), Info.getRevision()});
317-
317+
318318
// Get history first.
319319
getInstance().prepareIndexer(env, searchRepositories, addProjects,
320320
defaultProjects,
321-
listFiles, createDict, subFiles, new ArrayList<>(repositories),
321+
listFiles, createDict, runIndex, subFiles, new ArrayList<>(repositories),
322322
zapCache, listRepos);
323+
323324
if (listRepos || !zapCache.isEmpty()) {
324325
return;
325326
}
@@ -564,7 +565,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
564565

565566
parser.on("-m", "--memory", "=number", Double.class,
566567
"Amount of memory that may be used for buffering added documents and",
567-
"deletions before they are flushed to the directory (default "+Configuration.defaultRamBufferSize+"MB).",
568+
"deletions before they are flushed to the directory (default " + Configuration.defaultRamBufferSize + "MB).",
568569
"Please increase JVM heap accordingly, too.").Do(memSize -> {
569570
cfg.setRamBufferSize((Double)memSize);
570571
});
@@ -587,7 +588,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
587588
);
588589

589590
parser.on("-n", "--noIndex",
590-
"Do not generate indexes, but process all other command line options.").Do(v -> {
591+
"Do not generate indexes and other data (such as history cache and xref files), " +
592+
"but process all other command line options.").Do(v -> {
591593
runIndex = false;
592594
});
593595

@@ -766,7 +768,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
766768

767769
parser.on("--updateConfig",
768770
"Populate the webapp with bare configuration and exit.").Do(v -> {
769-
noindex = true;
771+
bareConfig = true;
770772
});
771773

772774
parser.on("--userPage", "=URL",
@@ -818,7 +820,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
818820
private static void checkConfiguration() {
819821
env = RuntimeEnvironment.getInstance();
820822

821-
if (noindex && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
823+
if (bareConfig && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
822824
die("Missing webappURI URL");
823825
}
824826

@@ -888,13 +890,43 @@ public static void writeConfigToFile(RuntimeEnvironment env, String filename) th
888890
}
889891
}
890892

891-
/*
893+
// Wrapper for prepareIndexer() that always generates history cache.
894+
public void prepareIndexer(RuntimeEnvironment env,
895+
boolean searchRepositories,
896+
boolean addProjects,
897+
Set<String> defaultProjects,
898+
boolean listFiles,
899+
boolean createDict,
900+
List<String> subFiles,
901+
List<String> repositories,
902+
List<String> zapCache,
903+
boolean listRepoPaths) throws IndexerException, IOException {
904+
prepareIndexer(env, searchRepositories, addProjects, defaultProjects, listFiles, createDict, true,
905+
subFiles, repositories, zapCache, listRepoPaths);
906+
}
907+
908+
/**
909+
* Generate history cache and/or scan the repositories.
910+
*
892911
* This is the first phase of the indexing where history cache is being
893912
* generated for repositories (at least for those which support getting
894913
* history per directory).
895914
*
896-
* PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
915+
* PMD wants us to use length() &gt; 0 &amp;&amp; charAt(0) instead of startsWith()
897916
* for performance. We prefer clarity over performance here, so silence it.
917+
*
918+
* @param env runtime environment
919+
* @param searchRepositories if true, search for repositories
920+
* @param addProjects if true, add projects
921+
* @param defaultProjects default projects
922+
* @param listFiles list files and return
923+
* @param createDict if true, create dictionary
924+
* @param subFiles list of directories
925+
* @param repositories list of repositories
926+
* @param zapCache list of projects to remove history cache for
927+
* @param listRepoPaths print repository paths to standard output
928+
* @throws IndexerException
929+
* @throws IOException
898930
*/
899931
@SuppressWarnings("PMD.SimplifyStartsWith")
900932
public void prepareIndexer(RuntimeEnvironment env,
@@ -903,6 +935,7 @@ public void prepareIndexer(RuntimeEnvironment env,
903935
Set<String> defaultProjects,
904936
boolean listFiles,
905937
boolean createDict,
938+
boolean createHistoryCache,
906939
List<String> subFiles,
907940
List<String> repositories,
908941
List<String> zapCache,
@@ -1011,6 +1044,14 @@ public void prepareIndexer(RuntimeEnvironment env,
10111044
}
10121045
}
10131046

1047+
if (listFiles) {
1048+
for (String file : IndexDatabase.getAllFiles(subFiles)) {
1049+
LOGGER.fine(file);
1050+
}
1051+
1052+
return;
1053+
}
1054+
10141055
if (defaultProjects != null && !defaultProjects.isEmpty()) {
10151056
Set<Project> projects = new TreeSet<>();
10161057
for (String projectPath : defaultProjects) {
@@ -1030,21 +1071,17 @@ public void prepareIndexer(RuntimeEnvironment env,
10301071
}
10311072
}
10321073

1033-
// Even if history is disabled globally, it can be enabled for some repositories.
1034-
if (repositories != null && !repositories.isEmpty()) {
1035-
LOGGER.log(Level.INFO, "Generating history cache for repositories: " +
1036-
repositories.stream().collect(Collectors.joining(",")));
1037-
HistoryGuru.getInstance().createCache(repositories);
1038-
LOGGER.info("Done...");
1039-
} else {
1040-
LOGGER.log(Level.INFO, "Generating history cache for all repositories ...");
1041-
HistoryGuru.getInstance().createCache();
1042-
LOGGER.info("Done...");
1043-
}
1044-
1045-
if (listFiles) {
1046-
for (String file : IndexDatabase.getAllFiles(subFiles)) {
1047-
LOGGER.fine(file);
1074+
if (createHistoryCache) {
1075+
// Even if history is disabled globally, it can be enabled for some repositories.
1076+
if (repositories != null && !repositories.isEmpty()) {
1077+
LOGGER.log(Level.INFO, "Generating history cache for repositories: " +
1078+
repositories.stream().collect(Collectors.joining(",")));
1079+
HistoryGuru.getInstance().createCache(repositories);
1080+
LOGGER.info("Done...");
1081+
} else {
1082+
LOGGER.log(Level.INFO, "Generating history cache for all repositories ...");
1083+
HistoryGuru.getInstance().createCache();
1084+
LOGGER.info("Done...");
10481085
}
10491086
}
10501087

0 commit comments

Comments
 (0)