Author: scabanovich
Date: 2012-01-06 12:11:30 -0500 (Fri, 06 Jan 2012)
New Revision: 37682
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIProjectTree.java
Log:
JBIDE-10586
https://issues.joss.org/browse/JBIDE-10586
Tests are added.
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java 2012-01-06
14:23:15 UTC (rev 37681)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java 2012-01-06
17:11:30 UTC (rev 37682)
@@ -470,8 +470,12 @@
}
}
} else {
+ try {
IType[] ts = unit.getTypes();
fileSet.add(f.getFullPath(), ts);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2012-01-06
14:23:15 UTC (rev 37681)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2012-01-06
17:11:30 UTC (rev 37682)
@@ -25,11 +25,8 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
@@ -46,10 +43,8 @@
import org.jboss.tools.common.util.EclipseJavaUtil;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.common.validation.internal.ProjectValidationContext;
-import org.jboss.tools.common.xml.XMLUtilities;
import org.jboss.tools.jst.web.kb.KbProjectFactory;
-import org.jboss.tools.jst.web.kb.WebKbPlugin;
-import org.w3c.dom.Element;
+import org.jboss.tools.jst.web.kb.internal.KbProject;
public class CDICoreNature implements IProjectNature {
public static String NATURE_ID = "org.jboss.tools.cdi.core.cdinature";
@@ -87,14 +82,7 @@
public void deconfigure() throws CoreException {
removeFromBuildSpec(CDICoreBuilder.BUILDER_ID);
- CDICoreNature[] ds = dependsOn.toArray(new CDICoreNature[0]);
- for (CDICoreNature d: ds) {
- removeCDIProject(d);
- }
- CDICoreNature[] us = usedBy.toArray(new CDICoreNature[0]);
- for (CDICoreNature u: us) {
- u.removeCDIProject(this);
- }
+ dispose();
}
public IProject getProject() {
@@ -267,13 +255,23 @@
return usedBy;
}
- public CDICoreNature[] getAllDependentProjects() {
+ public CDICoreNature[] getAllDependentProjects(boolean resolve) {
Map<CDICoreNature, Integer> set = new HashMap<CDICoreNature, Integer>();
getAllDependentProjects(set, 0);
+ if(resolve) {
+ for (CDICoreNature n: set.keySet()) {
+ n.resolve();
+ }
+ }
CDICoreNature[] result = set.keySet().toArray(new CDICoreNature[set.size()]);
Arrays.sort(result, new D(set));
return result;
}
+
+ public CDICoreNature[] getAllDependentProjects() {
+ return getAllDependentProjects(false);
+ }
+
private void getAllDependentProjects(Map<CDICoreNature, Integer> result, int
level) {
if(level > 10) return;
for (CDICoreNature n:usedBy) {
@@ -583,56 +581,51 @@
if(projectDependenciesLoaded) return;
projectDependenciesLoaded = true;
}
- Element root = null;
- File file = getKBStorageFile();
- if(file != null && file.isFile()) {
- root = XMLUtilities.getElement(file, null);
- if(root != null) {
- loadProjectDependencies(root);
- }
- }
+ _loadProjectDependencies();
}
- private File getKBStorageFile() {
- IPath path = WebKbPlugin.getDefault().getStateLocation();
- File file = new File(path.toFile(), "projects/" + project.getName() +
".xml"); //$NON-NLS-1$ //$NON-NLS-2$
- return file;
- }
-
- private void loadProjectDependencies(Element root) {
- Element dependsOnElement = XMLUtilities.getUniqueChild(root,
"depends-on-projects"); //$NON-NLS-1$
- if(dependsOnElement != null) {
- Element[] paths = XMLUtilities.getChildren(dependsOnElement, "project");
//$NON-NLS-1$
- for (int i = 0; i < paths.length; i++) {
- String p = paths[i].getAttribute("name"); //$NON-NLS-1$
- if(p == null || p.trim().length() == 0) continue;
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(p);
- if(project == null || !project.isAccessible()) continue;
- KbProjectFactory.getKbProject(project, true, true);
- CDICoreNature sp = CDICorePlugin.getCDI(project, false);
- if(sp != null) {
- addUsedCDIProject(sp);
- sp.addDependentCDIProject(this);
- }
+ private void _loadProjectDependencies() {
+ KbProject kb = (KbProject)KbProjectFactory.getKbProject(project, true, true);
+
+ if(kb == null) {
+ return;
+ }
+
+ Set<KbProject> ps = kb.getKbProjects();
+
+ for (KbProject kb1: ps) {
+ IProject project = kb1.getProject();
+ if(project == null || !project.isAccessible()) continue;
+ KbProjectFactory.getKbProject(project, true, true);
+ CDICoreNature sp = CDICorePlugin.getCDI(project, false);
+ if(sp != null) {
+ addUsedCDIProject(sp);
+ sp.addDependentCDIProject(this);
}
}
+
+ KbProject[] ps2 = kb.getDependentKbProjects();
- Element usedElement = XMLUtilities.getUniqueChild(root, "used-by-projects");
//$NON-NLS-1$
- if(usedElement != null) {
- Element[] paths = XMLUtilities.getChildren(usedElement, "project");
//$NON-NLS-1$
- for (int i = 0; i < paths.length; i++) {
- String p = paths[i].getAttribute("name"); //$NON-NLS-1$
- if(p == null || p.trim().length() == 0) continue;
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(p);
- if(project == null || !project.isAccessible()) continue;
- KbProjectFactory.getKbProject(project, true, true);
- CDICoreNature sp = CDICorePlugin.getCDI(project, false);
- if(sp != null) {
- addDependentCDIProject(sp);
- }
+ for (KbProject kb2: ps2) {
+ IProject project = kb2.getProject();
+ if(project == null || !project.isAccessible()) continue;
+ KbProjectFactory.getKbProject(project, true, true);
+ CDICoreNature sp = CDICorePlugin.getCDI(project, false);
+ if(sp != null) {
+ addDependentCDIProject(sp);
}
}
-
}
+ public void dispose() {
+ CDICoreNature[] ds = dependsOn.toArray(new CDICoreNature[0]);
+ for (CDICoreNature d: ds) {
+ removeCDIProject(d);
+ }
+ CDICoreNature[] us = usedBy.toArray(new CDICoreNature[0]);
+ for (CDICoreNature u: us) {
+ u.removeCDIProject(this);
+ }
+ }
+
}
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java 2012-01-06
14:23:15 UTC (rev 37681)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICorePlugin.java 2012-01-06
17:11:30 UTC (rev 37682)
@@ -15,6 +15,11 @@
import java.util.List;
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.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.jboss.tools.cdi.internal.core.event.CDIProjectChangeEvent;
@@ -39,6 +44,7 @@
* The constructor
*/
public CDICorePlugin() {
+ plugin = this;
}
/*
@@ -47,7 +53,7 @@
*/
public void start(BundleContext context) throws Exception {
super.start(context);
- plugin = this;
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
}
/*
@@ -55,10 +61,35 @@
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- plugin = null;
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
super.stop(context);
}
+ 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) {
+ IProject p = (IProject)r;
+ CDICoreNature n = (CDICoreNature)getCDINature(p);
+ 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();
+ getCDI(p, true);
+ }
+ }
+ }
+ }
+ }
/**
* Returns the shared instance
*
@@ -93,7 +124,7 @@
return null;
}
- public static CDICoreNature getCDI(IProject project, boolean resolve) {
+ private static CDICoreNature getCDINature(IProject project) {
if(project == null || !project.exists() || !project.isOpen()) return null;
try {
if(!project.hasNature(CDICoreNature.NATURE_ID)) return null;
@@ -104,13 +135,20 @@
CDICoreNature n = null;
try {
n = (CDICoreNature)project.getNature(CDICoreNature.NATURE_ID);
+ } catch (CoreException e) {
+ getDefault().logError(e);
+ }
+ return n;
+ }
+
+ public static CDICoreNature getCDI(IProject project, boolean resolve) {
+ CDICoreNature n = getCDINature(project);
+ if(n != null) {
if(resolve) {
n.resolve();
} else {
n.loadProjectDependencies();
}
- } catch (CoreException e) {
- getDefault().logError(e);
}
return n;
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2012-01-06
14:23:15 UTC (rev 37681)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2012-01-06
17:11:30 UTC (rev 37682)
@@ -882,7 +882,7 @@
CDICorePlugin.getCDI(p, true);
}
}
- CDICoreNature[] ns = getNature().getAllDependentProjects();
+ CDICoreNature[] ns = getNature().getAllDependentProjects(true);
for (CDICoreNature n: ns) {
if(n.getDelegate() instanceof CDIProject) {
CDIProject p = (CDIProject)n.getDelegate();
@@ -956,7 +956,7 @@
CDICorePlugin.getCDI(p, true);
}
}
- CDICoreNature[] ns = getNature().getAllDependentProjects();
+ CDICoreNature[] ns = getNature().getAllDependentProjects(true);
for (CDICoreNature n: ns) {
if(n.getDelegate() instanceof CDIProject) {
CDIProject p = (CDIProject)n.getDelegate();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIProjectTree.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIProjectTree.java 2012-01-06
14:23:15 UTC (rev 37681)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIProjectTree.java 2012-01-06
17:11:30 UTC (rev 37682)
@@ -109,7 +109,7 @@
private Set<CDICoreNature> getRootProjects(CDICoreNature project) {
Set<CDICoreNature> result = new HashSet<CDICoreNature>();
- CDICoreNature[] dependentProjects = project.getAllDependentProjects();
+ CDICoreNature[] dependentProjects = project.getAllDependentProjects(true);
if(dependentProjects.length == 0) {
result.add(project);
} else {