35
35
import java .text .ParseException ;
36
36
import java .util .ArrayList ;
37
37
import java .util .Arrays ;
38
+ import java .util .Collections ;
38
39
import java .util .HashMap ;
39
40
import java .util .HashSet ;
40
41
import java .util .List ;
@@ -118,6 +119,7 @@ public final class Indexer {
118
119
private static int status = 0 ;
119
120
120
121
private static final Set <String > repositories = new HashSet <>();
122
+ private static Set <String > searchPaths = new HashSet <>();
121
123
private static final HashSet <String > allowedSymlinks = new HashSet <>();
122
124
private static final HashSet <String > canonicalRoots = new HashSet <>();
123
125
private static final Set <String > defaultProjects = new TreeSet <>();
@@ -335,7 +337,16 @@ public static void main(String[] argv) {
335
337
new Object []{Info .getVersion (), Info .getRevision ()});
336
338
337
339
// Create history cache first.
338
- getInstance ().prepareIndexer (env , searchRepositories , addProjects ,
340
+ if (searchRepositories ) {
341
+ if (searchPaths .isEmpty ()) {
342
+ searchPaths .add (env .getSourceRootPath ());
343
+ } else {
344
+ searchPaths = searchPaths .stream ().
345
+ map (t -> Paths .get (env .getSourceRootPath (), t ).toString ()).
346
+ collect (Collectors .toSet ());
347
+ }
348
+ }
349
+ getInstance ().prepareIndexer (env , searchPaths , addProjects ,
339
350
createDict , runIndex , subFiles , new ArrayList <>(repositories ));
340
351
341
352
// prepareIndexer() populated the list of projects so now default projects can be set.
@@ -417,6 +428,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
417
428
});
418
429
});
419
430
431
+ searchPaths .clear ();
432
+
420
433
// Limit usage lines to 72 characters for concise formatting.
421
434
422
435
optParser = OptionParser .Do (parser -> {
@@ -689,9 +702,16 @@ public static String[] parseOptions(String[] argv) throws ParseException {
689
702
"are history-eligible; using --repository limits to only those specified." ,
690
703
"Option may be repeated." ).Do (v -> repositories .add ((String ) v ));
691
704
692
- parser .on ("-S" , "--search" ,
693
- "Search for source repositories under -s,--source, and add them." ).Do (v ->
694
- searchRepositories = true );
705
+ parser .on ("-S" , "--search" , "=[path/to/repository]" ,
706
+ "Search for source repositories under -s,--source, and add them." +
707
+ "Path (relative to the source root) to repository is optional. " +
708
+ "Option may be repeated." ).Do (v -> {
709
+ searchRepositories = true ;
710
+ String repoPath = (String ) v ;
711
+ if (!repoPath .isEmpty ()) {
712
+ searchPaths .add (repoPath );
713
+ }
714
+ });
695
715
696
716
parser .on ("-s" , "--source" , "=/path/to/source/root" ,
697
717
"The root directory of the source tree." ).
@@ -873,8 +893,9 @@ public void prepareIndexer(RuntimeEnvironment env,
873
893
List <String > subFiles ,
874
894
List <String > repositories ) throws IndexerException , IOException {
875
895
876
- prepareIndexer (env , searchRepositories , addProjects , createDict , true ,
877
- subFiles , repositories );
896
+ prepareIndexer (env ,
897
+ searchRepositories ? Collections .singleton (env .getSourceRootPath ()) : Collections .emptySet (),
898
+ addProjects , createDict , true , subFiles , repositories );
878
899
}
879
900
880
901
/**
@@ -888,7 +909,7 @@ public void prepareIndexer(RuntimeEnvironment env,
888
909
* for performance. We prefer clarity over performance here, so silence it.
889
910
*
890
911
* @param env runtime environment
891
- * @param searchRepositories if true, search for repositories
912
+ * @param searchPaths list of paths in which to search for repositories
892
913
* @param addProjects if true, add projects
893
914
* @param createDict if true, create dictionary
894
915
* @param createHistoryCache create history cache flag
@@ -899,7 +920,7 @@ public void prepareIndexer(RuntimeEnvironment env,
899
920
*/
900
921
@ SuppressWarnings ("PMD.SimplifyStartsWith" )
901
922
public void prepareIndexer (RuntimeEnvironment env ,
902
- boolean searchRepositories ,
923
+ Set < String > searchPaths ,
903
924
boolean addProjects ,
904
925
boolean createDict ,
905
926
boolean createHistoryCache ,
@@ -954,10 +975,10 @@ public void prepareIndexer(RuntimeEnvironment env,
954
975
}
955
976
}
956
977
957
- if (searchRepositories ) {
958
- LOGGER .log (Level .INFO , "Scanning for repositories..." );
978
+ if (! searchPaths . isEmpty () ) {
979
+ LOGGER .log (Level .INFO , "Scanning for repositories in {0} ..." , searchPaths );
959
980
Statistics stats = new Statistics ();
960
- env .setRepositories (env . getSourceRootPath ( ));
981
+ env .setRepositories (searchPaths . toArray ( new String [ 0 ] ));
961
982
stats .report (LOGGER , String .format ("Done scanning for repositories, found %d repositories" ,
962
983
env .getRepositories ().size ()));
963
984
}
0 commit comments