Search in sources :

Example 51 with RuntimeEnvironment

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

the class Repository method createCache.

/**
 * Create a history log cache for all files in this repository.
 * {@code getHistory()} is used to fetch the history for the entire
 * repository. If {@code hasHistoryForDirectories()} returns {@code false},
 * this method is a no-op.
 *
 * @param cache the cache instance in which to store the history log
 * @param sinceRevision if non-null, incrementally update the cache with all
 * revisions after the specified revision; otherwise, create the full
 * history starting with the initial revision
 *
 * @throws HistoryException on error
 */
final void createCache(HistoryCache cache, String sinceRevision) throws HistoryException {
    if (!isWorking()) {
        return;
    }
    // this way. Just give up and return.
    if (!hasHistoryForDirectories()) {
        LOGGER.log(Level.INFO, "Skipping creation of history cache for {0}, since retrieval " + "of history for directories is not implemented for this " + "repository type.", getDirectoryName());
        return;
    }
    File directory = new File(getDirectoryName());
    History history;
    try {
        history = getHistory(directory, sinceRevision);
    } catch (HistoryException he) {
        if (sinceRevision == null) {
            // Failed to get full history, so fail.
            throw he;
        }
        // Failed to get partial history. This may have been caused
        // by changes in the revision numbers since the last update
        // (bug #14724) so we'll try to regenerate the cache from
        // scratch instead.
        LOGGER.log(Level.INFO, "Failed to get partial history. Attempting to " + "recreate the history cache from scratch.", he);
        history = null;
    }
    if (sinceRevision != null && history == null) {
        // Failed to get partial history, now get full history instead.
        history = getHistory(directory);
        // Got full history successfully. Clear the history cache so that
        // we can recreate it from scratch.
        cache.clear(this);
    }
    // We need to refresh list of tags for incremental reindex.
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    if (env.isTagsEnabled() && this.hasFileBasedTags()) {
        this.buildTagList(new File(this.getDirectoryName()));
    }
    if (history != null) {
        cache.store(history, this);
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) File(java.io.File)

Example 52 with RuntimeEnvironment

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

the class RepositoryInfo method setDirectoryName.

/**
 * Specify the name of the root directory for this repository.
 *
 * @param dir the new name of the root directory. Can be absolute
 * path or relative to source root.
 */
public void setDirectoryName(File dir) {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String rootPath = env.getSourceRootPath();
    String path;
    String originalPath = dir.getPath();
    try {
        path = PathUtils.getRelativeToCanonical(originalPath, rootPath);
        // also stored as such.
        if (!path.equals(originalPath))
            path = File.separator + path;
    } catch (IOException e) {
        path = originalPath;
        LOGGER.log(Level.SEVERE, String.format("Failed to get canonical path for {0}", path), e);
    }
    if (path.startsWith(rootPath)) {
        this.directoryNameRelative = path.substring(rootPath.length());
    } else {
        this.directoryNameRelative = path;
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) IOException(java.io.IOException)

Example 53 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)) {
        RuntimeEnvironment env = RuntimeEnvironment.getInstance();
        boolean compressed = env.isCompressXref();
        File xrefFile = new File(xrefDir, path + (compressed ? ".gz" : ""));
        File parentFile = xrefFile.getParentFile();
        // only increase the file IO...
        if (!parentFile.mkdirs()) {
            assert parentFile.exists();
        }
        // Write to a pending file for later renaming.
        String xrefAbs = xrefFile.getAbsolutePath();
        File transientXref = new File(xrefAbs + PendingFileCompleter.PENDING_EXTENSION);
        PendingFileRenaming ren = new PendingFileRenaming(xrefAbs, transientXref.getAbsolutePath());
        completer.add(ren);
        return new BufferedWriter(new OutputStreamWriter(compressed ? new GZIPOutputStream(new FileOutputStream(transientXref)) : new FileOutputStream(transientXref)));
    }
    // 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)

Example 54 with RuntimeEnvironment

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

the class IndexDatabase method isLocal.

/**
 * Check if a file is local to the current project. If we don't have
 * projects, check if the file is in the source root.
 *
 * @param path the path to a file
 * @return true if the file is local to the current repository
 */
private boolean isLocal(String path) {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String srcRoot = env.getSourceRootPath();
    boolean local = false;
    if (path.startsWith(srcRoot)) {
        if (env.hasProjects()) {
            String relPath = path.substring(srcRoot.length());
            if (project.equals(Project.getProject(relPath))) {
                // File is under the current project, so it's local.
                local = true;
            }
        } else {
            // File is under source root, and we don't have projects, so
            // consider it local.
            local = true;
        }
    }
    return local;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment)

Example 55 with RuntimeEnvironment

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

the class IndexDatabase method markProjectIndexed.

private void markProjectIndexed(Project project) throws IOException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    // refresh.
    if (project != null) {
        if (env.getConfigHost() != null && env.getConfigPort() > 0) {
            Message m = Message.createMessage("project");
            m.addTag(project.getName());
            m.setText("indexed");
            try {
                m.write(env.getConfigHost(), env.getConfigPort());
            } catch (ConnectException ce) {
                LOGGER.log(Level.SEVERE, "Misconfig of webapp host or port", ce);
                System.err.println("Couldn't notify the webapp (and host or port set): " + ce.getLocalizedMessage());
            }
        }
        // Also need to store the correct value in configuration
        // when indexer writes it to a file.
        project.setIndexed(true);
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Message(org.opensolaris.opengrok.configuration.messages.Message) ConnectException(java.net.ConnectException)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)81 File (java.io.File)31 Project (org.opensolaris.opengrok.configuration.Project)27 IOException (java.io.IOException)23 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)17 TestRepository (org.opensolaris.opengrok.util.TestRepository)13 ForbiddenSymlinkException (org.opensolaris.opengrok.util.ForbiddenSymlinkException)12 BeforeClass (org.junit.BeforeClass)11 Ctags (org.opensolaris.opengrok.analysis.Ctags)6 BufferedReader (java.io.BufferedReader)5 FileNotFoundException (java.io.FileNotFoundException)5 InputStreamReader (java.io.InputStreamReader)5 ParseException (java.text.ParseException)5 DateFormat (java.text.DateFormat)4 Date (java.util.Date)4 RepositoryInfo (org.opensolaris.opengrok.history.RepositoryInfo)4 OutputStreamWriter (java.io.OutputStreamWriter)3 ConnectException (java.net.ConnectException)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3