1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import org.eclipse.core.resources.*; 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.osgi.util.NLS; 17 import org.eclipse.team.core.RepositoryProvider; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 21 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; 22 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 23 import org.eclipse.team.internal.ccvs.core.util.KnownRepositories; 24 import org.eclipse.team.internal.ccvs.core.util.Util; 25 26 32 public class CVSWorkspaceRoot { 33 34 private ICVSFolder localRoot; 35 36 public CVSWorkspaceRoot(IContainer resource){ 37 this.localRoot = getCVSFolderFor(resource); 38 } 39 40 46 public static void setSharing(IProject project, FolderSyncInfo info, IProgressMonitor monitor) throws TeamException { 47 48 ICVSFolder folder = (ICVSFolder)CVSWorkspaceRoot.getCVSResourceFor(project); 50 FolderSyncInfo folderInfo = folder.getFolderSyncInfo(); 51 if ( ! info.equals(folderInfo)) { 52 throw new CVSException(new CVSStatus(IStatus.ERROR, NLS.bind(CVSMessages.CVSProvider_infoMismatch, new String [] { project.getName() }))); 53 } 54 55 String root = info.getRoot(); 57 KnownRepositories.getInstance().getRepository(root); 60 61 RepositoryProvider.map(project, CVSProviderPlugin.getTypeId()); 63 } 64 65 public static ICVSFolder getCVSFolderFor(IContainer resource) { 66 return new EclipseFolder(resource); 67 } 68 69 70 public static ICVSFile getCVSFileFor(IFile resource) { 71 return new EclipseFile(resource); 72 } 73 74 75 public static ICVSResource getCVSResourceFor(IResource resource) { 76 if (resource.getType() == IResource.FILE) 77 return getCVSFileFor((IFile) resource); 78 else 79 return getCVSFolderFor((IContainer) resource); 80 } 81 82 public static ICVSRemoteResource getRemoteResourceFor(IResource resource) throws CVSException { 83 ICVSResource managed = getCVSResourceFor(resource); 84 return getRemoteResourceFor(managed); 85 } 86 87 public static ICVSRemoteResource getRemoteResourceFor(ICVSResource resource) throws CVSException { 88 if (resource.isFolder()) { 89 ICVSFolder folder = (ICVSFolder)resource; 90 FolderSyncInfo syncInfo = folder.getFolderSyncInfo(); 91 if (syncInfo != null) { 92 return new RemoteFolder(null, KnownRepositories.getInstance().getRepository(syncInfo.getRoot()), syncInfo.getRepository(), syncInfo.getTag()); 93 } 94 } else { 95 if (resource.isManaged()) { 96 RemoteFolder parent = (RemoteFolder)getRemoteResourceFor(resource.getParent()); 97 if (parent == null) { 98 if (resource.isManaged()) { 103 CVSProviderPlugin.log(new CVSStatus(IStatus.ERROR,CVSStatus.ERROR, NLS.bind(CVSMessages.CVSWorkspaceRoot_11, new String [] { Util.getFullestPath(resource) }),resource.getIResource())); 104 } 105 } else { 106 return RemoteFile.getBase(parent, (ICVSFile)resource); 107 } 108 } 109 } 110 return null; 111 } 112 113 117 private static ICVSRemoteResource getRemoteTreeFromParent(IResource resource, ICVSResource managed, CVSTag tag, IProgressMonitor progress) throws TeamException { 118 ICVSFolder parent = managed.getParent(); 120 FolderSyncInfo syncInfo = parent.getFolderSyncInfo(); 121 if (syncInfo == null) { 122 return null; 124 } 125 ICVSRepositoryLocation location = KnownRepositories.getInstance().getRepository(parent.getFolderSyncInfo().getRoot()); 126 RemoteFolder remoteParent = RemoteFolderTreeBuilder.buildRemoteTree((CVSRepositoryLocation)location, parent, tag, progress); 127 ICVSRemoteResource remote = null; 128 if (remoteParent != null) { 129 try { 130 remote = (ICVSRemoteResource)remoteParent.getChild(resource.getName()); 131 } catch (CVSException e) { 132 remote = null; 133 } 134 if (remote != null && !(remote.isContainer() == managed.isFolder())) 136 throw new CVSException(new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, NLS.bind(CVSMessages.CVSTeamProvider_typesDiffer, new String [] { resource.getFullPath().toString() }), resource)); 137 } 138 return remote; 139 } 140 141 154 public static ICVSRemoteResource getRemoteTree(IResource resource, CVSTag tag, boolean cacheFileContentsHint, int depth, IProgressMonitor progress) throws TeamException { 155 ICVSResource managed = CVSWorkspaceRoot.getCVSResourceFor(resource); 156 ICVSRemoteResource remote = CVSWorkspaceRoot.getRemoteResourceFor(resource); 157 if (remote == null) { 158 progress.beginTask(null, 100); 159 remote = getRemoteTreeFromParent(resource, managed, tag, Policy.subMonitorFor(progress, 50)); 160 if (cacheFileContentsHint && remote != null && remote instanceof RemoteFile) { 161 RemoteFile file = (RemoteFile)remote; 162 file.getStorage(Policy.subMonitorFor(progress, 50)); 164 } 165 progress.done(); 166 } else if(resource.getType() == IResource.FILE) { 167 ICVSRepositoryLocation location = remote.getRepository(); 168 if (cacheFileContentsHint) { 169 remote = UpdateContentCachingService.buildRemoteTree((CVSRepositoryLocation)location, (ICVSFile)managed, tag, progress); 170 } else { 171 remote = RemoteFolderTreeBuilder.buildRemoteTree((CVSRepositoryLocation)location, (ICVSFile)managed, tag, progress); 172 } 173 } else { 174 ICVSRepositoryLocation location = remote.getRepository(); 175 if (cacheFileContentsHint) { 176 remote = UpdateContentCachingService.buildRemoteTree((CVSRepositoryLocation)location, (ICVSFolder)managed, tag, depth, progress); 177 } else { 178 remote = RemoteFolderTreeBuilder.buildRemoteTree((CVSRepositoryLocation)location, (ICVSFolder)managed, tag, progress); 179 } 180 } 181 return remote; 182 } 183 184 public static boolean hasRemote(IResource resource) { 185 try { 186 ICVSResource cvsResource = getCVSResourceFor(resource); 187 int type = resource.getType(); 188 if(type!=IResource.FILE) { 189 if(type==IResource.PROJECT) { 190 return ((ICVSFolder)cvsResource).isCVSFolder(); 191 } else { 192 return cvsResource.isManaged(); 193 } 194 } else { 195 byte[] syncBytes = ((ICVSFile)cvsResource).getSyncBytes(); 196 if(syncBytes!=null) { 197 return !ResourceSyncInfo.isAddition(syncBytes); 198 } else { 199 return false; 200 } 201 } 202 } catch(CVSException e) { 203 return false; 204 } 205 } 206 207 public ICVSRepositoryLocation getRemoteLocation() throws CVSException { 208 FolderSyncInfo info = localRoot.getFolderSyncInfo(); 209 if (info == null) { 210 IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.RESOURCE_SYNC_INFO_ERROR,NLS.bind(CVSMessages.CVSWorkspaceRoot_notCVSFolder, new String [] { localRoot.getName() }),localRoot); 211 throw new CVSException(status); 212 } 213 return KnownRepositories.getInstance().getRepository(info.getRoot()); 214 } 215 216 public ICVSFolder getLocalRoot() { 217 return localRoot; 218 } 219 220 221 228 public static boolean isLinkedResource(IResource resource) { 229 return resource.isLinked(IResource.CHECK_ANCESTORS); 230 } 231 232 237 public static boolean isSharedWithCVS(IResource resource) throws CVSException { 238 if (!resource.isAccessible()) return false; 239 if(isLinkedResource(resource)) return false; 240 241 if(RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()) == null) { 242 return false; 243 } 244 245 ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); 246 if (cvsResource.isManaged()) return true; 247 if (!cvsResource.exists()) return false; 248 if (cvsResource.isFolder() && ((ICVSFolder) cvsResource).isCVSFolder()) return true; 249 if (cvsResource.isIgnored()) return false; 250 return cvsResource.getParent().isCVSFolder(); 251 } 252 253 262 public static boolean isOrphanedSubtree(IContainer container) throws CVSException { 263 ICVSFolder mFolder = CVSWorkspaceRoot.getCVSFolderFor(container); 264 return (mFolder.isCVSFolder() 265 && ! mFolder.isManaged() 266 && mFolder.getIResource().getType() == IResource.FOLDER 267 && !isLinkedResource(container)); 268 } 269 } 270 | Popular Tags |