Author: scabanovich
Date: 2009-12-07 07:58:44 -0500 (Mon, 07 Dec 2009)
New Revision: 19076
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/internal/core/impl/definition/DefinitionContext.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/CDIBuilderDelegate.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/FileSet.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4943
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 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreBuilder.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -25,13 +25,20 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceVisitor;
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.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.cdi.internal.core.scanner.CDIBuilderDelegate;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
@@ -128,7 +135,10 @@
}
if(n.getClassPath().update()) {
- n.getClassPath().process();
+ List<String> newJars = n.getClassPath().process();
+ buildJars(newJars);
+
+ n.getClassPath().validateProjectDependencies();
} else if(n.getClassPath().hasToUpdateProjectDependencies()) {
n.getClassPath().validateProjectDependencies();
}
@@ -166,6 +176,7 @@
CDIResourceVisitor rv = getResourceVisitor();
getProject().accept(rv);
FileSet fs = rv.fileSet;
+ builderDelegate.build(fs, getCDICoreNature());
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
@@ -180,6 +191,31 @@
builderDelegate.build(fs, getCDICoreNature());
}
+ protected void buildJars(List<String> newJars) throws CoreException {
+ IJavaProject jp = EclipseResourceUtil.getJavaProject(getCDICoreNature().getProject());
+ if(jp == null) return;
+ FileSet fileSet = new FileSet();
+
+ for (String jar: newJars) {
+ Path path = new Path(jar);
+ IPackageFragmentRoot root = jp.getPackageFragmentRoot(jar);
+ if (root == null || !root.exists())
+ return;
+ IJavaElement[] es = root.getChildren();
+ for (IJavaElement e : es) {
+ if (e instanceof IPackageFragment) {
+ IPackageFragment pf = (IPackageFragment) e;
+ IClassFile[] cs = pf.getClassFiles();
+ for (IClassFile c : cs) {
+ fileSet.add(path, c.getType());
+ }
+ }
+ }
+ //TODO add beans.xml object
+ }
+ builderDelegate.build(fileSet, getCDICoreNature());
+ }
+
protected void clean(IProgressMonitor monitor) throws CoreException {
CDICoreNature n = getCDICoreNature();
if(n != null) n.clean();
@@ -259,20 +295,14 @@
if(f.getName().endsWith(".java")) {
ICompilationUnit unit = EclipseUtil.getCompilationUnit(f);
IType[] ts = unit.getTypes();
- if(ts == null || ts.length == 0) {
- fileSet.getNonModelFiles().add(f);
- } else if(findPublicAnnotation(ts) != null) {
- fileSet.getAnnotations().put(f, unit);
- } else if(findPublicInterface(ts) != null) {
- fileSet.getInterfaces().put(f, unit);
- }
+ fileSet.add(f.getFullPath(), ts);
}
return false;
}
}
if(webinf != null && webinf.isPrefixOf(path)) {
if(f.getName().equals("beans.xml")) {
- fileSet.setBeanXML(f);
+ fileSet.setBeanXML(f.getFullPath(), f); //file
}
}
}
@@ -304,21 +334,5 @@
}
- static IType findPublicAnnotation(IType[] ts) throws JavaModelException {
- for (IType t: ts) {
- if(t.isAnnotation()) {
- return t;
- }
- }
- return null;
- }
- static IType findPublicInterface(IType[] ts) throws JavaModelException {
- for (IType t: ts) {
- if(t.isInterface()) {
- return t;
- }
- }
- return null;
- }
}
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 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/core/CDICoreNature.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.cdi.internal.core.impl.definition.DefinitionContext;
import org.jboss.tools.cdi.internal.core.scanner.lib.ClassPathMonitor;
import org.jboss.tools.common.util.FileUtil;
@@ -32,7 +33,10 @@
ICDIProject cdiProjectDelegate;
ClassPathMonitor classPath = new ClassPathMonitor(this);
+ DefinitionContext definitions = new DefinitionContext();
+ boolean isBuilt = false;
+
Map<IPath, Object> sourcePaths2 = new HashMap<IPath, Object>(); //TODO
private boolean isStorageResolved = false;
@@ -60,6 +64,10 @@
this.cdiProjectDelegate = cdiProject;
}
+ public DefinitionContext getDefinitions() {
+ return definitions;
+ }
+
public ICDIProject getDelegate() {
return cdiProjectDelegate;
}
@@ -120,6 +128,7 @@
if(file != null && file.isFile()) {
file.delete();
}
+ isBuilt = false;
classPath.clean();
postponeFiring();
IPath[] ps = sourcePaths2.keySet().toArray(new IPath[0]);
@@ -135,10 +144,10 @@
* @throws IOException
*/
public void store() throws IOException {
+ isBuilt = true;
File file = getStorageFile();
- file.getParentFile().mkdirs();
-
- //TODO
+//TODO
+// file.getParentFile().mkdirs();
}
/**
*
@@ -216,6 +225,7 @@
}
public boolean hasNoStorage() {
+ if(isBuilt) return false;
File f = getStorageFile();
return f == null || !f.exists();
}
@@ -232,6 +242,7 @@
public List<Long> statistics;
public void pathRemoved(IPath source) {
+ definitions.clean(source);
//TODO
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/definition/DefinitionContext.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -22,6 +22,16 @@
public DefinitionContext() {}
+ public DefinitionContext copy() {
+ DefinitionContext copy = new DefinitionContext();
+ copy.project = project;
+ copy.javaProject = javaProject;
+ copy.types.addAll(types);
+ copy.typeDefinitions.putAll(typeDefinitions);
+
+ return copy;
+ }
+
public void setProject(CDICoreNature project) {
this.project = project;
javaProject = EclipseResourceUtil.getJavaProject(project.getProject());
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/CDIBuilderDelegate.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/CDIBuilderDelegate.java 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/CDIBuilderDelegate.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -1,10 +1,12 @@
package org.jboss.tools.cdi.internal.core.scanner;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IType;
@@ -32,33 +34,26 @@
}
public void build(FileSet fileSet, CDICoreNature projectNature) {
- //TODO get context from projectNature
- DefinitionContext context = new DefinitionContext();
+ DefinitionContext context = projectNature.getDefinitions().copy();
+ Set<IPath> ps = fileSet.getAllPaths();
+ for (IPath p: ps) context.clean(p);
context.setProject(projectNature);
- Map<IFile, ICompilationUnit> as = fileSet.getAnnotations();
- for (IFile f: as.keySet()) {
- ICompilationUnit u = as.get(f);
- IType[] ts = null;
- try {
- ts = u.getTypes();
- if(ts != null) for (int i = 0; i < ts.length; i++) {
- if(ts[i].isAnnotation()) {
- //this builds annotation definition
- context.getAnnotationKind(ts[i]);
- }
- }
- } catch (CoreException e) {
- CDICorePlugin.getDefault().logError(e);
+ Map<IPath, Set<IType>> as = fileSet.getAnnotations();
+ for (IPath f: as.keySet()) {
+ Set<IType> ts = as.get(f);
+ for (IType type: ts) {
+ //this builds annotation definition
+ context.getAnnotationKind(type);
}
}
- Map<IFile, ICompilationUnit> is = fileSet.getInterfaces();
- for (IFile f: is.keySet()) {
-
+ Map<IPath, Set<IType>> is = fileSet.getInterfaces();
+ for (IPath f: is.keySet()) {
+ //TODO
}
- Map<IFile, ICompilationUnit> cs = fileSet.getClasses();
- for (IFile f: cs.keySet()) {
+ Map<IPath, Set<IType>> cs = fileSet.getClasses();
+ for (IPath f: cs.keySet()) {
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/FileSet.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/FileSet.java 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/FileSet.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -5,37 +5,85 @@
import java.util.Map;
import java.util.Set;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IType;
public class FileSet {
- Set<IFile> nonmodel = new HashSet<IFile>();
- Map<IFile, ICompilationUnit> annotations = new HashMap<IFile,
ICompilationUnit>();
- Map<IFile, ICompilationUnit> interfaces = new HashMap<IFile,
ICompilationUnit>();
- Map<IFile, ICompilationUnit> classes = new HashMap<IFile,
ICompilationUnit>();
- IFile beansXML = null;
+ Set<IPath> allpaths = new HashSet<IPath>();
+ Set<IPath> nonmodel = new HashSet<IPath>();
+ Map<IPath, Set<IType>> annotations = new HashMap<IPath,
Set<IType>>();
+ Map<IPath, Set<IType>> interfaces = new HashMap<IPath,
Set<IType>>();
+ Map<IPath, Set<IType>> classes = new HashMap<IPath,
Set<IType>>();
+ Map<IPath, Object> beanXMLs = new HashMap<IPath, Object>();
- public Set<IFile> getNonModelFiles() {
+ public FileSet() {}
+
+ public void add(IPath path, IType[] types) throws CoreException {
+ allpaths.add(path);
+ if(types == null || types.length == 0) {
+ nonmodel.add(path);
+ } else {
+ for (IType type: types) {
+ add(path, type);
+ }
+ }
+ }
+ public void add(IPath path, IType type) throws CoreException {
+ if(type == null) return;
+ allpaths.add(path);
+ if(type.isAnnotation()) {
+ add(annotations, path, type);
+ } else if(type.isInterface()) {
+ add(interfaces, path, type);
+ } else {
+ add(classes, path, type);
+ IType[] ts = type.getTypes();
+ for (IType t: ts) {
+ if(Flags.isStatic(t.getFlags())) {
+ add(path, t);
+ }
+ }
+ }
+ }
+
+ private void add(Map<IPath, Set<IType>> target, IPath path, IType type) {
+ Set<IType> ts = target.get(path);
+ if(ts == null) {
+ ts = new HashSet<IType>();
+ target.put(path, ts);
+ }
+ ts.add(type);
+ }
+
+ public Set<IPath> getAllPaths() {
+ return allpaths;
+ }
+
+ public Set<IPath> getNonModelFiles() {
return nonmodel;
}
-
- public Map<IFile, ICompilationUnit> getAnnotations() {
+
+ public Map<IPath, Set<IType>> getAnnotations() {
return annotations;
}
- public Map<IFile, ICompilationUnit> getInterfaces() {
+ public Map<IPath, Set<IType>> getInterfaces() {
return interfaces;
}
- public Map<IFile, ICompilationUnit> getClasses() {
+ public Map<IPath, Set<IType>> getClasses() {
return classes;
}
- public IFile getBeanXML() {
- return beansXML;
+ public Object getBeanXML(IPath f) {
+ return beanXMLs.get(f);
}
- public void setBeanXML(IFile f) {
- beansXML = f;
+ public void setBeanXML(IPath f, Object o) {
+ beanXMLs.put(f, o);
}
+
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java 2009-12-07
12:37:53 UTC (rev 19075)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/scanner/lib/ClassPathMonitor.java 2009-12-07
12:58:44 UTC (rev 19076)
@@ -10,10 +10,20 @@
******************************************************************************/
package org.jboss.tools.cdi.internal.core.scanner.lib;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Path;
import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.project.ext.AbstractClassPathMonitor;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.jst.web.kb.internal.scanner.LibraryScanner;
+import org.jboss.tools.jst.web.kb.internal.scanner.LoadedDeclarations;
+import org.jboss.tools.jst.web.kb.internal.scanner.ScannerException;
public class ClassPathMonitor extends AbstractClassPathMonitor<CDICoreNature>{
@@ -29,8 +39,32 @@
//TODO
}
- public void process() {
- //TODO
+ public List<String> process() {
+ List<String> newJars = new ArrayList<String>();
+ Iterator<String> it = processedPaths.iterator();
+ while(it.hasNext()) {
+ String p = it.next();
+ if(paths.contains(p)) continue;
+ project.pathRemoved(new Path(p));
+ it.remove();
+ }
+ for (int i = 0; i < paths.size(); i++) {
+ String p = paths.get(i);
+ if(processedPaths.contains(p)) continue;
+ processedPaths.add(p);
+
+ String fileName = new File(p).getName();
+ if(EclipseResourceUtil.SYSTEM_JAR_SET.contains(fileName)) continue;
+ String jsname = "lib-" + fileName; //$NON-NLS-1$
+ XModelObject o = model.getByPath("FileSystems").getChildByPath(jsname);
//$NON-NLS-1$
+ if(o == null) continue;
+ XModelObject b = o.getChildByPath("META-INF/beans.xml");
+ if(b == null) continue;
+ newJars.add(p);
+ }
+
+ return newJars;
+// validateProjectDependencies();
}
public boolean hasToUpdateProjectDependencies() {