Search in sources :

Example 1 with AbstractAnalyzer

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

the class XMLAnalyzerTest method xrefWithSpecialCharsInStringLiterals.

/**
 * XML special chars inside a string were not escaped if single quotes
 * were used around the string. Bug #15859.
 * @throws IOException I/O exception
 */
@Test
public void xrefWithSpecialCharsInStringLiterals() throws IOException {
    StringReader input = new StringReader("<foo xyz='<betweensinglequotes>'> </foo>");
    StringWriter output = new StringWriter();
    XMLAnalyzerFactory fac = new XMLAnalyzerFactory();
    AbstractAnalyzer analyzer = fac.getAnalyzer();
    analyzer.writeXref(new WriteXrefArgs(input, output));
    assertTrue(output.toString().contains("&lt;betweensinglequotes&gt;"));
    input = new StringReader("<foo xyz=\"<betweendoublequotes>\"> </foo>");
    output = new StringWriter();
    analyzer.writeXref(new WriteXrefArgs(input, output));
    assertTrue(output.toString().contains("&lt;betweendoublequotes&gt;"));
}
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 2 with AbstractAnalyzer

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

the class XMLAnalyzerTest method bug2225.

@Test
public void bug2225() throws IOException {
    String xmlText = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n" + "<foo>\n" + "  <bar name=\"com.foo.bar.MyClass\"/>\n" + "  <bar name=\"README.txt\"/>\n" + "</foo>";
    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");
    // Reference to a Java class should have / instead of . in the path
    assertTrue(xref[2].contains("path=com/foo/bar/MyClass"));
    // Ordinary file names should not have .'s replaced
    assertTrue(xref[3].contains("path=README.txt"));
}
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 3 with AbstractAnalyzer

use of org.opengrok.indexer.analysis.AbstractAnalyzer 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 4 with AbstractAnalyzer

use of org.opengrok.indexer.analysis.AbstractAnalyzer 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 5 with AbstractAnalyzer

use of org.opengrok.indexer.analysis.AbstractAnalyzer 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)

Aggregations

AbstractAnalyzer (org.opengrok.indexer.analysis.AbstractAnalyzer)15 StringWriter (java.io.StringWriter)8 WriteXrefArgs (org.opengrok.indexer.analysis.WriteXrefArgs)8 StringReader (java.io.StringReader)6 Test (org.junit.jupiter.api.Test)6 Writer (java.io.Writer)5 Document (org.apache.lucene.document.Document)5 Xrefer (org.opengrok.indexer.analysis.Xrefer)5 PlainAnalyzerFactory (org.opengrok.indexer.analysis.plain.PlainAnalyzerFactory)3 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Field (org.apache.lucene.document.Field)2 ScoreDoc (org.apache.lucene.search.ScoreDoc)2 StreamSource (org.opengrok.indexer.analysis.StreamSource)2 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ExecutionException (java.util.concurrent.ExecutionException)1