FileDocCategorySizeDatePackage
P4Change.javaAPI DocApache Ant 1.705578Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.perforce

P4Change

public class P4Change extends P4Base
Requests a new changelist from the Perforce server. P4Change creates a new changelist in perforce. P4Change sets the property ${p4.change} with the new changelist number. This should then be passed into p4edit and p4submit.
see
P4Edit
see
P4Submit
ant.task
category="scm"

Fields Summary
protected String
emptyChangeList
protected String
description
Constructors Summary
Methods Summary
public static final java.lang.Stringbackslash(java.lang.String value)
Ensure that a string is backslashing slashes so that it does not confuse them with Perl substitution delimiter in Oro. Backslashes are always backslashes in a string unless they escape the delimiter.

param
value the string to backslash for slashes
return
the backslashed string
see
Oro

        final StringBuffer buf = new StringBuffer(value.length());
        final int len = value.length();
        for (int i = 0; i < len; i++) {
            char c = value.charAt(i);
            if (c == '/") {
                buf.append('\\");
            }
            buf.append(c);
        }
        return buf.toString();
    
public voidexecute()
creates a new Perforce change list sets the p4.change property to the number of the new change list

throws
BuildException if the word error appears in the output coming from Perforce

    // CheckStyle:VisibilityModifier ON

                                        
         

        if (emptyChangeList == null) {
            emptyChangeList = getEmptyChangeList();
        }
        final Project myProj = getProject();

        P4Handler handler = new P4HandlerAdapter() {
            public void process(String line) {
                if (util.match("/Change/", line)) {

                    //Remove any non-numerical chars - should leave the change number
                    line = util.substitute("s/[^0-9]//g", line);

                    int changenumber = Integer.parseInt(line);
                    log("Change Number is " + changenumber, Project.MSG_INFO);
                    myProj.setProperty("p4.change", "" + changenumber);

                } else if (util.match("/error/", line)) {
                    throw new BuildException("Perforce Error, check client settings and/or server");
                }

            }
        };

        handler.setOutput(emptyChangeList);

        execP4Command("change -i", handler);
    
public java.lang.StringgetEmptyChangeList()
returns the text of an empty change list

return
the text of an empty change list
throws
BuildException if the text error is displayed in the Perforce output outside of a comment line

        final StringBuffer stringbuf = new StringBuffer();

        execP4Command("change -o", new P4HandlerAdapter() {
            public void process(String line) {
                if (!util.match("/^#/", line)) {
                    if (util.match("/error/", line)) {
                        log("Client Error", Project.MSG_VERBOSE);
                        throw new BuildException("Perforce Error, "
                        + "check client settings and/or server");
                    } else if (util.match("/<enter description here>/", line)) {
                        // we need to escape the description in case there are /
                        description = backslash(description);
                        line = util.substitute("s/<enter description here>/"
                            + description + "/", line);
                    } else if (util.match("/\\/\\//", line)) {
                        //Match "//" for begining of depot filespec
                        return;
                    }
                    stringbuf.append(line);
                    stringbuf.append("\n");
                }
            }
        });
        return stringbuf.toString();
    
public voidsetDescription(java.lang.String desc)
Description for ChangeList;optional. If none is specified, it will default to "AutoSubmit By Ant"

param
desc description for the change list

        this.description = desc;