1 11 package org.eclipse.team.internal.ccvs.core.client.listeners; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.CVSException; 21 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 22 import org.eclipse.team.internal.ccvs.core.CVSStatus; 23 import org.eclipse.team.internal.ccvs.core.ICVSFile; 24 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 25 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 26 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; 27 import org.eclipse.team.internal.ccvs.core.client.Update; 28 import org.eclipse.team.internal.ccvs.core.util.Util; 29 30 public class UpdateListener extends CommandOutputListener { 31 32 private static ServerMessageLineMatcher MERGED_BINARY_FILE_LINE_1; 34 private static ServerMessageLineMatcher MERGED_BINARY_FILE_LINE_2; 35 36 private static final String REVISION_VARIABLE_NAME = "revision"; private static final String LOCAL_FILE_PATH_VARIABLE_NAME = "localFilePath"; private static final String BACKUP_FILE_VARIABLE_NAME = "backupFile"; 41 static { 42 try { 43 String line1 = "revision " + Util.getVariablePattern(IMessagePatterns.REVISION_PATTERN, REVISION_VARIABLE_NAME) 45 + " from repository is now in " + Util.getVariablePattern(IMessagePatterns.FILE_PATH_PATTERN, LOCAL_FILE_PATH_VARIABLE_NAME); 47 MERGED_BINARY_FILE_LINE_1 = new ServerMessageLineMatcher( 48 line1, 49 new String [] {REVISION_VARIABLE_NAME, LOCAL_FILE_PATH_VARIABLE_NAME}); 50 String line2 = "file from working directory is now in " + Util.getVariablePattern(IMessagePatterns.REVISION_PATTERN, BACKUP_FILE_VARIABLE_NAME); 52 MERGED_BINARY_FILE_LINE_2 = new ServerMessageLineMatcher( 53 line2, 54 new String [] {BACKUP_FILE_VARIABLE_NAME}); 55 56 } catch (CVSException e) { 57 CVSProviderPlugin.log(e); 59 } 60 } 61 62 IUpdateMessageListener updateMessageListener; 63 boolean merging = false; 64 boolean mergingBinary = false; 65 String mergedBinaryFileRevision, mergedBinaryFilePath; 66 67 public UpdateListener(IUpdateMessageListener updateMessageListener) { 68 this.updateMessageListener = updateMessageListener; 69 } 70 71 public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, 72 IProgressMonitor monitor) { 73 mergingBinary = false; 74 if (updateMessageListener == null) return OK; 75 if(line.startsWith("Merging differences")) { merging = true; 77 } else if(line.indexOf(' ')==1) { 78 String path = line.substring(2); 81 char changeType = line.charAt(0); 82 83 int type = 0; 85 switch(changeType) { 86 case 'A': type = Update.STATE_ADDED_LOCAL; break; case '?': type = Update.STATE_UNKOWN; break; case 'U': type = Update.STATE_REMOTE_CHANGES; break; case 'R': type = Update.STATE_DELETED; break; case 'M': type = Update.STATE_MODIFIED; break; case 'C': type = Update.STATE_CONFLICT; break; case 'D': type = Update.STATE_DELETED; break; default: type = Update.STATE_NONE; 94 } 95 96 if (merging) { 97 if (type == Update.STATE_MODIFIED) 101 type = Update.STATE_MERGEABLE_CONFLICT; 102 merging = false; 103 } 104 updateMessageListener.fileInformation(type, commandRoot, path); 105 } 106 return OK; 107 } 108 109 145 public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, 146 IProgressMonitor monitor) { 147 148 try { 149 boolean wasMergingBinary = mergingBinary; 151 mergingBinary = false; 152 String serverMessage = getServerMessage(line, location); 153 if (serverMessage != null) { 154 String message = serverMessage; 156 if (message.startsWith("Updating")) { if (updateMessageListener != null) { 158 String path = message.substring(9); 159 updateMessageListener.directoryInformation(commandRoot, path, false); 160 } 161 return OK; 162 } else if (message.startsWith("skipping directory")) { if (updateMessageListener != null) { 164 String path = message.substring(18).trim(); 165 updateMessageListener.directoryDoesNotExist(commandRoot, path); 166 } 167 return OK; 168 } else if (message.startsWith("New directory")) { if (updateMessageListener != null) { 170 String path = message.substring(15, message.lastIndexOf('\'')); 171 updateMessageListener.directoryInformation(commandRoot, path, true); 172 } 173 return OK; 174 } else if (message.endsWith("is no longer in the repository")) { if (updateMessageListener != null) { 176 String filename = message.substring(0, message.length() - 31); 177 filename = stripQuotes(filename); 178 updateMessageListener.fileDoesNotExist(commandRoot, filename); 179 } 180 return OK; 181 } else if (message.startsWith("conflict:")) { 190 if (updateMessageListener != null) { 191 if (message.endsWith("is modified but no longer in the repository")) { String filename = message.substring(10, message.length() - 44); 194 filename = stripQuotes(filename); 195 updateMessageListener.fileDoesNotExist(commandRoot, filename); 196 } 197 } 198 return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); 199 } else if (message.startsWith("warning:")) { 205 if (updateMessageListener != null) { 206 if (message.endsWith("is not (any longer) pertinent")) { String filename = message.substring(9, message.length() - 30); 208 updateMessageListener.fileDoesNotExist(commandRoot, filename); 209 } 210 } 211 return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); 212 } else if (message.startsWith("conflicts")) { return new CVSStatus(IStatus.INFO, CVSStatus.CONFLICT, line, commandRoot); 215 } else if (message.startsWith("nonmergeable file needs merge")) { mergingBinary = true; 217 mergedBinaryFileRevision = null; 218 mergedBinaryFilePath = null; 219 return OK; 220 } else if (wasMergingBinary) { 221 Map variables = MERGED_BINARY_FILE_LINE_1.processServerMessage(message); 222 if (variables != null) { 223 mergedBinaryFileRevision = (String )variables.get(REVISION_VARIABLE_NAME); 224 mergedBinaryFilePath = (String )variables.get(LOCAL_FILE_PATH_VARIABLE_NAME); 225 mergingBinary = true; 226 return OK; 227 } 228 variables = MERGED_BINARY_FILE_LINE_2.processServerMessage(message); 229 if (variables != null) { 230 String backupFile = (String )variables.get(BACKUP_FILE_VARIABLE_NAME); 231 try { 232 if (mergedBinaryFileRevision != null && mergedBinaryFilePath != null) { 233 ICVSFile file = commandRoot.getFile(mergedBinaryFilePath); 234 IResource resource = file.getIResource(); 235 if (resource != null) { 236 return new CVSStatus(IStatus.ERROR, CVSStatus.UNMEGERED_BINARY_CONFLICT, 237 NLS.bind(CVSMessages.UpdateListener_0, (new Object [] { 238 resource.getFullPath().toString(), 239 mergedBinaryFileRevision, 240 resource.getFullPath().removeLastSegments(1).append(backupFile).toString()})), commandRoot); 241 } 242 } 243 } catch (CVSException e1) { 244 CVSProviderPlugin.log(e1); 245 } 246 return OK; 247 } 248 } 249 250 if (!message.startsWith("cannot open directory") && !message.startsWith("nothing known about")) { return super.errorLine(line, location, commandRoot, monitor); 254 } 255 } else { 256 String serverAbortedMessage = getServerAbortedMessage(line, location); 257 if (serverAbortedMessage != null) { 258 String message = serverAbortedMessage; 260 if (message.startsWith("no such tag")) { return new CVSStatus(IStatus.WARNING, CVSStatus.NO_SUCH_TAG, line, commandRoot); 264 } else if (message.startsWith("Numeric join") && message.endsWith("may not contain a date specifier")) { return super.errorLine(line, location, commandRoot, monitor); 267 } else { 268 return super.errorLine(line, location, commandRoot, monitor); 269 } 270 } else if (line.equals("rcsmerge: warning: conflicts during merge")) { return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot); 273 } 274 } 275 } catch (StringIndexOutOfBoundsException e) { 276 if (CVSProviderPlugin.getPlugin().isDebugging()) { 279 System.out.println("Error parsing E line: " + line); } 281 return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE_PARSE_FAILURE, line, commandRoot); 282 } 283 return super.errorLine(line, location, commandRoot, monitor); 284 } 285 286 private String stripQuotes(String filename) { 287 if (filename.startsWith("`") && filename.endsWith("'")) filename = filename.substring(1,filename.length()-1); 291 return filename; 292 } 293 294 } 295 | Popular Tags |