|
18 | 18 | */ |
19 | 19 |
|
20 | 20 | /* |
21 | | - * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
| 21 | + * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. |
22 | 22 | * Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>. |
23 | 23 | */ |
24 | 24 | package org.opengrok.indexer.analysis.plain; |
25 | 25 |
|
26 | 26 | import java.io.IOException; |
27 | 27 | import java.io.Reader; |
28 | 28 | import java.io.Writer; |
| 29 | +import java.util.concurrent.CompletableFuture; |
| 30 | +import java.util.concurrent.ExecutionException; |
| 31 | +import java.util.concurrent.TimeUnit; |
| 32 | + |
29 | 33 | import org.apache.lucene.document.Document; |
30 | 34 | import org.opengrok.indexer.analysis.AnalyzerFactory; |
31 | 35 | import org.opengrok.indexer.analysis.JFlexXref; |
|
34 | 38 | import org.opengrok.indexer.analysis.StreamSource; |
35 | 39 | import org.opengrok.indexer.analysis.TextAnalyzer; |
36 | 40 | import org.opengrok.indexer.analysis.WriteXrefArgs; |
| 41 | +import org.opengrok.indexer.analysis.XrefWork; |
37 | 42 | import org.opengrok.indexer.analysis.Xrefer; |
| 43 | +import org.opengrok.indexer.configuration.RuntimeEnvironment; |
38 | 44 | import org.opengrok.indexer.search.QueryBuilder; |
39 | 45 |
|
40 | 46 | /** |
41 | 47 | * Analyzes HTML files. |
42 | | - * |
43 | 48 | * Created on September 30, 2005 |
44 | 49 | * @author Chandan |
45 | 50 | */ |
@@ -73,26 +78,43 @@ protected int getSpecializedVersionNo() { |
73 | 78 | } |
74 | 79 |
|
75 | 80 | @Override |
76 | | - public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException { |
77 | | - doc.add(new OGKTextField(QueryBuilder.FULL, |
78 | | - getReader(src.getStream()))); |
| 81 | + public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException { |
| 82 | + doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream()))); |
| 83 | + |
| 84 | + RuntimeEnvironment env = RuntimeEnvironment.getInstance(); |
79 | 85 |
|
80 | 86 | if (xrefOut != null) { |
81 | 87 | try (Reader in = getReader(src.getStream())) { |
82 | 88 | WriteXrefArgs args = new WriteXrefArgs(in, xrefOut); |
83 | 89 | args.setProject(project); |
84 | | - Xrefer xref = writeXref(args); |
| 90 | + CompletableFuture<XrefWork> future = CompletableFuture.supplyAsync(() -> { |
| 91 | + try { |
| 92 | + return new XrefWork(writeXref(args)); |
| 93 | + } catch (IOException e) { |
| 94 | + return new XrefWork(e); |
| 95 | + } |
| 96 | + }, env.getIndexerParallelizer().getXrefWatcherExecutor()). |
| 97 | + orTimeout(env.getXrefTimeout(), TimeUnit.SECONDS); |
| 98 | + XrefWork xrefWork = future.get(); // Will throw ExecutionException wrapping TimeoutException on timeout. |
| 99 | + Xrefer xref = xrefWork.xrefer; |
85 | 100 |
|
86 | | - String path = doc.get(QueryBuilder.PATH); |
87 | | - addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC())); |
| 101 | + if (xref != null) { |
| 102 | + String path = doc.get(QueryBuilder.PATH); |
| 103 | + addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC())); |
| 104 | + } else { |
| 105 | + // Re-throw the exception from writeXref(). |
| 106 | + throw new IOException(xrefWork.exception); |
| 107 | + } |
| 108 | + } catch (ExecutionException e) { |
| 109 | + throw new InterruptedException("failed to generate xref :" + e); |
88 | 110 | } |
89 | 111 | } |
90 | 112 | } |
91 | 113 |
|
92 | 114 | /** |
93 | 115 | * Creates a wrapped {@link XMLXref} instance. |
94 | 116 | * @param reader the data to produce xref for |
95 | | - * @return an xref instance |
| 117 | + * @return xref instance |
96 | 118 | */ |
97 | 119 | @Override |
98 | 120 | protected JFlexXref newXref(Reader reader) { |
|
0 commit comments