1 19 20 21 package org.netbeans.modules.changelog; 22 23 27 import org.netbeans.modules.javacvs.events.CommandDisplayerAdapter; 28 import org.netbeans.modules.javacvs.commands.*; 29 import org.netbeans.modules.cvsclient.*; 30 31 import org.apache.regexp.RE; 32 import org.apache.regexp.RESyntaxException; 33 34 35 import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer; 36 import org.netbeans.lib.cvsclient.command.FileInfoContainer; 37 import org.netbeans.lib.cvsclient.command.log.LogInformation; 38 import java.util.*; 39 import java.io.*; 40 import org.openide.filesystems.*; 41 import org.openide.*; 42 import org.openide.loaders.*; 43 import org.openide.util.*; 44 import javax.swing.*; 45 import java.awt.Dialog ; 46 import java.awt.event.*; 47 48 public class ChangeLogDisplayer extends CommandDisplayerAdapter { 49 50 private static final String INITIAL_REV = "Initial revision"; private static final String WAS_ADDED_ON_BRANCH = "was initially added on branch"; 53 private int commandCount = 0; 54 private int finishedCommandCount = 0; 55 private long revisionsNumber = 0; 56 private boolean errorsOccured = false; 57 58 private HashMap fileObjectMap; 59 60 private RE messageRE = null; 61 62 private ChangeLogProcessor processor; 63 64 65 public ChangeLogDisplayer(ChangeLogProcessor proces) { 66 fileObjectMap = new HashMap(10); 67 processor = proces; 68 } 69 70 71 76 public void addFileObjects(FileObject[] fos) { 77 if (fos != null) { 78 for (int i=0; i < fos.length; i++) { 79 File file = FileSystemCommand.toFile(fos[i]); 80 if (file != null) { 81 fileObjectMap.put(file, fos[i]); 82 } 83 } 84 } 85 } 86 87 public synchronized void setNumberOfCommands(int number) { 88 commandCount = number; 89 } 90 91 public int getNumberOfCommand() { 92 return commandCount; 93 } 94 95 96 public synchronized void showFinishedCommand() { 97 finishedCommandCount = finishedCommandCount + 1; 99 if (finishedCommandCount == commandCount) { 100 showDialog(); 101 } 102 } 103 104 public synchronized void showExecutionFailed(Exception exception) { 105 errorsOccured = true; 106 System.out.println("exc=" + exception); 107 exception.printStackTrace(); 108 finishedCommandCount = finishedCommandCount + 1; 109 if (finishedCommandCount == commandCount) { 110 showDialog(); 111 } 112 } 113 114 public synchronized void showStartCommand() { 115 116 } 117 118 private java.util.List extractBranches(LogInformation info) { 119 LinkedList list = new LinkedList(); 120 if (info.getAllSymbolicNames() != null) { 121 Iterator it = info.getAllSymbolicNames().iterator(); 122 while (it.hasNext()) { 123 LogInformation.SymName name = (LogInformation.SymName)it.next(); 124 if (name.getRevision().indexOf(".0") > 0) { 126 int[] arr = ChangeLogUtils.convertRevisionToIntArray(name.getRevision()); 127 if (arr[arr.length - 2] == 0) { 128 130 name.setRevision(ChangeLogUtils.convertIntArrayToRevision(arr).intern()); 131 list.add(name); 132 } 133 } 134 } 135 } 136 return list; 137 } 138 139 public synchronized void showFileInfoGenerated(FileInfoContainer info) { 140 if (info.getClass().equals(LogInformation.class)) { 141 LogInformation lInfo = (LogInformation)info; 142 LogInfoRevision.LogInfoHeader header = createHeader(lInfo); 143 List branchList = extractBranches(lInfo); 144 boolean include = true; 145 Iterator it =lInfo.getRevisionList().iterator(); 146 while (it.hasNext()) { 147 include = true; 148 LogInformation.Revision rev = (LogInformation.Revision)it.next(); 149 if (rev.getState() != null && 152 rev.getMessage() != null && 153 rev.getNumber() != null && 154 rev.getState().equals("dead") && rev.getNumber().equals("1.1") && rev.getMessage().indexOf(WAS_ADDED_ON_BRANCH) > 0) { 157 continue; 158 } 159 if (rev.getMessage() != null && 162 rev.getNumber() != null && 163 rev.getNumber().equals("1.1") && rev.getMessage().indexOf(INITIAL_REV) >= 0) { 165 continue; 166 } 167 if (processor.messageMatchesFilterPattern(rev.getMessage())) { 168 LogInfoRevision revision = createRevision(rev, header); 169 revision.setBranch(findBranchInSymNamesList(branchList, revision.getNumber())); 170 processor.addRevision(revision, rev.getMessage()); 171 } 172 } 173 } 174 } 175 176 180 private String findBranchInSymNamesList(List list, String revisionNumber) { 181 Iterator it = list.iterator(); 182 if (revisionNumber.indexOf('.') == revisionNumber.lastIndexOf('.')) { 183 return null; 184 } 185 String branch = null; 186 String longestMatch = ""; 187 while (it.hasNext()) { 188 LogInformation.SymName name = (LogInformation.SymName)it.next(); 189 if (revisionNumber.startsWith(name.getRevision())) { 190 if (name.getRevision().length() > longestMatch.length()) { 191 branch = name.getName(); 192 longestMatch = name.getRevision(); 193 } 194 } 195 } 196 return branch; 197 } 198 199 private void showDialog() { 200 processor.finishProcessing(); 201 } 202 203 204 205 206 private LogInfoRevision.LogInfoHeader createHeader(LogInformation info) { 207 LogInfoRevision.LogInfoHeader header = new LogInfoRevision.LogInfoHeader(); 208 header.setAccessList(info.getAccessList()); 209 header.setBranch(info.getBranch()); 210 header.setDescription(info.getDescription()); 211 header.setFile(info.getFile()); 212 header.setHeadRevision(info.getHeadRevision()); 213 header.setKeywordSubstitution(info.getKeywordSubstitution()); 214 header.setLocks(info.getLocks()); 215 header.setRepositoryFilename(info.getRepositoryFilename()); 216 header.setSelectedRevisions(info.getSelectedRevisions()); 217 header.setTotalRevisions(info.getTotalRevisions()); 218 return header; 219 } 220 221 private LogInfoRevision createRevision(LogInformation.Revision jcvsRev, 222 LogInfoRevision.LogInfoHeader header) { 223 LogInfoRevision rev = new LogInfoRevision(header.getFile()); 224 rev.setAuthor(jcvsRev.getAuthor()); 225 rev.setDate(jcvsRev.getDate()); 227 rev.setLines(jcvsRev.getLines()); 228 rev.setLogInfoHeader(header); 229 rev.setNumber(jcvsRev.getNumber()); 230 rev.setState(jcvsRev.getState()); 231 return rev; 232 } 233 234 } 235 | Popular Tags |