@@ -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 ;
@@ -392,7 +397,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
392
397
}
393
398
394
399
OptionParser configure = OptionParser .scan (parser -> {
395
- parser .on ("-R configPath" ).Do ( cfgFile -> {
400
+ parser .on ("-R configPath" ).Do (cfgFile -> {
396
401
try {
397
402
cfg = Configuration .read (new File ((String )cfgFile ));
398
403
} catch (IOException e ) {
@@ -408,7 +413,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
408
413
parser .setPrologue (
409
414
String .format ("\n Usage: java -jar %s [options] [subDir1 [...]]\n " , program ));
410
415
411
- parser .on ("-?" , "-h" , "--help" , "Display this usage summary." ).Do ( v -> {
416
+ parser .on ("-?" , "-h" , "--help" , "Display this usage summary." ).Do (v -> {
412
417
help = true ;
413
418
helpUsage = parser .getUsage ();
414
419
});
@@ -431,7 +436,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
431
436
" with \" BAR\" (no full-stop)" ,
432
437
" Ex: -A .c:-" ,
433
438
" will disable specialized analyzers for all files ending with .c" ).
434
- Do ( analyzerSpec -> {
439
+ Do (analyzerSpec -> {
435
440
String [] arg = ((String )analyzerSpec ).split (":" );
436
441
String fileSpec = arg [0 ];
437
442
String analyzer = arg [1 ];
@@ -442,13 +447,13 @@ public static String[] parseOptions(String[] argv) throws ParseException {
442
447
parser .on ("-c" , "--ctags" ,"=/path/to/ctags" ,
443
448
"Path to Universal Ctags" ,
444
449
"By default takes the Universal Ctags in PATH." ).
445
- Do ( ctagsPath -> {
450
+ Do (ctagsPath -> {
446
451
cfg .setCtags ((String )ctagsPath );
447
452
}
448
453
);
449
454
450
455
parser .on ("--checkIndexVersion" , "=/path/to/conf" ,
451
- "Check if current Lucene version matches index version" ).Do ( v -> {
456
+ "Check if current Lucene version matches index version" ).Do (v -> {
452
457
try {
453
458
File cfgFile = new File ((String )v );
454
459
checkIndexVersionCfg = Configuration .read (cfgFile );
@@ -459,7 +464,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
459
464
460
465
parser .on ("-d" , "--dataRoot" , "=/path/to/data/root" ,
461
466
"The directory where OpenGrok stores the generated data." ).
462
- Do ( drPath -> {
467
+ Do (drPath -> {
463
468
File dataRoot = new File ((String )drPath );
464
469
if (!dataRoot .exists () && !dataRoot .mkdirs ()) {
465
470
die ("Cannot create data root: " + dataRoot );
@@ -477,59 +482,49 @@ public static String[] parseOptions(String[] argv) throws ParseException {
477
482
478
483
parser .on ("--deleteHistory" , "=/path/to/repository" ,
479
484
"Delete the history cache for the given repository and exit." ,
480
- "Use '*' to delete the cache for all repositories." ).Do ( repo -> {
485
+ "Use '*' to delete the cache for all repositories." ).Do (repo -> {
481
486
zapCache .add ((String )repo );
482
487
});
483
488
484
489
parser .on ("--depth" , "=number" , Integer .class ,
485
490
"Scanning depth for repositories in directory structure relative to" ,
486
- "source root. Default is " + Configuration .defaultScanningDepth + "." ).Do ( depth -> {
491
+ "source root. Default is " + Configuration .defaultScanningDepth + "." ).Do (depth -> {
487
492
cfg .setScanningDepth ((Integer )depth );
488
493
});
489
494
490
495
parser .on ("-e" , "--economical" ,
491
496
"Economical, consumes less disk space." ,
492
497
"It does not generate hyper text cross reference files offline," ,
493
- "but will do so on demand, which could be sightly slow." ).Do ( v -> {
498
+ "but will do so on demand, which could be sightly slow." ).Do (v -> {
494
499
cfg .setGenerateHtml (false );
495
500
});
496
501
497
502
parser .on ("-G" , "--assignTags" ,
498
- "Assign commit tags to all entries in history for all repositories." ).Do ( v -> {
503
+ "Assign commit tags to all entries in history for all repositories." ).Do (v -> {
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." ,
518
- "(supports wildcards, example: -I *.java -I *.c)" ).Do ( pattern -> {
513
+ "(supports wildcards, example: -I *.java -I *.c)" ).Do (pattern -> {
519
514
cfg .getIncludedNames ().add ((String )pattern );
520
515
});
521
516
522
517
parser .on ("-i" , "--ignore" , "=pattern" ,
523
518
"Ignore the named files (prefixed with 'f:')" ,
524
519
"or directories (prefixed with 'd:')." ,
525
- "Supports wildcards (example: -i *.so -i *.dll)" ).Do ( pattern -> {
520
+ "Supports wildcards (example: -i *.so -i *.dll)" ).Do (pattern -> {
526
521
cfg .getIgnoredNames ().add ((String )pattern );
527
522
});
528
523
529
524
parser .on ("-l" , "--lock" , "=on|off|simple|native" , LUCENE_LOCKS ,
530
525
"Set OpenGrok/Lucene locking mode of the Lucene database" ,
531
526
"during index generation. \" on\" is an alias for \" simple\" ." ,
532
- "Default is off." ).Do ( v -> {
527
+ "Default is off." ).Do (v -> {
533
528
try {
534
529
if (v != null ) {
535
530
String vuc = v .toString ().toUpperCase (Locale .ROOT );
@@ -542,22 +537,22 @@ public static String[] parseOptions(String[] argv) throws ParseException {
542
537
});
543
538
544
539
parser .on ("--leadingWildCards" , "=on|off" , ON_OFF , Boolean .class ,
545
- "Allow or disallow leading wildcards in a search." ).Do ( v -> {
540
+ "Allow or disallow leading wildcards in a search." ).Do (v -> {
546
541
cfg .setAllowLeadingWildcard ((Boolean )v );
547
542
});
548
543
549
- parser .on ("--listRepos" , "List all repository paths and exit." ).Do ( v -> {
544
+ parser .on ("--listRepos" , "List all repository paths and exit." ).Do (v -> {
550
545
listRepos = true ;
551
546
});
552
547
553
548
parser .on ("-m" , "--memory" , "=number" , Double .class ,
554
549
"Amount of memory that may be used for buffering added documents and" ,
555
550
"deletions before they are flushed to the directory (default " +Configuration .defaultRamBufferSize +"MB)." ,
556
- "Please increase JVM heap accordingly, too." ).Do ( memSize -> {
551
+ "Please increase JVM heap accordingly, too." ).Do (memSize -> {
557
552
cfg .setRamBufferSize ((Double )memSize );
558
553
});
559
554
560
- parser .on ("--man" , "Generate OpenGrok XML manual page." ).Do ( v -> {
555
+ parser .on ("--man" , "Generate OpenGrok XML manual page." ).Do (v -> {
561
556
try {
562
557
System .out .print (parser .getManPage ());
563
558
} catch (IOException e ) {
@@ -575,14 +570,14 @@ public static String[] parseOptions(String[] argv) throws ParseException {
575
570
);
576
571
577
572
parser .on ("-n" , "--noIndex" ,
578
- "Do not generate indexes, but process all other command line options." ).Do ( v -> {
573
+ "Do not generate indexes, but process all other command line options." ).Do (v -> {
579
574
runIndex = false ;
580
575
});
581
576
582
577
parser .on ("-O" , "--optimize" , "=on|off" , ON_OFF , Boolean .class ,
583
578
"Turn on/off the optimization of the index database" ,
584
579
"as part of the indexing step." ).
585
- Do ( v -> {
580
+ Do (v -> {
586
581
boolean oldval = cfg .isOptimizeDatabase ();
587
582
cfg .setOptimizeDatabase ((Boolean )v );
588
583
if (oldval != cfg .isOptimizeDatabase ()) {
@@ -593,7 +588,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
593
588
594
589
parser .on ("-o" , "--ctagOpts" , "=path" ,
595
590
"File with extra command line options for ctags." ).
596
- Do ( path -> {
591
+ Do (path -> {
597
592
String CTagsExtraOptionsFile = (String )path ;
598
593
File CTagsFile = new File (CTagsExtraOptionsFile );
599
594
if (!(CTagsFile .isFile () && CTagsFile .canRead ())) {
@@ -606,7 +601,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
606
601
);
607
602
608
603
parser .on ("-P" , "--projects" ,
609
- "Generate a project for each top-level directory in source root." ).Do ( v -> {
604
+ "Generate a project for each top-level directory in source root." ).Do (v -> {
610
605
addProjects = true ;
611
606
cfg .setProjectsEnabled (true );
612
607
});
@@ -616,7 +611,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
616
611
"by default in the web application (when no other project" ,
617
612
"set either in cookie or in parameter). May be used multiple" ,
618
613
"times for several projects. Use \" __all__\" for all projects." ,
619
- "You should strip off the source root." ).Do ( v -> {
614
+ "You should strip off the source root." ).Do (v -> {
620
615
defaultProjects .add ((String )v );
621
616
});
622
617
@@ -627,7 +622,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
627
622
"Print per project percentage progress information." ,
628
623
"(I/O extensive, since one read through directory structure is" ,
629
624
"made before indexing, needs -v, otherwise it just goes to the log)" ).
630
- Do ( v -> {
625
+ Do (v -> {
631
626
cfg .setPrintProgress (true );
632
627
}
633
628
);
@@ -636,17 +631,23 @@ public static String[] parseOptions(String[] argv) throws ParseException {
636
631
"Turn on/off quick context scan. By default, only the first" ,
637
632
"1024k of a file is scanned, and a '[..all..]' link is inserted" ,
638
633
"when the file is bigger. Activating this may slow the server down." ,
639
- "(Note: this is setting only affects the web application)" ).Do ( v -> {
634
+ "(Note: this is setting only affects the web application)" ).Do (v -> {
640
635
cfg .setQuickContextScan ((Boolean )v );
641
636
});
642
637
643
638
parser .on ("-q" , "--quiet" , "Run as quietly as possible." ,
644
- "Sets logging level to WARNING." ).Do ( v -> {
639
+ "Sets logging level to WARNING." ).Do (v -> {
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
- "Read configuration from the specified file." ).Do ( v -> {
650
+ "Read configuration from the specified file." ).Do (v -> {
650
651
// Already handled above. This populates usage.
651
652
});
652
653
@@ -658,7 +659,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
658
659
" uionly - support remote SCM for user interface only." ,
659
660
"dirbased - allow retrieval during history index only for repositories" ,
660
661
" which allow getting history for directories." ).
661
- Do ( v -> {
662
+ Do (v -> {
662
663
String option = (String ) v ;
663
664
if (option .equalsIgnoreCase (ON )) {
664
665
cfg .setRemoteScmSupported (Configuration .RemoteSCM .ON );
@@ -675,18 +676,18 @@ public static String[] parseOptions(String[] argv) throws ParseException {
675
676
parser .on ("--renamedHistory" , "=on|off" , ON_OFF , Boolean .class ,
676
677
"Enable or disable generating history for renamed files." ,
677
678
"If set to on, makes history indexing slower for repositories" ,
678
- "with lots of renamed files." ).Do ( v -> {
679
+ "with lots of renamed files." ).Do (v -> {
679
680
cfg .setHandleHistoryOfRenamedFiles ((Boolean )v );
680
681
});
681
682
682
683
parser .on ("-S" , "--search" ,
683
- "Search for \" external\" source repositories and add them." ).Do ( v -> {
684
+ "Search for \" external\" source repositories and add them." ).Do (v -> {
684
685
searchRepositories = true ;
685
686
});
686
687
687
688
parser .on ("-s" , "--source" , "=/path/to/source/root" ,
688
689
"The root directory of the source tree." ).
689
- Do ( source -> {
690
+ Do (source -> {
690
691
File sourceRoot = new File ((String )source );
691
692
if (!sourceRoot .isDirectory ()) {
692
693
die ("Source root " + sourceRoot + " must be a directory" );
@@ -702,27 +703,27 @@ public static String[] parseOptions(String[] argv) throws ParseException {
702
703
parser .on ("--style" , "=path" ,
703
704
"Path to the subdirectory in the web-application containing the" ,
704
705
"requested stylesheet. The factory-setting is: \" default\" ." ).
705
- Do ( stylePath -> {
706
+ Do (stylePath -> {
706
707
cfg .setWebappLAF ((String )stylePath );
707
708
}
708
709
);
709
710
710
711
parser .on ("--symlink" , "=/path/to/symlink" ,
711
712
"Allow this symlink to be followed. Option may be repeated." ,
712
713
"By default only symlinks directly under source root directory" ,
713
- "are allowed." ).Do ( symlink -> {
714
+ "are allowed." ).Do (symlink -> {
714
715
allowedSymlinks .add ((String )symlink );
715
716
});
716
717
717
718
parser .on ("-T" , "--threads" , "=number" , Integer .class ,
718
719
"The number of threads to use for index generation." ,
719
720
"By default the number of threads will be set to the number" ,
720
- "of available CPUs." ).Do ( threadCount -> {
721
+ "of available CPUs." ).Do (threadCount -> {
721
722
cfg .setIndexingParallelism ((Integer )threadCount );
722
723
});
723
724
724
725
parser .on ("-t" , "--tabSize" , "=number" , Integer .class ,
725
- "Default tab size to use (number of spaces per tab character)." ).Do ( tabSize -> {
726
+ "Default tab size to use (number of spaces per tab character)." ).Do (tabSize -> {
726
727
cfg .setTabSize ((Integer )tabSize );
727
728
});
728
729
@@ -738,35 +739,35 @@ public static String[] parseOptions(String[] argv) throws ParseException {
738
739
parser .on ("---unitTest" ); // For unit test only, will not appear in help
739
740
740
741
parser .on ("--updateConfig" ,
741
- "Populate the webapp with bare configuration and exit." ).Do ( v -> {
742
+ "Populate the webapp with bare configuration and exit." ).Do (v -> {
742
743
noindex = true ;
743
744
});
744
745
745
746
parser .on ("--userPage" , "=URL" ,
746
747
"Base URL of the user Information provider." ,
747
748
"Example: \" http://www.myserver.org/viewProfile.jspa?username=\" ." ,
748
- "Use \" none\" to disable link." ).Do ( v -> {
749
+ "Use \" none\" to disable link." ).Do (v -> {
749
750
cfg .setUserPage ((String )v );
750
751
});
751
752
752
753
parser .on ("--userPageSuffix" , "=URL-suffix" ,
753
- "URL Suffix for the user Information provider. Default: \" \" ." ).Do ( suffix -> {
754
+ "URL Suffix for the user Information provider. Default: \" \" ." ).Do (suffix -> {
754
755
cfg .setUserPageSuffix ((String )suffix );
755
756
});
756
757
757
- parser .on ("-V" , "--version" , "Print version and quit." ).Do ( v -> {
758
+ parser .on ("-V" , "--version" , "Print version and quit." ).Do (v -> {
758
759
System .out .println (Info .getFullVersion ());
759
760
System .exit (0 );
760
761
});
761
762
762
- parser .on ("-v" , "--verbose" , "Set logging level to INFO." ).Do ( v -> {
763
+ parser .on ("-v" , "--verbose" , "Set logging level to INFO." ).Do (v -> {
763
764
verbose = true ;
764
765
LoggerUtil .setBaseConsoleLogLevel (Level .INFO );
765
766
});
766
767
767
768
parser .on ("-W" , "--writeConfig" , "=/path/to/configuration" ,
768
769
"Write the current configuration to the specified file" ,
769
- "(so that the web application can use the same configuration)" ).Do ( configFile -> {
770
+ "(so that the web application can use the same configuration)" ).Do (configFile -> {
770
771
configFilename = (String )configFile ;
771
772
});
772
773
});
@@ -788,6 +789,12 @@ 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
+ die ("Repositories were specified however history is off" );
795
+ }
796
+ }
797
+
791
798
private static void die (String message ) {
792
799
System .err .println ("ERROR: " + message );
793
800
System .exit (1 );
0 commit comments