use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceHistoryParser method parseDirectory.
private History parseDirectory(File file, String sinceRevision) throws IOException {
ArrayList<String> cmd = new ArrayList<>();
// First run
cmd.add(repo.RepoCommand);
cmd.add("changes");
cmd.add("-tl");
String directorySpec = "..." + asRevisionSuffix(sinceRevision);
cmd.add(directorySpec);
Executor executor = new Executor(cmd, file);
executor.exec();
History history = parseChanges(executor.getOutputReader());
// Run filelog without -l
cmd.clear();
cmd.add(repo.RepoCommand);
cmd.add("filelog");
cmd.add("-sti");
cmd.add(directorySpec);
executor = new Executor(cmd, file);
executor.exec();
parseTruncatedFileLog(history, executor.getOutputReader());
return history;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceHistoryParser method getRevisions.
/**
* Retrieve the history of a given file.
*
* @param file the file to parse history for
* @param sinceRevision the revision at which to end history
* @return object representing the file's history
*/
History getRevisions(File file, String sinceRevision) throws IOException {
ArrayList<String> cmd = new ArrayList<>();
cmd.add(repo.RepoCommand);
cmd.add("filelog");
cmd.add("-slti");
cmd.add(protectPerforceFilename(file.getName()) + asRevisionSuffix(sinceRevision));
Executor executor = new Executor(cmd, file.getParentFile());
executor.exec();
return parseFileLog(executor.getOutputReader());
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SSCMRepository method getHistoryGet.
@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
File directory = new File(parent);
try {
final File tmp = Files.createTempDirectory("opengrokSSCMtmp").toFile();
String tmpName = tmp.getCanonicalPath();
List<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("get");
argv.add(basename);
argv.add("-d" + tmpName);
Properties props = getProperties(directory);
String branch = props.getProperty(BRANCH_PROPERTY);
if (branch != null && !branch.isEmpty()) {
argv.add("-b" + branch);
}
String repo = props.getProperty(REPOSITORY_PROPERTY);
if (repo != null && !repo.isEmpty()) {
argv.add("-p" + repo);
}
if (rev != null) {
argv.add("-v" + rev);
}
argv.add("-q");
argv.add("-tmodify");
argv.add("-wreplace");
Executor exec = new Executor(argv, directory);
int status = exec.exec();
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed get revision {2} for: \"{0}\" Exit code: {1}", new Object[] { new File(parent, basename).getAbsolutePath(), String.valueOf(status), rev });
return false;
}
File tmpFile = new File(tmp, basename);
try (FileInputStream in = new FileInputStream(tmpFile)) {
copyBytes(out::write, in);
} finally {
boolean deleteOnExit = false;
// delete the temporary file on close
if (!tmpFile.delete()) {
// try on JVM exit
deleteOnExit = true;
tmpFile.deleteOnExit();
}
// delete the temporary directory on close
if (deleteOnExit || !tmp.delete()) {
// try on JVM exit
tmp.deleteOnExit();
}
}
return true;
} catch (IOException exception) {
LOGGER.log(Level.SEVERE, "Failed to get file", exception);
}
return false;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SSCMRepository method getHistoryLogExecutor.
/**
* Get an executor to be used for retrieving the history log for the named
* file or directory.
*
* @param file The file or directory to retrieve history for
* @param sinceRevision the oldest changeset to return from the executor, or
* {@code null} if all changesets should be returned
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(final File file, String sinceRevision) throws IOException {
List<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("history");
if (file.isDirectory()) {
argv.add("/");
} else {
argv.add(file.getName());
}
if (sinceRevision != null) {
try (Scanner scanner = new Scanner(sinceRevision)) {
if (scanner.hasNextInt()) {
argv.add("-v" + (Integer.parseInt(sinceRevision) + 1) + ":" + Integer.MAX_VALUE);
}
}
}
argv.add("-w-");
Properties props = getProperties(file);
String branch = props.getProperty(BRANCH_PROPERTY);
if (branch != null && !branch.isEmpty()) {
argv.add("-b" + branch);
}
String repo = props.getProperty(REPOSITORY_PROPERTY);
if (repo != null && !repo.isEmpty()) {
argv.add("-p" + repo);
}
return new Executor(argv, new File(getDirectoryName()), sinceRevision != null);
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class SubversionHistoryParser method parse.
/**
* Parse the history for the specified file.
*
* @param file the file to parse history for
* @param repos Pointer to the SubversionRepository
* @param sinceRevision the revision number immediately preceding the first
* revision we want, or {@code null} to fetch the entire history
* @return object representing the file's history
*/
History parse(File file, SubversionRepository repos, String sinceRevision, int numEntries, CommandTimeoutType cmdType) throws HistoryException {
initSaxParser();
handler = new Handler(repos.getDirectoryName(), repos.reposPath, RuntimeEnvironment.getInstance().getSourceRootPath().length(), repos);
Executor executor;
try {
executor = repos.getHistoryLogExecutor(file, sinceRevision, numEntries, cmdType);
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\" Exit code: " + status);
}
List<HistoryEntry> entries = handler.entries;
// sinceRevision. Remove it.
if (sinceRevision != null) {
repos.removeAndVerifyOldestChangeset(entries, sinceRevision);
}
return new History(entries, handler.getRenamedFiles());
}
Aggregations