use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SCCSRepository method getAuthors.
private Map<String, String> getAuthors(File file) throws IOException {
ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("prs");
argv.add("-e");
argv.add("-d:I: :P:");
argv.add(file.getCanonicalPath());
Executor executor = new Executor(argv, file.getCanonicalFile().getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
SCCSRepositoryAuthorParser parser = new SCCSRepositoryAuthorParser();
executor.exec(true, parser);
return parser.getAuthors();
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SSCMHistoryParser method parse.
History parse(File file, String sinceRevision) throws HistoryException {
try {
Executor executor = repository.getHistoryLogExecutor(file, sinceRevision);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
return history;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class MercurialRepository method findOriginalName.
/**
* Get the name of file in given revision. This is used to get contents
* of a file in historical revision.
*
* @param fullpath file path
* @param fullRevToFind revision number (in the form of
* {rev}:{node|short})
* @return original filename
*/
private String findOriginalName(String fullpath, String fullRevToFind) throws IOException {
Matcher matcher = LOG_COPIES_PATTERN.matcher("");
String file = fullpath.substring(getDirectoryName().length() + 1);
ArrayList<String> argv = new ArrayList<>();
File directory = new File(getDirectoryName());
// Extract {rev} from the full revision specification string.
String[] revArray = fullRevToFind.split(":");
String revToFind = revArray[0];
if (revToFind.isEmpty()) {
LOGGER.log(Level.SEVERE, "Invalid revision string: {0}", fullRevToFind);
return null;
}
/*
* Get the list of file renames for given file to the specified
* revision. We need to get them from the newest to the oldest
* so that we can follow the renames down to the revision we are after.
*/
argv.add(ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK));
argv.add("log");
argv.add("--follow");
/*
* hg log --follow -r behavior has changed since Mercurial 3.4
* so filtering the changesets of a file no longer works with --follow.
* This is tracked by https://bz.mercurial-scm.org/show_bug.cgi?id=4959
* Once this is fixed and Mercurial versions with the fix are prevalent,
* we can revert to the old behavior.
*/
// argv.add("-r");
// Use reverse() to get the changesets from newest to oldest.
// argv.add("reverse(" + rev_to_find + ":)");
argv.add("--template");
argv.add("{rev}:{file_copies}\\n");
argv.add(fullpath);
Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
int status = executor.exec();
try (BufferedReader in = new BufferedReader(new InputStreamReader(executor.getOutputStream()))) {
String line;
while ((line = in.readLine()) != null) {
matcher.reset(line);
if (!matcher.find()) {
LOGGER.log(Level.SEVERE, "Failed to match: {0}", line);
return (null);
}
String rev = matcher.group(1);
String content = matcher.group(2);
if (rev.equals(revToFind)) {
break;
}
if (!content.isEmpty()) {
/*
* Split string of 'newfile1 (oldfile1)newfile2 (oldfile2) ...' into pairs of renames.
*/
String[] splitArray = content.split("\\)");
for (String s : splitArray) {
/*
* This will fail for file names containing ' ('.
*/
String[] move = s.split(" \\(");
if (file.equals(move[0])) {
file = move[1];
break;
}
}
}
}
}
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get original name in revision {2} for: \"{0}\" Exit code: {1}", new Object[] { fullpath, String.valueOf(status), fullRevToFind });
return null;
}
return (fullpath.substring(0, getDirectoryName().length() + 1) + file);
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class MercurialRepository method determineBranch.
/**
* Return name of the branch or "default".
*/
@Override
String determineBranch(CommandTimeoutType cmdType) throws IOException {
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("branch");
Executor executor = new Executor(cmd, new File(getDirectoryName()), RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
if (executor.exec(false) != 0) {
throw new IOException(executor.getErrorString());
}
return executor.getOutputString().trim();
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceRepository method determineCurrentVersion.
@Override
String determineCurrentVersion(CommandTimeoutType cmdType) throws IOException {
File directory = new File(getDirectoryName());
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("changes");
cmd.add("-t");
cmd.add("-m");
cmd.add("1");
cmd.add("...#have");
Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
if (executor.exec(false) != 0) {
throw new IOException(executor.getErrorString());
}
return executor.getOutputString().trim();
}
Aggregations