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 import org.apache.tools.ant.taskdefs.condition.Os; 26 27 85 public class CCMkattr extends ClearCase { 86 private boolean mReplace = false; 87 private boolean mRecurse = false; 88 private String mVersion = null; 89 private String mTypeName = null; 90 private String mTypeValue = null; 91 private String mComment = null; 92 private String mCfile = null; 93 94 101 public void execute() throws BuildException { 102 Commandline commandLine = new Commandline(); 103 Project aProj = getProject(); 104 int result = 0; 105 106 if (getTypeName() == null) { 108 throw new BuildException("Required attribute TypeName not specified"); 109 } 110 if (getTypeValue() == null) { 111 throw new BuildException("Required attribute TypeValue not specified"); 112 } 113 if (getViewPath() == null) { 115 setViewPath(aProj.getBaseDir().getPath()); 116 } 117 118 commandLine.setExecutable(getClearToolCommand()); 122 commandLine.createArgument().setValue(COMMAND_MKATTR); 123 124 checkOptions(commandLine); 125 126 if (!getFailOnErr()) { 127 getProject().log("Ignoring any errors that occur for: " 128 + getViewPathBasename(), Project.MSG_VERBOSE); 129 } 130 131 134 result = run(commandLine); 135 if (Execute.isFailure(result) && getFailOnErr()) { 136 String msg = "Failed executing: " + commandLine.toString(); 137 throw new BuildException(msg, getLocation()); 138 } 139 } 140 141 142 145 private void checkOptions(Commandline cmd) { 146 if (getReplace()) { 147 cmd.createArgument().setValue(FLAG_REPLACE); 149 } 150 151 if (getRecurse()) { 152 cmd.createArgument().setValue(FLAG_RECURSE); 154 } 155 156 if (getVersion() != null) { 157 getVersionCommand(cmd); 159 } 160 161 if (getComment() != null) { 162 getCommentCommand(cmd); 164 } else { 165 if (getCommentFile() != null) { 166 getCommentFileCommand(cmd); 168 } else { 169 cmd.createArgument().setValue(FLAG_NOCOMMENT); 170 } 171 } 172 173 if (getTypeName() != null) { 174 getTypeCommand(cmd); 176 } 177 if (getTypeValue() != null) { 178 getTypeValueCommand(cmd); 180 } 181 cmd.createArgument().setValue(getViewPath()); 183 } 184 185 186 191 public void setReplace(boolean replace) { 192 mReplace = replace; 193 } 194 195 200 public boolean getReplace() { 201 return mReplace; 202 } 203 204 209 public void setRecurse(boolean recurse) { 210 mRecurse = recurse; 211 } 212 213 218 public boolean getRecurse() { 219 return mRecurse; 220 } 221 222 227 public void setVersion(String version) { 228 mVersion = version; 229 } 230 231 236 public String getVersion() { 237 return mVersion; 238 } 239 240 245 public void setComment(String comment) { 246 mComment = comment; 247 } 248 249 254 public String getComment() { 255 return mComment; 256 } 257 258 263 public void setCommentFile(String cfile) { 264 mCfile = cfile; 265 } 266 267 272 public String getCommentFile() { 273 return mCfile; 274 } 275 276 281 public void setTypeName(String tn) { 282 mTypeName = tn; 283 } 284 285 290 public String getTypeName() { 291 return mTypeName; 292 } 293 294 299 public void setTypeValue(String tv) { 300 mTypeValue = tv; 301 } 302 303 308 public String getTypeValue() { 309 return mTypeValue; 310 } 311 312 313 319 private void getVersionCommand(Commandline cmd) { 320 if (getVersion() != null) { 321 326 cmd.createArgument().setValue(FLAG_VERSION); 327 cmd.createArgument().setValue(getVersion()); 328 } 329 } 330 331 337 private void getCommentCommand(Commandline cmd) { 338 if (getComment() != null) { 339 344 cmd.createArgument().setValue(FLAG_COMMENT); 345 cmd.createArgument().setValue(getComment()); 346 } 347 } 348 349 355 private void getCommentFileCommand(Commandline cmd) { 356 if (getCommentFile() != null) { 357 362 cmd.createArgument().setValue(FLAG_COMMENTFILE); 363 cmd.createArgument().setValue(getCommentFile()); 364 } 365 } 366 367 373 private void getTypeCommand(Commandline cmd) { 374 String typenm = getTypeName(); 375 376 if (typenm != null) { 377 cmd.createArgument().setValue(typenm); 378 } 379 } 380 381 387 private void getTypeValueCommand(Commandline cmd) { 388 String typevl = getTypeValue(); 389 390 if (typevl != null) { 391 if (Os.isFamily("windows")) { 392 typevl = "\\\"" + typevl + "\\\""; } else { 394 typevl = "\"" + typevl + "\""; 395 } 396 cmd.createArgument().setValue(typevl); 397 } 398 } 399 400 403 public static final String FLAG_REPLACE = "-replace"; 404 407 public static final String FLAG_RECURSE = "-recurse"; 408 411 public static final String FLAG_VERSION = "-version"; 412 415 public static final String FLAG_COMMENT = "-c"; 416 419 public static final String FLAG_COMMENTFILE = "-cfile"; 420 423 public static final String FLAG_NOCOMMENT = "-nc"; 424 } 425 426 | Popular Tags |