1 11 package org.eclipse.team.internal.ccvs.core; 12 13 import java.util.Arrays ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.IResourceStatus; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.team.core.RepositoryProvider; 21 import org.eclipse.team.core.TeamException; 22 import org.eclipse.team.core.diff.IDiff; 23 import org.eclipse.team.core.subscribers.Subscriber; 24 import org.eclipse.team.core.synchronize.SyncInfo; 25 import org.eclipse.team.core.variants.*; 26 import org.eclipse.team.internal.ccvs.core.filehistory.CVSResourceVariantFileRevision; 27 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 28 import org.eclipse.team.internal.core.mapping.ResourceVariantFileRevision; 29 import org.eclipse.team.internal.core.mapping.SyncInfoToDiffConverter; 30 31 35 public abstract class CVSSyncTreeSubscriber extends ResourceVariantTreeSubscriber implements IAdaptable { 36 37 public static final String SYNC_KEY_QUALIFIER = "org.eclipse.team.cvs"; 39 private IResourceVariantComparator comparisonCriteria; 40 41 private QualifiedName id; 42 private String name; 43 private SyncInfoToDiffConverter converter = new CVSSyncInfoToDiffConverter(); 44 45 public class CVSSyncInfoToDiffConverter extends SyncInfoToDiffConverter { 46 protected ResourceVariantFileRevision asFileRevision(IResourceVariant variant) { 47 return new CVSResourceVariantFileRevision(variant); 48 } 49 } 50 51 CVSSyncTreeSubscriber(QualifiedName id, String name) { 52 this.id = id; 53 this.name = name; 54 this.comparisonCriteria = new CVSRevisionNumberCompareCriteria(isThreeWay()); 55 } 56 57 60 public QualifiedName getId() { 61 return id; 62 } 63 64 67 public String getName() { 68 return name; 69 } 70 71 74 public SyncInfo getSyncInfo(IResource resource) throws TeamException { 75 if (!isSupervised(resource)) return null; 76 if(resource.getType() == IResource.FILE || !isThreeWay()) { 77 return super.getSyncInfo(resource); 78 } else { 79 IResourceVariant remoteResource = getRemoteTree().getResourceVariant(resource); 81 return getSyncInfo(resource, remoteResource, remoteResource); 82 } 83 } 84 85 88 public boolean isSupervised(IResource resource) throws TeamException { 89 try { 90 RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()); 91 if (provider == null) return false; 92 ICVSResource cvsThing = CVSWorkspaceRoot.getCVSResourceFor(resource); 95 if (cvsThing.isIgnored()) { 96 return getRemoteTree().hasResourceVariant(resource); 98 } 99 return true; 100 } catch (TeamException e) { 101 if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND || !resource.getProject().isAccessible()) { 104 return false; 105 } 106 throw e; 107 } 108 } 109 110 113 public IResourceVariantComparator getResourceComparator() { 114 return comparisonCriteria; 115 } 116 117 120 protected SyncInfo getSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote) throws TeamException { 121 CVSSyncInfo info = new CVSSyncInfo(local, base, remote, this); 122 info.init(); 123 return info; 124 } 125 126 129 protected boolean getCacheFileContentsHint() { 130 return false; 131 } 132 133 136 protected boolean isThreeWay() { 137 return true; 138 } 139 140 protected boolean rootsEqual(Subscriber other) { 141 Set roots1 = new HashSet (Arrays.asList(other.roots())); 142 Set roots2 = new HashSet (Arrays.asList(roots())); 143 if(roots1.size() != roots2.size()) return false; 144 return roots2.containsAll(roots1); 145 } 146 147 148 public IDiff getDiff(IResource resource) throws CoreException { 149 SyncInfo info = getSyncInfo(resource); 150 if (info == null || info.getKind() == SyncInfo.IN_SYNC) 151 return null; 152 return converter.getDeltaFor(info); 153 } 154 public Object getAdapter(Class adapter) { 155 if (adapter == SyncInfoToDiffConverter.class) { 156 return converter; 157 } 158 return Platform.getAdapterManager().getAdapter(this, adapter); 159 } 160 161 } 162 | Popular Tags |