@@ -25,7 +25,6 @@ Portions Copyright (c) 2017-2020, Chris Fraire <
[email protected] >.
25
25
java.io.BufferedInputStream,
26
26
java.io.File,
27
27
java.io.FileInputStream,
28
- java.io.InputStream,
29
28
java.io.InputStreamReader,
30
29
java.io.IOException,
31
30
java.io.Reader,
@@ -38,29 +37,23 @@ java.util.logging.Logger,
38
37
java.util.Set,
39
38
java.util.TreeSet,
40
39
org.opengrok.indexer.analysis.AnalyzerGuru,
41
- org.opengrok.indexer.analysis.Ctags,
42
40
org.opengrok.indexer.analysis.Definitions,
43
41
org.opengrok.indexer.analysis.AbstractAnalyzer,
44
- org.opengrok.indexer.analysis.AbstractAnalyzer.Genre,
45
42
org.opengrok.indexer.analysis.AnalyzerFactory,
46
43
org.opengrok.indexer.analysis.NullableNumLinesLOC,
47
44
org.opengrok.indexer.history.Annotation,
48
- org.opengrok.indexer.history.HistoryGuru,
49
45
org.opengrok.indexer.index.IndexDatabase,
50
46
org.opengrok.indexer.logger.LoggerFactory,
51
47
org.opengrok.indexer.search.DirectoryEntry,
52
48
org.opengrok.indexer.search.DirectoryExtraReader,
53
49
org.opengrok.indexer.util.FileExtraZipper,
54
50
org.opengrok.indexer.util.ForbiddenSymlinkException,
55
- org.opengrok.indexer.util.ObjectPool,
56
51
org.opengrok.indexer.util.IOUtils,
57
- org.opengrok.indexer.web.QueryParameters,
58
52
org.opengrok.web.DirectoryListing,
59
53
org.opengrok.indexer.web.SearchHelper"
60
54
%>
55
+ <%@ page import =" static org.opengrok.web.PageConfig.DUMMY_REVISION" %>
61
56
<%
62
- final String DUMMY_REVISION = " unknown" ;
63
-
64
57
{
65
58
// need to set it here since requesting parameters
66
59
if (request. getCharacterEncoding() == null ) {
@@ -193,11 +186,9 @@ document.pageReady.push(function() { pageReadyList();});
193
186
}
194
187
195
188
FileExtraZipper zipper = new FileExtraZipper ();
196
- List<DirectoryEntry > entries = zipper. zip(resourceFile, files,
197
- extras);
189
+ List<DirectoryEntry > entries = zipper. zip(resourceFile, files, extras);
198
190
199
- List<String > readMes = dl. extraListTo(
200
- Util . URIEncodePath(request. getContextPath()),
191
+ List<String > readMes = dl. extraListTo(Util . URIEncodePath(request. getContextPath()),
201
192
resourceFile, out, path, entries);
202
193
File [] catfiles = cfg. findDataFiles(readMes);
203
194
for (int i= 0 ; i < catfiles. length; i++ ) {
@@ -251,7 +242,7 @@ document.pageReady.push(function() { pageReadyList();});
251
242
<img src =" <%= rawPath % >" alt =" Image from Source Repository" />
252
243
</div ><%
253
244
} else if ( g == AbstractAnalyzer . Genre . HTML ) {
254
- /**
245
+ /*
255
246
* For backward compatibility, read the OpenGrok-produced
256
247
* document using the system default charset.
257
248
*/
@@ -296,147 +287,17 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
296
287
Util . dumpXref(out, xrefFile, compressed,
297
288
request. getContextPath());
298
289
% > </pre >
299
- </div ><%
290
+ </div >
291
+ <%
300
292
}
301
293
} 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
+ <%
440
301
}
441
302
} else {
442
303
// Requesting cross referenced file with no known revision.
@@ -448,10 +309,17 @@ Click <a href="<%= rawPath %>">download <%= basename %></a><%
448
309
boolean compressed = xrefFile. getName(). endsWith(" .gz" );
449
310
Util . dumpXref(out, xrefFile, compressed, request. getContextPath());
450
311
% > </pre >
451
- </div ><%
312
+ </div >
313
+ <%
452
314
} else {
315
+ // Failed to get xref, generate on the fly.
453
316
% >
454
- <p class =" error" >Failed to get xref file</p ><%
317
+ <% @
318
+
319
+ include file= " xref.jspf"
320
+
321
+ % >
322
+ <%
455
323
}
456
324
}
457
325
}
0 commit comments