1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 14 import org.eclipse.core.resources.*; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.team.core.Team; 17 import org.eclipse.team.internal.ccvs.core.*; 18 import org.eclipse.team.internal.ccvs.core.client.Session; 19 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; 20 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 21 import org.eclipse.team.internal.ccvs.core.util.Util; 22 23 24 31 abstract class EclipseResource implements ICVSResource, Comparable { 32 33 protected static final String SEPARATOR = Session.SERVER_SEPARATOR; 36 protected static final String CURRENT_LOCAL_FOLDER = Session.CURRENT_LOCAL_FOLDER; 37 38 41 IResource resource; 42 43 46 protected EclipseResource(IResource resource) { 47 Assert.isNotNull(resource); 48 this.resource = resource; 49 } 50 51 56 public String getRelativePath(ICVSFolder root) throws CVSException { 57 try { 58 EclipseResource rootFolder; 59 String result; 60 rootFolder = (EclipseResource)root; 61 result = Util.getRelativePath(rootFolder.getPath(), getPath()); 62 if (result.length() == 0) return CURRENT_LOCAL_FOLDER; 63 return result; 64 } catch (ClassCastException e) { 65 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR, CVSMessages.EclipseResource_invalidResourceClass, e, root); 66 throw new CVSException(status); 67 } 68 } 69 70 73 public boolean exists() { 74 return resource.exists(); 75 } 76 77 83 public ICVSFolder getParent() { 84 IContainer parent = resource.getParent(); 85 if (parent==null) { 86 return null; 87 } 88 return new EclipseFolder(parent); 89 } 90 91 94 public String getName() { 95 return resource.getName(); 96 } 97 98 101 public boolean isIgnored() throws CVSException { 102 if(isManaged() || resource.getType()==IResource.ROOT || resource.getType()==IResource.PROJECT) { 104 return false; 105 } 106 107 if (resource.isDerived() || resource.isLinked()) { 109 return true; 110 } 111 112 String name = getName(); 114 if (name.equals("CVS")) return true; 116 if (Team.isIgnoredHint(resource)) return true; 118 119 if(EclipseSynchronizer.getInstance().isIgnored(resource)) { 121 return true; 122 } 123 124 ICVSFolder parent = getParent(); 127 if(parent==null) return false; 128 if (parent.isIgnored()) return true; 129 FolderSyncInfo info = parent.getFolderSyncInfo(); 130 if (info == null) return false; 131 return info.isVirtualDirectory(); 132 } 133 134 137 public void setIgnoredAs(final String pattern) throws CVSException { 138 run(new ICVSRunnable() { 139 public void run(IProgressMonitor monitor) throws CVSException { 140 EclipseSynchronizer.getInstance().addIgnored(resource.getParent(), pattern); 141 } 142 }, null); 143 } 144 145 148 public boolean isManaged() throws CVSException { 149 return isManaged(getSyncBytes()); 150 } 151 152 155 public boolean isManaged(byte[] syncBytes) { 156 return syncBytes != null; 157 } 158 159 163 public boolean equals(Object obj) { 164 165 if (!(obj instanceof EclipseResource)) { 166 return false; 167 } else { 168 return getPath().equals(((EclipseResource) obj).getPath()); 169 } 170 } 171 172 175 public String getPath() { 176 return resource.getFullPath().toString(); 177 } 178 179 182 public boolean isFolder() { 183 return false; 184 } 185 186 189 public byte[] getSyncBytes() throws CVSException { 190 return EclipseSynchronizer.getInstance().getSyncBytes(getIResource()); 191 } 192 193 196 public void setSyncBytes(byte[] syncBytes) throws CVSException { 197 if (getParent().isCVSFolder()) { 198 EclipseSynchronizer.getInstance().setSyncBytes(getIResource(), syncBytes); 199 } 200 } 201 202 205 public ResourceSyncInfo getSyncInfo() throws CVSException { 206 return EclipseSynchronizer.getInstance().getResourceSync(resource); 207 } 208 209 212 public int hashCode() { 213 return getPath().hashCode(); 214 } 215 216 219 public String toString() { 220 return getPath(); 221 } 222 223 226 public void unmanage(IProgressMonitor monitor) throws CVSException { 227 EclipseSynchronizer.getInstance().deleteResourceSync(resource); 228 } 229 230 233 public int compareTo(Object arg0) { 234 EclipseResource other = (EclipseResource)arg0; 235 return resource.getFullPath().toString().compareTo(other.resource.getFullPath().toString()); 236 } 237 238 241 public IResource getIResource() { 242 return resource; 243 } 244 245 252 public abstract void handleModification(boolean forAddition) throws CVSException; 253 254 public void run(final ICVSRunnable job, IProgressMonitor monitor) throws CVSException { 255 final CVSException[] error = new CVSException[1]; 256 try { 257 ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { 260 public void run(IProgressMonitor monitor) throws CoreException { 261 try { 262 EclipseSynchronizer.getInstance().run(getIResource(), job, monitor); 263 } catch(CVSException e) { 264 error[0] = e; 265 } 266 } 267 }, null , 0, monitor); 268 } catch(CoreException e) { 269 throw CVSException.wrapException(e); 270 } 271 if(error[0]!=null) { 272 throw error[0]; 273 } 274 } 275 } 276 | Popular Tags |