use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceRepository method getHistoryGet.
@Override
boolean getHistoryGet(OutputStream out, String parent, String basename, String rev) {
ArrayList<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("print");
cmd.add("-q");
cmd.add(protectPerforceFilename(basename) + getRevisionCmd(rev));
Executor executor = new Executor(cmd, new File(parent));
// TODO: properly evaluate Perforce return code
executor.exec();
try {
copyBytes(out::write, executor.getOutputStream());
return true;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Failed to get history for file {0}/{1} in revision {2}: ", new Object[] { parent, basename, rev });
}
return false;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceRepository method isInP4Depot.
/**
* Check if a given file is in the depot.
*
* @param file The file to test
* @param cmdType command timeout type
* @return true if the given file is in the depot, false otherwise
*/
boolean isInP4Depot(File file, CommandTimeoutType cmdType) {
boolean status = false;
if (isWorking()) {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
ArrayList<String> cmd = new ArrayList<>();
String name = protectPerforceFilename(file.getName());
File dir = file.getParentFile();
if (file.isDirectory()) {
dir = file;
name = "*";
cmd.add(RepoCommand);
cmd.add("dirs");
cmd.add(name);
Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
executor.exec();
/* OUTPUT:
stdout: //depot_path/name
stderr: name - no such file(s).
*/
status = (executor.getOutputString().contains("//"));
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
}
}
if (!status) {
cmd.clear();
cmd.add(RepoCommand);
cmd.add("files");
cmd.add(name);
Executor executor = new Executor(cmd, dir, env.getCommandTimeout(cmdType));
executor.exec();
/* OUTPUT:
stdout: //depot_path/name
stderr: name - no such file(s).
*/
status = (executor.getOutputString().contains("//"));
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "p4 status is {0} for {1}", new Object[] { status, file });
}
}
}
return status;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class PerforceRepository method annotate.
@Override
public Annotation annotate(File file, String rev) {
ArrayList<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("annotate");
cmd.add("-qci");
cmd.add(protectPerforceFilename(file.getName()) + getRevisionCmd(rev));
Executor executor = new Executor(cmd, file.getParentFile(), RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
PerforceAnnotationParser parser = new PerforceAnnotationParser(this, file);
executor.exec(true, parser);
return parser.getAnnotation();
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class MercurialHistoryParserRevisionsOnly method parse.
void parse(File file, String sinceRevision) throws HistoryException {
try {
Executor executor = repository.getHistoryLogExecutor(file, sinceRevision, null, true);
int status = executor.exec(true, this);
if (status != 0) {
throw new HistoryException(String.format("Failed to get revisions for: \"%s\" since revision %s Exit code: %d", file.getAbsolutePath(), sinceRevision, status));
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"", e);
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class MonotoneRepository method annotate.
/**
* Annotate the specified file/revision using the {@code mnt annotate} command.
*
* @param file file to annotate
* @param revision revision to annotate
* @return file annotation
* @throws java.io.IOException if I/O exception occurred or the command failed
*/
@Override
public Annotation annotate(File file, String revision) throws IOException {
ArrayList<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("annotate");
cmd.add(getQuietOption());
if (revision != null) {
cmd.add("-r");
cmd.add(revision);
}
cmd.add(file.getName());
File directory = new File(getDirectoryName());
Executor executor = new Executor(cmd, directory, RuntimeEnvironment.getInstance().getInteractiveCommandTimeout());
MonotoneAnnotationParser parser = new MonotoneAnnotationParser(file);
int status = executor.exec(true, parser);
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get annotations for: \"{0}\" Exit code: {1}", new Object[] { file.getAbsolutePath(), String.valueOf(status) });
throw new IOException(executor.getErrorString());
} else {
return parser.getAnnotation();
}
}
Aggregations