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

P4Label

public class P4Label extends P4Base
Creates a new Perforce label and set contents to reflect current client file revisions. Label name defaults to AntLabel if none set. Example Usage:
<P4Label name="MyLabel-${TSTAMP}-${DSTAMP}" desc="Auto Build Label" />
ant.task
category="scm"

Fields Summary
protected String
name
protected String
desc
protected String
lock
Constructors Summary
Methods Summary
public voidexecute()
do the work

throws
BuildException if failonerror has been set to true and Perforce fails

        log("P4Label exec:", Project.MSG_INFO);

        if (P4View == null || P4View.length() < 1) {
            log("View not set, assuming //depot/...", Project.MSG_WARN);
            P4View = "//depot/...";
        } else {
            P4View = StringUtils.replace(P4View, ":", "\n\t");
            P4View = StringUtils.replace(P4View, ";", "\n\t");
        }

        if (desc == null || desc.length() < 1) {
            log("Label Description not set, assuming 'AntLabel'",
                Project.MSG_WARN);
            desc = "AntLabel";
        }

        if (lock != null && !lock.equalsIgnoreCase("locked")) {
            log("lock attribute invalid - ignoring", Project.MSG_WARN);
        }

        if (name == null || name.length() < 1) {
            SimpleDateFormat formatter
                = new SimpleDateFormat("yyyy.MM.dd-hh:mm");
            Date now = new Date();
            name = "AntLabel-" + formatter.format(now);
            log("name not set, assuming '" + name + "'", Project.MSG_WARN);
        }


        //We have to create a unlocked label first
        String newLabel =
                "Label: " + name
                + "\nDescription: " + desc
                + "\nOptions: unlocked"
                + "\nView: \n\t" + P4View;

        P4Handler handler = new P4HandlerAdapter() {
            public void process(String line) {
                log(line, Project.MSG_VERBOSE);
            }
        };

        handler.setOutput(newLabel);

        execP4Command("label -i", handler);

        execP4Command("labelsync -l " + name, new P4HandlerAdapter() {
            public void process(String line) {
                log(line, Project.MSG_VERBOSE);
            }
        });


        log("Created Label " + name + " (" + desc + ") with view:\n" + P4View,
            Project.MSG_INFO);

        //Now lock if required
        if (lock != null && lock.equalsIgnoreCase("locked")) {

            log("Modifying lock status to 'locked'", Project.MSG_INFO);

            final StringBuffer labelSpec = new StringBuffer();

            //Read back the label spec from perforce,
            //Replace Options
            //Submit back to Perforce

            handler = new P4HandlerAdapter() {
                public void process(String line) {
                    log(line, Project.MSG_VERBOSE);

                    if (util.match("/^Options:/", line)) {
                        line = "Options: " + lock;
                    }

                    labelSpec.append(line + "\n");
                }
            };


            execP4Command("label -o " + name, handler);
            log(labelSpec.toString(), Project.MSG_DEBUG);

            log("Now locking label...", Project.MSG_VERBOSE);
            handler = new P4HandlerAdapter() {
                public void process(String line) {
                    log(line, Project.MSG_VERBOSE);
                }
            };

            handler.setOutput(labelSpec.toString());
            execP4Command("label -i", handler);
        }
    
public voidsetDesc(java.lang.String desc)
Label Description; optional

param
desc description of the label

        this.desc = desc;
    
public voidsetLock(java.lang.String lock)
when set to "locked", Perforce will lock the label once created; optional.

param
lock only admissible value "locked"

        this.lock = lock;
    
public voidsetName(java.lang.String name)
The name of the label; optional, default "AntLabel"

param
name the name of the label

        this.name = name;