// 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()) {
Enumeration e = getPvcsprojects().elements();
while (e.hasMoreElements()) {
String projectName = ((PvcsProject) e.nextElement()).getName();
if (projectName == null || (projectName.trim()).equals("")) {
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");
FileOutputStream fos = new FileOutputStream(tmp);
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 {
fos.close();
}
if (result != 0 && !ignorerc) {
String msg = "Failed executing: " + commandLine.toString();
throw new BuildException(msg, location);
}
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 (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("-r" + getLabel());
}
}
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, location);
}
} catch (FileNotFoundException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, location);
} catch (IOException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, location);
} catch (ParseException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, location);
} finally {
if (tmp != null) {
tmp.delete();