31
31
import java .util .concurrent .ExecutionException ;
32
32
import java .util .concurrent .TimeUnit ;
33
33
import java .util .function .Supplier ;
34
- import java .util .logging .Level ;
35
- import java .util .logging .Logger ;
36
34
37
35
import org .apache .lucene .document .Document ;
38
36
import org .apache .lucene .document .StoredField ;
50
48
import org .opengrok .indexer .analysis .WriteXrefArgs ;
51
49
import org .opengrok .indexer .analysis .Xrefer ;
52
50
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
53
- import org .opengrok .indexer .logger .LoggerFactory ;
54
51
import org .opengrok .indexer .search .QueryBuilder ;
55
52
import org .opengrok .indexer .util .NullWriter ;
56
53
62
59
*/
63
60
public class PlainAnalyzer extends TextAnalyzer {
64
61
65
- private static final Logger LOGGER = LoggerFactory .getLogger (PlainAnalyzer .class );
66
-
67
62
/**
68
63
* Creates a new instance of PlainAnalyzer.
69
64
* @param factory defined instance for the analyzer
@@ -116,6 +111,19 @@ protected Reader getReader(InputStream stream) throws IOException {
116
111
return ExpandTabsReader .wrap (super .getReader (stream ), project );
117
112
}
118
113
114
+ private static class XrefWork {
115
+ Xrefer xrefer ;
116
+ Exception exception ;
117
+
118
+ XrefWork (Xrefer xrefer ) {
119
+ this .xrefer = xrefer ;
120
+ }
121
+
122
+ XrefWork (Exception e ) {
123
+ this .exception = e ;
124
+ }
125
+ }
126
+
119
127
@ Override
120
128
public void analyze (Document doc , StreamSource src , Writer xrefOut ) throws IOException , InterruptedException {
121
129
Definitions defs = null ;
@@ -157,16 +165,16 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
157
165
WriteXrefArgs args = new WriteXrefArgs (in , xrefOut );
158
166
args .setDefs (defs );
159
167
args .setProject (project );
160
- CompletableFuture <Xrefer > future = CompletableFuture .supplyAsync (() -> {
168
+ CompletableFuture <XrefWork > future = CompletableFuture .supplyAsync (() -> {
161
169
try {
162
- return writeXref (args );
170
+ return new XrefWork ( writeXref (args ) );
163
171
} catch (IOException e ) {
164
- LOGGER .log (Level .WARNING , "I/O exception when generating xref for " + fullPath , e );
165
- return null ;
172
+ return new XrefWork (e );
166
173
}
167
174
}, env .getIndexerParallelizer ().getXrefWatcherExecutor ()).
168
175
orTimeout (env .getXrefTimeout (), TimeUnit .SECONDS );
169
- Xrefer xref = future .get (); // Will throw ExecutionException wrapping TimeoutException on timeout.
176
+ XrefWork xrefWork = future .get (); // Will throw ExecutionException wrapping TimeoutException on timeout.
177
+ Xrefer xref = xrefWork .xrefer ;
170
178
171
179
if (xref != null ) {
172
180
Scopes scopes = xref .getScopes ();
@@ -179,8 +187,8 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
179
187
String path = doc .get (QueryBuilder .PATH );
180
188
addNumLinesLOC (doc , new NumLinesLOC (path , xref .getLineNumber (), xref .getLOC ()));
181
189
} else {
182
- // Re-throw the exception from writeXref(). We no longer have the original exception, though.
183
- throw new IOException ("I/O exception when generating xref for " + fullPath );
190
+ // Re-throw the exception from writeXref().
191
+ throw new IOException (xrefWork . exception );
184
192
}
185
193
} catch (ExecutionException e ) {
186
194
throw new InterruptedException ("failed to generate xref :" + e );
0 commit comments