use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevHistoryParser method parse.
/**
* Parse the history for the specified file.
*
* @param file the file to parse history for
* @param repos Pointer to the {@code AccuRevRepository}
* @return object representing the file's history
* @throws HistoryException if a problem occurs while executing p4 command
*/
History parse(File file, Repository repos) throws HistoryException {
repository = (AccuRevRepository) repos;
history = null;
foundHistory = false;
String relPath = repository.getDepotRelativePath(file);
/*
* When the path given is really just the root to the source
* workarea, no history is available, create fake.
*/
String rootRelativePath = File.separator + "." + File.separator;
if (relPath.equals(rootRelativePath)) {
List<HistoryEntry> entries = new ArrayList<HistoryEntry>();
entries.add(new HistoryEntry("", new Date(), "OpenGrok", null, "Workspace Root", true));
history = new History(entries);
} else {
try {
/*
* Errors will be logged, so not bothering to add to the output.
*/
Executor executor = repository.getHistoryLogExecutor(file);
executor.exec(true, this);
/*
* Try again because there was no 'keep' history.
*/
if (!foundHistory) {
executor = repository.getHistoryLogExecutor(file);
executor.exec(true, this);
}
} catch (IOException e) {
throw new HistoryException("Failed to get history for: \"" + file.getAbsolutePath() + "\"" + e);
}
}
return history;
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method getHistoryGet.
@Override
InputStream getHistoryGet(String parent, String basename, String rev) {
ArrayList<String> cmd = new ArrayList<>();
InputStream inputStream = null;
File directory = new File(parent);
/*
* ----------------------------------------------------------------- The
* only way to guarantee getting the contents of a file is to fire off
* an AccuRev 'stat'us command to get the element ID number for the
* subsequent 'cat' command. (Element ID's are unique for a file, unless
* evil twins are present) This is because it is possible that the file
* may have been moved to a different place in the depot. The 'stat'
* command will produce a line with the format:
*
* <filePath> <elementID> <virtualVersion> (<realVersion>) (<status>)
*
* /./myFile e:17715 CP.73_Depot/2 (3220/2) (backed)
*-----------------------------------------------------------------
*/
cmd.add(RepoCommand);
cmd.add("stat");
cmd.add("-fe");
cmd.add(basename);
Executor executor = new Executor(cmd, directory);
executor.exec();
String elementID = null;
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
String line = info.readLine();
String[] statInfo = line.split("\\s+");
// skip over 'e:'
elementID = statInfo[1].substring(2);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not obtain status for {0}", basename);
}
if (elementID != null) {
/*
* ------------------------------------------ This really gets the
* contents of the file.
*------------------------------------------
*/
cmd.clear();
cmd.add(RepoCommand);
cmd.add("cat");
cmd.add("-v");
cmd.add(rev.trim());
cmd.add("-e");
cmd.add(elementID);
executor = new Executor(cmd, directory);
executor.exec();
inputStream = new ByteArrayInputStream(executor.getOutputString().getBytes());
}
return inputStream;
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method isInAccuRevDepot.
/**
* Check if a given path is associated with an AccuRev workspace
*
* The AccuRev 'info' command provides a Depot name when in a known
* workspace. Otherwise, the Depot name will be missing.
*
* @param path The presumed path to an AccuRev workspace directory.
* @return true if the given path is in the depot, false otherwise
*/
private boolean isInAccuRevDepot(File wsPath) {
boolean status = false;
if (isWorking()) {
ArrayList<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("info");
Executor executor = new Executor(cmd, wsPath);
executor.exec(true);
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
String line;
while ((line = info.readLine()) != null) {
Matcher depotMatch = depotPattern.matcher(line);
if (line.contains("not logged in")) {
LOGGER.log(Level.SEVERE, "Not logged into AccuRev server");
break;
}
if (depotMatch.find()) {
status = true;
break;
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not find AccuRev repository for {0}", wsPath);
}
}
return status;
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method update.
@Override
public void update() throws IOException {
File directory = new File(getDirectoryName());
List<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("update");
Executor executor = new Executor(cmd, directory);
if (executor.exec() != 0) {
throw new IOException(executor.getErrorString());
}
}
use of org.opensolaris.opengrok.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method getHistoryLogExecutor.
/**
* Get an executor to be used for retrieving the history log for the given
* file. (used by AccuRevHistoryParser).
*
* @param file file for which history is to be retrieved.
* @return An Executor ready to be started
*/
Executor getHistoryLogExecutor(File file) throws IOException {
String path = file.getAbsolutePath();
ArrayList<String> cmd = new ArrayList<>();
cmd.add(RepoCommand);
cmd.add("hist");
if (!file.isDirectory()) {
cmd.add("-k");
// get a list of all 'real' file versions
cmd.add("keep");
}
cmd.add(path);
File workingDirectory = file.isDirectory() ? file : file.getParentFile();
return new Executor(cmd, workingDirectory);
}
Aggregations