Search in sources :

Example 1 with FileAnalyzer

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

the class IndexDatabase method addFile.

/**
     * Add a file to the Lucene index (and generate a xref file)
     *
     * @param file The file to add
     * @param path The path to the file (from source root)
     * @throws java.io.IOException if an error occurs
     */
private void addFile(File file, String path) throws IOException {
    FileAnalyzer fa;
    try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
        fa = AnalyzerGuru.getAnalyzer(in, path);
    }
    for (IndexChangedListener listener : listeners) {
        listener.fileAdd(path, fa.getClass().getSimpleName());
    }
    fa.setCtags(ctags);
    fa.setProject(Project.getProject(path));
    fa.setScopesEnabled(RuntimeEnvironment.getInstance().isScopesEnabled());
    fa.setFoldingEnabled(RuntimeEnvironment.getInstance().isFoldingEnabled());
    Document doc = new Document();
    try (Writer xrefOut = getXrefWriter(fa, path)) {
        analyzerGuru.populateDocument(doc, file, path, fa, xrefOut);
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "Skipped file ''{0}'' because the analyzer didn''t " + "understand it.", path);
        LOGGER.log(Level.FINE, "Exception from analyzer " + fa.getClass().getName(), e);
        cleanupResources(doc);
        return;
    }
    try {
        writer.addDocument(doc);
    } catch (Throwable t) {
        cleanupResources(doc);
        throw t;
    }
    setDirty();
    for (IndexChangedListener listener : listeners) {
        listener.fileAdded(path, fa.getClass().getSimpleName());
    }
}
Also used : FileAnalyzer(org.opensolaris.opengrok.analysis.FileAnalyzer) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(org.apache.lucene.document.Document) FileInputStream(java.io.FileInputStream) IndexWriter(org.apache.lucene.index.IndexWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) HistoryException(org.opensolaris.opengrok.history.HistoryException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Document (org.apache.lucene.document.Document)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 FileAnalyzer (org.opensolaris.opengrok.analysis.FileAnalyzer)1 HistoryException (org.opensolaris.opengrok.history.HistoryException)1