Skip to content

Commit 0647a5e

Browse files
authored
Merge pull request #1643 from vladak/history_off
disable history completely if Indexer is run without -H
2 parents e0eb89e + 5248cf5 commit 0647a5e

File tree

16 files changed

+119
-46
lines changed

16 files changed

+119
-46
lines changed

opengrok-web-nbproject/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ endorsed.classpath=
3434
excludes=
3535
file.reference.bcel-6.0.jar=../lib/bcel-6.0.jar
3636
file.reference.json-simple-1.1.1.jar=../lib/json-simple-1.1.1.jar
37-
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.6.3.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jaspic-api.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
37+
j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.server.home}/lib/catalina-ant.jar:${j2ee.server.home}/lib/catalina-ha.jar:${j2ee.server.home}/lib/catalina-storeconfig.jar:${j2ee.server.home}/lib/catalina-tribes.jar:${j2ee.server.home}/lib/catalina.jar:${j2ee.server.home}/lib/ecj-4.4.2.jar:${j2ee.server.home}/lib/el-api.jar:${j2ee.server.home}/lib/jasper-el.jar:${j2ee.server.home}/lib/jasper.jar:${j2ee.server.home}/lib/jsp-api.jar:${j2ee.server.home}/lib/servlet-api.jar:${j2ee.server.home}/lib/tomcat-api.jar:${j2ee.server.home}/lib/tomcat-coyote.jar:${j2ee.server.home}/lib/tomcat-dbcp.jar:${j2ee.server.home}/lib/tomcat-i18n-es.jar:${j2ee.server.home}/lib/tomcat-i18n-fr.jar:${j2ee.server.home}/lib/tomcat-i18n-ja.jar:${j2ee.server.home}/lib/tomcat-jdbc.jar:${j2ee.server.home}/lib/tomcat-jni.jar:${j2ee.server.home}/lib/tomcat-util-scan.jar:${j2ee.server.home}/lib/tomcat-util.jar:${j2ee.server.home}/lib/tomcat-websocket.jar:${j2ee.server.home}/lib/websocket-api.jar
3838
lucene.version=6.6.0
3939
lucene-core.jar=lucene-core-${lucene.version}.jar
4040
lucene-analyzers-common.jar=lucene-analyzers-common-${lucene.version}.jar

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.opensolaris.opengrok.analysis.uue.UuencodeAnalyzerFactory;
9090
import org.opensolaris.opengrok.analysis.vb.VBAnalyzerFactory;
9191
import org.opensolaris.opengrok.configuration.Project;
92+
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
9293
import org.opensolaris.opengrok.history.Annotation;
9394
import org.opensolaris.opengrok.history.HistoryException;
9495
import org.opensolaris.opengrok.history.HistoryGuru;
@@ -328,6 +329,7 @@ public static FileAnalyzer getAnalyzer(InputStream in, String file) throws IOExc
328329
public void populateDocument(Document doc, File file, String path,
329330
FileAnalyzer fa, Writer xrefOut)
330331
throws IOException {
332+
331333
String date = DateTools.timeToString(file.lastModified(),
332334
DateTools.Resolution.MILLISECOND);
333335
doc.add(new Field(QueryBuilder.U, Util.path2uid(path, date),
@@ -336,14 +338,16 @@ public void populateDocument(Document doc, File file, String path,
336338
string_ft_nstored_nanalyzed_norms));
337339
doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH, new BytesRef(file.getAbsolutePath())));
338340

339-
try {
340-
HistoryReader hr = HistoryGuru.getInstance().getHistoryReader(file);
341-
if (hr != null) {
342-
doc.add(new TextField(QueryBuilder.HIST, hr));
343-
// date = hr.getLastCommentDate() //RFE
341+
if (RuntimeEnvironment.getInstance().isHistoryEnabled()) {
342+
try {
343+
HistoryReader hr = HistoryGuru.getInstance().getHistoryReader(file);
344+
if (hr != null) {
345+
doc.add(new TextField(QueryBuilder.HIST, hr));
346+
// date = hr.getLastCommentDate() //RFE
347+
}
348+
} catch (HistoryException e) {
349+
LOGGER.log(Level.WARNING, "An error occurred while reading history: ", e);
344350
}
345-
} catch (HistoryException e) {
346-
LOGGER.log(Level.WARNING, "An error occurred while reading history: ", e);
347351
}
348352
doc.add(new Field(QueryBuilder.DATE, date, string_ft_stored_nanalyzed_norms));
349353
doc.add(new SortedDocValuesField(QueryBuilder.DATE, new BytesRef(date)));

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ public final class Configuration {
102102
* before its result is cached.
103103
*/
104104
private int historyCacheTime;
105-
105+
/**
106+
* flag to generate history. This is bigger hammer than @{code historyCache}
107+
* above. If set to false, no history query will be ever made and the webapp
108+
* will not display any history related links/allow any history queries.
109+
*/
110+
private boolean historyEnabled;
111+
/**
112+
* maximum number of messages in webapp.
113+
*/
106114
private int messageLimit;
107115
/**
108116
* Directory with authorization plugins. Default value is
@@ -360,6 +368,7 @@ public Configuration() {
360368
setHandleHistoryOfRenamedFiles(true);
361369
setHistoryCache(true);
362370
setHistoryCacheTime(30);
371+
setHistoryEnabled(true);
363372
setHitsPerPage(25);
364373
setIgnoredNames(new IgnoredNames());
365374
setIncludedNames(new Filter());
@@ -513,6 +522,24 @@ public void setHitsPerPage(int hitsPerPage) throws IllegalArgumentException {
513522
this.hitsPerPage = hitsPerPage;
514523
}
515524

525+
/**
526+
* Should the history be enabled ?
527+
*
528+
* @return {@code true} if history is enabled, {@code false} otherwise
529+
*/
530+
public boolean isHistoryEnabled() {
531+
return historyEnabled;
532+
}
533+
534+
/**
535+
* Set whether history should be enabled.
536+
*
537+
* @param flag if {@code true} enable history
538+
*/
539+
public void setHistoryEnabled(boolean flag) {
540+
this.historyEnabled = flag;
541+
}
542+
516543
/**
517544
* Should the history log be cached?
518545
*
@@ -531,7 +558,7 @@ public boolean isHistoryCache() {
531558
public void setHistoryCache(boolean historyCache) {
532559
this.historyCache = historyCache;
533560
}
534-
561+
535562
/**
536563
* How long can a history request take before it's cached? If the time is
537564
* exceeded, the result is cached. This setting only affects

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,14 @@ public int getGroupsCollapseThreshold() {
11321132
return threadConfig.get().getGroupsCollapseThreshold();
11331133
}
11341134

1135+
public boolean isHistoryEnabled() {
1136+
return threadConfig.get().isHistoryEnabled();
1137+
}
1138+
1139+
public void setHistoryEnabled(boolean flag) {
1140+
threadConfig.get().setHistoryEnabled(flag);
1141+
}
1142+
11351143
/**
11361144
* Read an configuration file and set it as the current configuration.
11371145
*

src/org/opensolaris/opengrok/index/CommandLineOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public CommandLineOptions() {
8181
options.add(new Option('D', null, "Disable generating history for renamed files. Makes indexing faster for repositories with lots of renamed files."));
8282
options.add(new Option('e', null, "Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow."));
8383
options.add(new Option('G', null, "Assign commit tags to all entries in history for all repositories."));
84-
options.add(new Option('H', null, "Generate history cache for all repositories"));
84+
options.add(new Option('H', null, "Get history for all repositories"));
8585
options.add(new Option('h', "/path/to/repository", "just generate history cache for the specified repos (absolute path from source root)"));
8686
options.add(new Option('I', "pattern", "Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c)"));
8787
options.add(new Option('i', "pattern", "Ignore the named files (prefix with 'f:') or directories (prefix with 'd:') (supports wildcards, example: -i *.so -i *.dll)"));

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,13 @@ public void update() throws IOException, HistoryException {
339339
}
340340

341341
try {
342+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
342343
Analyzer analyzer = AnalyzerGuru.getAnalyzer();
343344
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
344345
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
345-
iwc.setRAMBufferSizeMB(RuntimeEnvironment.getInstance().getRamBufferSize());
346+
iwc.setRAMBufferSizeMB(env.getRamBufferSize());
346347
writer = new IndexWriter(indexDirectory, iwc);
347-
writer.commit(); // to make sure index exists on the disk
348+
writer.commit(); // to make sure index exists on the disk
348349

349350
if (directories.isEmpty()) {
350351
if (project == null) {
@@ -357,12 +358,14 @@ public void update() throws IOException, HistoryException {
357358
for (String dir : directories) {
358359
File sourceRoot;
359360
if ("".equals(dir)) {
360-
sourceRoot = RuntimeEnvironment.getInstance().getSourceRootFile();
361+
sourceRoot = env.getSourceRootFile();
361362
} else {
362-
sourceRoot = new File(RuntimeEnvironment.getInstance().getSourceRootFile(), dir);
363+
sourceRoot = new File(env.getSourceRootFile(), dir);
363364
}
364365

365-
HistoryGuru.getInstance().ensureHistoryCacheExists(sourceRoot);
366+
if (env.isHistoryEnabled()) {
367+
HistoryGuru.getInstance().ensureHistoryCacheExists(sourceRoot);
368+
}
366369

367370
String startuid = Util.path2uid(dir, "");
368371
IndexReader reader = DirectoryReader.open(indexDirectory); // open existing index
@@ -386,7 +389,7 @@ public void update() throws IOException, HistoryException {
386389
}
387390
// The code below traverses the tree to get total count.
388391
int file_cnt = 0;
389-
if (RuntimeEnvironment.getInstance().isPrintProgress()) {
392+
if (env.isPrintProgress()) {
390393
LOGGER.log(Level.INFO, "Counting files in {0} ...", dir);
391394
file_cnt = indexDown(sourceRoot, dir, true, 0, 0);
392395
LOGGER.log(Level.INFO,

src/org/opensolaris/opengrok/index/Indexer.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static void main(String argv[]) {
118118
String configFilename = null;
119119
String configHost = null;
120120
boolean addProjects = false;
121-
boolean refreshHistory = false;
121+
boolean getHistory = false;
122122
Set<String> defaultProjects = new TreeSet<>();
123123
boolean listFiles = false;
124124
boolean listRepos = false;
@@ -253,7 +253,7 @@ public static void main(String argv[]) {
253253
cfg.setTagsEnabled(true);
254254
break;
255255
case 'H':
256-
refreshHistory = true;
256+
getHistory = true;
257257
break;
258258
case 'h':
259259
repositories.add(getopt.getOptarg());
@@ -452,6 +452,8 @@ public static void main(String argv[]) {
452452
}
453453
}
454454

455+
cfg.setHistoryEnabled(getHistory);
456+
455457
if (configHost != null) {
456458
String[] configHostArray = configHost.split(":");
457459
if (configHostArray.length == 2) {
@@ -568,7 +570,7 @@ public static void main(String argv[]) {
568570

569571
// Get history first.
570572
getInstance().prepareIndexer(env, searchRepositories, addProjects,
571-
defaultProjects, configFilename, refreshHistory,
573+
defaultProjects, configFilename,
572574
listFiles, createDict, subFiles, repositories,
573575
zapCache, listRepos);
574576
if (listRepos || !zapCache.isEmpty()) {
@@ -619,7 +621,6 @@ public void prepareIndexer(RuntimeEnvironment env,
619621
boolean addProjects,
620622
Set<String> defaultProjects,
621623
String configFilename,
622-
boolean refreshHistory,
623624
boolean listFiles,
624625
boolean createDict,
625626
List<String> subFiles,
@@ -645,7 +646,7 @@ public void prepareIndexer(RuntimeEnvironment env,
645646
if (searchRepositories || listRepoPaths || !zapCache.isEmpty()) {
646647
LOGGER.log(Level.INFO, "Scanning for repositories...");
647648
long start = System.currentTimeMillis();
648-
if (refreshHistory == true) {
649+
if (env.isHistoryEnabled()) {
649650
HistoryGuru.getInstance().addRepositories(env.getSourceRootPath());
650651
}
651652
long time = (System.currentTimeMillis() - start) / 1000;
@@ -751,7 +752,7 @@ public void prepareIndexer(RuntimeEnvironment env,
751752
LOGGER.info("Done...");
752753
}
753754

754-
if (refreshHistory) {
755+
if (env.isHistoryEnabled()) {
755756
if (repositories != null && !repositories.isEmpty()) {
756757
LOGGER.log(Level.INFO, "Generating history cache for repositories: " +
757758
repositories.stream().collect(Collectors.joining(",")));

src/org/opensolaris/opengrok/web/Util.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,21 @@ public static String uid2url(String uid) {
660660
public static void writeHAD(Writer out, String ctxE, String entry,
661661
boolean is_dir) throws IOException {
662662

663-
String histPrefixE = ctxE + Prefix.HIST_L;
664663
String downloadPrefixE = ctxE + Prefix.DOWNLOAD_P;
665664
String xrefPrefixE = ctxE + Prefix.XREF_P;
666665

667-
out.write("<td class=\"q\"><a href=\"");
668-
out.write(histPrefixE);
669-
if (!entry.startsWith("/")) {
670-
entry = "/" + entry;
666+
out.write("<td class=\"q\">");
667+
if (RuntimeEnvironment.getInstance().isHistoryEnabled()) {
668+
String histPrefixE = ctxE + Prefix.HIST_L;
669+
670+
out.write("<a href=\"");
671+
out.write(histPrefixE);
672+
if (!entry.startsWith("/")) {
673+
entry = "/" + entry;
674+
}
675+
out.write(entry);
676+
out.write("\" title=\"History\">H</a>");
671677
}
672-
out.write(entry);
673-
out.write("\" title=\"History\">H</a>");
674678

675679
if (!is_dir) {
676680
out.write(" <a href=\"");

test/org/opensolaris/opengrok/index/IndexDatabaseTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ public static void setUpClass() throws Exception {
5959

6060
env.setSourceRoot(repository.getSourceRoot());
6161
env.setDataRoot(repository.getDataRoot());
62+
env.setHistoryEnabled(false);
6263

6364
Indexer indexer = Indexer.getInstance();
6465
indexer.prepareIndexer(
6566
env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})), null,
66-
false, false, false, null, null, new ArrayList<String>(), false);
67+
false, false, null, null, new ArrayList<String>(), false);
6768
indexer.doIndexerExecution(true, 1, null, null);
6869
}
6970

test/org/opensolaris/opengrok/index/IndexerTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ public void testIndexGeneration() throws Exception {
103103
env.setSourceRoot(repository.getSourceRoot());
104104
env.setDataRoot(repository.getDataRoot());
105105
env.setVerbose(true);
106+
env.setHistoryEnabled(false);
106107
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})), null,
107-
false, false, false, null, null, new ArrayList<>(), false);
108+
false, false, null, null, new ArrayList<>(), false);
108109
Indexer.getInstance().doIndexerExecution(true, 1, null, null);
109110
} else {
110111
System.out.println("Skipping test. Could not find a ctags I could use in path.");
@@ -132,6 +133,7 @@ public void testRescanProjects() throws Exception {
132133
projects.put("nonexistent", p2);
133134
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
134135
env.setProjects(projects);
136+
env.setHistoryEnabled(false);
135137

136138
// Do a rescan of the projects, and only that (we don't care about
137139
// the other aspects of indexing in this test case).
@@ -141,7 +143,6 @@ public void testRescanProjects() throws Exception {
141143
true, // scan and add projects
142144
null, // no default project
143145
null, // don't write config file
144-
false, // don't refresh history
145146
false, // don't list files
146147
false, // don't create dictionary
147148
null, // subFiles - not needed since we don't list files
@@ -383,8 +384,9 @@ public void testDefaultProjectsSingleProject() throws Exception {
383384
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
384385
env.setSourceRoot(repository.getSourceRoot());
385386
env.setDataRoot(repository.getDataRoot());
387+
env.setHistoryEnabled(false);
386388
Indexer.getInstance().prepareIndexer(env, true, true, new TreeSet<>(Arrays.asList(new String[]{"/c"})), null,
387-
false, false, false, null, null, new ArrayList<>(), false);
389+
false, false, null, null, new ArrayList<>(), false);
388390
assertEquals(1, env.getDefaultProjects().size());
389391
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"/c"})),
390392
env.getDefaultProjects().stream().map((Project p) -> '/' + p.getName()).collect(Collectors.toSet()));
@@ -400,9 +402,10 @@ public void testDefaultProjectsNonExistent() throws Exception {
400402
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
401403
env.setSourceRoot(repository.getSourceRoot());
402404
env.setDataRoot(repository.getDataRoot());
405+
env.setHistoryEnabled(false);
403406
Indexer.getInstance().prepareIndexer(env, true, true,
404407
new TreeSet<>(Arrays.asList(new String[]{"/lisp", "/pascal", "/perl", "/data", "/no-project-x32ds1"})),
405-
null, false, false, false, null, null, new ArrayList<>(), false);
408+
null, false, false, null, null, new ArrayList<>(), false);
406409
assertEquals(4, env.getDefaultProjects().size());
407410
assertEquals(new TreeSet<>(Arrays.asList(new String[]{"/lisp", "/pascal", "/perl", "/data"})),
408411
env.getDefaultProjects().stream().map((Project p) -> '/' + p.getName()).collect(Collectors.toSet()));
@@ -418,9 +421,10 @@ public void testDefaultProjectsAll() throws Exception {
418421
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
419422
env.setSourceRoot(repository.getSourceRoot());
420423
env.setDataRoot(repository.getDataRoot());
424+
env.setHistoryEnabled(false);
421425
Indexer.getInstance().prepareIndexer(env, true, true,
422426
new TreeSet<>(Arrays.asList(new String[]{"/c", "/data", "__all__", "/no-project-x32ds1"})),
423-
null, false, false, false, null, null, new ArrayList<>(), false);
427+
null, false, false, null, null, new ArrayList<>(), false);
424428
Set<String> projects = new TreeSet<>(Arrays.asList(new File(repository.getSourceRoot()).list()));
425429
assertEquals(projects.size(), env.getDefaultProjects().size());
426430
assertEquals(projects, env.getDefaultProjects().stream().map((Project p) -> p.getName()).collect(Collectors.toSet()));

0 commit comments

Comments
 (0)