1 18 19 20 package org.netbeans.modules.changelog; 21 22 26 27 import org.apache.regexp.RE; 28 import org.apache.regexp.RESyntaxException; 29 30 31 import java.util.*; 32 import java.io.*; 33 import java.lang.reflect.*; 34 import org.openide.filesystems.*; 35 import org.openide.*; 36 import org.openide.loaders.*; 37 import org.openide.util.*; 38 import org.netbeans.modules.changelog.html.*; 39 import org.netbeans.modules.changelog.settings.*; 40 41 public class ChangeLogProcessor { 42 43 public static final int MESSAGE_FILTER_SUBSTRING = 0; 44 public static final int MESSAGE_FILTER_REGEXP = 1; 45 public static final int MESSAGE_FILTER_ALL_WORDS = 2; 46 public static final int MESSAGE_FILTER_SOME_WORDS = 3; 47 public static final int FILE_FILTER_SUBSTRING = 0; 48 public static final int FILE_FILTER_REGEXP = 1; 49 private static final String INITIAL_REV = "Initial revision"; private static final String WAS_ADDED_ON_BRANCH = "was initially added on branch"; 52 public static final int SORT_BY_USER = 0; 53 public static final int SORT_BY_DATE = 1; 54 55 private long revisionsNumber = 0; 56 57 private HashMap fileObjectMap; 58 59 private LinkedList rawResults; 60 61 private List groupedResults; 62 63 private List printerList; 64 65 private String messageFilter; 67 private int messageFilterType; 68 private int minutesGap; 69 70 private RE messageRE = null; 71 72 private String fileFilter; 74 private int fileFilterType; 75 76 private RE fileRE = null; 77 78 79 private String dateRange; 80 81 82 private String user; 83 84 private int sortMode; 85 86 87 private String revisionRange; 88 89 90 private boolean toOutputWindow; 91 92 93 private java.io.File toTextFile; 94 95 96 private java.io.File toXmlFile; 97 98 99 private java.io.File toHtmlFile; 100 101 102 private boolean toExplorer; 103 104 105 private boolean descendingSort; 106 107 private boolean viewInBrowser; 108 109 110 private ChangeLogHTMLService htmlSiteProcessor; 111 112 113 private boolean includeQueryDescription; 114 115 116 private boolean includeSummary; 117 118 119 private boolean includeBranchNames; 120 121 122 public ChangeLogProcessor() { 123 fileObjectMap = new HashMap(10); 124 rawResults = new LinkedList(); 125 groupedResults = new LinkedList(); 126 setMaxDateGap(10); 127 setSortMode(SORT_BY_DATE); 128 printerList = new LinkedList(); 129 setViewInBrowser(true); 130 setIncludeSummary(true); 131 setIncludeQueryDescription(true); 132 133 ChangeLogSettings settings = (ChangeLogSettings)SharedClassObject.findObject(ChangeLogSettings.class, true); 134 setIncludeBranchNames(settings.isShowBranchesByDefault()); 135 String id = settings.getDefaultServerInfo(); 136 if (!id.equals("")) { 137 Lookup.Template template = new Lookup.Template(ChangeLogHTMLService.class, id, null); 138 Lookup.Item item = Lookup.getDefault().lookupItem(template); 139 setHtmlSiteProcessor((ChangeLogHTMLService)item.getInstance()); 140 } 141 } 142 143 public void setViewInBrowser(boolean view) { 144 viewInBrowser = view; 145 } 146 public boolean isViewInBrowser() { 147 return viewInBrowser; 148 } 149 150 public void setMessageFilter(int type, String filter) { 151 messageFilter = filter; 152 messageFilterType = type; 153 if (messageFilterType == MESSAGE_FILTER_REGEXP) { 154 try { 155 messageRE = new RE(messageFilter); 156 } catch (RESyntaxException exc) { 157 messageRE = null; 158 } 159 } 160 if (messageFilterType == MESSAGE_FILTER_SOME_WORDS || 161 messageFilterType == MESSAGE_FILTER_ALL_WORDS) 162 { 163 try { 164 String regExp = ""; 165 StringTokenizer tok = new StringTokenizer(messageFilter, " "); 166 while (tok.hasMoreTokens()) { 167 regExp = regExp + tok.nextToken(); 168 if (tok.hasMoreTokens()) { 169 if (messageFilterType == MESSAGE_FILTER_ALL_WORDS) { 170 regExp = regExp + '&'; 171 } else { 172 regExp = regExp + '|'; 173 } 174 } 175 } 176 messageRE = new RE(regExp); 177 } catch (RESyntaxException exc) { 178 messageRE = null; 179 } 180 } 181 } 182 183 public String getMessageFilter() { 184 return messageFilter; 185 } 186 187 public int getMessageFilterType() { 188 return messageFilterType; 189 } 190 191 public void setFileFilter(int type, String filter) { 192 fileFilter = filter; 193 fileFilterType = type; 194 if (fileFilterType == FILE_FILTER_REGEXP) { 195 try { 196 fileRE = new RE(fileFilter); 197 } catch (RESyntaxException exc) { 198 fileRE = null; 199 } 200 } 201 } 202 203 public String getFileFilter() { 204 return fileFilter; 205 } 206 207 public int getFileFilterType() { 208 return fileFilterType; 209 } 210 211 212 public void setMaxDateGap(int numberOfMinutes) { 213 minutesGap = numberOfMinutes; 214 } 215 216 public int getMaxDateGap() { 217 return minutesGap; 218 } 219 220 private long getMaxDateGapInTime() { 221 return (long)((minutesGap * 60) * 1000); 222 } 223 224 229 240 241 public boolean messageMatchesFilterPattern(String message) { 242 if (messageFilter == null || message == null) { 243 return true; 244 } 245 if (messageFilterType == MESSAGE_FILTER_SUBSTRING) { 246 if (message.indexOf(messageFilter) >= 0) { 247 return true; 248 } 249 } 250 else if (messageFilterType == MESSAGE_FILTER_REGEXP || 251 messageFilterType == MESSAGE_FILTER_SOME_WORDS || 252 messageFilterType == MESSAGE_FILTER_ALL_WORDS) { 253 if (messageRE != null) { 254 if (messageRE.match(message)) { 255 return true; 256 } 257 } else { 258 return true; 259 } 260 } 261 return false; 262 } 263 264 public boolean fileMatchesFilterPattern(String file) { 265 if (fileFilter == null || file == null) { 266 return true; 267 } 268 if (fileFilterType == FILE_FILTER_SUBSTRING) { 269 if (file.indexOf(fileFilter) >= 0) { 270 return true; 271 } 272 } 273 else if (fileFilterType == FILE_FILTER_REGEXP) { 274 if (fileRE != null) { 275 if (fileRE.match(file)) { 276 return true; 277 } 278 } else { 279 return true; 280 } 281 } 282 return false; 283 } 284 285 public void addRevision(LogInfoRevision rev, String message) { 286 Iterator it = groupedResults.iterator(); 287 boolean found = false; 288 while (it.hasNext()) { 289 RevisionsGroup group = (RevisionsGroup)it.next(); 290 if (message != null && 293 group.getMessage() != null && 294 message.equals(group.getMessage())) 295 { 296 297 long gap1 = Math.abs(rev.getDate().getTime() - group.getStartingDate().getTime()); 298 long gap2 = Math.abs(rev.getDate().getTime() - group.getTrailingDate().getTime()); 299 if (gap2 < getMaxDateGapInTime() || gap1 < getMaxDateGapInTime()) { 300 group.addRevision(rev, message); 301 found = true; 302 break; 303 } 304 } 305 } 306 if (!found) { 307 RevisionsGroup newGroup = new RevisionsGroup(); 308 newGroup.addRevision(rev, message); 309 groupedResults.add(newGroup); 310 } 311 } 312 313 314 private List findFOsForFiles(List fileList) { 315 328 return null; 329 } 330 331 332 335 public List getGroupsList() { 336 return groupedResults; 337 } 338 339 342 public String getDateRange() { 343 return this.dateRange; 344 } 345 346 349 public void setDateRange(String dateRange) { 350 this.dateRange = dateRange; 351 } 352 353 356 public String getUser() { 357 return this.user; 358 } 359 360 363 public void setUser(String user) { 364 this.user = user; 365 } 366 367 370 public String getRevisionRange() { 371 return this.revisionRange; 372 } 373 374 377 public void setRevisionRange(String revisionRange) { 378 this.revisionRange = revisionRange; 379 } 380 381 384 public boolean isToOutputWindow() { 385 return this.toOutputWindow; 386 } 387 388 391 public void setToOutputWindow(boolean toOutputWindow) { 392 this.toOutputWindow = toOutputWindow; 393 } 394 395 399 public java.io.File getToTextFile() { 400 return this.toTextFile; 401 } 402 403 406 public void setToTextFile(java.io.File toTextFile) { 407 this.toTextFile = toTextFile; 408 } 409 410 414 public java.io.File getToXmlFile() { 415 return this.toXmlFile; 416 } 417 418 421 public void setToXmlFile(java.io.File toXmlFile) { 422 this.toXmlFile = toXmlFile; 423 } 424 425 429 public java.io.File getToHtmlFile() { 430 return this.toHtmlFile; 431 } 432 433 436 public void setToHtmlFile(java.io.File toHtmlFile) { 437 this.toHtmlFile = toHtmlFile; 438 } 439 440 443 public boolean isToExplorer() { 444 return this.toExplorer; 445 } 446 447 450 public void setToExplorer(boolean toExplorer) { 451 this.toExplorer = toExplorer; 452 } 453 454 public void setSortMode(int mode) { 455 this.sortMode = mode; 456 } 457 458 public int getSortMode() { 459 return sortMode; 460 } 461 462 463 public void finishProcessing() { 464 if (getFileFilter() != null) { 465 postprocess(); 468 } 469 sort(); 470 if (isToOutputWindow()) { 471 printerList.add(new LogPrinter_Output()); 472 } 473 if (getToTextFile() != null) { 474 printerList.add(new LogPrinter_Text(getToTextFile())); 475 } 476 if (getToXmlFile() != null) { 477 printerList.add(new LogPrinter_XML(getToXmlFile())); 478 } 479 if (getToHtmlFile() != null || isViewInBrowser()) { 480 printerList.add(new LogPrinter_HTML(getToHtmlFile(), isViewInBrowser(), getHtmlSiteProcessor())); 481 } 482 printResults(); 483 } 484 485 private void postprocess() { 486 List groupedResults = getGroupsList(); 487 Iterator it = groupedResults.iterator(); 488 while (it.hasNext()) { 489 RevisionsGroup group = (RevisionsGroup)it.next(); 490 List list = group.getList(); 491 boolean ok = false; 492 Iterator it2 = list.iterator(); 493 while (it2.hasNext()) { 494 LogInfoRevision rev = (LogInfoRevision)it2.next(); 495 if (fileMatchesFilterPattern(rev.getLogInfoHeader().getRepositoryFilename())) { 496 ok = true; 497 break; 498 } 499 } 500 if (!ok) { 501 it.remove(); 502 } 503 } 504 505 } 506 507 private void sort() { 508 Comparator comp; 509 if (getSortMode() == SORT_BY_DATE) { 510 comp = new RevisionsGroup.GroupDateComparator(isDescendingSort()); 511 } else if (getSortMode() == SORT_BY_USER) { 512 comp = new RevisionsGroup.UserDateComparator(isDescendingSort()); 513 } else { 514 comp = new RevisionsGroup.GroupDateComparator(false); 515 } 516 Collections.sort(getGroupsList(), comp); 517 } 518 519 private void processPrinters(String methodName, Class [] paramTypes, Object [] params) { 520 Iterator it = printerList.iterator(); 521 while (it.hasNext()) { 522 Object printer = it.next(); 523 try { 524 Method method = printer.getClass().getMethod(methodName, paramTypes); 525 method.invoke(printer, params); 526 } catch (InvocationTargetException exc1) { 527 org.openide.ErrorManager.getDefault().annotate(exc1.getTargetException(), ""); 528 } catch (Exception exc) { 529 org.openide.ErrorManager.getDefault().annotate(exc, ""); 530 } 531 } 532 } 533 534 private void printResults() { 535 List groupedResults = getGroupsList(); 536 SummaryProcessor sumProc = new SummaryProcessor(); 537 processPrinters("printHeader", new Class [] {ChangeLogProcessor.class}, new Object [] {this}); 538 Iterator it = groupedResults.iterator(); 539 while (it.hasNext()) { 540 RevisionsGroup group = (RevisionsGroup)it.next(); 541 processPrinters("printGroupHeader", new Class [] {RevisionsGroup.class}, new Object [] {group}); 542 sumProc.processGroup(group); 543 List list = group.getSortedList(RevisionsGroup.SORTING_BY_FILE_NAME); 544 Iterator it2 = list.iterator(); 545 while (it2.hasNext()) { 546 LogInfoRevision rev = (LogInfoRevision)it2.next(); 547 processPrinters("printSingleRevision", new Class [] {LogInfoRevision.class}, new Object [] {rev}); 548 } 549 processPrinters("printGroupFooter", new Class [] {RevisionsGroup.class}, new Object [] {group}); 550 } 551 processPrinters("printSummary", new Class [] {SummaryProcessor.class}, new Object [] {sumProc}); 552 processPrinters("printFooter", new Class [] {ChangeLogProcessor.class}, new Object [] {this}); 553 } 554 555 556 557 560 public boolean isDescendingSort() { 561 return this.descendingSort; 562 } 563 564 567 public void setDescendingSort(boolean descendingSort) { 568 this.descendingSort = descendingSort; 569 } 570 571 574 public ChangeLogHTMLService getHtmlSiteProcessor() { 575 return this.htmlSiteProcessor; 576 } 577 578 581 public void setHtmlSiteProcessor(ChangeLogHTMLService htmlSiteProcessor) { 582 this.htmlSiteProcessor = htmlSiteProcessor; 583 } 584 585 588 public boolean isIncludeQueryDescription() { 589 return this.includeQueryDescription; 590 } 591 592 595 public void setIncludeQueryDescription(boolean includeQueryDescription) { 596 this.includeQueryDescription = includeQueryDescription; 597 } 598 599 602 public boolean isIncludeSummary() { 603 return this.includeSummary; 604 } 605 606 609 public void setIncludeSummary(boolean includeSummary) { 610 this.includeSummary = includeSummary; 611 } 612 613 616 public boolean isIncludeBranchNames() { 617 return this.includeBranchNames; 618 } 619 620 623 public void setIncludeBranchNames(boolean includeBranchNames) { 624 this.includeBranchNames = includeBranchNames; 625 } 626 627 } 628 | Popular Tags |