1 11 package org.eclipse.team.internal.ccvs.core.syncinfo; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.IStatus; 19 import org.eclipse.core.runtime.Status; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.core.RepositoryProvider; 22 import org.eclipse.team.core.TeamException; 23 import org.eclipse.team.core.variants.PersistantResourceVariantByteStore; 24 import org.eclipse.team.core.variants.ResourceVariantByteStore; 25 import org.eclipse.team.internal.ccvs.core.*; 26 import org.eclipse.team.internal.core.subscribers.DescendantResourceVariantByteStore; 27 28 31 public class CVSDescendantResourceVariantByteStore extends DescendantResourceVariantByteStore { 32 33 public CVSDescendantResourceVariantByteStore(ResourceVariantByteStore baseCache, PersistantResourceVariantByteStore remoteCache) { 34 super(baseCache, remoteCache); 35 } 36 37 40 protected boolean isDescendant(IResource resource, byte[] baseBytes, byte[] remoteBytes) throws TeamException { 41 if (resource.getType() != IResource.FILE) return true; 42 try { 43 return ResourceSyncInfo.isLaterRevisionOnSameBranch(remoteBytes, baseBytes); 44 } catch (CVSException e) { 45 throw TeamException.asTeamException(e); 46 } 47 } 48 49 52 public boolean setBytes(IResource resource, byte[] bytes) throws TeamException { 53 boolean changed = super.setBytes(resource, bytes); 54 if (resource.getType() == IResource.FILE && getBytes(resource) != null && !parentHasSyncBytes(resource)) { 55 CVSProviderPlugin.log(new TeamException(NLS.bind(CVSMessages.ResourceSynchronizer_missingParentBytesOnSet, new String [] { ((PersistantResourceVariantByteStore)getRemoteStore()).getSyncName().toString(), resource.getFullPath().toString() }))); 58 } 59 return changed; 60 } 61 62 67 protected boolean parentHasSyncBytes(IResource resource) throws TeamException { 68 if (resource.getType() == IResource.PROJECT) return true; 69 return (getBytes(resource.getParent()) != null); 70 } 71 72 75 public boolean isVariantKnown(IResource resource) throws TeamException { 76 return ((PersistantResourceVariantByteStore)getRemoteStore()).isVariantKnown(resource); 77 } 78 79 82 public IStatus handleResourceChanges(IResource[] changedResources, boolean canModifyWorkspace) { 83 List errors = new ArrayList (); 85 for (int i = 0; i < changedResources.length; i++) { 86 IResource resource = changedResources[i]; 87 try { 88 if (!isInCVSProject(resource)) continue; 89 if (resource.getType() == IResource.FILE 90 && (resource.exists() || resource.isPhantom())) { 91 byte[] remoteBytes = getBytes(resource); 92 if (remoteBytes == null) { 93 if (isVariantKnown(resource)) { 94 if (getBaseStore().getBytes(resource) != null) { 97 if (canModifyWorkspace) { 98 flushBytes(resource, IResource.DEPTH_ZERO); 99 } else { 100 } 103 } 104 } 105 } else { 106 byte[] localBytes = getBaseStore().getBytes(resource); 107 if (localBytes == null || !isDescendant(resource, localBytes, remoteBytes)) { 108 if (canModifyWorkspace) { 109 flushBytes(resource, IResource.DEPTH_ZERO); 110 } else { 111 } 113 } 114 } 115 } else if (resource.getType() == IResource.FOLDER) { 116 if (getBaseStore().getBytes(resource) != null && canModifyWorkspace) { 118 flushBytes(resource, IResource.DEPTH_ZERO); 119 } 120 } 121 } catch (TeamException e) { 122 errors.add(e); 123 } 124 } 125 for (Iterator iter = errors.iterator(); iter.hasNext();) { 126 TeamException e = (TeamException) iter.next(); 127 CVSProviderPlugin.log(e); 128 } 129 return Status.OK_STATUS; } 131 132 private boolean isInCVSProject(IResource resource) { 133 return RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()) != null; 134 } 135 } 136 | Popular Tags |