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);
}
}
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;
}
}
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;
}
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;
}
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);
}
}
Aggregations