1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.NullProgressMonitor; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.diff.IDiff; 21 import org.eclipse.team.core.diff.IThreeWayDiff; 22 import org.eclipse.team.core.history.IFileRevision; 23 import org.eclipse.team.core.mapping.IResourceDiff; 24 import org.eclipse.team.core.mapping.IResourceDiffTree; 25 import org.eclipse.team.core.synchronize.SyncInfoFilter; 26 import org.eclipse.team.core.synchronize.SyncInfoFilter.ContentComparisonSyncInfoFilter; 27 import org.eclipse.team.core.variants.IResourceVariant; 28 import org.eclipse.team.internal.ccvs.core.*; 29 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 30 import org.eclipse.team.internal.ccvs.ui.Policy; 31 import org.eclipse.ui.IWorkbenchPart; 32 33 37 public class CacheBaseContentsOperation extends CacheTreeContentsOperation { 38 39 40 public CacheBaseContentsOperation(IWorkbenchPart part, ResourceMapping[] mappings, IResourceDiffTree tree, boolean includeOutgoing) { 41 super(part, mappings, tree); 42 } 43 44 47 protected IFileRevision getRemoteFileState(IThreeWayDiff twd) { 48 IResourceDiff diff = (IResourceDiff)twd.getRemoteChange(); 49 if (diff == null) 50 diff = (IResourceDiff)twd.getLocalChange(); 51 IFileRevision base = diff.getBeforeState(); 52 return base; 53 } 54 55 58 protected boolean isEnabledForDirection(int direction) { 59 return true; 60 } 61 62 65 protected ICVSRemoteResource buildTree(CVSTeamProvider provider) throws TeamException { 66 return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().buildBaseTree(provider.getProject(), true, new NullProgressMonitor()); 67 } 68 69 protected void execute(CVSTeamProvider provider, IResource[] resources, boolean recurse, IProgressMonitor monitor) throws CVSException, InterruptedException { 70 IResource[] localChanges = getFilesWithLocalChanges(resources, recurse); 71 super.execute(provider, resources, recurse, monitor); 72 if (localChanges.length > 0) { 74 performCleanTimestamps(localChanges[0].getProject(), localChanges, monitor); 75 } 76 } 77 78 private IResource[] getFilesWithLocalChanges(IResource[] resources, boolean recurse) { 79 ArrayList result = new ArrayList (); 80 for (int i = 0; i < resources.length; i++) { 81 IResource resource = resources[i]; 82 IDiff[] nodes = getTree().getDiffs(resource, recurse ? IResource.DEPTH_INFINITE: IResource.DEPTH_ONE); 83 for (int j = 0; j < nodes.length; j++) { 84 IDiff node = nodes[j]; 85 if (isFileWithLocalChange(node)) { 86 result.add(getTree().getResource(node)); 87 } 88 } 89 } 90 return (IResource[]) result.toArray(new IResource[result.size()]); 91 } 92 93 private boolean isFileWithLocalChange(IDiff node) { 94 if (node instanceof IThreeWayDiff) { 95 IThreeWayDiff twd = (IThreeWayDiff) node; 96 return (twd.getDirection() == IThreeWayDiff.OUTGOING || twd.getDirection() == IThreeWayDiff.CONFLICTING) 97 && getTree().getResource(node).getType() == IResource.FILE; 98 } 99 return false; 100 } 101 102 private void performCleanTimestamps(IProject project, final IResource[] resources, IProgressMonitor monitor) throws CVSException { 103 ICVSFolder folder = CVSWorkspaceRoot.getCVSFolderFor(project); 104 final ContentComparisonSyncInfoFilter comparator = new SyncInfoFilter.ContentComparisonSyncInfoFilter(false); 105 folder.run(new ICVSRunnable() { 106 public void run(IProgressMonitor monitor) throws CVSException { 107 monitor.beginTask(null, resources.length * 100); 108 for (int i = 0; i < resources.length; i++) { 109 IResource resource = resources[i]; 110 if (resource.exists() && resource.getType() == IResource.FILE) { 111 IResourceVariant remoteResource = (IResourceVariant)CVSWorkspaceRoot.getRemoteResourceFor(resource); 112 if (remoteResource != null && comparator.compareContents((IFile)resource, remoteResource, Policy.subMonitorFor(monitor, 100))) { 113 ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile)resource); 114 cvsFile.checkedIn(null, false ); 115 } 116 } 117 } 118 monitor.done(); 119 } 120 }, Policy.subMonitorFor(monitor, 100)); 121 } 122 123 } 124 | Popular Tags |