1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.Date ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.team.core.TeamException; 21 import org.eclipse.team.core.synchronize.SyncInfoFilter.ContentComparisonSyncInfoFilter; 22 import org.eclipse.team.core.variants.IResourceVariant; 23 import org.eclipse.team.internal.ccvs.core.*; 24 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 25 import org.eclipse.team.internal.ccvs.core.syncinfo.MutableResourceSyncInfo; 26 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 27 import org.eclipse.team.internal.ccvs.ui.*; 28 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 29 import org.eclipse.team.internal.ccvs.ui.Policy; 30 31 34 public class ReconcileProjectOperation extends ShareProjectOperation { 35 36 private ICVSRemoteFolder folder; 37 private ContentComparisonSyncInfoFilter contentCompare = new ContentComparisonSyncInfoFilter(false); 38 39 public ReconcileProjectOperation(Shell shell, IProject project, ICVSRemoteFolder folder) { 40 super(shell, folder.getRepository(), project, folder.getRepositoryRelativePath()); 41 this.folder = folder; 42 } 43 44 47 protected String getTaskName() { 48 return NLS.bind(CVSUIMessages.ReconcileProjectOperation_0, new String [] { getProject().getName(), folder.getRepositoryRelativePath() }); 49 } 50 51 54 protected ICVSRemoteFolder createRemoteFolder(IProgressMonitor monitor) throws CVSException { 55 return folder; 57 } 58 59 62 protected void mapProjectToRemoteFolder(ICVSRemoteFolder remote, IProgressMonitor monitor) throws TeamException { 63 monitor.beginTask(null, 100); 65 super.mapProjectToRemoteFolder(remote, Policy.subMonitorFor(monitor, 10)); 66 reconcileSyncInfo(Policy.subMonitorFor(monitor, 90)); 68 monitor.done(); 69 } 70 71 74 protected void reconcileSyncInfo(IProgressMonitor monitor) throws CVSException { 75 try { 76 monitor.beginTask(null, 100); 77 ICVSRemoteFolder remote = CheckoutToRemoteFolderOperation.checkoutRemoteFolder(getPart(), folder, Policy.subMonitorFor(monitor, 80)); 79 populateWorkspace(remote, Policy.subMonitorFor(monitor, 20)); 82 } catch (InvocationTargetException e) { 83 throw CVSException.wrapException(e); 84 } catch (TeamException e) { 85 throw CVSException.wrapException(e); 86 } catch (InterruptedException e) { 87 throw new OperationCanceledException(); 88 } finally { 89 monitor.done(); 90 } 91 92 } 93 94 private void populateWorkspace(final ICVSRemoteFolder remote, IProgressMonitor monitor) throws CVSException { 95 CVSWorkspaceRoot.getCVSFolderFor(getProject()).run(new ICVSRunnable() { 96 public void run(IProgressMonitor monitor) throws CVSException { 97 populateWorkspace(getProject(), remote, monitor); 98 } 99 }, monitor); 100 101 } 102 103 void populateWorkspace(IResource resource, ICVSRemoteResource remote, IProgressMonitor monitor) throws CVSException { 104 try { 105 if (resource.getType() == IResource.FILE) { 106 if (remote.isContainer()) { 107 CVSUIPlugin.log(IStatus.ERROR, NLS.bind(CVSUIMessages.ReconcileProjectOperation_1, new String [] { resource.getFullPath().toString(), remote.getRepositoryRelativePath() }), null); 108 } else { 109 IFile file = (IFile)resource; 110 IResourceVariant variant = (IResourceVariant)remote; 111 if (file.exists() 112 && variant != null 113 && contentCompare.compareContents(file, variant, monitor)) { 114 makeInSync(file, remote, monitor); 117 } else { 118 } 122 } 123 } else { 124 if (!remote.isContainer()) { 125 CVSUIPlugin.log(IStatus.ERROR, NLS.bind(CVSUIMessages.ReconcileProjectOperation_2, new String [] { resource.getFullPath().toString(), remote.getRepositoryRelativePath() }), null); 126 } else { 127 ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(resource); 130 folder.setFolderSyncInfo(((ICVSFolder)remote).getFolderSyncInfo()); 131 ICVSRemoteResource[] members = remote.members(monitor); 134 for (int i = 0; i < members.length; i++) { 135 ICVSRemoteResource member = members[i]; 136 populateWorkspace(getLocalChild((IContainer)resource, member), member, monitor); 137 } 138 } 139 } 140 } catch (TeamException e) { 141 throw CVSException.wrapException(e); 142 } 143 } 144 145 148 private IResource getLocalChild(IContainer parent, ICVSRemoteResource member) { 149 IResource resource = parent.findMember(member.getName()); 150 if (resource == null) { 151 if (member.isContainer()) { 152 resource = parent.getFolder(new Path(null, member.getName())); 153 } else { 154 resource = parent.getFile(new Path(null, member.getName())); 155 } 156 } 157 return resource; 158 } 159 160 163 private void makeInSync(IFile file, ICVSRemoteResource remote, IProgressMonitor monitor) throws CVSException { 164 ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor(file); 165 ResourceSyncInfo info = remote.getSyncInfo(); 166 Date modTime = info.getTimeStamp(); 167 if (modTime != null) { 168 cvsFile.setTimeStamp(modTime); 169 } 170 modTime = cvsFile.getTimeStamp(); 171 MutableResourceSyncInfo newInfoWithTimestamp = info.cloneMutable(); 172 newInfoWithTimestamp.setTimeStamp(modTime); 173 cvsFile.setSyncInfo(newInfoWithTimestamp, ICVSFile.CLEAN); 174 } 175 176 } 177 | Popular Tags |