Skip to content

Commit ee13dba

Browse files
idodeclareVladimir Kotal
authored andcommitted
Re-gen xref if missing. Fix list.jsp w.r.t. isGenerateHtml().
This also fixes #2092, since stale xrefs will be ignored and instead the latest content will be xrefed anew. Also fixes #2316
1 parent 11cc45a commit ee13dba

File tree

3 files changed

+71
-23
lines changed

3 files changed

+71
-23
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/AnalyzerGuru.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,16 @@ public static Genre getGenre(FileAnalyzerFactory factory) {
700700
return null;
701701
}
702702

703+
/**
704+
* Finds a {@code FileAnalyzerFactory} for the specified
705+
* {@link FileAnalyzer#getFileTypeName()}.
706+
* @param fileTypeName a defined instance
707+
* @return a defined instance or {@code null}
708+
*/
709+
public static FileAnalyzerFactory findByFileTypeName(String fileTypeName) {
710+
return FILETYPE_FACTORIES.get(fileTypeName);
711+
}
712+
703713
/**
704714
* Find a {@code FileAnalyzerFactory} with the specified class name. If one
705715
* doesn't exist, create one and register it. Allow specification of either

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

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import org.opengrok.indexer.analysis.Definitions;
8888
import org.opengrok.indexer.analysis.FileAnalyzer;
8989
import org.opengrok.indexer.analysis.FileAnalyzer.Genre;
90+
import org.opengrok.indexer.analysis.FileAnalyzerFactory;
9091
import org.opengrok.indexer.configuration.Project;
9192
import org.opengrok.indexer.configuration.RuntimeEnvironment;
9293
import org.opengrok.indexer.history.HistoryException;
@@ -313,9 +314,7 @@ private void initialize() throws IOException {
313314
ignoredNames = env.getIgnoredNames();
314315
includedNames = env.getIncludedNames();
315316
analyzerGuru = new AnalyzerGuru();
316-
if (env.isGenerateHtml()) {
317-
xrefDir = new File(env.getDataRootFile(), XREF_DIR);
318-
}
317+
xrefDir = new File(env.getDataRootFile(), XREF_DIR);
319318
listeners = new CopyOnWriteArrayList<>();
320319
dirtyFile = new File(indexDir, "dirty");
321320
dirty = dirtyFile.exists();
@@ -677,17 +676,17 @@ private void setDirty() {
677676
}
678677
}
679678

679+
private File whatXrefFile(String path, boolean compress) {
680+
return new File(xrefDir, path + (compress ? ".gz" : ""));
681+
}
682+
680683
/**
681684
* Queue the removal of xref file for given path
682685
* @param path path to file under source root
683686
*/
684687
private void removeXrefFile(String path) {
685-
File xrefFile;
686-
if (RuntimeEnvironment.getInstance().isCompressXref()) {
687-
xrefFile = new File(xrefDir, path + ".gz");
688-
} else {
689-
xrefFile = new File(xrefDir, path);
690-
}
688+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
689+
File xrefFile = whatXrefFile(path, env.isCompressXref());
691690
PendingFileDeletion pending = new PendingFileDeletion(
692691
xrefFile.getAbsolutePath());
693692
completer.add(pending);
@@ -750,7 +749,7 @@ private void addFile(File file, String path, Ctags ctags)
750749
fa.setFoldingEnabled(RuntimeEnvironment.getInstance().isFoldingEnabled());
751750

752751
Document doc = new Document();
753-
try (Writer xrefOut = getXrefWriter(fa, path)) {
752+
try (Writer xrefOut = newXrefWriter(fa, path)) {
754753
analyzerGuru.populateDocument(doc, file, path, fa, xrefOut);
755754
} catch (InterruptedException e) {
756755
LOGGER.log(Level.WARNING, "File ''{0}'' interrupted--{1}",
@@ -1076,6 +1075,8 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
10761075
}
10771076
Arrays.sort(files, FILENAME_COMPARATOR);
10781077

1078+
final boolean[] outIsXrefWriter = new boolean[1];
1079+
10791080
for (File file : files) {
10801081
String path = parent + File.separator + file.getName();
10811082
if (!accept(dir, file, outLocalRelPath)) {
@@ -1127,7 +1128,9 @@ private void indexDown(File dir, String parent, IndexDownArgs args)
11271128
*/
11281129
if (uidIter != null && uidIter.term() != null
11291130
&& uidIter.term().bytesEquals(buid)) {
1130-
boolean chkres = chkSettings(file, path);
1131+
boolean chkres = chkSettings(outIsXrefWriter, file,
1132+
path) && (!outIsXrefWriter[0] ||
1133+
checkXrefExistence(path));
11311134
if (!chkres) {
11321135
removeFile(false);
11331136
}
@@ -1579,16 +1582,21 @@ public int hashCode() {
15791582
return hash;
15801583
}
15811584

1585+
private boolean isXrefWriter(FileAnalyzer fa) {
1586+
Genre g = fa.getFactory().getGenre();
1587+
return (g == Genre.PLAIN || g == Genre.XREFABLE);
1588+
}
1589+
15821590
/**
15831591
* Get a writer to which the xref can be written, or null if no xref
15841592
* should be produced for files of this type.
15851593
*/
1586-
private Writer getXrefWriter(FileAnalyzer fa, String path) throws IOException {
1587-
Genre g = fa.getFactory().getGenre();
1588-
if (xrefDir != null && (g == Genre.PLAIN || g == Genre.XREFABLE)) {
1589-
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
1594+
private Writer newXrefWriter(FileAnalyzer fa, String path)
1595+
throws IOException {
1596+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
1597+
if (env.isGenerateHtml() && isXrefWriter(fa)) {
15901598
boolean compressed = env.isCompressXref();
1591-
File xrefFile = new File(xrefDir, path + (compressed ? ".gz" : ""));
1599+
File xrefFile = whatXrefFile(path, compressed);
15921600
File parentFile = xrefFile.getParentFile();
15931601

15941602
// If mkdirs() returns false, the failure is most likely
@@ -1662,7 +1670,9 @@ private void finishWriting() throws IOException {
16621670
* @param path the source file path
16631671
* @return {@code false} if a mismatch is detected
16641672
*/
1665-
private boolean chkSettings(File file, String path) throws IOException {
1673+
private boolean chkSettings(boolean[] outIsXrefWriter, File file,
1674+
String path) throws IOException {
1675+
16661676
int reqTabSize = project != null && project.hasTabSizeSetting() ?
16671677
project.getTabSize() : 0;
16681678
Integer actTabSize = settings.getTabSize();
@@ -1693,6 +1703,7 @@ private boolean chkSettings(File file, String path) throws IOException {
16931703
break;
16941704
}
16951705

1706+
FileAnalyzer fa = null;
16961707
String fileTypeName;
16971708
if (actGuruVersion.equals(reqGuruVersion)) {
16981709
fileTypeName = doc.get(QueryBuilder.TYPE);
@@ -1701,6 +1712,12 @@ private boolean chkSettings(File file, String path) throws IOException {
17011712
LOGGER.log(Level.FINEST, "Missing TYPE field: {0}", path);
17021713
break;
17031714
}
1715+
1716+
FileAnalyzerFactory fac =
1717+
AnalyzerGuru.findByFileTypeName(fileTypeName);
1718+
if (fac != null) {
1719+
fa = fac.getAnalyzer();
1720+
}
17041721
} else {
17051722
/**
17061723
* If the stored guru version does not match, re-verify the
@@ -1709,7 +1726,7 @@ private boolean chkSettings(File file, String path) throws IOException {
17091726
*/
17101727
LOGGER.log(Level.FINER, "Guru version mismatch: {0}", path);
17111728

1712-
FileAnalyzer fa = getAnalyzerFor(file, path);
1729+
fa = getAnalyzerFor(file, path);
17131730
fileTypeName = fa.getFileTypeName();
17141731
String oldTypeName = doc.get(QueryBuilder.TYPE);
17151732
if (!fileTypeName.equals(oldTypeName)) {
@@ -1732,6 +1749,10 @@ private boolean chkSettings(File file, String path) throws IOException {
17321749
return false;
17331750
}
17341751

1752+
if (fa != null) {
1753+
outIsXrefWriter[0] = isXrefWriter(fa);
1754+
}
1755+
17351756
// The versions checks have passed.
17361757
break;
17371758
}
@@ -1761,6 +1782,24 @@ private IndexAnalysisSettings2 readAnalysisSettings() throws IOException {
17611782
return dao.read(reader);
17621783
}
17631784

1785+
private boolean checkXrefExistence(String path) {
1786+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
1787+
boolean chkres = whatXrefFile(path, env.isCompressXref()).exists();
1788+
1789+
if (!env.isGenerateHtml()) {
1790+
if (chkres) {
1791+
LOGGER.log(Level.FINEST, "Extraneous {0}", path);
1792+
removeXrefFile(path);
1793+
}
1794+
return true;
1795+
}
1796+
1797+
if (!chkres) {
1798+
LOGGER.log(Level.FINEST, "Missing {0}", path);
1799+
}
1800+
return chkres;
1801+
}
1802+
17641803
private class IndexDownArgs {
17651804
boolean count_only;
17661805
int cur_count;

opengrok-web/src/main/webapp/list.jsp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CDDL HEADER END
2020
2121
Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
2222
Portions Copyright 2011 Jens Elkner.
23-
Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
23+
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2424
2525
--%>
2626
<%@page errorPage="error.jsp" import="
@@ -176,7 +176,9 @@ document.pageReady.push(function() { pageReadyList();});
176176
}
177177
} else if (rev.length() != 0) {
178178
// requesting a revision
179-
if (cfg.isLatestRevision(rev)) {
179+
File xrefFile = null;
180+
if (cfg.isLatestRevision(rev) &&
181+
(xrefFile = cfg.findDataFile()) != null) {
180182
if (cfg.annotate()) {
181183
// annotate
182184
BufferedInputStream bin =
@@ -232,8 +234,6 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
232234
}
233235
234236
} else {
235-
File xrefFile = cfg.findDataFile();
236-
if (xrefFile != null) {
237237
%>
238238
<div id="src" data-navigate-window-enabled="<%= navigateWindowEnabled %>">
239239
<pre><%
@@ -242,7 +242,6 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
242242
request.getContextPath());
243243
%></pre>
244244
</div><%
245-
}
246245
}
247246
} else {
248247
// requesting a previous revision

0 commit comments

Comments
 (0)