use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class AccuRevRepository method getAccuRevInfo.
/**
* Expecting data of the form:
*
* Principal: shaehn
* Host: waskly
* Server name: lean.machine.com
* Port: 5050
* DB Encoding: Unicode
* ACCUREV_BIN: C:\Program Files (x86)\AccuRev\bin
* Client time: 2017/08/02 13:30:31 Eastern Daylight Time (1501695031)
* Server time: 2017/08/02 13:30:54 Eastern Daylight Time (1501695054)
* Depot: bread_and_butter
* Workspace/ref: BABS_2_shaehn
* Basis: BABS2
* Top: C:\Users\shaehn\workspaces\BABS_2
*
* Output would be similar on Unix boxes, but with '/' appearing
* in path names instead of '\'. The 'Basis' (BABS2) is the parent
* stream of the user workspace (BABS_2_shaehn). The 'Top' is the
* path to the root of the user workspace/repository. The elements
* below 'Server time' will be missing when current working directory
* is not within a known AccuRev workspace/repository.
*/
private boolean getAccuRevInfo(File wsPath, CommandTimeoutType cmdType) {
ArrayList<String> cmd = new ArrayList<>();
boolean status = false;
Path given = Paths.get(wsPath.toString());
Path realWsPath = null;
try {
// This helps overcome symbolic link issues so that
// Accurev will report the desired information.
// Otherwise it claims:
// "You are not in a directory associated with a workspace"
realWsPath = given.toRealPath();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not determine real path for {0}", wsPath);
}
cmd.add(RepoCommand);
cmd.add("info");
Executor executor = new Executor(cmd, realWsPath.toFile(), env.getCommandTimeout(cmdType));
executor.exec();
try (BufferedReader info = new BufferedReader(executor.getOutputReader())) {
String line;
while ((line = info.readLine()) != null) {
if (line.contains("not logged in")) {
LOGGER.log(Level.SEVERE, "Not logged into AccuRev server");
break;
}
if (line.startsWith("Depot")) {
Matcher depotMatch = DEPOT_PATTERN.matcher(line);
if (depotMatch.find()) {
depotName = depotMatch.group(1);
status = true;
}
} else if (line.startsWith("Basis")) {
Matcher parentMatch = PARENT_PATTERN.matcher(line);
if (parentMatch.find()) {
parentInfo = parentMatch.group(1);
}
} else if (line.startsWith("Top")) {
Matcher workspaceRoot = WORKSPACE_ROOT_PATTERN.matcher(line);
if (workspaceRoot.find()) {
wsRoot = workspaceRoot.group(1);
if (Files.isSymbolicLink(given)) {
LOGGER.log(Level.INFO, "{0} is symbolic link.", wsPath);
// the relative root fragment can be extracted.
if (!Files.isSameFile(given, Paths.get(wsRoot))) {
String linkedTo = Files.readSymbolicLink(given).toRealPath().toString();
if (linkedTo.regionMatches(0, wsRoot, 0, wsRoot.length())) {
relRoot = linkedTo.substring(wsRoot.length());
}
}
} else {
// The source root and the workspace root will both
// be canonical paths. There will be a non-empty
// relative root whenever the source root is longer
// than the workspace root known to AccuRev.
String srcRoot = env.getSourceRootPath();
if (srcRoot.length() > wsRoot.length()) {
relRoot = srcRoot.substring(wsRoot.length());
}
}
if (relRoot.length() > 0) {
LOGGER.log(Level.INFO, "Source root relative to workspace root by: {0}", relRoot);
}
}
}
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Could not find AccuRev repository for {0}", wsPath);
}
return status;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository method buildTagList.
/**
* @param directory Directory where we list tags
*/
@Override
protected void buildTagList(File directory, CommandTimeoutType cmdType) {
this.tagList = new TreeSet<>();
ArrayList<String> argv = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
argv.add(RepoCommand);
argv.add("tags");
Executor executor = new Executor(argv, directory, RuntimeEnvironment.getInstance().getCommandTimeout(cmdType));
final BazaarTagParser parser = new BazaarTagParser();
int status = executor.exec(true, parser);
if (status != 0) {
LOGGER.log(Level.WARNING, "Failed to get tags for: \"{0}\" Exit code: {1}", new Object[] { directory.getAbsolutePath(), String.valueOf(status) });
} else {
tagList = parser.getEntries();
}
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BazaarRepository method getHistoryLogExecutor.
/**
* Get an executor to be used for retrieving the history log for the named
* file.
*
* @param file The file 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, final String sinceRevision) throws IOException {
String filename = getRepoRelativePath(file);
List<String> cmd = new ArrayList<>();
ensureCommand(CMD_PROPERTY_KEY, CMD_FALLBACK);
cmd.add(RepoCommand);
cmd.add("log");
if (file.isDirectory()) {
cmd.add("-v");
}
cmd.add(filename);
if (sinceRevision != null) {
cmd.add("-r");
cmd.add(sinceRevision + "..-1");
}
return new Executor(cmd, new File(getDirectoryName()), sinceRevision != null);
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class CVSHistoryParser method parse.
/**
* Parse the history for the specified file.
*
* @param file the file to parse history for
* @param repos Pointer to the SubversionRepository
* @return object representing the file's history
*/
History parse(File file, Repository repos) throws HistoryException {
cvsrepo = (CVSRepository) repos;
try {
Executor executor = cvsrepo.getHistoryLogExecutor(file);
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);
}
// so they need to be sorted according to revision.
if (cvsrepo.getBranch() != null && !cvsrepo.getBranch().isEmpty()) {
List<HistoryEntry> entries = history.getHistoryEntries();
entries.sort((o1, o2) -> o2.getRevision().compareTo(o1.getRevision()));
history.setHistoryEntries(entries);
}
return history;
}
use of org.opengrok.indexer.util.Executor in project OpenGrok by OpenGrok.
the class BazaarHistoryParser 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);
}
// an exception.
if (sinceRevision != null) {
repository.removeAndVerifyOldestChangeset(entries, sinceRevision);
}
return new History(entries);
}
Aggregations