1 22 package org.netbeans.lib.cvsclient.command; 23 24 import java.io.File ; 25 import java.util.*; 26 27 import org.netbeans.lib.cvsclient.request.*; 28 29 41 public class GlobalOptions implements Cloneable { 42 43 private List variables; 44 48 private boolean doNoChanges; 49 50 53 private boolean checkedOutFilesReadOnly; 54 55 58 private String cvsRoot; 59 60 63 private boolean useGzip = true; 64 65 68 private int compressionLevel = 0; 69 70 73 private boolean noHistoryLogging; 74 75 81 private boolean moderatelyQuiet; 82 83 90 private boolean veryQuiet; 91 92 98 private boolean traceExecution; 99 100 103 private boolean showHelp; 104 105 108 private boolean showVersion; 109 110 113 private boolean ignoreCvsrc; 114 115 118 private File tempDir; 119 120 123 private String editor; 124 125 128 private File [] exclusions; 129 130 public GlobalOptions() { 131 variables = new ArrayList(); 132 } 133 134 140 public void setExclusions(File [] exclusions) { 141 this.exclusions = exclusions; 142 } 143 144 150 public File [] getExclusions() { 151 return exclusions; 152 } 153 154 160 public boolean isExcluded(File file) { 161 if (exclusions != null) { 162 for (int i = 0; i < exclusions.length; i++) { 163 if (isParentOrEqual(exclusions[i], file)) return true; 164 } 165 } 166 return false; 167 } 168 169 176 private static boolean isParentOrEqual(File parent, File file) { 177 for (; file != null; file = file.getParentFile()) { 178 if (file.equals(parent)) return true; 179 } 180 return false; 181 } 182 183 189 public List createRequestList() { 190 List requestList = new LinkedList(); 191 if (variables.size() > 0) { 192 Iterator it = variables.iterator(); 193 while (it.hasNext()) { 194 String keyValue = it.next().toString(); 195 requestList.add(new SetRequest(keyValue)); 196 } 197 } 198 if (isNoHistoryLogging()) { 199 requestList.add(new GlobalOptionRequest("-l")); } 201 if (isDoNoChanges()) { 202 requestList.add(new GlobalOptionRequest("-n")); } 204 if (isModeratelyQuiet()) { 205 requestList.add(new GlobalOptionRequest("-q")); } 207 if (isVeryQuiet()) { 208 requestList.add(new GlobalOptionRequest("-Q")); } 210 if (isTraceExecution()) { 211 requestList.add(new GlobalOptionRequest("-t")); } 213 return requestList; 214 } 215 216 220 public String getOptString() { 221 return "Hvnfd:lqQtrws:z:T:e:"; } 223 224 227 public boolean setCVSCommand(char opt, String optArg) { 228 if (opt == 'n') { 229 setDoNoChanges(true); 230 } 231 else if (opt == 'd') { 232 setCVSRoot(optArg); 233 } 234 else if (opt == 'l') { 235 setNoHistoryLogging(true); 236 } 237 else if (opt == 'q') { 238 setModeratelyQuiet(true); 239 } 240 else if (opt == 'Q') { 241 setVeryQuiet(true); 242 } 243 else if (opt == 't') { 244 setTraceExecution(true); 245 } 246 else if (opt == 't') { 247 setTraceExecution(true); 248 } 249 else if (opt == 'r') { 250 setCheckedOutFilesReadOnly(true); 251 } 252 else if (opt == 'w') { 253 setCheckedOutFilesReadOnly(false); 254 } 255 else if (opt == 's') { 256 setCvsVariable(optArg); 257 } 258 else if (opt == 'z') { 259 try { 260 setCompressionLevel(Integer.parseInt(optArg)); 261 } catch (NumberFormatException nfex) { 262 263 } 264 } 265 else if (opt == 'H') { 266 setShowHelp(true); 267 } 268 else if (opt == 'v') { 269 setShowVersion(true); 270 } 271 else if (opt == 'f') { 272 setIgnoreCvsrc(true); 273 } 274 else if (opt == 'T') { 275 setTempDir(new File (optArg)); 276 } 277 else if (opt == 'e') { 278 setEditor(optArg); 279 } 280 else { 281 return false; 282 } 283 return true; 284 } 285 286 291 public void resetCVSCommand() { 292 setCheckedOutFilesReadOnly(false); 293 setDoNoChanges(false); 294 setModeratelyQuiet(false); 295 setNoHistoryLogging(false); 296 setTraceExecution(false); 297 setUseGzip(true); 298 setCompressionLevel(0); 299 setVeryQuiet(false); 300 setShowHelp(false); 301 setShowVersion(false); 302 setIgnoreCvsrc(false); 303 setTempDir(null); 304 setEditor(null); 305 setCVSRoot(""); 306 clearCvsVariables(); 307 } 308 309 313 public String getCVSCommand() { 314 StringBuffer switches = new StringBuffer (); 315 if (isDoNoChanges()) { 316 switches.append("-n "); } 318 if (isNoHistoryLogging()) { 319 switches.append("-l "); } 321 if (isModeratelyQuiet()) { 322 switches.append("-q "); } 324 if (isVeryQuiet()) { 325 switches.append("-Q "); } 327 if (isTraceExecution()) { 328 switches.append("-t "); } 330 if (isCheckedOutFilesReadOnly()) { 331 switches.append("-r "); } 333 if (variables.size() > 0) { 334 Iterator it = variables.iterator(); 335 while (it.hasNext()) { 336 String keyValue = it.next().toString(); 337 switches.append("-s " + keyValue + " "); } 339 } 340 if (compressionLevel != 0) { 341 switches.append("-z "); 342 switches.append(Integer.toString(compressionLevel)); 343 switches.append(" "); 344 } 345 if (isIgnoreCvsrc()) { 346 switches.append("-f "); 347 } 348 if (tempDir != null) { 349 switches.append("-T "); 350 switches.append(tempDir.getAbsolutePath()); 351 switches.append(" "); 352 } 353 if (editor != null) { 354 switches.append("-e "); 355 switches.append(editor); 356 switches.append(" "); 357 } 358 return switches.toString(); 359 } 360 361 365 public void setCvsVariable(String variable) { 366 variables.add(variable); 367 } 368 369 372 373 public void clearCvsVariables() { 374 this.variables.clear(); 375 } 376 377 382 public void setCvsVariables(String [] variables) { 383 clearCvsVariables(); 384 for (int i = 0; i < variables.length; i++) { 385 String variable = variables[i]; 386 this.variables.add(variable); 387 } 388 } 389 390 public String [] getCvsVariables() { 391 String [] vars = new String [variables.size()]; 392 vars = (String [])variables.toArray(vars); 393 return vars; 394 } 395 396 397 400 public void setDoNoChanges(boolean doNoChanges) { 401 this.doNoChanges = doNoChanges; 402 } 403 404 407 public boolean isDoNoChanges() { 408 return doNoChanges; 409 } 410 411 415 public boolean isCheckedOutFilesReadOnly() { 416 return checkedOutFilesReadOnly; 417 } 418 419 423 public void setCheckedOutFilesReadOnly(boolean readOnly) { 424 checkedOutFilesReadOnly = readOnly; 425 } 426 427 431 public String getCVSRoot() { 432 return cvsRoot; 433 } 434 435 439 public void setCVSRoot(String cvsRoot) { 440 this.cvsRoot = cvsRoot; 441 } 442 443 447 public void setUseGzip(boolean useGzip) { 448 this.useGzip = useGzip; 449 } 450 451 455 public boolean isUseGzip() { 456 return useGzip; 457 } 458 459 463 public int getCompressionLevel() { 464 return compressionLevel; 465 } 466 467 471 public void setCompressionLevel(int compressionLevel) { 472 this.compressionLevel = compressionLevel; 473 } 474 475 478 public boolean isNoHistoryLogging() { 479 return noHistoryLogging; 480 } 481 482 485 public void setNoHistoryLogging(boolean noHistoryLogging) { 486 this.noHistoryLogging = noHistoryLogging; 487 } 488 489 492 public boolean isModeratelyQuiet() { 493 return moderatelyQuiet; 494 } 495 496 499 public void setModeratelyQuiet(boolean moderatelyQuiet) { 500 this.moderatelyQuiet = moderatelyQuiet; 501 } 502 503 506 public boolean isVeryQuiet() { 507 return veryQuiet; 508 } 509 510 513 public void setVeryQuiet(boolean veryQuiet) { 514 this.veryQuiet = veryQuiet; 515 } 516 517 520 public boolean isTraceExecution() { 521 return traceExecution; 522 } 523 524 527 public void setTraceExecution(boolean traceExecution) { 528 this.traceExecution = traceExecution; 529 } 530 531 535 public boolean isShowHelp() { 536 return showHelp; 537 } 538 539 543 public void setShowHelp(boolean showHelp) { 544 this.showHelp = showHelp; 545 } 546 547 551 public boolean isShowVersion() { 552 return showVersion; 553 } 554 555 559 public void setShowVersion(boolean showVersion) { 560 this.showVersion = showVersion; 561 } 562 563 567 public boolean isIgnoreCvsrc() { 568 return ignoreCvsrc; 569 } 570 571 575 public void setIgnoreCvsrc(boolean ignoreCvsrc) { 576 this.ignoreCvsrc = ignoreCvsrc; 577 } 578 579 583 public java.io.File getTempDir() { 584 return tempDir; 585 } 586 587 591 public void setTempDir(java.io.File tempDir) { 592 this.tempDir = tempDir; 593 } 594 595 599 public String getEditor() { 600 return editor; 601 } 602 603 607 public void setEditor(String editor) { 608 this.editor = editor; 609 } 610 611 614 public Object clone() { 615 try { 616 return super.clone(); 617 } 618 catch (CloneNotSupportedException ex) { 619 return null; 621 } 622 } 623 624 } 625 | Popular Tags |