Methods Summary |
---|
public void | addPvcsproject(PvcsProject p)Specify a project within the PVCS repository to extract files from.
pvcsProjects.addElement(p);
|
private void | createFolders(java.io.File file)Parses the file and creates the folders specified in the output section
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
MessageFormat mf = new MessageFormat(getFilenameFormat());
String line = in.readLine();
while (line != null) {
log("Considering \"" + line + "\"", Project.MSG_VERBOSE);
if (line.startsWith("\"\\") // Checking for "\
|| line.startsWith("\"/") // or "/
// or "X:\...
|| (line.length() > POS_3 && line.startsWith("\"")
&& Character.isLetter(line.charAt(POS_1))
&& String.valueOf(line.charAt(POS_2)).equals(":")
&& String.valueOf(line.charAt(POS_3)).equals("\\"))) {
Object[] objs = mf.parse(line);
String f = (String) objs[1];
// Extract the name of the directory from the filename
int index = f.lastIndexOf(File.separator);
if (index > -1) {
File dir = new File(f.substring(0, index));
if (!dir.exists()) {
log("Creating " + dir.getAbsolutePath(),
Project.MSG_VERBOSE);
if (dir.mkdirs()) {
log("Created " + dir.getAbsolutePath(),
Project.MSG_INFO);
} else {
log("Failed to create "
+ dir.getAbsolutePath(),
Project.MSG_INFO);
}
} else {
log(dir.getAbsolutePath() + " exists. Skipping",
Project.MSG_VERBOSE);
}
} else {
log("File separator problem with " + line,
Project.MSG_WARN);
}
} else {
log("Skipped \"" + line + "\"", Project.MSG_VERBOSE);
}
line = in.readLine();
}
} finally {
if (in != null) {
in.close();
}
}
|
public void | execute()
int result = 0;
if (repository == null || repository.trim().equals("")) {
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()) {
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 (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().length() > 0) {
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 (FileNotFoundException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, getLocation());
} catch (IOException e) {
String msg = "Failed executing: " + commandLine.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, getLocation());
} catch (ParseException 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();
}
}
|
public java.lang.String | getConfig()returns the path of the configuration file to be used
return config;
|
private java.lang.String | getExecutable(java.lang.String exe)
StringBuffer correctedExe = new StringBuffer();
if (getPvcsbin() != null) {
if (pvcsbin.endsWith(File.separator)) {
correctedExe.append(pvcsbin);
} else {
correctedExe.append(pvcsbin).append(File.separator);
}
}
return correctedExe.append(exe).toString();
|
public java.lang.String | getFilenameFormat()The filenameFormat attribute defines a MessageFormat string used
to parse the output of the pcli command. It defaults to
{0}-arc({1}) . Repositories where the archive
extension is not -arc should set this.
return filenameFormat;
|
public java.lang.String | getForce()Get value of force
return force;
|
public boolean | getIgnoreReturnCode()Get value of ignorereturncode
return ignorerc;
|
public java.lang.String | getLabel()Get value of label
return label;
|
public java.lang.String | getLineStart()The lineStart attribute is used to parse the output of the pcli
command. It defaults to "P: . The parser already
knows about / and \\, this property is useful in cases where the
repository is accessed on a Windows platform via a drive letter
mapping.
return lineStart;
|
public java.lang.String | getPromotiongroup()Get value of promotiongroup
return promotiongroup;
|
public java.lang.String | getPvcsbin()Get name of the PVCS bin directory
return pvcsbin;
|
public java.lang.String | getPvcsproject()Get name of the project in the PVCS repository
return pvcsProject;
|
public java.util.Vector | getPvcsprojects()Get name of the project in the PVCS repository
return pvcsProjects;
|
public java.lang.String | getRepository()Get network name of the PVCS repository
return repository;
|
public java.lang.String | getRevision()Get value of revision
return revision;
|
public boolean | getUpdateOnly()get the updateOnly attribute.
return updateOnly;
|
public java.lang.String | getUserId()Get the userid.
return userId;
|
public java.lang.String | getWorkspace()Get name of the workspace to store the retrieved files
return workspace;
|
private void | massagePCLI(java.io.File in, java.io.File out)Simple hack to handle the PVCS command-line tools botch when
handling UNC notation.
BufferedReader inReader = null;
BufferedWriter outWriter = null;
try {
inReader = new BufferedReader(new FileReader(in));
outWriter = new BufferedWriter(new FileWriter(out));
String s = null;
while ((s = inReader.readLine()) != null) {
String sNormal = s.replace('\\", '/");
outWriter.write(sNormal);
outWriter.newLine();
}
} finally {
if (inReader != null) {
inReader.close();
}
if (outWriter != null) {
outWriter.close();
}
}
|
protected int | runCmd(org.apache.tools.ant.types.Commandline cmd, org.apache.tools.ant.taskdefs.ExecuteStreamHandler out)Run the command.
try {
Project aProj = getProject();
Execute exe = new Execute(out);
exe.setAntRun(aProj);
exe.setWorkingDirectory(aProj.getBaseDir());
exe.setCommandline(cmd.getCommandline());
return exe.execute();
} catch (java.io.IOException e) {
String msg = "Failed executing: " + cmd.toString()
+ ". Exception: " + e.getMessage();
throw new BuildException(msg, getLocation());
}
|
public void | setConfig(java.io.File f)Sets a configuration file other than the default to be used.
These files have a .cfg extension and are often found in archive or pvcsprop folders.
config = f.toString();
|
public void | setFilenameFormat(java.lang.String f)The format of the folder names; optional.
This must be in a format suitable for
java.text.MessageFormat .
Index 1 of the format will be used as the file name.
Defaults to {0}-arc({1})
filenameFormat = f;
|
public void | setForce(java.lang.String f)Specifies the value of the force argument; optional.
If set to yes all files that exists and are
writable are overwritten. Default no causes the files
that are writable to be ignored. This stops the PVCS command
get to stop asking questions!
if (f != null && f.equalsIgnoreCase("yes")) {
force = "yes";
} else {
force = "no";
}
|
public void | setIgnoreReturnCode(boolean b)If set to true the return value from executing the pvcs
commands are ignored; optional, default false.
ignorerc = b;
|
public void | setLabel(java.lang.String l)Only files marked with this label are extracted; optional.
label = l;
|
public void | setLineStart(java.lang.String l)What a valid return value from PVCS looks like
when it describes a file. Defaults to "P: .
If you are not using an UNC name for your repository and the
drive letter P is incorrect for your setup, you may
need to change this value, UNC names will always be
accepted.
lineStart = l;
|
public void | setPromotiongroup(java.lang.String w)Specifies the name of the promotiongroup argument
promotiongroup = w;
|
public void | setPvcsbin(java.lang.String bin)Specifies the location of the PVCS bin directory; optional if on the PATH.
On some systems the PVCS executables pcli
and get are not found in the PATH. In such cases this attribute
should be set to the bin directory of the PVCS installation containing
the executables mentioned before. If this attribute isn't specified the
tag expects the executables to be found using the PATH environment variable.
pvcsbin = bin;
|
public void | setPvcsproject(java.lang.String prj)The project within the PVCS repository to extract files from;
optional, default "/"
pvcsProject = prj;
|
public void | setRepository(java.lang.String repo)The network name of the PVCS repository; required.
repository = repo;
|
public void | setRevision(java.lang.String r)Only files with this revision are extract; optional.
revision = r;
|
public void | setUpdateOnly(boolean l)If set to true files are fetched only if
newer than existing local files; optional, default false.
updateOnly = l;
|
public void | setUserId(java.lang.String u)User ID
userId = u;
|
public void | setWorkspace(java.lang.String ws)Workspace to use; optional.
By specifying a workspace, the files are extracted to that location.
A PVCS workspace is a name for a location of the workfiles and
isn't as such the location itself.
You define the location for a workspace using the PVCS GUI clients.
If this isn't specified the default workspace for the current user is used.
workspace = ws;
|