Search in sources :

Example 11 with WriteXrefArgs

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

the class TroffAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    // this is to explicitly use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
    JFlexTokenizer symbolTokenizer = symbolTokenizerFactory.get();
    symbolTokenizer.setReader(getReader(src.getStream()));
    OGKTextField full = new OGKTextField(QueryBuilder.FULL, symbolTokenizer);
    doc.add(full);
    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
            args.setProject(project);
            Xrefer xref = writeXref(args);
            String path = doc.get(QueryBuilder.PATH);
            addNumLinesLOC(doc, new NumLinesLOC(path, xref.getLineNumber(), xref.getLOC()));
        }
    }
}
Also used : JFlexTokenizer(org.opengrok.indexer.analysis.JFlexTokenizer) OGKTextField(org.opengrok.indexer.analysis.OGKTextField) NumLinesLOC(org.opengrok.indexer.analysis.NumLinesLOC) Xrefer(org.opengrok.indexer.analysis.Xrefer) Reader(java.io.Reader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs)

Example 12 with WriteXrefArgs

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

the class XMLAnalyzerTest method bug806.

@Test
public void bug806() throws IOException {
    String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<server>\n" + "  <mbean code=\"QuartzBean\" \n" + "      name=\"user:service=QuartzService,name=QuartzService\">\n" + "    <depends>jboss.jca:service=DataSourceBinding,name=ServerDS</depends>\n" + "    <attribute name=\"JndiName\">Quartz</attribute>\n" + "    <attribute name=\"Properties\">\n" + "      org.quartz.plugin.jobInitializer.fileNames = ../server/default/conf/scheduler/quartz_jobs.xml\n" + "    </attribute>\n" + "  </mbean>\n" + "</server>";
    StringReader sr = new StringReader(xmlText);
    StringWriter sw = new StringWriter();
    XMLAnalyzerFactory fac = new XMLAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    analyzer.writeXref(new WriteXrefArgs(sr, sw));
    String[] xref = sw.toString().split("\n");
    // don't remove ../
    assertTrue(xref[7].contains("org.quartz.plugin.jobInitializer.fileNames</a> = <a href=\"/source/s?path=../\">..</a>/"));
}
Also used : StringWriter(java.io.StringWriter) AbstractAnalyzer(org.opengrok.indexer.analysis.AbstractAnalyzer) StringReader(java.io.StringReader) WriteXrefArgs(org.opengrok.indexer.analysis.WriteXrefArgs) Test(org.junit.jupiter.api.Test)

Example 13 with WriteXrefArgs

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

the class PhpXrefTest method basicTest.

@Test
public void basicTest() throws IOException {
    String s = "<?php foo bar";
    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);
    assertEquals("<a class=\"l\" name=\"1\" href=\"#1\">1</a><strong>&lt;?php</strong> <a href=\"/" + "source/s?defs=foo\" class=\"intelliWindow-symbol\" data-definition-place=\"undefined-in-file\">foo</a>" + " <a href=\"/source/s?defs=bar\" class=\"intelliWindow-symbol\" data-definition-place=\"undefined-in-file\">bar</a>", 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)

Aggregations

WriteXrefArgs (org.opengrok.indexer.analysis.WriteXrefArgs)13 Xrefer (org.opengrok.indexer.analysis.Xrefer)9 StringWriter (java.io.StringWriter)8 AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)8 StringReader (java.io.StringReader)6 Test (org.junit.jupiter.api.Test)6 Reader (java.io.Reader)5 Writer (java.io.Writer)5 OGKTextField (org.opengrok.indexer.analysis.OGKTextField)5 JFlexTokenizer (org.opengrok.indexer.analysis.JFlexTokenizer)4 NumLinesLOC (org.opengrok.indexer.analysis.NumLinesLOC)4 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