1 12 package org.eclipse.team.internal.ccvs.core.client; 13 14 import java.util.ArrayList ; 15 import java.util.Date ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.core.resources.*; 20 import org.eclipse.core.runtime.*; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.core.client.listeners.*; 23 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 24 25 30 public class UpdateMergableOnly extends Update { 31 32 private static final String LOCAL_FILE_PATH_VARIABLE_NAME = "localFilePath"; private static ServerMessageLineMatcher MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER; 34 static { 35 initializePatterns(); 37 } 38 public static void initializePatterns() { 39 try { 40 MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER = new ServerMessageLineMatcher( 41 IMessagePatterns.MERGE_UPDATE_CONFLICTING_ADDITION, new String [] {LOCAL_FILE_PATH_VARIABLE_NAME}); 42 } catch (CVSException e) { 43 CVSProviderPlugin.log(e); 45 } 46 } 47 48 List skippedFiles = new ArrayList (); 49 50 public class MergableOnlyUpdatedHandler extends UpdatedHandler { 51 52 public MergableOnlyUpdatedHandler() { 53 super(UpdatedHandler.HANDLE_MERGED); 55 } 56 57 60 protected ICVSFile getTargetFile(ICVSFolder mParent, String fileName, byte[] entryBytes) throws CVSException { 61 String adjustedFileName = fileName; 62 if (ResourceSyncInfo.isMergedWithConflicts(entryBytes)) { 63 adjustedFileName = ".##" + adjustedFileName + " " + ResourceSyncInfo.getRevision(entryBytes); skippedFiles.add(((IContainer)mParent.getIResource()).getFile(new Path(null, fileName))); 66 } 67 return super.getTargetFile(mParent, adjustedFileName, entryBytes); 68 } 69 70 73 protected void receiveTargetFile( 74 Session session, 75 ICVSFile mFile, 76 String entryLine, 77 Date modTime, 78 boolean binary, 79 boolean readOnly, 80 boolean executable, 81 IProgressMonitor monitor) 82 throws CVSException { 83 84 if (ResourceSyncInfo.isMergedWithConflicts(entryLine.getBytes())) { 85 session.receiveFile(mFile, binary, UpdatedHandler.HANDLE_UPDATED, monitor); 89 mFile.delete(); 91 } else { 92 super.receiveTargetFile(session, mFile, entryLine, modTime, binary, readOnly, executable, monitor); 93 } 94 } 95 } 96 97 105 public class MergeUpdateListener extends UpdateListener { 106 public MergeUpdateListener(IUpdateMessageListener updateMessageListener) { 107 super(updateMessageListener); 108 } 109 public IStatus errorLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) { 110 Map variables = MERGE_UPDATE_CONFLICTING_ADDITION_MATCHER.processServerMessage(line); 111 if (variables != null) { 112 String filePath = (String )variables.get(LOCAL_FILE_PATH_VARIABLE_NAME); 113 try { 114 ICVSResource cvsResource = commandRoot.getChild(filePath); 115 IResource resource = cvsResource.getIResource(); 116 if (resource != null && resource.getType() == IResource.FILE) { 117 skippedFiles.add(resource); 118 return OK; 119 } 120 } catch (CVSException e) { 121 CVSProviderPlugin.log(e); 122 } 124 } 125 return super.errorLine(line, location, commandRoot, monitor); 126 } 127 } 128 129 132 protected IStatus doExecute( 133 Session session, 134 GlobalOption[] globalOptions, 135 LocalOption[] localOptions, 136 String [] arguments, 137 ICommandOutputListener listener, 138 IProgressMonitor monitor) 139 throws CVSException { 140 141 MergableOnlyUpdatedHandler newHandler = new MergableOnlyUpdatedHandler(); 142 ResponseHandler oldHandler = session.getResponseHandler(newHandler.getResponseID()); 143 skippedFiles.clear(); 144 try { 145 session.registerResponseHandler(newHandler); 146 session.setCreateBackups(false); 148 return super.doExecute( 149 session, 150 globalOptions, 151 localOptions, 152 arguments, 153 new MergeUpdateListener(null), 154 monitor); 155 } finally { 156 session.registerResponseHandler(oldHandler); 157 session.setCreateBackups(true); 158 } 159 } 160 161 public IFile[] getSkippedFiles() { 162 return (IFile[]) skippedFiles.toArray(new IFile[skippedFiles.size()]); 163 } 164 165 } 166 | Popular Tags |