FileDocCategorySizeDatePackage
P4Counter.javaAPI DocApache Ant 1.705065Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.perforce

P4Counter

public class P4Counter extends P4Base
Obtains or sets 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.

The user performing this task must have Perforce "review" permissions as defined by Perforce protections in order for this task to succeed.

Example Usage:
<p4counter name="${p4.counter}" property=${p4.change}"/>
ant.task
category="scm"

Fields Summary
public String
counter
name of the counter
public String
property
name of an optional property
public boolean
shouldSetValue
flag telling whether the value of the counter should be set
public boolean
shouldSetProperty
flag telling whether a property should be set
public int
value
new value for the counter
Constructors Summary
Methods Summary
public voidexecute()
again, properties are mutable in this tsk

throws
BuildException if the required parameters are not supplied.


        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 = "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;
        }

        if (shouldSetProperty) {
            final Project myProj = getProject();

            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));
        }
    
public voidsetName(java.lang.String counter)
The name of the counter; required

param
counter name of the counter


    // CheckStyle:VisibilityModifier ON

                     
        
        this.counter = counter;
    
public voidsetProperty(java.lang.String property)
A property to be set with the value of the counter

param
property the name of a property to set with the value of the counter

        this.property = property;
        shouldSetProperty = true;
    
public voidsetValue(int value)
The new value for the counter; optional.

param
value new value for the counter

        this.value = value;
        shouldSetValue = true;