use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class MercurialHistoryParser method processStream.
/**
* Process the output from the {@code hg log} command and collect
* {@link HistoryEntry} elements.
*
* @param input The output from the process
* @throws java.io.IOException If an error occurs while reading the stream
*/
@Override
public void processStream(InputStream input) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
entries = new ArrayList<>();
String s;
HistoryEntry entry = null;
while ((s = in.readLine()) != null) {
if (s.startsWith(MercurialRepository.CHANGESET)) {
entry = new HistoryEntry();
entries.add(entry);
entry.setActive(true);
entry.setRevision(s.substring(MercurialRepository.CHANGESET.length()).trim());
} else if (s.startsWith(MercurialRepository.USER) && entry != null) {
entry.setAuthor(s.substring(MercurialRepository.USER.length()).trim());
} else if (s.startsWith(MercurialRepository.DATE) && entry != null) {
Date date;
try {
date = repository.parse(s.substring(MercurialRepository.DATE.length()).trim());
} catch (ParseException pe) {
//
throw new IOException("Could not parse date: " + s, pe);
}
entry.setDate(date);
} else if (s.startsWith(MercurialRepository.FILES) && entry != null) {
String[] strings = s.split(" ");
for (int ii = 1; ii < strings.length; ++ii) {
if (strings[ii].length() > 0) {
File f = new File(mydir, strings[ii]);
try {
String path = env.getPathRelativeToSourceRoot(f);
entry.addFile(path.intern());
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
// ignore
} catch (FileNotFoundException e) {
// NOPMD
// If the file is not located under the source root,
// ignore it (bug #11664).
} catch (InvalidPathException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
}
}
} else if (repository.isHandleRenamedFiles() && s.startsWith(MercurialRepository.FILE_COPIES) && entry != null && isDir) {
/*
* 'file_copies:' should be present only for directories but
* we use isDir to be on the safe side.
*/
s = s.replaceFirst(MercurialRepository.FILE_COPIES, "");
String[] splitArray = s.split("\\)");
for (String part : splitArray) {
/*
* This will fail for file names containing ' ('.
*/
String[] move = part.split(" \\(");
File f = new File(mydir + move[0]);
if (!move[0].isEmpty() && f.exists()) {
renamedFiles.add(repository.getDirectoryNameRelative() + File.separator + move[0]);
}
}
} else if (s.startsWith(DESC_PREFIX) && entry != null) {
entry.setMessage(decodeDescription(s));
} else if (s.equals(MercurialRepository.END_OF_ENTRY) && entry != null) {
entry = null;
} else if (s.length() > 0) {
LOGGER.log(Level.WARNING, "Invalid/unexpected output {0} from hg log for repo {1}", new Object[] { s, repository.getDirectoryName() });
}
}
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class MonotoneHistoryParser method processStream.
/**
* Process the output from the hg log command and insert the HistoryEntries
* into the history field.
*
* @param input The output from the process
* @throws java.io.IOException If an error occurs while reading the stream
*/
@Override
public void processStream(InputStream input) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
String s;
HistoryEntry entry = null;
int state = 0;
while ((s = in.readLine()) != null) {
s = s.trim();
// the minimum amount for maximum compatibility between monotone versions.
if (s.startsWith("-----------------------------------------------------------------")) {
if (entry != null && state > 2) {
entries.add(entry);
}
entry = new HistoryEntry();
entry.setActive(true);
state = 0;
continue;
}
switch(state) {
case 0:
if (s.startsWith("Revision:")) {
String rev = s.substring("Revision:".length()).trim();
entry.setRevision(rev);
++state;
}
break;
case 1:
if (s.startsWith("Author:")) {
entry.setAuthor(s.substring("Author:".length()).trim());
++state;
}
break;
case 2:
if (s.startsWith("Date:")) {
Date date = new Date();
try {
date = repository.parse(s.substring("date:".length()).trim());
} catch (ParseException pe) {
//
throw new IOException("Could not parse date: " + s, pe);
}
entry.setDate(date);
++state;
}
break;
case 3:
if (s.startsWith("Modified ") || s.startsWith("Added ") || s.startsWith("Deleted ")) {
++state;
} else if (s.equalsIgnoreCase("ChangeLog:")) {
state = 5;
}
break;
case 4:
if (s.startsWith("Modified ") || s.startsWith("Added ") || s.startsWith("Deleted ")) {
continue;
} else if (s.equalsIgnoreCase("ChangeLog:")) {
state = 5;
} else {
String[] files = s.split(" ");
for (String f : files) {
File file = new File(mydir, f);
try {
String path = env.getPathRelativeToSourceRoot(file);
entry.addFile(path.intern());
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
// ignore
} catch (FileNotFoundException e) {
// NOPMD
// If the file is not located under the source root, ignore it
} catch (InvalidPathException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
}
}
break;
case 5:
entry.appendMessage(s);
break;
default:
LOGGER.warning("Unknown parser state: " + state);
break;
}
}
if (entry != null && state > 2) {
entries.add(entry);
}
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class BazaarHistoryParser method processStream.
/**
* Process the output from the log command and insert the HistoryEntries
* into the history field.
*
* @param input The output from the process
* @throws java.io.IOException If an error occurs while reading the stream
*/
@Override
public void processStream(InputStream input) throws IOException {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
BufferedReader in = new BufferedReader(new InputStreamReader(input));
String s;
HistoryEntry entry = null;
int state = 0;
while ((s = in.readLine()) != null) {
if ("------------------------------------------------------------".equals(s)) {
if (entry != null && state > 2) {
entries.add(entry);
}
entry = new HistoryEntry();
entry.setActive(true);
state = 0;
continue;
}
switch(state) {
case 0:
// First, go on until revno is found.
if (s.startsWith("revno:")) {
String[] rev = s.substring("revno:".length()).trim().split(" ");
entry.setRevision(rev[0]);
++state;
}
break;
case 1:
// Then, look for committer.
if (s.startsWith("committer:")) {
entry.setAuthor(s.substring("committer:".length()).trim());
++state;
}
break;
case 2:
// And then, look for timestamp.
if (s.startsWith("timestamp:")) {
try {
Date date = repository.parse(s.substring("timestamp:".length()).trim());
entry.setDate(date);
} catch (ParseException e) {
//
throw new IOException("Failed to parse history timestamp:" + s, e);
}
++state;
}
break;
case 3:
// message.
if (s.startsWith("modified:") || s.startsWith("added:") || s.startsWith("removed:")) {
++state;
} else if (s.startsWith(" ")) {
// Commit messages returned by bzr log -v are prefixed
// with two blanks.
entry.appendMessage(s.substring(2));
}
break;
case 4:
// files. (Except the labels.)
if (!(s.startsWith("modified:") || s.startsWith("added:") || s.startsWith("removed:"))) {
// The list of files is prefixed with blanks.
s = s.trim();
int idx = s.indexOf(" => ");
if (idx != -1) {
s = s.substring(idx + 4);
}
File f = new File(myDir, s);
try {
String name = env.getPathRelativeToSourceRoot(f);
entry.addFile(name.intern());
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
// ignored
} catch (InvalidPathException e) {
LOGGER.log(Level.WARNING, e.getMessage());
}
}
break;
default:
LOGGER.log(Level.WARNING, "Unknown parser state: {0}", state);
break;
}
}
if (entry != null && state > 2) {
entries.add(entry);
}
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class IndexerMainTest method testMainWithoutH.
/**
* Test cleanup of renamed thread pool after indexing without -H.
*/
@Test
public void testMainWithoutH() {
System.out.println("Generate index by using command line options without -H");
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String[] argv = { "-S", "-P", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v", "-c", env.getCtags() };
Indexer.main(argv);
checkNumberOfThreads();
}
use of org.opengrok.indexer.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class IndexerTest method testMain.
/**
* Test of doIndexerExecution method, of class Indexer.
*/
@Test
void testMain() {
System.out.println("Generate index by using command line options");
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
String[] argv = { "-S", "-P", "-H", "-Q", "off", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v", "-c", env.getCtags() };
Indexer.main(argv);
}
Aggregations