Search in sources :

Example 31 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class MercurialRepository method getHistory.

@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // Note that the filtering of revisions based on sinceRevision is done
    // in the history log executor by passing appropriate options to
    // the 'hg' executable.
    // This is done only for directories since if getHistory() is used
    // for file, the file is renamed and its complete history is fetched
    // so no sinceRevision filter is needed.
    // See findOriginalName() code for more details.
    History result = new MercurialHistoryParser(this).parse(file, sinceRevision);
    // because we know it :-)
    if (env.isTagsEnabled()) {
        assignTagsInHistory(result);
    }
    return result;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 32 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class GitHistoryParser method process.

private void process(BufferedReader in) throws IOException {
    DateFormat df = repository.getDateFormat();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    entries = new ArrayList<>();
    HistoryEntry entry = null;
    ParseState state = ParseState.HEADER;
    String s = in.readLine();
    while (s != null) {
        if (state == ParseState.HEADER) {
            if (s.startsWith("commit")) {
                if (entry != null) {
                    entries.add(entry);
                }
                entry = new HistoryEntry();
                entry.setActive(true);
                String commit = s.substring("commit".length()).trim();
                entry.setRevision(commit);
            } else if (s.startsWith("Author:") && entry != null) {
                entry.setAuthor(s.substring("Author:".length()).trim());
            } else if (s.startsWith("AuthorDate:") && entry != null) {
                String dateString = s.substring("AuthorDate:".length()).trim();
                try {
                    entry.setDate(df.parse(dateString));
                } catch (ParseException pe) {
                    //
                    throw new IOException("Failed to parse author date: " + s, pe);
                }
            } else if (StringUtils.isOnlyWhitespace(s)) {
                // We are done reading the heading, start to read the message
                state = ParseState.MESSAGE;
                // The current line is empty - the message starts on the next line (to be parsed below).
                s = in.readLine();
            }
        }
        if (state == ParseState.MESSAGE) {
            if ((s.length() == 0) || Character.isWhitespace(s.charAt(0))) {
                if (entry != null) {
                    entry.appendMessage(s);
                }
            } else {
                // This is the list of files after the message - add them
                state = ParseState.FILES;
            }
        }
        if (state == ParseState.FILES) {
            if (StringUtils.isOnlyWhitespace(s) || s.startsWith("commit")) {
                state = ParseState.HEADER;
                // Parse this line again - do not read a new line
                continue;
            }
            if (entry != null) {
                try {
                    File f = new File(myDir, s);
                    entry.addFile(env.getPathRelativeToSourceRoot(f, 0));
                } catch (FileNotFoundException e) {
                //NOPMD
                // If the file is not located under the source root,
                // ignore it (bug #11664).
                }
            }
        }
        s = in.readLine();
    }
    if (entry != null) {
        entries.add(entry);
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) DateFormat(java.text.DateFormat) FileNotFoundException(java.io.FileNotFoundException) ParseException(java.text.ParseException) IOException(java.io.IOException) File(java.io.File)

Example 33 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexDatabase method updateAll.

/**
     * Update the index database for all of the projects
     *
     * @param executor An executor to run the job
     * @param listener where to signal the changes to the database
     * @throws IOException if an error occurs
     */
static void updateAll(ExecutorService executor, IndexChangedListener listener) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<>();
    if (env.hasProjects()) {
        for (Project project : env.getProjects()) {
            dbs.add(new IndexDatabase(project));
        }
    } else {
        dbs.add(new IndexDatabase());
    }
    for (IndexDatabase d : dbs) {
        final IndexDatabase db = d;
        if (listener != null) {
            db.addIndexChangedListener(listener);
        }
        executor.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    db.update();
                } catch (Throwable e) {
                    LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
                }
            }
        });
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList)

Example 34 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexDatabase method update.

/**
     * Update the index database for a number of sub-directories
     *
     * @param executor An executor to run the job
     * @param listener where to signal the changes to the database
     * @param paths list of paths to be indexed
     * @throws IOException if an error occurs
     */
public static void update(ExecutorService executor, IndexChangedListener listener, List<String> paths) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    List<IndexDatabase> dbs = new ArrayList<>();
    for (String path : paths) {
        Project project = Project.getProject(path);
        if (project == null && env.hasProjects()) {
            LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
        } else {
            IndexDatabase db;
            try {
                if (project == null) {
                    db = new IndexDatabase();
                } else {
                    db = new IndexDatabase(project);
                }
                int idx = dbs.indexOf(db);
                if (idx != -1) {
                    db = dbs.get(idx);
                }
                if (db.addDirectory(path)) {
                    if (idx == -1) {
                        dbs.add(db);
                    }
                } else {
                    LOGGER.log(Level.WARNING, "Directory does not exist \"{0}\" .", path);
                }
            } catch (IOException e) {
                LOGGER.log(Level.WARNING, "An error occured while updating index", e);
            }
        }
        for (final IndexDatabase db : dbs) {
            db.addIndexChangedListener(listener);
            executor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        db.update();
                    } catch (Throwable e) {
                        LOGGER.log(Level.SEVERE, "An error occured while updating index", e);
                    }
                }
            });
        }
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 35 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexDatabase method getXrefWriter.

/**
     * Get a writer to which the xref can be written, or null if no xref
     * should be produced for files of this type.
     */
private Writer getXrefWriter(FileAnalyzer fa, String path) throws IOException {
    Genre g = fa.getFactory().getGenre();
    if (xrefDir != null && (g == Genre.PLAIN || g == Genre.XREFABLE)) {
        File xrefFile = new File(xrefDir, path);
        // only increase the file IO...
        if (!xrefFile.getParentFile().mkdirs()) {
            assert xrefFile.getParentFile().exists();
        }
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        boolean compressed = env.isCompressXref();
        File file = new File(xrefDir, path + (compressed ? ".gz" : ""));
        return new BufferedWriter(new OutputStreamWriter(compressed ? new GZIPOutputStream(new FileOutputStream(file)) : new FileOutputStream(file)));
    }
    // no Xref for this analyzer
    return null;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Genre(org.opensolaris.opengrok.analysis.FileAnalyzer.Genre) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)45 File (java.io.File)20 IOException (java.io.IOException)17 Project (org.opensolaris.opengrok.configuration.Project)12 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)5 ParseException (java.text.ParseException)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 DateFormat (java.text.DateFormat)4 TestRepository (org.opensolaris.opengrok.util.TestRepository)4 Date (java.util.Date)3 IndexReader (org.apache.lucene.index.IndexReader)3 BeforeClass (org.junit.BeforeClass)3 OutputStreamWriter (java.io.OutputStreamWriter)2 HistoryException (org.opensolaris.opengrok.history.HistoryException)2 Repository (org.opensolaris.opengrok.history.Repository)2 Executor (org.opensolaris.opengrok.util.Executor)2 BufferedWriter (java.io.BufferedWriter)1