Skip to content

Commit 64ad4c5

Browse files
author
Vladimir Kotal
committed
Merge branch 'vladak-indexer_get_repos_for_projects'
2 parents 5c4b57f + 1750e43 commit 64ad4c5

File tree

1 file changed

+64
-57
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/index

1 file changed

+64
-57
lines changed

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

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public final class Indexer {
9898
private static String configFilename = null;
9999
private static int status = 0;
100100

101-
private static final ArrayList<String> repositories = new ArrayList<>();
101+
private static final Set<String> repositories = new HashSet<>();
102102
private static final HashSet<String> allowedSymlinks = new HashSet<>();
103103
private static final Set<String> defaultProjects = new TreeSet<>();
104104
private static final ArrayList<String> zapCache = new ArrayList<>();
@@ -141,7 +141,9 @@ public static void main(String argv[]) {
141141
}
142142
System.exit(status);
143143
}
144-
144+
145+
checkConfiguration();
146+
145147
if (awaitProfiler) {
146148
pauseToAwaitProfiler();
147149
}
@@ -256,8 +258,11 @@ public static void main(String argv[]) {
256258
path = path.substring(srcPath.length());
257259
if (env.hasProjects()) {
258260
// The paths need to correspond to a project.
259-
if (Project.getProject(path) != null) {
261+
Project project;
262+
if ((project = Project.getProject(path)) != null) {
260263
subFiles.add(path);
264+
repositories.addAll(env.getProjectRepositoriesMap().get(project).
265+
stream().map(x -> x.getDirectoryNameRelative()).collect(Collectors.toSet()));
261266
} else {
262267
System.err.println("The path " + path
263268
+ " does not correspond to a project");
@@ -292,7 +297,7 @@ public static void main(String argv[]) {
292297
// Get history first.
293298
getInstance().prepareIndexer(env, searchRepositories, addProjects,
294299
defaultProjects,
295-
listFiles, createDict, subFiles, repositories,
300+
listFiles, createDict, subFiles, new ArrayList(repositories),
296301
zapCache, listRepos);
297302
if (listRepos || !zapCache.isEmpty()) {
298303
return;
@@ -392,7 +397,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
392397
}
393398

394399
OptionParser configure = OptionParser.scan(parser -> {
395-
parser.on("-R configPath").Do( cfgFile -> {
400+
parser.on("-R configPath").Do(cfgFile -> {
396401
try {
397402
cfg = Configuration.read(new File((String)cfgFile));
398403
} catch(IOException e) {
@@ -408,7 +413,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
408413
parser.setPrologue(
409414
String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program));
410415

411-
parser.on("-?", "-h", "--help", "Display this usage summary.").Do( v -> {
416+
parser.on("-?", "-h", "--help", "Display this usage summary.").Do(v -> {
412417
help = true;
413418
helpUsage = parser.getUsage();
414419
});
@@ -431,7 +436,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
431436
" with \"BAR\" (no full-stop)",
432437
" Ex: -A .c:-",
433438
" will disable specialized analyzers for all files ending with .c").
434-
Do( analyzerSpec -> {
439+
Do(analyzerSpec -> {
435440
String[] arg = ((String)analyzerSpec).split(":");
436441
String fileSpec = arg[0];
437442
String analyzer = arg[1];
@@ -442,13 +447,13 @@ public static String[] parseOptions(String[] argv) throws ParseException {
442447
parser.on("-c", "--ctags","=/path/to/ctags",
443448
"Path to Universal Ctags",
444449
"By default takes the Universal Ctags in PATH.").
445-
Do( ctagsPath -> {
450+
Do(ctagsPath -> {
446451
cfg.setCtags((String)ctagsPath);
447452
}
448453
);
449454

450455
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 -> {
452457
try {
453458
File cfgFile = new File((String)v);
454459
checkIndexVersionCfg = Configuration.read(cfgFile);
@@ -459,7 +464,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
459464

460465
parser.on("-d", "--dataRoot", "=/path/to/data/root",
461466
"The directory where OpenGrok stores the generated data.").
462-
Do( drPath -> {
467+
Do(drPath -> {
463468
File dataRoot = new File((String)drPath);
464469
if (!dataRoot.exists() && !dataRoot.mkdirs()) {
465470
die("Cannot create data root: " + dataRoot);
@@ -477,59 +482,49 @@ public static String[] parseOptions(String[] argv) throws ParseException {
477482

478483
parser.on("--deleteHistory", "=/path/to/repository",
479484
"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 -> {
481486
zapCache.add((String)repo);
482487
});
483488

484489
parser.on("--depth", "=number", Integer.class,
485490
"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 -> {
487492
cfg.setScanningDepth((Integer)depth);
488493
});
489494

490495
parser.on("-e", "--economical",
491496
"Economical, consumes less disk space.",
492497
"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 -> {
494499
cfg.setGenerateHtml(false);
495500
});
496501

497502
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 -> {
499504
cfg.setTagsEnabled(true);
500505
});
501506

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+
});
515510

516511
parser.on("-I", "--include", "=pattern",
517512
"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 -> {
519514
cfg.getIncludedNames().add((String)pattern);
520515
});
521516

522517
parser.on("-i", "--ignore", "=pattern",
523518
"Ignore the named files (prefixed with 'f:')",
524519
"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 -> {
526521
cfg.getIgnoredNames().add((String)pattern);
527522
});
528523

529524
parser.on("-l", "--lock", "=on|off|simple|native", LUCENE_LOCKS,
530525
"Set OpenGrok/Lucene locking mode of the Lucene database",
531526
"during index generation. \"on\" is an alias for \"simple\".",
532-
"Default is off.").Do( v -> {
527+
"Default is off.").Do(v -> {
533528
try {
534529
if (v != null) {
535530
String vuc = v.toString().toUpperCase(Locale.ROOT);
@@ -542,22 +537,22 @@ public static String[] parseOptions(String[] argv) throws ParseException {
542537
});
543538

544539
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 -> {
546541
cfg.setAllowLeadingWildcard((Boolean)v);
547542
});
548543

549-
parser.on("--listRepos", "List all repository paths and exit.").Do( v -> {
544+
parser.on("--listRepos", "List all repository paths and exit.").Do(v -> {
550545
listRepos = true;
551546
});
552547

553548
parser.on("-m", "--memory", "=number", Double.class,
554549
"Amount of memory that may be used for buffering added documents and",
555550
"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 -> {
557552
cfg.setRamBufferSize((Double)memSize);
558553
});
559554

560-
parser.on("--man", "Generate OpenGrok XML manual page.").Do( v -> {
555+
parser.on("--man", "Generate OpenGrok XML manual page.").Do(v -> {
561556
try {
562557
System.out.print(parser.getManPage());
563558
} catch(IOException e) {
@@ -575,14 +570,14 @@ public static String[] parseOptions(String[] argv) throws ParseException {
575570
);
576571

577572
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 -> {
579574
runIndex = false;
580575
});
581576

582577
parser.on("-O", "--optimize", "=on|off", ON_OFF, Boolean.class,
583578
"Turn on/off the optimization of the index database",
584579
"as part of the indexing step.").
585-
Do( v -> {
580+
Do(v -> {
586581
boolean oldval = cfg.isOptimizeDatabase();
587582
cfg.setOptimizeDatabase((Boolean)v);
588583
if (oldval != cfg.isOptimizeDatabase()) {
@@ -593,7 +588,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
593588

594589
parser.on("-o", "--ctagOpts", "=path",
595590
"File with extra command line options for ctags.").
596-
Do( path -> {
591+
Do(path -> {
597592
String CTagsExtraOptionsFile = (String)path;
598593
File CTagsFile = new File(CTagsExtraOptionsFile);
599594
if (!(CTagsFile.isFile() && CTagsFile.canRead())) {
@@ -606,7 +601,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
606601
);
607602

608603
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 -> {
610605
addProjects = true;
611606
cfg.setProjectsEnabled(true);
612607
});
@@ -616,7 +611,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
616611
"by default in the web application (when no other project",
617612
"set either in cookie or in parameter). May be used multiple",
618613
"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 -> {
620615
defaultProjects.add((String)v);
621616
});
622617

@@ -627,7 +622,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
627622
"Print per project percentage progress information.",
628623
"(I/O extensive, since one read through directory structure is",
629624
"made before indexing, needs -v, otherwise it just goes to the log)").
630-
Do( v -> {
625+
Do(v -> {
631626
cfg.setPrintProgress(true);
632627
}
633628
);
@@ -636,17 +631,23 @@ public static String[] parseOptions(String[] argv) throws ParseException {
636631
"Turn on/off quick context scan. By default, only the first",
637632
"1024k of a file is scanned, and a '[..all..]' link is inserted",
638633
"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 -> {
640635
cfg.setQuickContextScan((Boolean)v);
641636
});
642637

643638
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 -> {
645640
LoggerUtil.setBaseConsoleLogLevel(Level.WARNING);
646641
});
647642

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+
648649
parser.on("-R /path/to/configuration",
649-
"Read configuration from the specified file.").Do( v-> {
650+
"Read configuration from the specified file.").Do(v-> {
650651
// Already handled above. This populates usage.
651652
});
652653

@@ -658,7 +659,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
658659
" uionly - support remote SCM for user interface only.",
659660
"dirbased - allow retrieval during history index only for repositories",
660661
" which allow getting history for directories.").
661-
Do( v -> {
662+
Do(v -> {
662663
String option = (String) v;
663664
if (option.equalsIgnoreCase(ON)) {
664665
cfg.setRemoteScmSupported(Configuration.RemoteSCM.ON);
@@ -675,18 +676,18 @@ public static String[] parseOptions(String[] argv) throws ParseException {
675676
parser.on("--renamedHistory", "=on|off", ON_OFF, Boolean.class,
676677
"Enable or disable generating history for renamed files.",
677678
"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 -> {
679680
cfg.setHandleHistoryOfRenamedFiles((Boolean)v);
680681
});
681682

682683
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 -> {
684685
searchRepositories = true;
685686
});
686687

687688
parser.on("-s", "--source", "=/path/to/source/root",
688689
"The root directory of the source tree.").
689-
Do( source -> {
690+
Do(source -> {
690691
File sourceRoot = new File((String)source);
691692
if (!sourceRoot.isDirectory()) {
692693
die("Source root " + sourceRoot + " must be a directory");
@@ -702,27 +703,27 @@ public static String[] parseOptions(String[] argv) throws ParseException {
702703
parser.on("--style", "=path",
703704
"Path to the subdirectory in the web-application containing the",
704705
"requested stylesheet. The factory-setting is: \"default\".").
705-
Do( stylePath -> {
706+
Do(stylePath -> {
706707
cfg.setWebappLAF((String)stylePath);
707708
}
708709
);
709710

710711
parser.on("--symlink", "=/path/to/symlink",
711712
"Allow this symlink to be followed. Option may be repeated.",
712713
"By default only symlinks directly under source root directory",
713-
"are allowed.").Do( symlink -> {
714+
"are allowed.").Do(symlink -> {
714715
allowedSymlinks.add((String)symlink);
715716
});
716717

717718
parser.on("-T", "--threads", "=number", Integer.class,
718719
"The number of threads to use for index generation.",
719720
"By default the number of threads will be set to the number",
720-
"of available CPUs.").Do( threadCount -> {
721+
"of available CPUs.").Do(threadCount -> {
721722
cfg.setIndexingParallelism((Integer)threadCount);
722723
});
723724

724725
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 -> {
726727
cfg.setTabSize((Integer)tabSize);
727728
});
728729

@@ -738,35 +739,35 @@ public static String[] parseOptions(String[] argv) throws ParseException {
738739
parser.on("---unitTest"); // For unit test only, will not appear in help
739740

740741
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 -> {
742743
noindex = true;
743744
});
744745

745746
parser.on("--userPage", "=URL",
746747
"Base URL of the user Information provider.",
747748
"Example: \"http://www.myserver.org/viewProfile.jspa?username=\".",
748-
"Use \"none\" to disable link.").Do( v -> {
749+
"Use \"none\" to disable link.").Do(v -> {
749750
cfg.setUserPage((String)v);
750751
});
751752

752753
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 -> {
754755
cfg.setUserPageSuffix((String)suffix);
755756
});
756757

757-
parser.on("-V", "--version", "Print version and quit.").Do( v -> {
758+
parser.on("-V", "--version", "Print version and quit.").Do(v -> {
758759
System.out.println(Info.getFullVersion());
759760
System.exit(0);
760761
});
761762

762-
parser.on("-v", "--verbose", "Set logging level to INFO.").Do( v -> {
763+
parser.on("-v", "--verbose", "Set logging level to INFO.").Do(v -> {
763764
verbose = true;
764765
LoggerUtil.setBaseConsoleLogLevel(Level.INFO);
765766
});
766767

767768
parser.on("-W", "--writeConfig", "=/path/to/configuration",
768769
"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 -> {
770771
configFilename = (String)configFile;
771772
});
772773
});
@@ -788,6 +789,12 @@ public static String[] parseOptions(String[] argv) throws ParseException {
788789
return argv;
789790
}
790791

792+
private static void checkConfiguration() {
793+
if (repositories.size() > 0 && !cfg.isHistoryEnabled()) {
794+
die("Repositories were specified however history is off");
795+
}
796+
}
797+
791798
private static void die(String message) {
792799
System.err.println("ERROR: " + message);
793800
System.exit(1);

0 commit comments

Comments
 (0)