1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.core.runtime.CoreException; 18 import org.eclipse.core.runtime.QualifiedName; 19 import org.eclipse.team.core.RepositoryProvider; 20 import org.eclipse.team.internal.ccvs.core.*; 21 import org.eclipse.team.internal.ccvs.core.util.ResourceStateChangeListeners; 22 23 31 public class FileModificationManager implements IResourceChangeListener { 32 33 private static final QualifiedName UPDATE_TIMESTAMP = new QualifiedName(CVSProviderPlugin.ID, "update-timestamp"); 35 Set modifiedResources = new HashSet (); 36 37 protected int INTERESTING_CHANGES = IResourceDelta.CONTENT | 39 IResourceDelta.MOVED_FROM | 40 IResourceDelta.MOVED_TO | 41 IResourceDelta.OPEN | 42 IResourceDelta.REPLACED | 43 IResourceDelta.TYPE; 44 45 50 public void resourceChanged(IResourceChangeEvent event) { 51 try { 52 event.getDelta().accept(new IResourceDeltaVisitor() { 53 public boolean visit(IResourceDelta delta) { 54 IResource resource = delta.getResource(); 55 56 if (resource.getType()==IResource.PROJECT) { 57 IProject project = (IProject)resource; 58 if (!project.isAccessible()) { 59 return false; 60 } 61 if ((delta.getFlags() & IResourceDelta.OPEN) != 0) { 62 return false; 63 } 64 if (RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId()) == null) { 65 return false; 66 } 67 } 68 69 if (resource.getType()==IResource.FILE && delta.getKind() == IResourceDelta.CHANGED && resource.exists()) { 70 int flags = delta.getFlags(); 71 if((flags & INTERESTING_CHANGES) != 0) { 72 resourceChanged(resource, false); 73 } 74 } else if (delta.getKind() == IResourceDelta.ADDED) { 75 resourceChanged(resource, true); 76 } else if (delta.getKind() == IResourceDelta.REMOVED) { 77 try { 78 EclipseSynchronizer.getInstance().handleDeleted(resource); 79 } catch (CVSException e) { 80 CVSProviderPlugin.log(e); 81 } 82 modifiedResources.add(resource); 83 } 84 85 return true; 86 } 87 }); 88 if (!modifiedResources.isEmpty()) { 89 ResourceStateChangeListeners.getListener().resourceModified( 90 (IResource[])modifiedResources.toArray(new IResource[modifiedResources.size()])); 91 modifiedResources.clear(); 92 } 93 } catch (CoreException e) { 94 CVSProviderPlugin.log(e); 95 } 96 97 } 98 99 106 public void updated(ICVSFile mFile) { 107 try { 108 if (mFile instanceof EclipseFile) { 109 IFile file = (IFile)mFile.getIResource(); 110 file.setSessionProperty(UPDATE_TIMESTAMP, new Long (file.getModificationStamp())); 111 } 112 } catch (CoreException e) { 113 CVSProviderPlugin.log(e); 114 } 115 } 116 117 121 void resourceChanged(IResource resource, boolean addition) { 122 if (isCleanUpdate(resource)) return; 123 try { 124 EclipseResource cvsResource = (EclipseResource)CVSWorkspaceRoot.getCVSResourceFor(resource); 125 if (!cvsResource.isIgnored()) { 126 cvsResource.handleModification(addition); 127 modifiedResources.add(resource); 128 } 129 if(cvsResource.getName().equals(".cvsignore") && cvsResource.isIgnored()){ EclipseSynchronizer.getInstance().setModified((EclipseFile) cvsResource, ICVSFile.CLEAN); 133 modifiedResources.add(resource); 134 } 135 } catch (CVSException e) { 136 CVSProviderPlugin.log(e); 138 } 139 } 140 141 148 private boolean isCleanUpdate(IResource resource) { 149 if(resource.getType() != IResource.FILE) return false; 150 long modStamp = resource.getModificationStamp(); 151 Long whenWeWrote; 152 try { 153 whenWeWrote = (Long )resource.getSessionProperty(UPDATE_TIMESTAMP); 154 resource.setSessionProperty(UPDATE_TIMESTAMP, null); 155 } catch(CoreException e) { 156 CVSProviderPlugin.log(e); 157 whenWeWrote = null; 158 } 159 return (whenWeWrote!=null && whenWeWrote.longValue() == modStamp); 160 } 161 } 162 163 | Popular Tags |