in src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java [163:296]
public void execute() throws BuildException {
int result = 0;
if (repository == null || repository.trim().isEmpty()) {
throw new BuildException("Required argument repository not specified");
}
// Check workspace exists
// Launch PCLI listversionedfiles -z -aw
// Capture output
// build the command line from what we got the format is
Commandline commandLine = new Commandline();
commandLine.setExecutable(getExecutable(PCLI_EXE));
commandLine.createArgument().setValue("lvf");
commandLine.createArgument().setValue("-z");
commandLine.createArgument().setValue("-aw");
if (getWorkspace() != null) {
commandLine.createArgument().setValue("-sp" + getWorkspace());
}
commandLine.createArgument().setValue("-pr" + getRepository());
String uid = getUserId();
if (uid != null) {
commandLine.createArgument().setValue("-id" + uid);
}
// default pvcs project is "/"
if (getPvcsproject() == null && getPvcsprojects().isEmpty()) {
pvcsProject = "/";
}
if (getPvcsproject() != null) {
commandLine.createArgument().setValue(getPvcsproject());
}
if (!getPvcsprojects().isEmpty()) {
for (PvcsProject pvcsProject : getPvcsprojects()) {
String projectName = pvcsProject.getName();
if (projectName == null || projectName.trim().isEmpty()) {
throw new BuildException("name is a required attribute of pvcsproject");
}
commandLine.createArgument().setValue(projectName);
}
}
File tmp = null;
File tmp2 = null;
try {
Random rand = new Random(System.currentTimeMillis());
tmp = new File("pvcs_ant_" + rand.nextLong() + ".log");
OutputStream fos = Files.newOutputStream(tmp.toPath());
tmp2 = new File("pvcs_ant_" + rand.nextLong() + ".log");
log(commandLine.describeCommand(), Project.MSG_VERBOSE);
try {
result = runCmd(commandLine, new PumpStreamHandler(fos,
new LogOutputStream(this, Project.MSG_WARN)));
} finally {
FileUtils.close(fos);
}
if (Execute.isFailure(result) && !ignorerc) {
String msg = "Failed executing: " + commandLine.toString();
throw new BuildException(msg, getLocation());
}
if (!tmp.exists()) {
throw new BuildException("Communication between ant and pvcs "
+ "failed. No output generated from executing PVCS "
+ "commandline interface \"pcli\" and \"get\"");
}
// Create folders in workspace
log("Creating folders", Project.MSG_INFO);
createFolders(tmp);
// Massage PCLI lvf output transforming '\' to '/' so get command works appropriately
massagePCLI(tmp, tmp2);
// Launch get on output captured from PCLI lvf
commandLine.clearArgs();
commandLine.setExecutable(getExecutable(GET_EXE));
if (getConfig() != null && !getConfig().isEmpty()) {
commandLine.createArgument().setValue("-c" + getConfig());
}
if (getForce() != null && getForce().equals("yes")) {
commandLine.createArgument().setValue("-Y");
} else {
commandLine.createArgument().setValue("-N");
}
if (getPromotiongroup() != null) {
commandLine.createArgument().setValue("-G"
+ getPromotiongroup());
} else {
if (getLabel() != null) {
commandLine.createArgument().setValue("-v" + getLabel());
} else {
if (getRevision() != null) {
commandLine.createArgument().setValue("-r" + getRevision());
}
}
}
if (updateOnly) {
commandLine.createArgument().setValue("-U");
}
commandLine.createArgument().setValue("@" + tmp2.getAbsolutePath());
log("Getting files", Project.MSG_INFO);
log("Executing " + commandLine.toString(), Project.MSG_VERBOSE);
result = runCmd(commandLine,
new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));
if (result != 0 && !ignorerc) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Return code was " + result;
throw new BuildException(msg, getLocation());
}
} catch (ParseException | IOException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, getLocation());
} finally {
if (tmp != null) {
tmp.delete();
}
if (tmp2 != null) {
tmp2.delete();
}
}
}