1 11 package org.eclipse.pde.internal.core.builders; 12 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.Set ; 16 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.IResourceChangeEvent; 20 import org.eclipse.core.resources.IResourceChangeListener; 21 import org.eclipse.core.resources.IWorkspaceRoot; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.NullProgressMonitor; 24 import org.eclipse.jdt.core.JavaCore; 25 import org.eclipse.osgi.service.resolver.BundleDelta; 26 import org.eclipse.osgi.service.resolver.State; 27 import org.eclipse.osgi.service.resolver.StateDelta; 28 import org.eclipse.pde.core.plugin.IPluginModelBase; 29 import org.eclipse.pde.core.plugin.PluginRegistry; 30 import org.eclipse.pde.internal.core.IStateDeltaListener; 31 import org.eclipse.pde.internal.core.PDECore; 32 import org.eclipse.pde.internal.core.WorkspaceModelManager; 33 34 public class PluginRebuilder implements IStateDeltaListener, IResourceChangeListener { 35 36 private Set fProjectNames = new HashSet (); 37 38 private boolean fTouchWorkspace = false; 39 40 public void start() { 41 PDECore.getDefault().getModelManager().addStateDeltaListener(this); 42 JavaCore.addPreProcessingResourceChangedListener(this, IResourceChangeEvent.PRE_BUILD); 43 } 44 45 public void stop() { 46 PDECore.getDefault().getModelManager().removeStateDeltaListener(this); 47 JavaCore.removePreProcessingResourceChangedListener(this); 48 } 49 50 public void resourceChanged(IResourceChangeEvent event) { 51 if (event.getType() == IResourceChangeEvent.PRE_BUILD) { 52 IWorkspaceRoot root = PDECore.getWorkspace().getRoot(); 53 if (fTouchWorkspace) { 54 IProject[] projects = root.getProjects(); 55 for (int i = 0; i < projects.length; i++) { 56 touchProject(projects[i]); 57 } 58 } else { 59 Iterator iter = fProjectNames.iterator(); 60 while (iter.hasNext()) { 61 touchProject(root.getProject((String )iter.next())); 62 } 63 } 64 fTouchWorkspace = false; 65 fProjectNames.clear(); 66 } 67 } 68 69 private void touchProject(IProject project) { 70 if (WorkspaceModelManager.isPluginProject(project) 71 && !WorkspaceModelManager.isBinaryProject(project)) { 72 try { 73 project.setSessionProperty(PDECore.TOUCH_PROJECT, Boolean.TRUE); 76 project.touch(new NullProgressMonitor()); 78 } catch (CoreException e) { 79 PDECore.log(e); 80 } 81 } 82 } 83 84 public void stateChanged(State newState) { 85 fTouchWorkspace = true; 86 fProjectNames.clear(); 87 } 88 89 public void stateResolved(StateDelta delta) { 90 if (delta == null) { 91 fTouchWorkspace = true; 94 fProjectNames.clear(); 95 } else { 96 BundleDelta[] deltas = delta.getChanges(); 97 for (int i = 0; i < deltas.length; i++) { 98 int type = deltas[i].getType(); 101 if ((type & BundleDelta.UPDATED) == BundleDelta.UPDATED 102 || (type & BundleDelta.ADDED) == BundleDelta.ADDED 103 || (type & BundleDelta.REMOVED) == BundleDelta.REMOVED) 104 continue; 105 106 IPluginModelBase model = PluginRegistry.findModel(deltas[i].getBundle()); 107 IResource resource = model == null ? null : model.getUnderlyingResource(); 108 if (resource != null) 109 fProjectNames.add(resource.getProject().getName()); 110 } 111 } 112 } 113 114 } 115 | Popular Tags |