Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/

/*
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.analysis;

public class XrefWork {
public Xrefer xrefer;
public Exception exception;

public XrefWork(Xrefer xrefer) {
this.xrefer = xrefer;
}

public XrefWork(Exception e) {
this.exception = e;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.plain;
Expand Down Expand Up @@ -46,6 +46,7 @@
import org.opengrok.indexer.analysis.StreamSource;
import org.opengrok.indexer.analysis.TextAnalyzer;
import org.opengrok.indexer.analysis.WriteXrefArgs;
import org.opengrok.indexer.analysis.XrefWork;
import org.opengrok.indexer.analysis.Xrefer;
import org.opengrok.indexer.configuration.RuntimeEnvironment;
import org.opengrok.indexer.search.QueryBuilder;
Expand Down Expand Up @@ -111,19 +112,6 @@ protected Reader getReader(InputStream stream) throws IOException {
return ExpandTabsReader.wrap(super.getReader(stream), project);
}

private static class XrefWork {
Xrefer xrefer;
Exception exception;

XrefWork(Xrefer xrefer) {
this.xrefer = xrefer;
}

XrefWork(Exception e) {
this.exception = e;
}
}

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
Definitions defs = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
*/

/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
package org.opengrok.indexer.analysis.plain;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import org.apache.lucene.document.Document;
import org.opengrok.indexer.analysis.AnalyzerFactory;
import org.opengrok.indexer.analysis.JFlexXref;
Expand All @@ -34,12 +38,13 @@
import org.opengrok.indexer.analysis.StreamSource;
import org.opengrok.indexer.analysis.TextAnalyzer;
import org.opengrok.indexer.analysis.WriteXrefArgs;
import org.opengrok.indexer.analysis.XrefWork;
import org.opengrok.indexer.analysis.Xrefer;
import org.opengrok.indexer.configuration.RuntimeEnvironment;
import org.opengrok.indexer.search.QueryBuilder;

/**
* Analyzes HTML files.
*
* Created on September 30, 2005
* @author Chandan
*/
Expand Down Expand Up @@ -73,26 +78,43 @@ protected int getSpecializedVersionNo() {
}

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
doc.add(new OGKTextField(QueryBuilder.FULL,
getReader(src.getStream())));
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));

RuntimeEnvironment env = RuntimeEnvironment.getInstance();

if (xrefOut != null) {
try (Reader in = getReader(src.getStream())) {
WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
args.setProject(project);
Xrefer xref = writeXref(args);
CompletableFuture<XrefWork> future = CompletableFuture.supplyAsync(() -> {
try {
return new XrefWork(writeXref(args));
} catch (IOException e) {
return new XrefWork(e);
}
}, env.getIndexerParallelizer().getXrefWatcherExecutor()).
orTimeout(env.getXrefTimeout(), TimeUnit.SECONDS);
XrefWork xrefWork = future.get(); // Will throw ExecutionException wrapping TimeoutException on timeout.
Xrefer xref = xrefWork.xrefer;

String path = doc.get(QueryBuilder.PATH);
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
if (xref != null) {
String path = doc.get(QueryBuilder.PATH);
addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
} else {
// Re-throw the exception from writeXref().
throw new IOException(xrefWork.exception);
}
} catch (ExecutionException e) {
throw new InterruptedException("failed to generate xref :" + e);
}
}
}

/**
* Creates a wrapped {@link XMLXref} instance.
* @param reader the data to produce xref for
* @return an xref instance
* @return xref instance
*/
@Override
protected JFlexXref newXref(Reader reader) {
Expand Down