@@ -98,7 +98,7 @@ public final class Indexer {
98
98
private static String configFilename = null ;
99
99
private static int status = 0 ;
100
100
101
- private static final ArrayList <String > repositories = new ArrayList <>();
101
+ private static final Set <String > repositories = new HashSet <>();
102
102
private static final HashSet <String > allowedSymlinks = new HashSet <>();
103
103
private static final Set <String > defaultProjects = new TreeSet <>();
104
104
private static final ArrayList <String > zapCache = new ArrayList <>();
@@ -141,7 +141,9 @@ public static void main(String argv[]) {
141
141
}
142
142
System .exit (status );
143
143
}
144
-
144
+
145
+ checkConfiguration ();
146
+
145
147
if (awaitProfiler ) {
146
148
pauseToAwaitProfiler ();
147
149
}
@@ -256,8 +258,11 @@ public static void main(String argv[]) {
256
258
path = path .substring (srcPath .length ());
257
259
if (env .hasProjects ()) {
258
260
// The paths need to correspond to a project.
259
- if (Project .getProject (path ) != null ) {
261
+ Project project ;
262
+ if ((project = Project .getProject (path )) != null ) {
260
263
subFiles .add (path );
264
+ repositories .addAll (env .getProjectRepositoriesMap ().get (project ).
265
+ stream ().map (x -> x .getDirectoryNameRelative ()).collect (Collectors .toSet ()));
261
266
} else {
262
267
System .err .println ("The path " + path
263
268
+ " does not correspond to a project" );
@@ -292,7 +297,7 @@ public static void main(String argv[]) {
292
297
// Get history first.
293
298
getInstance ().prepareIndexer (env , searchRepositories , addProjects ,
294
299
defaultProjects ,
295
- listFiles , createDict , subFiles , repositories ,
300
+ listFiles , createDict , subFiles , new ArrayList ( repositories ) ,
296
301
zapCache , listRepos );
297
302
if (listRepos || !zapCache .isEmpty ()) {
298
303
return ;
@@ -499,19 +504,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
499
504
cfg .setTagsEnabled (true );
500
505
});
501
506
502
- parser .on ("-H" , "--history" , "=[/path/to/repository]" ,
503
- "Get history for specific repositories (specified as" ,
504
- "absolute path from source root), or ALL repositories" ,
505
- "when none specified." ).
506
- Do ( repo -> {
507
- String repository = (String ) repo ;
508
- if (repository .equals ("" )) {
509
- cfg .setHistoryEnabled (true ); // all repositories
510
- } else {
511
- repositories .add ((String )repository ); // specific repository
512
- }
513
- }
514
- );
507
+ parser .on ("-H" , "--history" , "Enable history." ).Do ( v -> {
508
+ cfg .setHistoryEnabled (true );
509
+ });
515
510
516
511
parser .on ("-I" , "--include" , "=pattern" ,
517
512
"Only files matching this pattern will be examined." ,
@@ -645,6 +640,12 @@ public static String[] parseOptions(String[] argv) throws ParseException {
645
640
LoggerUtil .setBaseConsoleLogLevel (Level .WARNING );
646
641
});
647
642
643
+ parser .on ("--repository" , "=repository" ,
644
+ "Generate history for specific repository specified as relative path to source root. " ,
645
+ "Can be used multiple times. Assumes history is on." ).Do ( repo -> {
646
+ repositories .add ((String )repo );
647
+ });
648
+
648
649
parser .on ("-R /path/to/configuration" ,
649
650
"Read configuration from the specified file." ).Do ( v -> {
650
651
// Already handled above. This populates usage.
@@ -788,6 +789,13 @@ public static String[] parseOptions(String[] argv) throws ParseException {
788
789
return argv ;
789
790
}
790
791
792
+ private static void checkConfiguration () {
793
+ if (repositories .size () > 0 && !cfg .isHistoryEnabled ()) {
794
+ System .out .println ("Repositories were specified however history is off" );
795
+ System .exit (1 );
796
+ }
797
+ }
798
+
791
799
private static void die (String message ) {
792
800
System .err .println ("ERROR: " + message );
793
801
System .exit (1 );
0 commit comments