ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce P4Counter.java
Date Fri, 06 Apr 2001 08:50:13 GMT
bodewig     01/04/06 01:50:12

  Modified:    docs/manual/OptionalTasks perforce.html
               src/main/org/apache/tools/ant/taskdefs/optional/perforce
                        P4Counter.java
  Log:
  Add property attribute to <p4counter>
  
  Submitted by:	Kirk Wylie <kirk@radik.com>
  
  Revision  Changes    Path
  1.5       +26 -1     jakarta-ant/docs/manual/OptionalTasks/perforce.html
  
  Index: perforce.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/OptionalTasks/perforce.html,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- perforce.html	2001/04/04 09:12:47	1.4
  +++ perforce.html	2001/04/06 08:50:09	1.5
  @@ -339,8 +339,19 @@
   
   <h2><a name="p4counter">P4Counter</a></h2>
   <h3>Description:</h3>
  -<p>Obtain or set the value of a counter
  +<p>
  +Obtain or set the value of a counter. When used in its base form
  +(where only the counter name is provided), the counter value will be
  +printed to the output stream. When the value is provided, the counter
  +will be set to the value provided. When a property name is provided,
  +the property will be filled with the value of the counter. You may
  +not specify to both get and set the value of the counter in the same
  +Task.
   </p>
  +<P>
  +The user performing this task must have Perforce &quot;review&quot; permissions
  +as defined by Perforce protections in order for this task to succeed.
  +</P>
   <h3>Parameters</h3>
   <table border="1" cellpadding="2" cellspacing="0">
     <tr>
  @@ -358,12 +369,26 @@
       <td valign="top">The new value for the counter</td>
       <td valign="top" align="center">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">property</td>
  +    <td valign="top">The property to be set with the value of the counter</td>
  +    <td valign="top" align="center">No</td>
  +  </tr>
   </table>
   
   <h3>Examples</h3>
  +Print the value of the counter named &quot;last-clean-build&quot; to the output
stream:
   <pre>
   &lt;p4counter name=&quot;last-clean-build&quot; /&gt;
  +</PRE>
  +Set the value of the counter based on the value of the &quot;TSTAMP&quot; property:
  +<PRE>
   &lt;p4counter name=&quot;last-clean-build&quot; value=&quot;${TSTAMP}&quot;
/&gt;
  +</PRE>
  +Set the value of the &quot;p4.last.clean.build&quot; property to the current
  +value of the &quot;last-clean-build&quot; counter:
  +<PRE>
  +&lt;p4counter name=&quot;last-clean-build&quot; property=&quot;${p4.last.clean.build}&quot;
/&gt;
   </pre>
   <hr>
   
  
  
  
  1.2       +45 -9     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java
  
  Index: P4Counter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Counter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- P4Counter.java	2001/04/04 09:12:48	1.1
  +++ P4Counter.java	2001/04/06 08:50:11	1.2
  @@ -60,21 +60,23 @@
   
   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 @@
           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");
           }
  +
  +        if(shouldSetValue && shouldSetProperty) {
  +            throw new BuildException("Cannot both set the value of the property and retrieve
the value of the property.");
  +        }
   
  -        String command = "-s counter " + P4CmdOpts + " " + counter;
  +        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));
  +        }
       }
   }
  
  
  

Mime
View raw message