1 11 package org.eclipse.team.internal.ccvs.core; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.team.core.TeamException; 17 import org.eclipse.team.core.subscribers.Subscriber; 18 import org.eclipse.team.core.synchronize.SyncInfo; 19 import org.eclipse.team.core.variants.IResourceVariant; 20 import org.eclipse.team.core.variants.ResourceVariantTreeSubscriber; 21 import org.eclipse.team.internal.ccvs.core.client.Update; 22 import org.eclipse.team.internal.ccvs.core.resources.*; 23 import org.eclipse.team.internal.ccvs.core.syncinfo.*; 24 import org.eclipse.team.internal.ccvs.core.util.SyncFileChangeListener; 25 26 29 public class CVSSyncInfo extends SyncInfo { 30 31 34 private static final int INVALID_RESOURCE_TYPE = 1; 35 private static final int INVALID_SYNC_KIND = 2; 36 private static final int PARENT_NOT_MANAGED = 3; 37 private static final int REMOTE_DOES_NOT_EXIST = 4; 38 private static final int SYNC_INFO_CONFLICTS = 5; 39 private Subscriber subscriber; 40 41 public CVSSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, Subscriber subscriber) { 42 super(local, base, remote, ((ResourceVariantTreeSubscriber)subscriber).getResourceComparator()); 43 this.subscriber = subscriber; 44 } 45 46 public Subscriber getSubscriber() { 47 return subscriber; 48 } 49 50 53 protected int calculateKind() throws TeamException { 54 IResource local = getLocal(); 58 if(local.getType() != IResource.FILE) { 59 int folderKind = SyncInfo.IN_SYNC; 60 ICVSRemoteFolder remote = (ICVSRemoteFolder)getRemote(); 61 ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor((IContainer)local); 62 boolean isCVSFolder = false; 63 try { 64 isCVSFolder = cvsFolder.isCVSFolder(); 65 } catch (CVSException e) { 66 } 68 if(!local.exists()) { 69 if(remote != null) { 70 if (isCVSFolder) { 71 folderKind = SyncInfo.IN_SYNC; 73 } else { 74 folderKind = SyncInfo.INCOMING | SyncInfo.ADDITION; 75 } 76 } else { 77 } 79 } else { 80 if(remote == null) { 81 if(isCVSFolder) { 82 folderKind = SyncInfo.IN_SYNC; 85 } else { 87 folderKind = SyncInfo.OUTGOING | SyncInfo.ADDITION; 88 } 89 } else if(!isCVSFolder) { 90 folderKind = SyncInfo.CONFLICTING | SyncInfo.ADDITION; 91 } else { 92 } 95 } 96 return folderKind; 97 } 98 99 int kind = super.calculateKind(); 102 103 IResourceVariant remote = getRemote(); 106 if(remote!=null && (kind & SyncInfo.PSEUDO_CONFLICT) == 0) { 107 RemoteResource cvsRemote = (RemoteResource)remote; 108 int type = cvsRemote.getWorkspaceSyncState(); 109 switch(type) { 110 case Update.STATE_CONFLICT: 113 return kind | SyncInfo.MANUAL_CONFLICT; 114 115 case Update.STATE_MERGEABLE_CONFLICT: 118 return kind | SyncInfo.AUTOMERGE_CONFLICT; 119 } 120 } 121 122 kind = handleDeletionConflicts(kind); 124 125 return kind; 126 } 127 128 132 protected int handleDeletionConflicts(int kind) { 133 if(kind == (SyncInfo.CONFLICTING | SyncInfo.DELETION | SyncInfo.PSEUDO_CONFLICT)) { 134 try { 135 IResource local = getLocal(); 136 ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(local); 137 if(!cvsResource.isFolder() && cvsResource.isManaged()) { 138 SyncFileChangeListener.getDeferredHandler().handleConflictingDeletion(local); 140 } 141 return SyncInfo.IN_SYNC; 142 } catch(CVSException e) { 143 CVSProviderPlugin.log(e); 144 return SyncInfo.CONFLICTING | SyncInfo.DELETION; 145 } 146 } 147 return kind; 148 } 149 150 156 public IStatus makeOutgoing(IProgressMonitor monitor) throws TeamException { 157 158 if (getLocal().getType() == IResource.FOLDER) { 160 return makeInSync(); 161 } 162 int syncKind = getKind(); 163 boolean incoming = (syncKind & DIRECTION_MASK) == INCOMING; 164 boolean outgoing = (syncKind & DIRECTION_MASK) == OUTGOING; 165 166 ICVSResource local = CVSWorkspaceRoot.getCVSResourceFor(getLocal()); 167 RemoteResource remote = (RemoteResource)getRemote(); 168 ResourceSyncInfo origInfo = local.getSyncInfo(); 169 MutableResourceSyncInfo info = null; 170 if(origInfo!=null) { 171 info = origInfo.cloneMutable(); 172 } 173 174 if (outgoing) { 175 return Status.OK_STATUS; 177 } else if (incoming) { 178 if (local.exists()) { 180 if (remote == null) { 181 info.setAdded(); 182 } else { 183 info.setRevision(remote.getSyncInfo().getRevision()); 185 info.setTimeStamp(null); 186 } 187 } else { 188 if (remote == null) { 190 info = null; 192 return Status.OK_STATUS; 193 } else { 194 info = remote.getSyncInfo().cloneMutable(); 195 info.setDeleted(true); 196 } 197 } 198 } else if (local.exists()) { 199 if (getRemote() != null) { 201 if (getBase() != null) { 202 info.setRevision(remote.getSyncInfo().getRevision()); 204 } else { 205 try { 206 remote.getStorage(Policy.monitorFor(monitor)).getContents(); 210 info = remote.getSyncInfo().cloneMutable(); 211 } catch (CoreException e) { 212 throw TeamException.asTeamException(e); 213 } 214 } 215 } else if (getBase() != null) { 216 info.setAdded(); 218 } else { 219 Assert.isTrue(false); 221 } 222 } else { 223 if (getRemote() != null) { 225 info.setRevision(remote.getSyncInfo().getRevision()); 227 info.setDeleted(true); 228 } else { 229 info = null; 231 return Status.OK_STATUS; 232 } 233 } 234 if(info!=null) { 235 FolderSyncInfo parentInfo = local.getParent().getFolderSyncInfo(); 236 if (parentInfo == null) { 237 return new CVSStatus(IStatus.ERROR, PARENT_NOT_MANAGED, NLS.bind(CVSMessages.CVSSyncInfo_9, new String [] { getLocal().getFullPath().toString()}), getLocal()); 238 } 239 info.setTag(parentInfo.getTag()); 240 } 241 ((ICVSFile)local).setSyncInfo(info, ICVSFile.UNKNOWN); 242 return Status.OK_STATUS; 243 } 244 245 268 public IStatus makeInSync() throws CVSException { 269 270 if (getLocal().getType() == IResource.FILE) { 272 return new CVSStatus(IStatus.WARNING, INVALID_RESOURCE_TYPE, NLS.bind(CVSMessages.CVSSyncInfo_7, new String [] { getLocal().getFullPath().toString()}), getLocal()); 273 } 274 275 boolean outgoing = (getKind() & DIRECTION_MASK) == OUTGOING; 277 if (outgoing) { 278 return new CVSStatus(IStatus.WARNING, INVALID_SYNC_KIND, NLS.bind(CVSMessages.CVSSyncInfo_8, new String [] { getLocal().getFullPath().toString() }), getLocal()); 279 } 280 281 ICVSFolder local = CVSWorkspaceRoot.getCVSFolderFor((IContainer)getLocal()); 283 if (getLocal().getType() == IResource.FOLDER && ! local.getParent().isCVSFolder()) 284 return new CVSStatus(IStatus.ERROR, PARENT_NOT_MANAGED, NLS.bind(CVSMessages.CVSSyncInfo_9, new String [] { getLocal().getFullPath().toString() }), getLocal()); 285 286 if (! local.exists()) { 288 local.mkdir(); 289 } 290 291 RemoteFolder remote = (RemoteFolder)getRemote(); 293 if((local.isManaged() || getLocal().getType() == IResource.PROJECT) && local.isCVSFolder()) { 294 if (remote == null) return Status.OK_STATUS; 296 FolderSyncInfo remoteInfo = remote.getFolderSyncInfo(); 298 FolderSyncInfo localInfo = local.getFolderSyncInfo(); 299 if ( ! localInfo.getRoot().equals(remoteInfo.getRoot())) { 300 return new CVSStatus(IStatus.ERROR, SYNC_INFO_CONFLICTS, NLS.bind(CVSMessages.CVSRemoteSyncElement_rootDiffers, (new Object [] {local.getName(), remoteInfo.getRoot(), localInfo.getRoot()})),getLocal()); 301 } else if ( ! localInfo.getRepository().equals(remoteInfo.getRepository())) { 302 return new CVSStatus(IStatus.ERROR, SYNC_INFO_CONFLICTS, NLS.bind(CVSMessages.CVSRemoteSyncElement_repositoryDiffers, (new Object [] {local.getName(), remoteInfo.getRepository(), localInfo.getRepository()})),getLocal()); 303 } 304 return Status.OK_STATUS; 306 } 307 308 if (remote == null) { 310 return new CVSStatus(IStatus.ERROR, REMOTE_DOES_NOT_EXIST, NLS.bind(CVSMessages.CVSSyncInfo_10, new String [] { getLocal().getFullPath().toString() }),getLocal()); 311 } 312 313 FolderSyncInfo remoteInfo = remote.getFolderSyncInfo(); 318 FolderSyncInfo localInfo = local.getParent().getFolderSyncInfo(); 319 MutableFolderSyncInfo newInfo = remoteInfo.cloneMutable(); 320 newInfo.setTag(localInfo.getTag()); 321 newInfo.setStatic(false); 322 local.setFolderSyncInfo(newInfo); 323 return Status.OK_STATUS; 324 } 325 326 public String toString() { 327 IResourceVariant base = getBase(); 328 IResourceVariant remote = getRemote(); 329 StringBuffer result = new StringBuffer (super.toString()); 330 result.append("Local: "); result.append(getLocal().toString()); 332 result.append(" Base: "); if (base == null) { 334 result.append("none"); } else { 336 result.append(base.toString()); 337 } 338 result.append(" Remote: "); if (remote == null) { 340 result.append("none"); } else { 342 result.append(remote.toString()); 343 } 344 return result.toString(); 345 } 346 347 350 public String getLocalContentIdentifier() { 351 try { 352 IResource local = getLocal(); 353 if (local != null && local.getType() == IResource.FILE) { 354 ICVSFile cvsFile = CVSWorkspaceRoot.getCVSFileFor((IFile) local); 356 ResourceSyncInfo info = cvsFile.getSyncInfo(); 357 if (info != null) { 358 return info.getRevision(); 359 } 360 } 361 } catch (CVSException e) { 362 CVSProviderPlugin.log(e); 363 return null; 364 } 365 return null; 366 } 367 } 368 | Popular Tags |