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 96 public class CCCheckout extends ClearCase { 97 private boolean mReserved = true; 98 private String mOut = null; 99 private boolean mNdata = false; 100 private String mBranch = null; 101 private boolean mVersion = false; 102 private boolean mNwarn = false; 103 private String mComment = null; 104 private String mCfile = null; 105 private boolean mNotco = true; 106 107 114 public void execute() throws BuildException { 115 Commandline commandLine = new Commandline(); 116 Project aProj = getProject(); 117 int result = 0; 118 119 if (getViewPath() == null) { 121 setViewPath(aProj.getBaseDir().getPath()); 122 } 123 124 commandLine.setExecutable(getClearToolCommand()); 128 commandLine.createArgument().setValue(COMMAND_CHECKOUT); 129 130 checkOptions(commandLine); 131 136 if (!getNotco() && lsCheckout()) { 137 getProject().log("Already checked out in this view: " 138 + getViewPathBasename(), Project.MSG_VERBOSE); 139 return; 140 } 141 if (!getFailOnErr()) { 142 getProject().log("Ignoring any errors that occur for: " 143 + getViewPathBasename(), Project.MSG_VERBOSE); 144 } 145 result = run(commandLine); 146 if (Execute.isFailure(result) && getFailOnErr()) { 147 String msg = "Failed executing: " + commandLine.toString(); 148 throw new BuildException(msg, getLocation()); 149 } 150 } 151 152 155 private boolean lsCheckout() { 156 Commandline cmdl = new Commandline(); 157 String result; 158 159 cmdl.setExecutable(getClearToolCommand()); 163 cmdl.createArgument().setValue(COMMAND_LSCO); 164 cmdl.createArgument().setValue("-cview"); 165 cmdl.createArgument().setValue("-short"); 166 cmdl.createArgument().setValue("-d"); 167 cmdl.createArgument().setValue(getViewPath()); 169 170 result = runS(cmdl); 171 172 174 return (result != null && result.length() > 0) ? true : false; 175 } 176 179 private void checkOptions(Commandline cmd) { 180 if (getReserved()) { 182 cmd.createArgument().setValue(FLAG_RESERVED); 184 } else { 185 cmd.createArgument().setValue(FLAG_UNRESERVED); 187 } 188 189 if (getOut() != null) { 190 getOutCommand(cmd); 192 } else { 193 if (getNoData()) { 194 cmd.createArgument().setValue(FLAG_NODATA); 196 } 197 198 } 199 200 if (getBranch() != null) { 201 getBranchCommand(cmd); 203 } else { 204 if (getVersion()) { 205 cmd.createArgument().setValue(FLAG_VERSION); 207 } 208 209 } 210 211 if (getNoWarn()) { 212 cmd.createArgument().setValue(FLAG_NOWARN); 214 } 215 216 if (getComment() != null) { 217 getCommentCommand(cmd); 219 } else { 220 if (getCommentFile() != null) { 221 getCommentFileCommand(cmd); 223 } else { 224 cmd.createArgument().setValue(FLAG_NOCOMMENT); 225 } 226 } 227 228 cmd.createArgument().setValue(getViewPath()); 230 231 } 234 235 240 public void setReserved(boolean reserved) { 241 mReserved = reserved; 242 } 243 244 249 public boolean getReserved() { 250 return mReserved; 251 } 252 253 259 public void setNotco(boolean notco) { 260 mNotco = notco; 261 } 262 263 269 public boolean getNotco() { 270 return mNotco; 271 } 272 273 274 279 public void setOut(String outf) { 280 mOut = outf; 281 } 282 283 288 public String getOut() { 289 return mOut; 290 } 291 292 298 public void setNoData(boolean ndata) { 299 mNdata = ndata; 300 } 301 302 307 public boolean getNoData() { 308 return mNdata; 309 } 310 311 316 public void setBranch(String branch) { 317 mBranch = branch; 318 } 319 320 325 public String getBranch() { 326 return mBranch; 327 } 328 329 334 public void setVersion(boolean version) { 335 mVersion = version; 336 } 337 338 343 public boolean getVersion() { 344 return mVersion; 345 } 346 347 352 public void setNoWarn(boolean nwarn) { 353 mNwarn = nwarn; 354 } 355 356 361 public boolean getNoWarn() { 362 return mNwarn; 363 } 364 365 370 public void setComment(String comment) { 371 mComment = comment; 372 } 373 374 379 public String getComment() { 380 return mComment; 381 } 382 383 388 public void setCommentFile(String cfile) { 389 mCfile = cfile; 390 } 391 392 397 public String getCommentFile() { 398 return mCfile; 399 } 400 401 407 private void getOutCommand(Commandline cmd) { 408 if (getOut() != null) { 409 414 cmd.createArgument().setValue(FLAG_OUT); 415 cmd.createArgument().setValue(getOut()); 416 } 417 } 418 419 425 private void getBranchCommand(Commandline cmd) { 426 if (getBranch() != null) { 427 432 cmd.createArgument().setValue(FLAG_BRANCH); 433 cmd.createArgument().setValue(getBranch()); 434 } 435 } 436 437 438 444 private void getCommentCommand(Commandline cmd) { 445 if (getComment() != null) { 446 451 cmd.createArgument().setValue(FLAG_COMMENT); 452 cmd.createArgument().setValue(getComment()); 453 } 454 } 455 456 462 private void getCommentFileCommand(Commandline cmd) { 463 if (getCommentFile() != null) { 464 469 cmd.createArgument().setValue(FLAG_COMMENTFILE); 470 cmd.createArgument().setValue(getCommentFile()); 471 } 472 } 473 474 477 public static final String FLAG_RESERVED = "-reserved"; 478 481 public static final String FLAG_UNRESERVED = "-unreserved"; 482 485 public static final String FLAG_OUT = "-out"; 486 489 public static final String FLAG_NODATA = "-ndata"; 490 493 public static final String FLAG_BRANCH = "-branch"; 494 497 public static final String FLAG_VERSION = "-version"; 498 501 public static final String FLAG_NOWARN = "-nwarn"; 502 505 public static final String FLAG_COMMENT = "-c"; 506 509 public static final String FLAG_COMMENTFILE = "-cfile"; 510 513 public static final String FLAG_NOCOMMENT = "-nc"; 514 515 } 516 517 | Popular Tags |