@@ -101,7 +101,7 @@ public final class Indexer {
101
101
private static boolean optimizedChanged = false ;
102
102
private static boolean addProjects = false ;
103
103
private static boolean searchRepositories = false ;
104
- private static boolean noindex = false ;
104
+ private static boolean bareConfig = false ;
105
105
private static boolean awaitProfiler ;
106
106
107
107
private static boolean help ;
@@ -252,7 +252,7 @@ public static void main(String argv[]) {
252
252
// call above.
253
253
RepositoryFactory .initializeIgnoredNames (env );
254
254
255
- if (noindex ) {
255
+ if (bareConfig ) {
256
256
getInstance ().sendToConfigHost (env , webappURI );
257
257
writeConfigToFile (env , configFilename );
258
258
System .exit (0 );
@@ -314,12 +314,13 @@ public static void main(String argv[]) {
314
314
315
315
LOGGER .log (Level .INFO , "Indexer version {0} ({1})" ,
316
316
new Object []{Info .getVersion (), Info .getRevision ()});
317
-
317
+
318
318
// Get history first.
319
319
getInstance ().prepareIndexer (env , searchRepositories , addProjects ,
320
320
defaultProjects ,
321
- listFiles , createDict , subFiles , new ArrayList <>(repositories ),
321
+ listFiles , createDict , runIndex , subFiles , new ArrayList <>(repositories ),
322
322
zapCache , listRepos );
323
+
323
324
if (listRepos || !zapCache .isEmpty ()) {
324
325
return ;
325
326
}
@@ -564,7 +565,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
564
565
565
566
parser .on ("-m" , "--memory" , "=number" , Double .class ,
566
567
"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)." ,
568
569
"Please increase JVM heap accordingly, too." ).Do (memSize -> {
569
570
cfg .setRamBufferSize ((Double )memSize );
570
571
});
@@ -587,7 +588,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
587
588
);
588
589
589
590
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 -> {
591
593
runIndex = false ;
592
594
});
593
595
@@ -766,7 +768,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
766
768
767
769
parser .on ("--updateConfig" ,
768
770
"Populate the webapp with bare configuration and exit." ).Do (v -> {
769
- noindex = true ;
771
+ bareConfig = true ;
770
772
});
771
773
772
774
parser .on ("--userPage" , "=URL" ,
@@ -818,7 +820,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
818
820
private static void checkConfiguration () {
819
821
env = RuntimeEnvironment .getInstance ();
820
822
821
- if (noindex && (env .getConfigURI () == null || env .getConfigURI ().isEmpty ())) {
823
+ if (bareConfig && (env .getConfigURI () == null || env .getConfigURI ().isEmpty ())) {
822
824
die ("Missing webappURI URL" );
823
825
}
824
826
@@ -888,13 +890,43 @@ public static void writeConfigToFile(RuntimeEnvironment env, String filename) th
888
890
}
889
891
}
890
892
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
+ *
892
911
* This is the first phase of the indexing where history cache is being
893
912
* generated for repositories (at least for those which support getting
894
913
* history per directory).
895
914
*
896
- * PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
915
+ * PMD wants us to use length() > 0 && charAt(0) instead of startsWith()
897
916
* 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
898
930
*/
899
931
@ SuppressWarnings ("PMD.SimplifyStartsWith" )
900
932
public void prepareIndexer (RuntimeEnvironment env ,
@@ -903,6 +935,7 @@ public void prepareIndexer(RuntimeEnvironment env,
903
935
Set <String > defaultProjects ,
904
936
boolean listFiles ,
905
937
boolean createDict ,
938
+ boolean createHistoryCache ,
906
939
List <String > subFiles ,
907
940
List <String > repositories ,
908
941
List <String > zapCache ,
@@ -1011,6 +1044,14 @@ public void prepareIndexer(RuntimeEnvironment env,
1011
1044
}
1012
1045
}
1013
1046
1047
+ if (listFiles ) {
1048
+ for (String file : IndexDatabase .getAllFiles (subFiles )) {
1049
+ LOGGER .fine (file );
1050
+ }
1051
+
1052
+ return ;
1053
+ }
1054
+
1014
1055
if (defaultProjects != null && !defaultProjects .isEmpty ()) {
1015
1056
Set <Project > projects = new TreeSet <>();
1016
1057
for (String projectPath : defaultProjects ) {
@@ -1030,21 +1071,17 @@ public void prepareIndexer(RuntimeEnvironment env,
1030
1071
}
1031
1072
}
1032
1073
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..." );
1048
1085
}
1049
1086
}
1050
1087
0 commit comments