1 19 20 package org.netbeans.lib.cvsclient.command.diff; 21 22 import java.io.*; 23 24 import org.netbeans.lib.cvsclient.*; 25 import org.netbeans.lib.cvsclient.command.*; 26 import org.netbeans.lib.cvsclient.connection.*; 27 import org.netbeans.lib.cvsclient.event.*; 28 import org.netbeans.lib.cvsclient.request.*; 29 30 34 public class DiffCommand extends BasicCommand { 35 38 protected EventManager eventManager; 39 40 43 private String beforeDate1; 44 45 48 private String revision1; 49 50 53 private String revision2; 54 55 58 private String beforeDate2; 59 60 63 private String keywordSubst; 64 65 66 private boolean ignoreAllWhitespace; 67 68 69 private boolean ignoreBlankLines; 70 71 72 private boolean ignoreCase; 73 74 75 private boolean ignoreSpaceChange; 76 77 78 private boolean contextDiff; 79 80 81 private boolean unifiedDiff; 82 83 86 public DiffCommand() { 87 } 88 89 93 public Builder createBuilder(EventManager eventMan) { 94 if (isContextDiff() || isUnifiedDiff()) { 95 return null; 96 } 97 return new SimpleDiffBuilder(eventMan, this); 98 } 99 100 106 public void execute(ClientServices client, EventManager em) 107 throws CommandException, AuthenticationException { 108 client.ensureConnection(); 109 110 eventManager = em; 111 112 super.execute(client, em); 113 114 try { 115 addRDSwitches(); 117 if (getKeywordSubst() != null && !getKeywordSubst().equals("")) { requests.add(new ArgumentRequest("-k" + getKeywordSubst())); } 120 121 addArgumentRequest(isIgnoreAllWhitespace(), "-w"); addArgumentRequest(isIgnoreBlankLines(), "-B"); addArgumentRequest(isIgnoreSpaceChange(), "-b"); addArgumentRequest(isIgnoreCase(), "-i"); addArgumentRequest(isContextDiff(), "-c"); addArgumentRequest(isUnifiedDiff(), "-u"); 128 addRequestForWorkingDirectory(client); 129 addArgumentRequests(); 130 addRequest(CommandRequest.DIFF); 131 client.processRequests(requests); 132 } 133 catch (CommandException ex) { 134 throw ex; 135 } 136 catch (Exception ex) { 137 throw new CommandException(ex, ex.getLocalizedMessage()); 138 } 139 finally { 140 requests.clear(); 141 } 142 } 143 144 147 private void addRDSwitches() { 148 if (getRevision2() != null) { 149 requests.add(1, new ArgumentRequest("-r")); requests.add(2, new ArgumentRequest(getRevision2())); 151 } 152 else { 153 if (getBeforeDate2() != null) { 154 requests.add(1, new ArgumentRequest("-D " + getBeforeDate2())); } 156 } 157 if (getRevision1() != null) { 159 requests.add(1, new ArgumentRequest("-r")); requests.add(2, new ArgumentRequest(getRevision1())); 161 } 162 else { 163 if (getBeforeDate1() != null) { 164 requests.add(1, new ArgumentRequest("-D " + getBeforeDate1())); } 166 else { 167 return; 170 } 171 } 172 } 173 174 176 public void commandTerminated(TerminationEvent e) { 177 if (builder != null) { 178 builder.outputDone(); 179 } 180 } 181 182 185 public String getBeforeDate1() { 186 return beforeDate1; 187 } 188 189 192 public void setBeforeDate1(String beforeDate) { 193 this.beforeDate1 = beforeDate; 194 } 195 196 199 public String getRevision1() { 200 return revision1; 201 } 202 203 206 public void setRevision1(String firstRevision) { 207 revision1 = firstRevision; 208 } 209 210 213 public String getRevision2() { 214 return revision2; 215 } 216 217 220 public void setRevision2(String secondRevision) { 221 this.revision2 = secondRevision; 222 } 223 224 227 public String getBeforeDate2() { 228 return beforeDate2; 229 } 230 231 234 public void setBeforeDate2(String beforeDate2) { 235 this.beforeDate2 = beforeDate2; 236 } 237 238 242 public String getKeywordSubst() { 243 return keywordSubst; 244 } 245 246 250 public void setKeywordSubst(String keywordSubst) { 251 this.keywordSubst = keywordSubst; 252 } 253 254 259 public String getCVSCommand() { 260 StringBuffer toReturn = new StringBuffer ("diff "); toReturn.append(getCVSArguments()); 262 File[] files = getFiles(); 263 if (files != null) { 264 for (int index = 0; index < files.length; index++) { 265 toReturn.append(files[index].getName() + " "); } 267 } 268 return toReturn.toString(); 269 } 270 271 275 public boolean setCVSCommand(char opt, String optArg) { 276 if (opt == 'R') { 277 setRecursive(true); 278 } 279 else if (opt == 'l') { 280 setRecursive(false); 281 } 282 else if (opt == 'r') { 283 if (getRevision1() == null) { 284 setRevision1(optArg); 285 } 286 else { 287 setRevision2(optArg); 288 } 289 } 290 else if (opt == 'D') { 291 if (getBeforeDate1() == null) { 292 setBeforeDate1(optArg); 293 } 294 else { 295 setBeforeDate2(optArg); 296 } 297 } 298 else if (opt == 'k') { 299 setKeywordSubst(optArg); 300 } 301 else if (opt == 'w') { 302 setIgnoreAllWhitespace(true); 303 } 304 else if (opt == 'b') { 305 setIgnoreSpaceChange(true); 306 } 307 else if (opt == 'B') { 308 setIgnoreBlankLines(true); 309 } 310 else if (opt == 'i') { 311 setIgnoreCase(true); 312 } 313 else if (opt == 'c') { 314 setContextDiff(true); 315 } 316 else if (opt == 'u') { 317 setUnifiedDiff(true); 318 } 319 else { 320 return false; 321 } 322 return true; 323 } 324 325 328 public String getOptString() { 329 return "Rlr:D:k:wBbicu"; } 331 332 336 public void resetCVSCommand() { 337 setRecursive(true); 338 setRevision1(null); 339 setRevision2(null); 340 setBeforeDate1(null); 341 setBeforeDate2(null); 342 setKeywordSubst(null); 343 setIgnoreAllWhitespace(false); 344 setIgnoreBlankLines(false); 345 setIgnoreCase(false); 346 setIgnoreSpaceChange(false); 347 setContextDiff(false); 348 setUnifiedDiff(false); 349 } 350 351 355 public String getCVSArguments() { 356 StringBuffer toReturn = new StringBuffer (""); if (getKeywordSubst() != null && getKeywordSubst().length() > 0) { 358 toReturn.append("-k" + getKeywordSubst() + " "); } 360 if (!isRecursive()) { 361 toReturn.append("-l "); } 363 if (getRevision1() != null) { 364 toReturn.append("-r " + getRevision1() + " "); } 366 if (getBeforeDate1() != null) { 367 toReturn.append("-D " + getBeforeDate1() + " "); } 369 if (getRevision2() != null) { 370 toReturn.append("-r " + getRevision2() + " "); } 372 if (getBeforeDate2() != null) { 373 toReturn.append("-D " + getBeforeDate2() + " "); } 375 if (isIgnoreAllWhitespace()) { 376 toReturn.append("-w "); } 378 if (isIgnoreBlankLines()) { 379 toReturn.append("-B "); } 381 if (isIgnoreCase()) { 382 toReturn.append("-i "); } 384 if (isIgnoreSpaceChange()) { 385 toReturn.append("-b "); } 387 if (isContextDiff()) { 388 toReturn.append("-c "); } 390 if (isUnifiedDiff()) { 391 toReturn.append("-u "); } 393 return toReturn.toString(); 394 } 395 396 399 public boolean isIgnoreAllWhitespace() { 400 return this.ignoreAllWhitespace; 401 } 402 403 407 public void setIgnoreAllWhitespace(boolean ignoreAllWhitespace) { 408 this.ignoreAllWhitespace = ignoreAllWhitespace; 409 } 410 411 414 public boolean isIgnoreBlankLines() { 415 return this.ignoreBlankLines; 416 } 417 418 421 public void setIgnoreBlankLines(boolean ignoreBlankLines) { 422 this.ignoreBlankLines = ignoreBlankLines; 423 } 424 425 428 public boolean isIgnoreCase() { 429 return this.ignoreCase; 430 } 431 432 435 public void setIgnoreCase(boolean ignoreCase) { 436 this.ignoreCase = ignoreCase; 437 } 438 439 442 public boolean isIgnoreSpaceChange() { 443 return this.ignoreSpaceChange; 444 } 445 446 449 public void setIgnoreSpaceChange(boolean ignoreSpaceChange) { 450 this.ignoreSpaceChange = ignoreSpaceChange; 451 } 452 453 458 public boolean isContextDiff() { 459 return this.contextDiff; 460 } 461 462 467 public void setContextDiff(boolean contextDiff) { 468 this.contextDiff = contextDiff; 469 } 470 471 476 public boolean isUnifiedDiff() { 477 return this.unifiedDiff; 478 } 479 480 485 public void setUnifiedDiff(boolean unifiedDiff) { 486 this.unifiedDiff = unifiedDiff; 487 } 488 489 } 490 | Popular Tags |