diff options
author | rkulp | 2005-06-30 16:23:58 +0000 |
---|---|---|
committer | rkulp | 2005-06-30 16:23:58 +0000 |
commit | be6ecb4a22d404c20e465b309d26278844a6c586 (patch) | |
tree | 533accfd0859224b3905c1c26b92e10aeaedd42e | |
parent | 739a7d98c93305c8094ab54de31d0abee0fdb202 (diff) | |
download | webtools.javaee-be6ecb4a22d404c20e465b309d26278844a6c586.tar.gz webtools.javaee-be6ecb4a22d404c20e465b309d26278844a6c586.tar.xz webtools.javaee-be6ecb4a22d404c20e465b309d26278844a6c586.zip |
[101888] Pass 2: Forgot that clean needs to mark any open beaninfos as stale too.
3 files changed, 52 insertions, 41 deletions
diff --git a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/adapters/BeaninfoNature.java b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/adapters/BeaninfoNature.java index 807c095fe..5548bce61 100644 --- a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/adapters/BeaninfoNature.java +++ b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/adapters/BeaninfoNature.java @@ -11,7 +11,7 @@ package org.eclipse.jem.internal.beaninfo.adapters; /* * $RCSfile: BeaninfoNature.java,v $ - * $Revision: 1.32 $ $Date: 2005/06/21 19:17:03 $ + * $Revision: 1.33 $ $Date: 2005/06/30 16:23:58 $ */ import java.io.*; @@ -61,27 +61,6 @@ public class BeaninfoNature implements IProjectNature { public static final QualifiedName CONFIG_INFO_SESSION_KEY = new QualifiedName(BeaninfoPlugin.PI_BEANINFO_PLUGINID, "CONFIG_INFO"); //$NON-NLS-1$ public static final QualifiedName BEANINFO_CONTRIBUTORS_SESSION_KEY = new QualifiedName(BeaninfoPlugin.PI_BEANINFO_PLUGINID, "BEANINFO_CONTRIBUTORS"); //$NON-NLS-1$ - private ResourceTracker resourceTracker; - // This class listens for changes to the beaninfo paths file, and if changed it marks all stale - // so the next time anything is needed it will recycle the vm. It will also listen about to close or - // about to delete of the project so that it can cleanup. - private class ResourceTracker implements IResourceChangeListener{ - public void resourceChanged(IResourceChangeEvent e) { - // About to close or delete the project and it is ours, so we need to cleanup. - // Performance: It has been noted that dres.equals(...) can be slow with the number - // of visits done. Checking just the last segment (getName()) first before checking - // the entire resource provides faster testing. If the last segment is not equal, - // then the entire resource could not be equal. - IResource eventResource = e.getResource(); - if (eventResource.getName().equals(getProject().getName()) && eventResource.equals(getProject())) { - cleanup(false, true); // No need to clean up resources (false parm) because in this case Java EMF Model will always be going away. - return; - } - // Note: the BeaninfoModelSynchronizer takes care of both .classpath and .beaninfoconfig changes - // in this project and any required projects. - } - } - private ProxyFactoryRegistry.IRegistryListener registryListener = new ProxyFactoryRegistry.IRegistryListener() { /** * @see org.eclipse.jem.internal.proxy.core.ProxyFactoryRegistry.IRegistryListener#registryTerminated(ProxyFactoryRegistry) @@ -277,6 +256,9 @@ public class BeaninfoNature implements IProjectNature { * This should be called ONLY when this instance of the nature is no longer needed. It * will be recreated for any new uses. That is because we will be removing ourselves * from the list of active natures in the BeanInfoPlugin. + * <p> + * <b>Note:</b> This will be called from the BeanInfoCacheController. It knows when the project is + * being closed or deleted. * * @param clearResults clear the results such that any JEM model objects have no BeanInfo * adapters attached to them. This allows BeanInfo to be GC'd without being hung onto. @@ -284,11 +266,9 @@ public class BeaninfoNature implements IProjectNature { * @param deregister Deregister from the BeanInfoPlugin. Normally this will always be true, but it * will be called with false when BeanInfoPlugin is calling back to shutdown. */ - protected void cleanup(boolean clearResults, boolean deregister) { + public void cleanup(boolean clearResults, boolean deregister) { if (deregister) BeaninfoPlugin.getPlugin().removeBeanInfoNature(this); - getProject().getWorkspace().removeResourceChangeListener(resourceTracker); - resourceTracker = null; fSynchronizer.stopSynchronizer(clearResults); Init.cleanup(javaRSet, clearResults); if (fRegistry != null) @@ -318,6 +298,7 @@ public class BeaninfoNature implements IProjectNature { * @param project the project to which this nature applies */ public void setProject(IProject project) { +// BeanInfoCacheController.INSTANCE.getClass(); // Instantiates the controller if not already started. fProject = project; BeaninfoPlugin.getPlugin().addBeanInfoNature(this); @@ -353,9 +334,8 @@ public class BeaninfoNature implements IProjectNature { new BeaninfoModelSynchronizer( (BeaninfoAdapterFactory) EcoreUtil.getAdapterFactory(javaRSet.getAdapterFactories(), IIntrospectionAdapter.ADAPTER_KEY), JavaCore.create(javaNature.getProject())); - resourceTracker = new ResourceTracker(); - project.getWorkspace().addResourceChangeListener(resourceTracker, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE); } catch (CoreException e) { +e.printStackTrace(); BeaninfoPlugin.getPlugin().getLogger().log(e.getStatus()); } } diff --git a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeanInfoCacheController.java b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeanInfoCacheController.java index da7cb9c1f..cc9f3f69c 100644 --- a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeanInfoCacheController.java +++ b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeanInfoCacheController.java @@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: BeanInfoCacheController.java,v $ - * $Revision: 1.11 $ $Date: 2005/06/29 20:47:02 $ + * $Revision: 1.12 $ $Date: 2005/06/30 16:23:58 $ */ package org.eclipse.jem.internal.beaninfo.core; @@ -21,8 +21,7 @@ import java.util.logging.Level; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.common.notify.Adapter; -import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.*; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; @@ -34,7 +33,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.jdt.core.*; -import org.eclipse.jem.internal.beaninfo.adapters.BeaninfoClassAdapter; +import org.eclipse.jem.internal.beaninfo.adapters.*; +import org.eclipse.jem.internal.java.beaninfo.IIntrospectionAdapter; import org.eclipse.jem.java.JavaClass; import org.eclipse.jem.util.emf.workbench.ProjectResourceSet; import org.eclipse.jem.util.logger.proxy.Logger; @@ -124,6 +124,13 @@ public class BeanInfoCacheController { projectIndex.markDead(); cleanDirectory(getCacheDir(project).toFile(), true); } + BeaninfoNature nature = BeaninfoPlugin.getPlugin().getNature(project); + if (nature != null) { + BeaninfoAdapterFactory adapterFactory = (BeaninfoAdapterFactory) EcoreUtil.getAdapterFactory(nature.getResourceSet().getAdapterFactories(), IIntrospectionAdapter.ADAPTER_KEY); + if (adapterFactory != null) { + adapterFactory.markAllStale(); + } + } } catch (CoreException e) { // Shouldn't occur. } @@ -158,6 +165,14 @@ public class BeanInfoCacheController { // Shouldn't occur. } } + // Flow into PRE_CLOSE to release the nature. + case IResourceChangeEvent.PRE_CLOSE: + // About to close or delete, so release the nature, if any. + IProject project = (IProject) event.getResource(); + BeaninfoNature nature = BeaninfoPlugin.getPlugin().getNature(project); + if (nature != null) { + nature.cleanup(false, true); + } break; default: super.resourceChanged(event); @@ -165,7 +180,7 @@ public class BeanInfoCacheController { } } - }, IResourceChangeEvent.PRE_DELETE); + }, IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE); } protected SaveParticipant saveParticipant; diff --git a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeaninfoPlugin.java b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeaninfoPlugin.java index 42ec2ed21..0d1e73bb9 100644 --- a/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeaninfoPlugin.java +++ b/plugins/org.eclipse.jem.beaninfo/beaninfo/org/eclipse/jem/internal/beaninfo/core/BeaninfoPlugin.java @@ -11,7 +11,7 @@ package org.eclipse.jem.internal.beaninfo.core; /* * $RCSfile: BeaninfoPlugin.java,v $ - * $Revision: 1.15 $ $Date: 2005/05/18 20:59:17 $ + * $Revision: 1.16 $ $Date: 2005/06/30 16:23:58 $ */ @@ -72,13 +72,16 @@ public class BeaninfoPlugin extends Plugin { /* - * List of open natures. This list is needed because on shutdown of beaninfo plugin we need + * Map of open natures. This map is needed because on shutdown of beaninfo plugin we need * to shutdown the natures. If we don't do that there is a slight possibility of an error * because proxy plugin will shutdown and this can cause a callback into beaninfo which has * already been shutdown. It calls back through the registry listener that BeaninfoNature * added to the registry to notify that the registry is being shutdown. + * + * Also BeanInfoCacheController needs to know so that it can tell it the project is closing or + * being deleted or that it needs to be cleared due to a clear request. */ - private List openNatures; + private Map openNatures; private Map containerIdsToBeaninfoEntryContributions; private Map pluginToBeaninfoEntryContributions; @@ -654,8 +657,8 @@ public class BeaninfoPlugin extends Plugin { */ public void addBeanInfoNature(BeaninfoNature nature) { if (openNatures == null) - openNatures = new ArrayList(); - openNatures.add(nature); + openNatures = new HashMap(); + openNatures.put(nature.getProject(), nature); } /** @@ -669,17 +672,30 @@ public class BeaninfoPlugin extends Plugin { */ public void removeBeanInfoNature(BeaninfoNature nature) { if (openNatures != null) - openNatures.remove(nature); + openNatures.remove(nature.getProject()); } + /** + * Return the registered nature, if any, for the project. This will not cause the + * nature to be created. + * <p> + * <package-protected> because only BeanInfoCacheController should access it. + * @param project + * @return nature for project or <code>null</code> if not registered. + * + * @since 1.1.0 + */ + BeaninfoNature getNature(IProject project) { + return (BeaninfoNature) openNatures.get(project); + } /* (non-Javadoc) * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { - if (openNatures != null) { - for (int i = 0; i < openNatures.size(); i++) { - BeaninfoNature nature = (BeaninfoNature) openNatures.get(i); + if (openNatures != null && !openNatures.isEmpty()) { + for (Iterator natureItr = openNatures.values().iterator(); natureItr.hasNext();) { + BeaninfoNature nature = (BeaninfoNature) natureItr.next(); nature.shutdown(); } } |