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