1 11 package org.eclipse.team.internal.ccvs.core.client.listeners; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.team.internal.ccvs.core.CVSException; 18 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 19 import org.eclipse.team.internal.ccvs.core.CVSStatus; 20 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 21 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 22 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; 23 import org.eclipse.team.internal.ccvs.core.Policy; 24 25 29 public class CompareDiffListener extends CommandOutputListener { 30 31 private static ServerMessageLineMatcher LOCAL_FILE_MATCHER; 32 private static ServerMessageLineMatcher REMOTE_FILE_MATCHER; 33 private static ServerMessageLineMatcher REVISION_LINE_MATCHER; 34 35 static { 36 try { 37 LOCAL_FILE_MATCHER = new ServerMessageLineMatcher( 38 "Index: (localFile:.*:localFile)", new String [] {"localFile"}); REMOTE_FILE_MATCHER = new ServerMessageLineMatcher( 40 "RCS file: (remoteFile:.*:remoteFile),v", new String [] {"remoteFile"}); REVISION_LINE_MATCHER = new ServerMessageLineMatcher( 42 "diff .* -r(leftRevision:.*:leftRevision) -r(rightRevision:.*:rightRevision)", new String [] {"leftRevision", "rightRevision"}); } catch (CVSException e) { 44 CVSProviderPlugin.log(e); 46 LOCAL_FILE_MATCHER = null; 47 REMOTE_FILE_MATCHER = null; 48 REVISION_LINE_MATCHER = null; 49 } 50 } 51 52 private String localFilePath, remoteFilePath, leftRevision, rightRevision; 53 54 private IFileDiffListener listener; 55 56 public interface IFileDiffListener { 57 public void fileDiff( 58 String localFilePath, 59 String remoteFilePath, 60 String leftRevision, 61 String rightRevision); 62 } 63 64 public CompareDiffListener(IFileDiffListener listener) { 65 this.listener = listener; 66 } 67 68 public IStatus messageLine( 69 String line, 70 ICVSRepositoryLocation location, 71 ICVSFolder commandRoot, 72 IProgressMonitor monitor) { 73 if (getServerMessage(line, location) != null) { 75 return OK; 76 } 77 Map map = LOCAL_FILE_MATCHER.processServerMessage(line); 78 if (map != null) { 79 localFilePath = (String )map.get("localFile"); return OK; 81 } 82 map = REMOTE_FILE_MATCHER.processServerMessage(line); 83 if (map != null) { 84 remoteFilePath = (String )map.get("remoteFile"); return OK; 86 } 87 map = REVISION_LINE_MATCHER.processServerMessage(line); 88 if (map != null) { 89 leftRevision = (String )map.get("leftRevision"); rightRevision = (String )map.get("rightRevision"); if (localFilePath == null || remoteFilePath == null) { 92 return new CVSStatus(IStatus.ERROR, Policy.bind("CompareDiffListener.11")); } 94 listener.fileDiff(localFilePath, remoteFilePath, leftRevision, rightRevision); 95 localFilePath = remoteFilePath = leftRevision = rightRevision = null; 96 return OK; 97 } 98 return OK; 100 } 101 102 private IStatus handleUnknownDiffFormat(String line) { 103 return new CVSStatus(IStatus.ERROR, Policy.bind("CompareDiffListener.12", line)); } 105 106 public IStatus errorLine( 107 String line, 108 ICVSRepositoryLocation location, 109 ICVSFolder commandRoot, 110 IProgressMonitor monitor) { 111 if (getServerMessage(line, location) != null) { 114 return OK; 115 } 116 return super.errorLine(line, location, commandRoot, monitor); 117 } 118 119 } 120 | Popular Tags |