Search in sources :

Example 1 with Xrefer

use of org.opengrok.indexer.analysis.Xrefer in project OpenGrok by OpenGrok.

the class HaskellXrefTest method writeHaskellXref.

private static int writeHaskellXref(InputStream is, PrintStream os, Definitions defs) throws IOException {
    os.println("<!DOCTYPE html><html lang=\"en\"><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"http://localhost:8080/source/default/style.css\" /><title>Haskell Xref Test</title></head>");
    os.println("<body><div id=\"src\"><pre>");
    Writer w = new StringWriter();
    HaskellAnalyzerFactory fac = new HaskellAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs args = new WriteXrefArgs(new InputStreamReader(is, StandardCharsets.UTF_8), w);
    args.setDefs(defs);
    Xrefer xref = analyzer.writeXref(args);
    os.print(w.toString());
    os.println("</pre></div></body></html>");
    return xref.getLOC();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 2 with Xrefer

use of org.opengrok.indexer.analysis.Xrefer in project OpenGrok by OpenGrok.

the class PhpXrefTest method writePhpXref.

public int writePhpXref(InputStream is, PrintStream os) throws IOException {
    os.println("<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\" />" + "<link rel=\"stylesheet\" type=\"text/css\" " + "href=\"http://localhost:8080/source/default/style.css\" /><title>PHP Xref Test</title></head>");
    os.println("<body><div id=\"src\"><pre>");
    Writer w = new StringWriter();
    PhpAnalyzerFactory fac = new PhpAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs wargs = new WriteXrefArgs(new InputStreamReader(is, StandardCharsets.UTF_8), w);
    wargs.setDefs(getTagsDefinitions());
    analyzer.setScopesEnabled(true);
    analyzer.setFoldingEnabled(true);
    Xrefer xref = analyzer.writeXref(wargs);
    os.print(w.toString());
    os.println("</pre></div></body></html>");
    return xref.getLOC();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 3 with Xrefer

use of org.opengrok.indexer.analysis.Xrefer in project OpenGrok by OpenGrok.

the class PhpXrefTest method basicSingleQuotedStringTest.

@Test
public void basicSingleQuotedStringTest() throws IOException {
    String s = "<?php define(\"FOO\", 'BAR\\'\"'); $foo='bar'; $hola=\"ls\"; $hola=''; $hola=\"\";";
    Writer w = new StringWriter();
    PhpAnalyzerFactory fac = new PhpAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs xargs = new WriteXrefArgs(new StringReader(s), w);
    Xrefer xref = analyzer.writeXref(xargs);
    assertLinesEqual("PHP quoting", "<a class=\"l\" name=\"1\" href=\"#1\">1</a><strong>&lt;?php</strong> " + "<a href=\"/source/s?defs=define\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">define</a>(<span class=\"s\">&quot;FOO&quot;</span>," + " <span class=\"s\">&apos;BAR<strong>\\&apos;</strong>&quot;&apos;</span>); " + "$<a href=\"/source/s?defs=foo\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">foo</a>=<span class=\"s\">&apos;bar&apos;</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">&quot;ls&quot;</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">&apos;&apos;</span>; " + "$<a href=\"/source/s?defs=hola\" class=\"intelliWindow-symbol\" " + "data-definition-place=\"undefined-in-file\">hola</a>=<span class=\"s\">&quot;&quot;</span>;", w.toString());
    assertEquals(1, xref.getLOC(), "PHP LOC");
}
Also used : StringWriter(java.io.StringWriter) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) StringReader(java.io.StringReader) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.jupiter.api.Test)

Example 4 with Xrefer

use of org.opengrok.indexer.analysis.Xrefer in project OpenGrok by OpenGrok.

the class HaskellXrefTest method basicTest.

@Test
public void basicTest() throws IOException {
    String s = "putStrLn \"Hello, world!\"";
    Writer w = new StringWriter();
    HaskellAnalyzerFactory fac = new HaskellAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    WriteXrefArgs xargs = new WriteXrefArgs(new StringReader(s), w);
    Xrefer xref = analyzer.writeXref(xargs);
    assertLinesEqual("Haskell basicTest", "<a class=\"l\" name=\"1\" href=\"#1\">1</a>" + "<a href=\"/source/s?defs=putStrLn\" class=\"intelliWindow-symbol\"" + " data-definition-place=\"undefined-in-file\">putStrLn</a>" + " <span class=\"s\">&quot;Hello, world!&quot;</span>\n", w.toString());
    assertEquals(1, xref.getLOC(), "Haskell LOC");
}
Also used : StringWriter(java.io.StringWriter) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) StringReader(java.io.StringReader) Xrefer(org.opengrok.indexer.analysis.Xrefer) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.jupiter.api.Test)

Example 5 with Xrefer

use of org.opengrok.indexer.analysis.Xrefer in project OpenGrok by OpenGrok.

the class PlainAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
    Definitions defs = null;
    NullWriter nullWriter = null;
    doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));
    String fullPath = doc.get(QueryBuilder.FULLPATH);
    if (fullPath != null && ctags != null) {
        defs = ctags.doCtags(fullPath);
        if (defs != null && defs.numberOfSymbols() > 0) {
            tryAddingDefs(doc, defs, src);
            byte[] tags = defs.serialize();
            doc.add(new StoredField(QueryBuilder.TAGS, tags));
        }
    }
    /*
         * This is to explicitly use appropriate analyzer's token stream to
         * work around #1376: symbols search works like full text search.
         */
    JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
    OGKTextField ref = new OGKTextField(QueryBuilder.REFS, symbolTokenizer);
    symbolTokenizer.setReader(getReader(src.getStream()));
    doc.add(ref);
    if (scopesEnabled && xrefOut == null) {
        /*
             * Scopes are generated during xref generation. If xrefs are
             * turned off we still need to run writeXref() to produce scopes,
             * we use a dummy writer that will throw away any xref output.
             */
        nullWriter = new NullWriter();
        xrefOut = nullWriter;
    }
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            RuntimeEnvironment env = RuntimeEnvironment.getInstance();
            WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
            args.setDefs(defs);
            args.setProject(project);
            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);
            // Will throw ExecutionException wrapping TimeoutException on timeout.
            XrefWork xrefWork = future.get();
            Xrefer xref = xrefWork.xrefer;
            if (xref != null) {
                Scopes scopes = xref.getScopes();
                if (scopes.size() > 0) {
                    byte[] scopesSerialized = scopes.serialize();
                    doc.add(new StoredField(QueryBuilder.SCOPES, scopesSerialized));
                }
                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);
        } finally {
            if (nullWriter != null) {
                nullWriter.close();
            }
        }
    }
}
Also used : JFlexTokenizer(org.opengrok.indexer.analysis.JFlexTokenizer) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) Definitions(org.opengrok.indexer.analysis.Definitions) Xrefer(org.opengrok.indexer.analysis.Xrefer) Reader(java.io.Reader) ExpandTabsReader(org.opengrok.indexer.analysis.ExpandTabsReader) IOException(java.io.IOException) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) NullWriter(org.opengrok.indexer.util.NullWriter) StoredField(org.apache.lucene.document.StoredField) Scopes(org.opengrok.indexer.analysis.Scopes) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

WriteXrefArgs (org.opengrok.indexer.analysis.WriteXrefArgs)9 Xrefer (org.opengrok.indexer.analysis.Xrefer)9 StringWriter (java.io.StringWriter)5 Writer (java.io.Writer)5 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)5 Reader (java.io.Reader)4 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)4 OGKTextField (org.opengrok.indexer.analysis.OGKTextField)4 StringReader (java.io.StringReader)3 Test (org.junit.jupiter.api.Test)3 JFlexTokenizer (org.opengrok.indexer.analysis.JFlexTokenizer)3 InputStreamReader (java.io.InputStreamReader)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 StoredField (org.apache.lucene.document.StoredField)1 Definitions (org.opengrok.indexer.analysis.Definitions)1 ExpandTabsReader (org.opengrok.indexer.analysis.ExpandTabsReader)1 Scopes (org.opengrok.indexer.analysis.Scopes)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 NullWriter (org.opengrok.indexer.util.NullWriter)1