1 19 package org.netbeans.lib.cvsclient.command.log; 20 21 import java.io.*; 22 import java.util.*; 23 import java.text.SimpleDateFormat ; 24 import java.text.ParseException ; 25 26 import org.netbeans.lib.cvsclient.command.*; 27 import org.netbeans.lib.cvsclient.event.*; 28 import org.netbeans.lib.cvsclient.util.*; 29 30 35 public class LogBuilder implements Builder { 36 private static final String LOGGING_DIR = ": Logging "; private static final String RCS_FILE = "RCS file: "; private static final String WORK_FILE = "Working file: "; private static final String REV_HEAD = "head: "; private static final String BRANCH = "branch: "; private static final String LOCKS = "locks: "; private static final String ACCESS_LIST = "access list: "; private static final String SYM_NAME = "symbolic names:"; private static final String KEYWORD_SUBST = "keyword substitution: "; private static final String TOTAL_REV = "total revisions: "; private static final String SEL_REV = ";\tselected revisions: "; private static final String DESCRIPTION = "description:"; private static final String REVISION = "revision "; private static final String DATE = "date: "; private static final String BRANCHES = "branches: "; private static final String AUTHOR = "author: "; private static final String STATE = "state: "; private static final String LINES = "lines: "; private static final String COMMITID = "commitid: "; private static final String SPLITTER = "----------------------------"; private static final String FINAL_SPLIT = "============================================================================="; private static final String ERROR = ": nothing known about "; private static final String NO_FILE = "no file"; 62 protected EventManager eventManager; 63 protected BasicCommand logCommand; 64 67 protected LogInformation logInfo; 68 protected LogInformation.Revision revision; 69 73 protected String fileDirectory; 74 private boolean addingSymNames; 75 private boolean addingDescription; 76 private boolean addingLogMessage; 77 private StringBuffer tempBuffer = null; 78 79 private List messageList; 80 81 private final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss Z"); 83 public LogBuilder(EventManager eventMan, BasicCommand command) { 84 logCommand = command; 85 eventManager = eventMan; 86 addingSymNames = false; 87 addingDescription = false; 88 addingLogMessage = false; 89 logInfo = null; 90 revision = null; 91 messageList = new ArrayList(500); 92 } 93 94 public void outputDone() { 95 if (logInfo != null) { 96 eventManager.fireCVSEvent(new FileInfoEvent(this, logInfo)); 97 logInfo = null; 98 messageList = null; 99 } 100 } 101 102 public void parseLine(String line, boolean isErrorMessage) { 103 if (line.equals(FINAL_SPLIT)) { 104 if (addingDescription) { 105 addingDescription = false; 106 logInfo.setDescription(tempBuffer.toString()); 107 } 108 if (addingLogMessage) { 109 addingLogMessage = false; 110 revision.setMessage(CommandUtils.findUniqueString(tempBuffer.toString(), messageList)); 111 } 112 if (revision != null) { 113 logInfo.addRevision(revision); 114 revision = null; 115 } 116 if (logInfo != null) { 118 eventManager.fireCVSEvent(new FileInfoEvent(this, logInfo)); 119 logInfo = null; 120 tempBuffer = null; 121 } 122 return; 123 } 124 if (addingLogMessage) { 125 if (line.startsWith(BRANCHES)) { 127 processBranches(line.substring(BRANCHES.length())); 128 } 129 else { 130 processLogMessage(line); 131 return; 132 } 133 } 134 if (addingSymNames) { 135 processSymbolicNames(line); 136 } 137 if (addingDescription) { 138 processDescription(line); 139 } 140 if (line.startsWith(REVISION)) { 142 processRevisionStart(line); 143 } 144 if (line.startsWith(DATE)) { 145 processRevisionDate(line); 146 } 147 148 if (line.startsWith(KEYWORD_SUBST)) { 149 logInfo.setKeywordSubstitution(line.substring(KEYWORD_SUBST.length()).trim().intern()); 150 addingSymNames = false; 151 return; 152 } 153 154 if (line.startsWith(DESCRIPTION)) { 155 tempBuffer = new StringBuffer (line.substring(DESCRIPTION.length())); 156 addingDescription = true; 157 } 158 159 if (line.indexOf(LOGGING_DIR) >= 0) { 160 fileDirectory = line.substring(line.indexOf(LOGGING_DIR) + LOGGING_DIR.length()).trim(); 161 return; 162 } 163 if (line.startsWith(RCS_FILE)) { 164 processRcsFile(line.substring(RCS_FILE.length())); 165 return; 166 } 167 if (line.startsWith(WORK_FILE)) { 168 processWorkingFile(line.substring(WORK_FILE.length())); 169 return; 170 } 171 if (line.startsWith(REV_HEAD)) { 172 logInfo.setHeadRevision(line.substring(REV_HEAD.length()).trim().intern()); 173 return; 174 } 175 if (line.startsWith(BRANCH)) { 176 logInfo.setBranch(line.substring(BRANCH.length()).trim().intern()); 177 } 178 if (line.startsWith(LOCKS)) { 179 logInfo.setLocks(line.substring(LOCKS.length()).trim().intern()); 180 } 181 if (line.startsWith(ACCESS_LIST)) { 182 logInfo.setAccessList(line.substring(ACCESS_LIST.length()).trim().intern()); 183 } 184 if (line.startsWith(SYM_NAME)) { 185 addingSymNames = true; 186 } 187 if (line.startsWith(TOTAL_REV)) { 188 int ind = line.indexOf(';'); 189 if (ind < 0) { 190 logInfo.setTotalRevisions(line.substring(TOTAL_REV.length()).trim().intern()); 192 logInfo.setSelectedRevisions("0"); } 194 else { 195 String total = line.substring(0, ind); 196 String select = line.substring(ind, line.length()); 197 logInfo.setTotalRevisions(total.substring(TOTAL_REV.length()).trim().intern()); 198 logInfo.setSelectedRevisions(select.substring(SEL_REV.length()).trim().intern()); 199 } 200 } 201 } 202 203 private String findUniqueString(String name, List list) { 204 if (name == null) { 205 return null; 206 } 207 int index = list.indexOf(name); 208 if (index >= 0) { 209 return (String )list.get(index); 210 } 211 else { 212 String newName = name; 213 list.add(newName); 214 return newName; 215 } 216 } 217 218 private void processRcsFile(String line) { 219 if (logInfo != null) { 220 } 222 logInfo = new LogInformation(); 223 logInfo.setRepositoryFilename(line.trim()); 224 } 225 226 private void processWorkingFile(String line) { 227 String fileName = line.trim(); 228 if (fileName.startsWith(NO_FILE)) { 229 fileName = fileName.substring(8); 230 } 231 232 logInfo.setFile(createFile(line)); 233 } 234 235 private void processBranches(String line) { 236 int ind = line.lastIndexOf(';'); 237 if (ind > 0) { 238 line = line.substring(0, ind); 239 } 240 revision.setBranches(line.trim()); 241 } 242 243 private void processLogMessage(String line) { 244 if (line.startsWith(SPLITTER)) { 245 addingLogMessage = false; 246 revision.setMessage(findUniqueString(tempBuffer.toString(), messageList)); 247 return; 248 } 249 tempBuffer.append(line + "\n"); } 251 252 private void processSymbolicNames(String line) { 253 if (!line.startsWith(KEYWORD_SUBST)) { 254 line = line.trim(); 255 int index = line.indexOf(':'); 256 if (index > 0) { 257 String symName = line.substring(0, index).trim(); 258 String revName = line.substring(index + 1, line.length()).trim(); 259 logInfo.addSymbolicName(symName.intern(), revName.intern()); 260 } 261 } 262 } 263 264 private void processDescription(String line) { 265 if (line.startsWith(SPLITTER)) { 266 addingDescription = false; 267 logInfo.setDescription(tempBuffer.toString()); 268 return; 269 } 270 tempBuffer.append(line); 271 } 272 273 private void processRevisionStart(String line) { 274 if (revision != null) { 275 logInfo.addRevision(revision); 276 } 277 revision = logInfo.createNewRevision( 278 line.substring(REVISION.length()).intern()); 279 } 280 281 private void processRevisionDate(String line) { 282 StringTokenizer tokenizer = new StringTokenizer(line, ";", false); while (tokenizer.hasMoreTokens()) { 284 String token = tokenizer.nextToken().trim(); 285 if (token.startsWith(DATE)) { 286 String dateString = token.substring(DATE.length()); 287 Date date = null; 288 try { 289 dateString = dateString.replace('/', '-') + " +0000"; date = dateFormat.parse(dateString); 293 } catch (ParseException e) { 294 BugLog.getInstance().bug("Couldn't parse date " + dateString); } 296 revision.setDate(date, dateString); 297 } 298 else if (token.startsWith(AUTHOR)) revision.setAuthor(token.substring(AUTHOR.length())); 299 else if (token.startsWith(STATE)) revision.setState(token.substring(STATE.length())); 300 else if (token.startsWith(LINES)) revision.setLines(token.substring(LINES.length())); 301 else if (token.startsWith(COMMITID)) revision.setCommitID(token.substring(COMMITID.length())); 302 } 303 addingLogMessage = true; 304 tempBuffer = new StringBuffer (); 305 } 306 307 310 protected File createFile(String fileName) { 311 StringBuffer path = new StringBuffer (); 312 path.append(logCommand.getLocalDirectory()); 313 path.append(File.separator); 314 315 path.append(fileName.replace('/', File.separatorChar)); return new File(path.toString()); 317 } 318 319 public void parseEnhancedMessage(String key, Object value) { 320 } 321 } 322 | Popular Tags |