Search in sources :

Example 6 with RuntimeEnvironment

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

the class FileHistoryCache method storeFile.

/**
     * Store history object (encoded as XML and compressed with gzip) in a file.
     *
     * @param history history object to store
     * @param file file to store the history object into
     * @param repo repository for the file
     * @throws HistoryException
     */
private void storeFile(History histNew, File file, Repository repo) throws HistoryException {
    File cacheFile = getCachedFile(file);
    History history = histNew;
    File dir = cacheFile.getParentFile();
    if (!dir.isDirectory() && !dir.mkdirs()) {
        throw new HistoryException("Unable to create cache directory '" + dir + "'.");
    }
    // Incremental update of the history for this file.
    History histOld;
    try {
        histOld = readCache(cacheFile);
        // Merge old history with the new history.
        List<HistoryEntry> listOld = histOld.getHistoryEntries();
        if (!listOld.isEmpty()) {
            RuntimeEnvironment env = RuntimeEnvironment.getInstance();
            List<HistoryEntry> listNew = histNew.getHistoryEntries();
            ListIterator li = listNew.listIterator(listNew.size());
            while (li.hasPrevious()) {
                listOld.add(0, (HistoryEntry) li.previous());
            }
            history = new History(listOld);
            // to this somewhat crude solution.
            if (env.isTagsEnabled() && repo.hasFileBasedTags()) {
                for (HistoryEntry ent : history.getHistoryEntries()) {
                    ent.setTags(null);
                }
                repo.assignTagsInHistory(history);
            }
        }
    } catch (IOException ex) {
    // Ideally we would want to catch the case when incremental update
    // is done but the cached file is not there however we do not have
    // the data to do it here.
    }
    writeHistoryToFile(dir, history, cacheFile);
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) IOException(java.io.IOException) ListIterator(java.util.ListIterator) File(java.io.File)

Example 7 with RuntimeEnvironment

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

the class FileHistoryCache method getCachedFile.

/**
     * Get a <code>File</code> object describing the cache file.
     *
     * @param file the file to find the cache for
     * @return file that might contain cached history for <code>file</code>
     */
private static File getCachedFile(File file) throws HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    StringBuilder sb = new StringBuilder();
    sb.append(env.getDataRootPath());
    sb.append(File.separatorChar);
    sb.append("historycache");
    try {
        String add = env.getPathRelativeToSourceRoot(file, 0);
        if (add.length() == 0) {
            add = File.separator;
        }
        sb.append(add);
        sb.append(".gz");
    } catch (IOException e) {
        throw new HistoryException("Failed to get path relative to " + "source root for " + file, e);
    }
    return new File(sb.toString());
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) IOException(java.io.IOException) File(java.io.File)

Example 8 with RuntimeEnvironment

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

the class BazaarRepository method getHistory.

@Override
History getHistory(File file, String sinceRevision) throws HistoryException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    History result = new BazaarHistoryParser(this).parse(file, sinceRevision);
    // We don't need to check if this repository supports tags, because we know it:-)
    if (env.isTagsEnabled()) {
        assignTagsInHistory(result);
    }
    return result;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 9 with RuntimeEnvironment

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

the class IndexDatabase method listFrequentTokens.

static void listFrequentTokens(List<String> subFiles) throws IOException {
    final int limit = 4;
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.hasProjects()) {
        if (subFiles == null || subFiles.isEmpty()) {
            for (Project project : env.getProjects()) {
                IndexDatabase db = new IndexDatabase(project);
                db.listTokens(4);
            }
        } else {
            for (String path : subFiles) {
                Project project = Project.getProject(path);
                if (project == null) {
                    LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
                } else {
                    IndexDatabase db = new IndexDatabase(project);
                    db.listTokens(4);
                }
            }
        }
    } else {
        IndexDatabase db = new IndexDatabase();
        db.listTokens(limit);
    }
}
Also used : Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 10 with RuntimeEnvironment

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

the class IndexDatabase method initialize.

@SuppressWarnings("PMD.CollapsibleIfStatements")
private void initialize() throws IOException {
    synchronized (this) {
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        File indexDir = new File(env.getDataRootFile(), INDEX_DIR);
        if (project != null) {
            indexDir = new File(indexDir, project.getPath());
        }
        if (!indexDir.exists() && !indexDir.mkdirs()) {
            // to avoid race conditions, just recheck..
            if (!indexDir.exists()) {
                throw new FileNotFoundException("Failed to create root directory [" + indexDir.getAbsolutePath() + "]");
            }
        }
        if (!env.isUsingLuceneLocking()) {
            lockfact = NoLockFactory.INSTANCE;
        }
        indexDirectory = FSDirectory.open(indexDir.toPath(), lockfact);
        ignoredNames = env.getIgnoredNames();
        includedNames = env.getIncludedNames();
        analyzerGuru = new AnalyzerGuru();
        if (env.isGenerateHtml()) {
            xrefDir = new File(env.getDataRootFile(), "xref");
        }
        listeners = new ArrayList<>();
        dirtyFile = new File(indexDir, "dirty");
        dirty = dirtyFile.exists();
        directories = new ArrayList<>();
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) AnalyzerGuru(org.opensolaris.opengrok.analysis.AnalyzerGuru)

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