Author: scabanovich
Date: 2012-01-06 13:03:03 -0500 (Fri, 06 Jan 2012)
New Revision: 37685
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
Log:
JBIDE-10583
https://issues.joss.org/browse/JBIDE-10583
Processed pre-delete and pre-close project events to clean dependencies.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2012-01-06
17:34:37 UTC (rev 37684)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2012-01-06
18:03:03 UTC (rev 37685)
@@ -6,6 +6,10 @@
import java.util.Set;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -39,6 +43,7 @@
* The constructor
*/
public WebKbPlugin() {
+ plugin = this;
}
/*
@@ -47,7 +52,7 @@
*/
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
ResourcesPlugin.getWorkspace().addSaveParticipant(PLUGIN_ID, new ISaveParticipant() {
@@ -73,8 +78,6 @@
KbProject sp = (KbProject)KbProjectFactory.getKbProject(context.getProject(),
false, true);
try {
if(sp != null && sp.getModificationsSinceLastStore() > 0) {
-// sp.printModifications();
- //Not any project is a seam project
sp.store();
}
} catch (IOException e) {
@@ -101,7 +104,9 @@
private void cleanObsoleteFiles() {
IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
Set<String> projectNames = new HashSet<String>();
- for (IProject p: ps) projectNames.add(p.getName());
+ for (IProject p: ps) {
+ projectNames.add(p.getName());
+ }
WebKbPlugin plugin = WebKbPlugin.getDefault();
if(plugin!=null) {
IPath path = plugin.getStateLocation();
@@ -125,14 +130,34 @@
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
super.stop(context);
-
- // Fix for JBIDE-7621: The following line is moved to the very end of the method
- // due to prevent NullPointerException to be thrown in cleanObsoleteFiles() method
--->>>
- plugin = null;
- // <<<---
}
+ IResourceChangeListener resourceChangeListener = new RCL();
+
+ class RCL implements IResourceChangeListener {
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ if(event.getType() == IResourceChangeEvent.PRE_DELETE || event.getType() ==
IResourceChangeEvent.PRE_CLOSE) {
+ IResource r = event.getResource();
+ if(r instanceof IProject) {
+ KbProject n = (KbProject)KbProjectFactory.getKbProject((IProject)r, false, true);
+ if(n != null) {
+ n.dispose();
+ }
+ }
+ } else if(event.getType() == IResourceChangeEvent.POST_CHANGE) {
+ IResourceDelta[] cs = event.getDelta().getAffectedChildren(IResourceDelta.CHANGED);
+ for (IResourceDelta c: cs) {
+ if((c.getFlags() & IResourceDelta.OPEN) != 0 && c.getResource()
instanceof IProject) {
+ IProject p = (IProject)c.getResource();
+ KbProjectFactory.getKbProject(p, true, true);
+ }
+ }
+ }
+ }
+ }
/**
* Returns the shared instance
*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2012-01-06
17:34:37 UTC (rev 37684)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/KbProject.java 2012-01-06
18:03:03 UTC (rev 37685)
@@ -141,6 +141,8 @@
*/
public void deconfigure() throws CoreException {
removeFromBuildSpec(KbBuilder.BUILDER_ID);
+ dispose();
+ clearStorage();
}
/*
@@ -219,7 +221,7 @@
}
}
- KbProject[] getDependentKbProjects() {
+ public KbProject[] getDependentKbProjects() {
synchronized (usedBy) {
return usedBy.toArray(new KbProject[0]);
}
@@ -336,7 +338,9 @@
} finally {
fireChanges();
- modifications = 0;
+ if(getStorageFile() != null && getStorageFile().exists()) {
+ modifications = 0;
+ }
}
}
@@ -1088,4 +1092,17 @@
public void setExtensionModel(String id, Object model) {
extensionModels.put(id, model);
}
+
+ public void dispose() {
+ KbProject[] ds = dependsOn.toArray(new KbProject[0]);
+ for (KbProject p: ds) {
+ removeKbProject(p);
+ }
+ KbProject[] us = usedBy.toArray(new KbProject[0]);
+ for (KbProject p: us) {
+ p.removeKbProject(this);
+ }
+ modifications++;
+ }
+
}
\ No newline at end of file