Search in sources :

Example 1 with FileAnalyzerFactory

use of org.opensolaris.opengrok.analysis.FileAnalyzerFactory in project OpenGrok by OpenGrok.

the class JarAnalyzer method analyze.

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String ename = entry.getName();
            if (xrefOut != null) {
                xrefOut.append("<br/><b>");
                Util.htmlize(ename, xrefOut);
                xrefOut.append("</b>");
            }
            doc.add(new TextField("full", ename, Store.NO));
            FileAnalyzerFactory fac = AnalyzerGuru.find(ename);
            if (fac instanceof JavaClassAnalyzerFactory) {
                if (xrefOut != null) {
                    xrefOut.append("<br/>");
                }
                JavaClassAnalyzer jca = (JavaClassAnalyzer) fac.getAnalyzer();
                jca.analyze(doc, new BufferedInputStream(zis), xrefOut);
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) FileAnalyzerFactory(org.opensolaris.opengrok.analysis.FileAnalyzerFactory) ZipEntry(java.util.zip.ZipEntry) TextField(org.apache.lucene.document.TextField)

Example 2 with FileAnalyzerFactory

use of org.opensolaris.opengrok.analysis.FileAnalyzerFactory in project OpenGrok by OpenGrok.

the class IndexerTest method testXref.

@Test
public void testXref() throws IOException {
    List<File> files = new ArrayList<>();
    FileUtilities.getAllFiles(new File(repository.getSourceRoot()), files, false);
    for (File f : files) {
        FileAnalyzerFactory factory = AnalyzerGuru.find(f.getAbsolutePath());
        if (factory == null) {
            continue;
        }
        StringWriter out;
        try (FileReader in = new FileReader(f)) {
            out = new StringWriter();
            try {
                AnalyzerGuru.writeXref(factory, in, out, null, null, null);
            } catch (UnsupportedOperationException exp) {
            // ignore
            }
        }
        out.close();
    }
}
Also used : StringWriter(java.io.StringWriter) FileAnalyzerFactory(org.opensolaris.opengrok.analysis.FileAnalyzerFactory) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) File(java.io.File) Test(org.junit.Test)

Aggregations

FileAnalyzerFactory (org.opensolaris.opengrok.analysis.FileAnalyzerFactory)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 TextField (org.apache.lucene.document.TextField)1 Test (org.junit.Test)1