Skip to content

Commit 7af88e2

Browse files
author
Vladimir Kotal
committed
generate xref on the fly if existing xref is stale
fixes #3445
1 parent ac5c3bc commit 7af88e2

File tree

3 files changed

+215
-168
lines changed

3 files changed

+215
-168
lines changed

opengrok-web/src/main/java/org/opengrok/web/PageConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public final class PageConfig {
125125
// cookie name
126126
public static final String OPEN_GROK_PROJECT = "OpenGrokProject";
127127

128+
public static final String DUMMY_REVISION = "unknown";
129+
128130
// query parameters
129131
protected static final String ALL_PROJECT_SEARCH = "searchall";
130132
protected static final String PROJECT_PARAM_NAME = "project";

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

Lines changed: 22 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Portions Copyright (c) 2017-2020, Chris Fraire <[email protected]>.
2525
java.io.BufferedInputStream,
2626
java.io.File,
2727
java.io.FileInputStream,
28-
java.io.InputStream,
2928
java.io.InputStreamReader,
3029
java.io.IOException,
3130
java.io.Reader,
@@ -38,29 +37,23 @@ java.util.logging.Logger,
3837
java.util.Set,
3938
java.util.TreeSet,
4039
org.opengrok.indexer.analysis.AnalyzerGuru,
41-
org.opengrok.indexer.analysis.Ctags,
4240
org.opengrok.indexer.analysis.Definitions,
4341
org.opengrok.indexer.analysis.AbstractAnalyzer,
44-
org.opengrok.indexer.analysis.AbstractAnalyzer.Genre,
4542
org.opengrok.indexer.analysis.AnalyzerFactory,
4643
org.opengrok.indexer.analysis.NullableNumLinesLOC,
4744
org.opengrok.indexer.history.Annotation,
48-
org.opengrok.indexer.history.HistoryGuru,
4945
org.opengrok.indexer.index.IndexDatabase,
5046
org.opengrok.indexer.logger.LoggerFactory,
5147
org.opengrok.indexer.search.DirectoryEntry,
5248
org.opengrok.indexer.search.DirectoryExtraReader,
5349
org.opengrok.indexer.util.FileExtraZipper,
5450
org.opengrok.indexer.util.ForbiddenSymlinkException,
55-
org.opengrok.indexer.util.ObjectPool,
5651
org.opengrok.indexer.util.IOUtils,
57-
org.opengrok.indexer.web.QueryParameters,
5852
org.opengrok.web.DirectoryListing,
5953
org.opengrok.indexer.web.SearchHelper"
6054
%>
55+
<%@ page import="static org.opengrok.web.PageConfig.DUMMY_REVISION" %>
6156
<%
62-
final String DUMMY_REVISION = "unknown";
63-
6457
{
6558
// need to set it here since requesting parameters
6659
if (request.getCharacterEncoding() == null) {
@@ -193,11 +186,9 @@ document.pageReady.push(function() { pageReadyList();});
193186
}
194187
195188
FileExtraZipper zipper = new FileExtraZipper();
196-
List<DirectoryEntry> entries = zipper.zip(resourceFile, files,
197-
extras);
189+
List<DirectoryEntry> entries = zipper.zip(resourceFile, files, extras);
198190
199-
List<String> readMes = dl.extraListTo(
200-
Util.URIEncodePath(request.getContextPath()),
191+
List<String> readMes = dl.extraListTo(Util.URIEncodePath(request.getContextPath()),
201192
resourceFile, out, path, entries);
202193
File[] catfiles = cfg.findDataFiles(readMes);
203194
for (int i=0; i < catfiles.length; i++) {
@@ -251,7 +242,7 @@ document.pageReady.push(function() { pageReadyList();});
251242
<img src="<%= rawPath %>" alt="Image from Source Repository"/>
252243
</div><%
253244
} else if ( g == AbstractAnalyzer.Genre.HTML) {
254-
/**
245+
/*
255246
* For backward compatibility, read the OpenGrok-produced
256247
* document using the system default charset.
257248
*/
@@ -296,147 +287,17 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
296287
Util.dumpXref(out, xrefFile, compressed,
297288
request.getContextPath());
298289
%></pre>
299-
</div><%
290+
</div>
291+
<%
300292
}
301293
} else {
302-
// requesting a previous revision or needed to generate xref on the fly
303-
// (either economy mode is enabled or the cfg.findDataFile() call above failed).
304-
AnalyzerFactory a = AnalyzerGuru.find(basename);
305-
Genre g = AnalyzerGuru.getGenre(a);
306-
String error = null;
307-
if (g == Genre.PLAIN || g == Genre.HTML || g == null) {
308-
InputStream in = null;
309-
File tempf = null;
310-
try {
311-
if (rev.equals(DUMMY_REVISION)) {
312-
in = new BufferedInputStream(new FileInputStream(resourceFile));
313-
} else {
314-
tempf = File.createTempFile("ogtags", basename);
315-
if (HistoryGuru.getInstance().getRevision(tempf, resourceFile.getParent(), basename, rev)) {
316-
in = new BufferedInputStream(new FileInputStream(tempf));
317-
} else {
318-
tempf.delete();
319-
tempf = null;
320-
}
321-
}
322-
} catch (Exception e) {
323-
// fall through to error message
324-
error = e.getMessage();
325-
if (tempf != null) {
326-
tempf.delete();
327-
tempf = null;
328-
}
329-
}
330-
if (in != null) {
331-
try {
332-
if (g == null) {
333-
a = AnalyzerGuru.find(in, basename);
334-
g = AnalyzerGuru.getGenre(a);
335-
}
336-
if (g == AbstractAnalyzer.Genre.DATA || g == AbstractAnalyzer.Genre.XREFABLE || g == null) {
337-
%>
338-
<div id="src">
339-
Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %>
340-
<%= Util.URIEncode(rev) %>"><%= basename %></a>
341-
</div><%
342-
} else {
343-
%>
344-
<div id="src">
345-
<pre><%
346-
if (g == AbstractAnalyzer.Genre.PLAIN) {
347-
Definitions defs = null;
348-
ObjectPool<Ctags> ctagsPool = cfg.getEnv().getIndexerParallelizer().getCtagsPool();
349-
int tries = 2;
350-
while (cfg.getEnv().isWebappCtags()) {
351-
Ctags ctags = ctagsPool.get();
352-
try {
353-
ctags.setTabSize(project != null ?
354-
project.getTabSize() : 0);
355-
defs = ctags.doCtags(tempf.getPath());
356-
break;
357-
} catch (InterruptedException ex) {
358-
if (--tries > 0) {
359-
LOGGER.log(Level.WARNING, "doCtags() interrupted--{0}",
360-
ex.getMessage());
361-
continue;
362-
}
363-
LOGGER.log(Level.WARNING, "doCtags()", ex);
364-
break;
365-
} catch (Exception ex) {
366-
LOGGER.log(Level.WARNING, "doCtags()", ex);
367-
break;
368-
} finally {
369-
ctags.reset();
370-
ctagsPool.release(ctags);
371-
}
372-
}
373-
Annotation annotation = cfg.getAnnotation();
374-
//not needed yet
375-
//annotation.writeTooltipMap(out);
376-
// The data under source root is read with UTF-8 as a default.
377-
r = IOUtils.createBOMStrippedReader(in, StandardCharsets.UTF_8.name());
378-
AnalyzerGuru.writeDumpedXref(request.getContextPath(),
379-
a, r, out,
380-
defs, annotation, project);
381-
} else if (g == AbstractAnalyzer.Genre.IMAGE) {
382-
%></pre>
383-
<img src="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %><%= Util.URIEncode(rev) %>"/>
384-
<pre><%
385-
} else if (g == AbstractAnalyzer.Genre.HTML) {
386-
/*
387-
* For backward compatibility, read the
388-
* OpenGrok-produced document using the system
389-
* default charset.
390-
*/
391-
r = new InputStreamReader(in);
392-
/*
393-
* dumpXref() is also useful here for
394-
* translating links.
395-
*/
396-
Util.dumpXref(out, r, request.getContextPath());
397-
} else {
398-
%>Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %>
399-
<%= Util.URIEncode(rev) %>"><%= basename %></a><%
400-
}
401-
}
402-
} catch (IOException e) {
403-
LOGGER.log(Level.SEVERE, "Failed xref on-the-fly", e);
404-
} finally {
405-
if (r != null) {
406-
IOUtils.close(r);
407-
in = null;
408-
}
409-
if (in != null) {
410-
IOUtils.close(in);
411-
in = null;
412-
}
413-
if (tempf != null) {
414-
tempf.delete();
415-
}
416-
}
417-
%></pre>
418-
</div><%
419-
} else {
420-
%>
421-
<h3 class="error">Error reading file</h3><%
422-
if (error != null) {
423-
%>
424-
<p class="error"><%= error %></p><%
425-
}
426-
}
427-
} else if (g == AbstractAnalyzer.Genre.IMAGE) {
428-
%>
429-
<div id="src">
430-
<img src="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %><%= Util.URIEncode(rev) %>"
431-
alt="Image from Source Repository"/>
432-
</div><%
433-
} else {
434-
%>
435-
<div id="src">
436-
Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %>
437-
<%= Util.URIEncode(rev) %>"><%= basename %></a>
438-
</div><%
439-
}
294+
%>
295+
<%@
296+
297+
include file="xref.jspf"
298+
299+
%>
300+
<%
440301
}
441302
} else {
442303
// Requesting cross referenced file with no known revision.
@@ -448,10 +309,17 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
448309
boolean compressed = xrefFile.getName().endsWith(".gz");
449310
Util.dumpXref(out, xrefFile, compressed, request.getContextPath());
450311
%></pre>
451-
</div><%
312+
</div>
313+
<%
452314
} else {
315+
// Failed to get xref, generate on the fly.
453316
%>
454-
<p class="error">Failed to get xref file</p><%
317+
<%@
318+
319+
include file="xref.jspf"
320+
321+
%>
322+
<%
455323
}
456324
}
457325
}

0 commit comments

Comments
 (0)