1 19 package org.netbeans.lib.cvsclient.command.history; 20 21 import java.util.*; 22 23 import org.netbeans.lib.cvsclient.*; 24 import org.netbeans.lib.cvsclient.command.*; 25 import org.netbeans.lib.cvsclient.connection.*; 26 import org.netbeans.lib.cvsclient.event.*; 27 import org.netbeans.lib.cvsclient.request.*; 28 29 33 public class HistoryCommand extends Command { 34 37 private final List requests = new LinkedList(); 38 39 42 private EventManager eventManager; 43 44 45 private boolean forAllUsers; 46 47 48 private String showBackToRecordContaining; 49 50 51 private boolean reportCommits; 52 53 54 private String sinceDate; 55 56 57 private boolean reportEverything; 58 59 60 private boolean lastEventOfProject; 61 62 63 private boolean reportCheckouts; 64 65 66 private String sinceRevision; 67 68 69 private boolean reportTags; 70 71 72 private String sinceTag; 73 74 75 private boolean forWorkingDirectory; 76 77 78 private String reportEventType; 79 80 81 private String timeZone; 82 83 84 private String [] lastEventForFile; 85 86 87 private String [] reportOnModule; 88 89 90 private String [] reportLastEventForModule; 91 92 93 private String [] forUsers; 94 95 98 public HistoryCommand() { 99 } 100 101 105 public Builder createBuilder(EventManager eventMan) { 106 return null; 107 } 108 109 115 public void execute(ClientServices client, EventManager em) 116 throws CommandException, AuthenticationException { 117 118 client.ensureConnection(); 119 120 eventManager = em; 121 requests.clear(); 122 123 super.execute(client, em); 124 125 try { 126 if (client.isFirstCommand()) { 127 requests.add(new RootRequest(client.getRepository())); 128 requests.add(new UseUnchangedRequest()); 129 } 130 131 addBooleanArgument(requests, isForAllUsers(), "-a"); addBooleanArgument(requests, isForWorkingDirectory(), "-w"); addBooleanArgument(requests, isLastEventOfProject(), "-l"); addBooleanArgument(requests, isReportCheckouts(), "-o"); addBooleanArgument(requests, isReportCommits(), "-c"); addBooleanArgument(requests, isReportEverything(), "-e"); addBooleanArgument(requests, isReportTags(), "-T"); addStringArgument(requests, getReportEventType(), "-x"); addStringArgument(requests, getShowBackToRecordContaining(), "-b"); addStringArgument(requests, getSinceDate(), "-D"); addStringArgument(requests, getSinceRevision(), "-r"); addStringArgument(requests, getSinceTag(), "-t"); addStringArrayArgument(requests, getForUsers(), "-u"); addStringArrayArgument(requests, getReportLastEventForModule(), "-n"); addStringArrayArgument(requests, getReportOnModule(), "-m"); addStringArrayArgument(requests, getLastEventForFile(), "-f"); if (!isReportCheckouts() && !isReportCommits() && !isReportTags() && 148 !isReportEverything() && getReportEventType() == null && getReportOnModule() == null) { 149 addBooleanArgument(requests, true, "-c"); } 152 if (getTimeZone() != null) { 153 addStringArgument(requests, getTimeZone(), "-z"); } 155 else { 156 addStringArgument(requests, "+0000", "-z"); } 158 requests.add(CommandRequest.HISTORY); 159 client.processRequests(requests); 160 } 161 catch (CommandException ex) { 162 throw ex; 163 } 164 catch (Exception ex) { 165 throw new CommandException(ex, ex.getLocalizedMessage()); 166 } 167 finally { 168 requests.clear(); 169 } 170 } 171 172 private void addStringArgument(List reqList, String property, String cvsSwitch) { 173 if (property != null) { 174 reqList.add(new ArgumentRequest(cvsSwitch)); 175 reqList.add(new ArgumentRequest(property)); 176 } 177 } 178 179 private void addStringArrayArgument(List reqList, String [] property, String cvsSwitch) { 180 if (property != null) { 181 for (int i = 0; i < property.length; i++) { 182 reqList.add(new ArgumentRequest(cvsSwitch)); 183 reqList.add(new ArgumentRequest(property[i])); 184 } 185 } 186 } 187 188 private void addBooleanArgument(List reqList, boolean property, String cvsSwitch) { 189 if (property == true) { 190 reqList.add(new ArgumentRequest(cvsSwitch)); 191 } 192 } 193 194 196 public void commandTerminated(TerminationEvent e) { 197 } 198 199 204 public String getCVSCommand() { 205 StringBuffer toReturn = new StringBuffer ("history "); toReturn.append(getCVSArguments()); 207 return toReturn.toString(); 208 } 209 210 214 public boolean setCVSCommand(char opt, String optArg) { 215 if (opt == 'a') { 216 setForAllUsers(true); 217 } 218 else if (opt == 'b') { 219 setShowBackToRecordContaining(optArg); 220 } 221 else if (opt == 'c') { 222 setReportCommits(true); 223 } 224 else if (opt == 'D') { 225 setSinceDate(optArg); 226 } 227 else if (opt == 'e') { 228 setReportEverything(true); 229 } 230 else if (opt == 'l') { 231 setLastEventOfProject(true); 232 } 233 else if (opt == 'o') { 234 setReportCheckouts(true); 235 } 236 else if (opt == 'r') { 237 setSinceRevision(optArg); 238 } 239 else if (opt == 'T') { 240 setReportTags(true); 241 } 242 else if (opt == 't') { 243 setSinceTag(optArg); 244 } 245 else if (opt == 'w') { 246 setForWorkingDirectory(true); 247 } 248 else if (opt == 'x') { 249 setReportEventType(optArg); 250 } 251 else if (opt == 'z') { 252 setTimeZone(optArg); 253 } 254 else if (opt == 'f') { 255 addLastEventForFile(optArg); 256 } 257 else if (opt == 'm') { 258 addReportOnModule(optArg); 259 } 260 else if (opt == 'n') { 261 addReportLastEventForModule(optArg); 262 } 263 else if (opt == 'u') { 264 addForUsers(optArg); 265 } 266 else { 267 return false; 268 } 269 return true; 270 } 271 272 275 public String getOptString() { 276 return "ab:cD:ef:lm:n:or:Tt:u:wx:z:"; } 278 279 283 public void resetCVSCommand() { 284 setForAllUsers(false); 285 setForUsers(null); 286 setForWorkingDirectory(false); 287 setLastEventForFile(null); 288 setLastEventOfProject(false); 289 setReportCheckouts(false); 290 setReportCommits(false); 291 setReportEventType(null); 292 setReportEverything(false); 293 setReportLastEventForModule(null); 294 setReportOnModule(null); 295 setReportTags(false); 296 setShowBackToRecordContaining(null); 297 setSinceDate(null); 298 setSinceRevision(null); 299 setSinceTag(null); 300 setTimeZone(null); 301 } 302 303 307 public String getCVSArguments() { 308 StringBuffer toReturn = new StringBuffer (""); if (isForAllUsers()) { 310 toReturn.append("-a "); } 312 if (isForWorkingDirectory()) { 313 toReturn.append("-w "); } 315 if (isLastEventOfProject()) { 316 toReturn.append("-l "); } 318 if (isReportCheckouts()) { 319 toReturn.append("-o "); } 321 if (isReportCommits()) { 322 toReturn.append("-c "); } 324 if (isReportEverything()) { 325 toReturn.append("-e "); } 327 if (isReportTags()) { 328 toReturn.append("-T "); } 330 if (getForUsers() != null) { 331 appendArrayToSwitches(toReturn, getForUsers(), "-u "); } 333 if (getLastEventForFile() != null) { 334 appendArrayToSwitches(toReturn, getLastEventForFile(), "-f "); } 336 if (getReportEventType() != null) { 337 toReturn.append("-x "); toReturn.append(getReportEventType()); 339 toReturn.append(" "); } 341 if (getReportLastEventForModule() != null) { 342 appendArrayToSwitches(toReturn, getReportLastEventForModule(), "-n "); } 344 if (getReportOnModule() != null) { 345 appendArrayToSwitches(toReturn, getReportOnModule(), "-m "); } 347 if (getShowBackToRecordContaining() != null) { 348 toReturn.append("-b "); toReturn.append(getShowBackToRecordContaining()); 350 toReturn.append(" "); } 352 if (getSinceDate() != null) { 353 toReturn.append("-D "); toReturn.append(getSinceDate()); 355 toReturn.append(" "); } 357 if (getSinceRevision() != null) { 358 toReturn.append("-r "); toReturn.append(getSinceRevision()); 360 toReturn.append(" "); } 362 if (getSinceTag() != null) { 363 toReturn.append("-t "); toReturn.append(getSinceTag()); 365 toReturn.append(" "); } 367 if (getTimeZone() != null) { 368 toReturn.append("-z "); toReturn.append(getTimeZone()); 370 toReturn.append(" "); } 372 return toReturn.toString(); 373 } 374 375 private void appendArrayToSwitches(StringBuffer buff, String [] arr, String cvsSwitch) { 376 if (arr == null) { 377 return; 378 } 379 380 for (int i = 0; i < arr.length; i++) { 381 buff.append(cvsSwitch); 382 buff.append(arr[i]); 383 buff.append(" "); } 385 } 386 387 390 public boolean isForAllUsers() { 391 return this.forAllUsers; 392 } 393 394 397 public void setForAllUsers(boolean forAllUsers) { 398 this.forAllUsers = forAllUsers; 399 } 400 401 404 public String getShowBackToRecordContaining() { 405 return this.showBackToRecordContaining; 406 } 407 408 411 public void setShowBackToRecordContaining(String goBackToRecord) { 412 this.showBackToRecordContaining = goBackToRecord; 413 } 414 415 418 public boolean isReportCommits() { 419 return this.reportCommits; 420 } 421 422 425 public void setReportCommits(boolean reportCommits) { 426 this.reportCommits = reportCommits; 427 } 428 429 432 public String getSinceDate() { 433 return this.sinceDate; 434 } 435 436 439 public void setSinceDate(String sinceDate) { 440 this.sinceDate = sinceDate; 441 } 442 443 446 public boolean isReportEverything() { 447 return this.reportEverything; 448 } 449 450 453 public void setReportEverything(boolean reportEverything) { 454 this.reportEverything = reportEverything; 455 } 456 457 460 public boolean isLastEventOfProject() { 461 return this.lastEventOfProject; 462 } 463 464 467 public void setLastEventOfProject(boolean lastEventOfProject) { 468 this.lastEventOfProject = lastEventOfProject; 469 } 470 471 474 public boolean isReportCheckouts() { 475 return this.reportCheckouts; 476 } 477 478 481 public void setReportCheckouts(boolean reportCheckout) { 482 this.reportCheckouts = reportCheckout; 483 } 484 485 488 public String getSinceRevision() { 489 return this.sinceRevision; 490 } 491 492 495 public void setSinceRevision(String sinceRevision) { 496 this.sinceRevision = sinceRevision; 497 } 498 499 502 public boolean isReportTags() { 503 return this.reportTags; 504 } 505 506 509 public void setReportTags(boolean reportTags) { 510 this.reportTags = reportTags; 511 } 512 513 516 public String getSinceTag() { 517 return this.sinceTag; 518 } 519 520 523 public void setSinceTag(String sinceTag) { 524 this.sinceTag = sinceTag; 525 } 526 527 530 public boolean isForWorkingDirectory() { 531 return this.forWorkingDirectory; 532 } 533 534 537 public void setForWorkingDirectory(boolean forWorkingDirectory) { 538 this.forWorkingDirectory = forWorkingDirectory; 539 } 540 541 544 public String getReportEventType() { 545 return this.reportEventType; 546 } 547 548 551 public void setReportEventType(String reportEventType) { 552 this.reportEventType = reportEventType; 553 } 554 555 558 public String getTimeZone() { 559 return this.timeZone; 560 } 561 562 565 public void setTimeZone(String timeZone) { 566 this.timeZone = timeZone; 567 } 568 569 572 public String [] getLastEventForFile() { 573 return this.lastEventForFile; 574 } 575 576 579 public void setLastEventForFile(String [] lastEventForFile) { 580 this.lastEventForFile = lastEventForFile; 581 } 582 583 public void addLastEventForFile(String newFile) { 584 this.lastEventForFile = addNewValue(this.lastEventForFile, newFile); 585 } 586 587 590 public String [] getReportOnModule() { 591 return this.reportOnModule; 592 } 593 594 597 public void setReportOnModule(String [] reportOnModule) { 598 this.reportOnModule = reportOnModule; 599 } 600 601 public void addReportOnModule(String newReportOnModule) { 602 this.reportOnModule = addNewValue(this.reportOnModule, newReportOnModule); 603 } 604 605 608 public String [] getReportLastEventForModule() { 609 return this.reportLastEventForModule; 610 } 611 612 615 public void setReportLastEventForModule(String [] reportLastEventForModule) { 616 this.reportLastEventForModule = reportLastEventForModule; 617 } 618 619 public void addReportLastEventForModule(String newModule) { 620 this.reportLastEventForModule = addNewValue(this.reportLastEventForModule, newModule); 621 } 622 623 626 public String [] getForUsers() { 627 return this.forUsers; 628 } 629 630 633 public void setForUsers(String [] forUsers) { 634 this.forUsers = forUsers; 635 } 636 637 public void addForUsers(String forUser) { 638 this.forUsers = addNewValue(this.forUsers, forUser); 639 } 640 641 private String [] addNewValue(String [] arr, String newVal) { 642 if (arr == null) { 643 arr = new String []{newVal}; 644 return arr; 645 } 646 String [] newValue = new String [arr.length + 1]; 647 for (int i = 0; i < arr.length; i++) { 648 newValue[i] = arr[i]; 649 } 650 newValue[newValue.length] = newVal; 651 return newValue; 652 } 653 } 654 | Popular Tags |