1 18 19 package org.apache.tools.ant.taskdefs.optional.clearcase; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.Project; 23 import org.apache.tools.ant.taskdefs.Execute; 24 import org.apache.tools.ant.types.Commandline; 25 26 27 31 32 33 34 87 public class CCLock extends ClearCase { 88 private boolean mReplace = false; 89 private boolean mObsolete = false; 90 private String mComment = null; 91 private String mNusers = null; 92 private String mPname = null; 93 private String mObjselect = null; 94 95 102 public void execute() throws BuildException { 103 Commandline commandLine = new Commandline(); 104 Project aProj = getProject(); 105 int result = 0; 106 107 if (getViewPath() == null) { 109 setViewPath(aProj.getBaseDir().getPath()); 110 } 111 112 commandLine.setExecutable(getClearToolCommand()); 116 commandLine.createArgument().setValue(COMMAND_LOCK); 117 118 checkOptions(commandLine); 120 121 124 if (!getFailOnErr()) { 125 getProject().log("Ignoring any errors that occur for: " 126 + getOpType(), Project.MSG_VERBOSE); 127 } 128 result = run(commandLine); 129 if (Execute.isFailure(result) && getFailOnErr()) { 130 String msg = "Failed executing: " + commandLine.toString(); 131 throw new BuildException(msg, getLocation()); 132 } 133 } 134 135 138 private void checkOptions(Commandline cmd) { 139 if (getReplace()) { 141 cmd.createArgument().setValue(FLAG_REPLACE); 143 } 144 if (getObsolete()) { 145 cmd.createArgument().setValue(FLAG_OBSOLETE); 147 } else { 148 getNusersCommand(cmd); 149 } 150 getCommentCommand(cmd); 151 152 if (getObjselect() == null && getPname() == null) { 153 throw new BuildException("Should select either an element " 154 + "(pname) or an object (objselect)"); 155 } 156 getPnameCommand(cmd); 157 if (getObjselect() != null) { 159 cmd.createArgument().setValue(getObjselect()); 160 } 161 } 162 163 168 public void setReplace(boolean replace) { 169 mReplace = replace; 170 } 171 172 177 public boolean getReplace() { 178 return mReplace; 179 } 180 181 186 public void setObsolete(boolean obsolete) { 187 mObsolete = obsolete; 188 } 189 190 195 public boolean getObsolete() { 196 return mObsolete; 197 } 198 199 205 public void setNusers(String nusers) { 206 mNusers = nusers; 207 } 208 209 214 public String getNusers() { 215 return mNusers; 216 } 217 218 224 public void setComment(String comment) { 225 mComment = comment; 226 } 227 228 233 public String getComment() { 234 return mComment; 235 } 236 237 242 public void setPname(String pname) { 243 mPname = pname; 244 } 245 246 251 public String getPname() { 252 return mPname; 253 } 254 255 261 public void setObjSel(String objsel) { 262 mObjselect = objsel; 263 } 264 265 270 public void setObjselect(String objselect) { 271 mObjselect = objselect; 272 } 273 274 279 public String getObjselect() { 280 return mObjselect; 281 } 282 283 289 private void getNusersCommand(Commandline cmd) { 290 if (getNusers() == null) { 291 return; 292 } else { 293 298 cmd.createArgument().setValue(FLAG_NUSERS); 299 cmd.createArgument().setValue(getNusers()); 300 } 301 } 302 303 309 private void getCommentCommand(Commandline cmd) { 310 if (getComment() == null) { 311 return; 312 } else { 313 318 cmd.createArgument().setValue(FLAG_COMMENT); 319 cmd.createArgument().setValue(getComment()); 320 } 321 } 322 323 329 private void getPnameCommand(Commandline cmd) { 330 if (getPname() == null) { 331 return; 332 } else { 333 338 cmd.createArgument().setValue(FLAG_PNAME); 339 cmd.createArgument().setValue(getPname()); 340 } 341 } 342 343 348 private String getOpType() { 349 350 if (getPname() != null) { 351 return getPname(); 352 } else { 353 return getObjselect(); 354 } 355 } 356 357 360 public static final String FLAG_REPLACE = "-replace"; 361 364 public static final String FLAG_NUSERS = "-nusers"; 365 368 public static final String FLAG_OBSOLETE = "-obsolete"; 369 372 public static final String FLAG_COMMENT = "-comment"; 373 376 public static final String FLAG_PNAME = "-pname"; 377 } 378 379 | Popular Tags |