do the work
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);
}