You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/07/13 15:57:55 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional PvcsTest.java
bodewig 01/07/13 06:57:54
Modified: docs/manual/OptionalTasks pvcstask.html
src/etc/testcases/taskdefs/optional pvcs.xml
src/main/org/apache/tools/ant/taskdefs/optional/pvcs
Pvcs.java
src/testcases/org/apache/tools/ant/taskdefs/optional
PvcsTest.java
Log:
Various patches to PCVS task:
More robust parser that allows for platform independant paths.
Support for UNC names and a new updateonly attribute.
Submitted by: Thomas Christensen <tc...@nordija.com>
Don Jeffery <do...@apogeenet.com>
Fix for problematic file names
Submitted by: ScottCarlson@email.com
Revision Changes Path
1.3 +19 -4 jakarta-ant/docs/manual/OptionalTasks/pvcstask.html
Index: pvcstask.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/pvcstask.html,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- pvcstask.html 2001/04/27 12:36:06 1.2
+++ pvcstask.html 2001/07/13 13:57:24 1.3
@@ -12,11 +12,14 @@
by
<br><!-- Names are in alphabetical order, on last name -->
<ul>
-<li>
-Thomas Christensen (<a href="mailto:tchristensen@nordija.com">tchristensen@nordija.com</a>)</li>
+ <li>Thomas Christensen (<a href="mailto:tchristensen@nordija.com">tchristensen@nordija.com</a>)</li>
+ <li>Don Jeffery (<a href="mailto:donj@apogeenet.com">donj@apogeenet.com</a>)</li>
</ul>
-Version 1.0 - 2001/01/31
-<br>
+Version 1.1 - 2001/06/27<br>
+<p>Problems with UNC pathnames and the use of () in paths are fixed and an updateonly
+ argument introduced.</p>
+Version 1.0 - 2001/01/31<br>
+<p>Initial release.</p>
<hr>
<h2>
Table of Contents</h2>
@@ -130,6 +133,18 @@
<td VALIGN=TOP WIDTH="10%">No</td>
</tr>
+ <tr>
+ <td VALIGN=TOP WIDTH="12%">ignorereturncode</td>
+ <td VALIGN=TOP WIDTH="78%">If set to <i>true</i> the return value from executing
+ the pvcs commands are ignored.</td>
+ <td VALIGN=TOP WIDTH="10%">No</td>
+ </tr>
+ <tr>
+ <td VALIGN=TOP WIDTH="12%">updateonly</td>
+ <td VALIGN=TOP WIDTH="78%">If set to <i>true</i> files are gotten only if
+ newer than existing local files.</td>
+ <td VALIGN=TOP WIDTH="10%">No</td>
+ </tr>
</table>
<h3><a name="nested">Nested Elements</a></h3>
1.2 +13 -2 jakarta-ant/src/etc/testcases/taskdefs/optional/pvcs.xml
Index: pvcs.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/optional/pvcs.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- pvcs.xml 2001/02/23 05:03:16 1.1
+++ pvcs.xml 2001/07/13 13:57:32 1.2
@@ -13,11 +13,22 @@
</target>
<target name="test3">
- <pvcs pvcsbin="/home/tc/projects/pvcsant/src/etc/testcases/taskdefs" repository="/mnt/pvcs" pvcsproject="/qviknet"/>
+ <pvcs pvcsbin="\home\cvs\pvcsant\src\etc\testcases\taskdefs" repository="/mnt/pvcs" pvcsproject="/qviknet"/>
</target>
<target name="test4">
- <pvcs pvcsbin="/home/tc/projects/pvcsant/src/etc/testcases/taskdefs" repository="/mnt/pvcs" pvcsproject="/qviknet" workspace="/@/Public/buildws"/>
+ <pvcs pvcsbin="\home\cvs\pvcsant\src\etc\testcases\taskdefs" repository="/mnt/pvcs" pvcsproject="/qviknet" workspace="/@/Public/buildws"/>
</target>
+
+ <target name="test5" description="Get the latest from PVCS">
+ <pvcs pvcsbin="/home/cvs/pvcsant/src/etc/testcases/taskdefs"
+ repository="//ct4serv2/pvcs/monitor"/>
+ </target>
+
+ <target name="test6" description="No pcli to be found">
+ <pvcs pvcsbin="/never/heard/of/a/directory/structure/like/this"
+ repository="//ct4serv2/pvcs/monitor"/>
+ </target>
+
</project>
1.2 +107 -36 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
Index: Pvcs.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Pvcs.java 2001/04/27 12:36:12 1.1
+++ Pvcs.java 2001/07/13 13:57:40 1.2
@@ -1,8 +1,8 @@
/* ====================================================================
- *
+ *
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -10,7 +10,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -18,15 +18,15 @@
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
- * any, must include the following acknowlegement:
- * "This product includes software developed by the
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
- * from this software without prior written permission. For written
+ * from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
@@ -74,7 +74,19 @@
/**
* A task that fetches source files from a PVCS archive
*
+ * <b>19-04-2001</b> <p>The task now has a more robust
+ * parser. It allows for platform independant file paths
+ * and supports file names with <i>()</i>. Thanks to Erik Husby for
+ * bringing the bug to my attention.
+ *
+ * <b>27-04-2001</b> <p>UNC paths are now handled properly.
+ * Fix provided by Don Jeffery. He also added an <i>UpdateOnly</i> flag
+ * that, when true, conditions the PVCS get using the -U option to only
+ * update those files that have a modification time (in PVCS) that is newer
+ * than the existing workfile.
+ *
* @author Thomas Christensen <tc...@nordija.com>
+ * @author Don Jeffery <do...@apogeenet.com>
*/
public class Pvcs extends org.apache.tools.ant.Task {
private String pvcsbin;
@@ -86,6 +98,7 @@
private String promotiongroup;
private String label;
private boolean ignorerc;
+ private boolean updateOnly;
/**
* Constant for the thing to execute
@@ -113,7 +126,7 @@
return exe.execute();
}
catch (java.io.IOException e) {
- String msg = "Failed executing: " + cmd.toString();
+ String msg = "Failed executing: " + cmd.toString() + ". Exception: "+e.getMessage();
throw new BuildException(msg, location);
}
}
@@ -169,8 +182,12 @@
}
File tmp = null;
+ File tmp2 = null;
try {
- tmp = new File("pvcs_ant_"+(new Random(System.currentTimeMillis())).nextLong()+".log");
+ Random rand = new Random(System.currentTimeMillis());
+ tmp = new File("pvcs_ant_"+rand.nextLong()+".log");
+ tmp2 = new File("pvcs_ant_"+rand.nextLong()+".log");
+ log("Executing " + commandLine.toString(), Project.MSG_VERBOSE);
result = runCmd(commandLine, new PumpStreamHandler(new FileOutputStream(tmp), new LogOutputStream(this,Project.MSG_WARN)));
if ( result != 0 && !ignorerc) {
String msg = "Failed executing: " + commandLine.toString();
@@ -178,11 +195,15 @@
}
if(!tmp.exists())
- throw new BuildException("Communication between ant and pvcs failed");
-
- // Create foldes in workspace
+ 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));
@@ -197,27 +218,37 @@
else {
if(getLabel()!=null)
commandLine.createArgument().setValue("-r"+getLabel());
+ }
+
+ if (updateOnly) {
+ commandLine.createArgument().setValue("-U");
}
- commandLine.createArgument().setValue("@"+tmp.getAbsolutePath());
+
+ 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();
+ String msg = "Failed executing: " + commandLine.toString() + ". Return code was "+result;
throw new BuildException(msg, location);
}
} catch(FileNotFoundException e) {
- String msg = "Failed executing: " + commandLine.toString();
- throw new BuildException(e.getMessage(),location);
+ String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage();
+ throw new BuildException(msg,location);
} catch(IOException e) {
- String msg = "Failed executing: " + commandLine.toString();
- throw new BuildException(e.getMessage(),location);
+ String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage();
+ throw new BuildException(msg,location);
} catch(ParseException e) {
- String msg = "Failed executing: " + commandLine.toString();
- throw new BuildException(e.getMessage(),location);
+ String msg = "Failed executing: " + commandLine.toString() + ". Exception: "+e.getMessage();
+ throw new BuildException(msg,location);
} finally {
if (tmp != null) {
tmp.delete();
}
+ if (tmp2 != null) {
+ tmp2.delete();
+ }
}
}
@@ -226,22 +257,56 @@
*/
private void createFolders(File file) throws IOException, ParseException {
BufferedReader in = new BufferedReader(new FileReader(file));
- MessageFormat mf = new MessageFormat("{0}({1})");
+ MessageFormat mf = new MessageFormat("{0}-arc({1})");
String line = in.readLine();
while(line != null) {
- if(line.startsWith("\"")) {
+ log("Considering \""+line+"\"", Project.MSG_VERBOSE);
+ if(line.startsWith("\"\\") || line.startsWith("\"/")) {
Object[] objs = mf.parse(line);
String f = (String)objs[1];
// Extract the name of the directory from the filename
- File dir = new File(f.substring(0,f.lastIndexOf(File.separator)));
- if(!dir.exists())
- dir.mkdirs();
+ 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();
}
}
-
+
/**
+ * Simple hack to handle the PVCS command-line tools botch when handling UNC notation.
+ */
+ private void massagePCLI(File in, File out) throws FileNotFoundException, IOException
+ {
+ BufferedReader inReader = new BufferedReader(new FileReader(in));
+ BufferedWriter outWriter = new BufferedWriter(new FileWriter(out));
+ String s = null;
+ while ((s = inReader.readLine()) != null) {
+ String sNormal = s.replace('\\', '/');
+ outWriter.write(sNormal);
+ outWriter.newLine();
+ }
+ inReader.close();
+ outWriter.close();
+ }
+
+ /**
* Get network name of the PVCS repository
* @return String
*/
@@ -368,23 +433,16 @@
* Get value of ignorereturncode
* @return String
*/
- public String getIgnoreReturnCode() {
- if(ignorerc)
- return "true";
- else
- return "false";
+ public boolean getIgnoreReturnCode() {
+ return ignorerc;
}
/**
* If set to true the return value from executing the pvcs
* commands are ignored.
- * @param l String "true/false"
*/
- public void setIgnoreReturnCode(String l) {
- if(l.trim().equalsIgnoreCase("true"))
- ignorerc=true;
- else
- ignorerc=false;
+ public void setIgnoreReturnCode(boolean b) {
+ ignorerc = b;
}
/**
@@ -395,6 +453,18 @@
pvcsProjects.addElement(p);
}
+ public boolean getUpdateOnly() {
+ return updateOnly;
+ }
+
+ /**
+ * If set to true files are gotten only if newer
+ * than existing local files.
+ */
+ public void setUpdateOnly(boolean l) {
+ updateOnly = l;
+ }
+
/**
* Creates a Pvcs object
*/
@@ -409,5 +479,6 @@
promotiongroup=null;
label=null;
ignorerc=false;
+ updateOnly = false;
}
}
1.3 +12 -0 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/PvcsTest.java
Index: PvcsTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/optional/PvcsTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PvcsTest.java 2001/02/23 05:06:01 1.2
+++ PvcsTest.java 2001/07/13 13:57:49 1.3
@@ -81,4 +81,16 @@
public void test3() {
executeTarget("test3");
}
+
+ public void test4() {
+ executeTarget("test4");
+ }
+
+ public void test5() {
+ executeTarget("test5");
+ }
+
+ public void test6() {
+ expectBuildException("test6", "Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z -aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found");
+ }
}