1 18 23 24 package org.apache.tools.ant.taskdefs.optional.perforce; 25 26 import java.text.SimpleDateFormat ; 27 import java.util.Date ; 28 import org.apache.tools.ant.BuildException; 29 import org.apache.tools.ant.Project; 30 import org.apache.tools.ant.util.StringUtils; 31 32 45 public class P4Label extends P4Base { 46 47 protected String name; 49 protected String desc; 50 protected String lock; 51 53 57 public void setName(String name) { 58 this.name = name; 59 } 60 61 65 public void setDesc(String desc) { 66 this.desc = desc; 67 } 68 69 73 public void setLock(String lock) { 74 this.lock = lock; 75 } 76 77 81 public void execute() throws BuildException { 82 log("P4Label exec:", Project.MSG_INFO); 83 84 if (P4View == null || P4View.length() < 1) { 85 log("View not set, assuming //depot/...", Project.MSG_WARN); 86 P4View = "//depot/..."; 87 } else { 88 P4View = StringUtils.replace(P4View, ":", "\n\t"); 89 P4View = StringUtils.replace(P4View, ";", "\n\t"); 90 } 91 92 if (desc == null || desc.length() < 1) { 93 log("Label Description not set, assuming 'AntLabel'", 94 Project.MSG_WARN); 95 desc = "AntLabel"; 96 } 97 98 if (lock != null && !lock.equalsIgnoreCase("locked")) { 99 log("lock attribute invalid - ignoring", Project.MSG_WARN); 100 } 101 102 if (name == null || name.length() < 1) { 103 SimpleDateFormat formatter 104 = new SimpleDateFormat ("yyyy.MM.dd-hh:mm"); 105 Date now = new Date (); 106 name = "AntLabel-" + formatter.format(now); 107 log("name not set, assuming '" + name + "'", Project.MSG_WARN); 108 } 109 110 111 String newLabel = 113 "Label: " + name 114 + "\nDescription: " + desc 115 + "\nOptions: unlocked" 116 + "\nView: \n\t" + P4View; 117 118 P4Handler handler = new P4HandlerAdapter() { 119 public void process(String line) { 120 log(line, Project.MSG_VERBOSE); 121 } 122 }; 123 124 handler.setOutput(newLabel); 125 126 execP4Command("label -i", handler); 127 128 execP4Command("labelsync -l " + name, new P4HandlerAdapter() { 129 public void process(String line) { 130 log(line, Project.MSG_VERBOSE); 131 } 132 }); 133 134 135 log("Created Label " + name + " (" + desc + ") with view:\n" + P4View, 136 Project.MSG_INFO); 137 138 if (lock != null && lock.equalsIgnoreCase("locked")) { 140 141 log("Modifying lock status to 'locked'", Project.MSG_INFO); 142 143 final StringBuffer labelSpec = new StringBuffer (); 144 145 149 handler = new P4HandlerAdapter() { 150 public void process(String line) { 151 log(line, Project.MSG_VERBOSE); 152 153 if (util.match("/^Options:/", line)) { 154 line = "Options: " + lock; 155 } 156 157 labelSpec.append(line + "\n"); 158 } 159 }; 160 161 162 execP4Command("label -o " + name, handler); 163 log(labelSpec.toString(), Project.MSG_DEBUG); 164 165 log("Now locking label...", Project.MSG_VERBOSE); 166 handler = new P4HandlerAdapter() { 167 public void process(String line) { 168 log(line, Project.MSG_VERBOSE); 169 } 170 }; 171 172 handler.setOutput(labelSpec.toString()); 173 execP4Command("label -i", handler); 174 } 175 } 176 } 177 | Popular Tags |