summaryrefslogtreecommitdiff
path: root/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
diff options
context:
space:
mode:
authorStefan Bodewig <bodewig@apache.org>2001-04-06 08:50:11 +0000
committerStefan Bodewig <bodewig@apache.org>2001-04-06 08:50:11 +0000
commit405db5ebc65b2d89985d03b4882ca6c6c18b8375 (patch)
tree33941fb73da61106b11cb51649f2690189d84b0c /src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
parent4e4e5054b4660bce6d1929c67d07a27ddb47d17d (diff)
downloadant-405db5ebc65b2d89985d03b4882ca6c6c18b8375.tar.gz
Add property attribute to <p4counter>
Submitted by: Kirk Wylie <kirk@radik.com> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268919 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java')
-rw-r--r--src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
index f92189be9..de6c29653 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
@@ -60,21 +60,23 @@ package org.apache.tools.ant.taskdefs.optional.perforce;
import org.apache.tools.ant.*;
-/** P4Counter - Obtain the value of a counter.
+/** P4Counter - Obtain or set the value of a counter.
+ * P4Counter can be used to either print the value of a counter
+ * to the output stream for the project (by setting the "name"
+ * attribute only), to set a property based on the value of
+ * a counter (by setting the "property" attribute) or to set the counter
+ * on the perforce server (by setting the "value" attribute).
*
* Example Usage:<br>
- * &lt;p4counter name="${p4.change}"/&gt;
+ * &lt;p4counter name="${p4.counter}" property=${p4.change}"/&gt;
* @author <a href="mailto:kirk@radik.com">Kirk Wylie</a>
- *
- * ToDo: Should be able to write the counter value to a property.
- * I've left that out of the first version here because it involves
- * changing the P4OutputHandler fairly substantially, and thus
- * shouldn't be the second thing that I do here.
*/
public class P4Counter extends P4Base {
public String counter = null;
+ public String property = null;
public boolean shouldSetValue = false;
+ public boolean shouldSetProperty = false;
public int value = 0;
public void setName(String counter) {
@@ -86,17 +88,51 @@ public class P4Counter extends P4Base {
shouldSetValue = true;
}
+ public void setProperty(String property) {
+ this.property = property;
+ shouldSetProperty = true;
+ }
+
public void execute() throws BuildException {
if((counter == null) || counter.length() == 0) {
throw new BuildException("No counter specified to retrieve");
}
- String command = "-s counter " + P4CmdOpts + " " + counter;
+ if(shouldSetValue && shouldSetProperty) {
+ throw new BuildException("Cannot both set the value of the property and retrieve the value of the property.");
+ }
+
+ String command = "counter " + P4CmdOpts + " " + counter;
+ if(!shouldSetProperty) {
+ // NOTE kirk@radik.com 04-April-2001 -- If you put in the -s, you
+ // have to start running through regular expressions here. Much easier
+ // to just not include the scripting information than to try to add it
+ // and strip it later.
+ command = "-s " + command;
+ }
if(shouldSetValue) {
command += " " + value;
}
- execP4Command(command, new SimpleP4OutputHandler(this));
+ if(shouldSetProperty) {
+ final Project myProj = project;
+
+ P4Handler handler = new P4HandlerAdapter() {
+ public void process(String line) {
+ log("P4Counter retrieved line \""+ line + "\"", Project.MSG_VERBOSE);
+ try {
+ value = Integer.parseInt(line);
+ myProj.setProperty(property, ""+value);
+ } catch (NumberFormatException nfe) {
+ throw new BuildException("Perforce error. Could not retrieve counter value.");
+ }
+ }
+ };
+
+ execP4Command(command, handler);
+ } else {
+ execP4Command(command, new SimpleP4OutputHandler(this));
+ }
}
}