diff --git a/docs/manual/OptionalTasks/perforce.html b/docs/manual/OptionalTasks/perforce.html index e2bd099d7..8518807f8 100644 --- a/docs/manual/OptionalTasks/perforce.html +++ b/docs/manual/OptionalTasks/perforce.html @@ -325,6 +325,11 @@ although P4Edit can open files to the default change, P4Submit cannot yet submi Label Description No + + lock + Lock the label once created. + No + @@ -333,6 +338,7 @@ although P4Edit can open files to the default change, P4Submit cannot yet submi <p4label name="NightlyBuild:${DSTAMP}:${TSTAMP}" desc="Auto Nightly Build" + lock="locked" />
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java index e97229b20..ef86dc70e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java @@ -79,6 +79,7 @@ public class P4Label extends P4Base { protected String name; protected String desc; + protected String lock; public void setName(String name) { this.name = name; @@ -87,7 +88,11 @@ public class P4Label extends P4Base { public void setDesc(String desc) { this.desc = desc; } - + + public void setLock(String lock) { + this.lock = lock; + } + public void execute() throws BuildException { log("P4Label exec:",Project.MSG_INFO); @@ -101,7 +106,10 @@ public class P4Label extends P4Base { 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(); @@ -110,6 +118,7 @@ public class P4Label extends P4Base { } + //We have to create a unlocked label first String newLabel = "Label: "+name+"\n"+ "Description: "+desc+"\n"+ @@ -134,6 +143,46 @@ public class P4Label extends P4Base { log("Created Label "+name+" ("+desc+")", 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); + } + }