You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2009/02/11 00:20:18 UTC

svn commit: r743162 - in /openejb/trunk/sandbox/openejb-eclipse-plugin: pde-test/ plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/ plug...

Author: jgallimore
Date: Tue Feb 10 23:20:17 2009
New Revision: 743162

URL: http://svn.apache.org/viewvc?rev=743162&view=rev
Log:
OEP-15 made singleton dep finder more incremental

Added:
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java   (with props)
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java   (with props)
Modified:
    openejb/trunk/sandbox/openejb-eclipse-plugin/pde-test/test.xml
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Activator.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Dependency.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/IncrementalProjectBuilder.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/MethodCall.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/SingletonDependencyFinder.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/CompilationUnitCache.java
    openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.helper.annotation.test/src/main/resources/org/apache/openejb/helper/annotation/tests/ExpectedSessionBean.txt

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/pde-test/test.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/pde-test/test.xml?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/pde-test/test.xml (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/pde-test/test.xml Tue Feb 10 23:20:17 2009
@@ -38,7 +38,7 @@
 	<target name="linux">
 		<property name="os" value="linux"/>
 		<property name="ws" value="gtk"/>
-		<property name="arch" value="x86"/>
+		<property name="arch" value="x86_64"/>
 		
 		<ant target="run" antfile="test.xml"/>
 	</target>

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Activator.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Activator.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Activator.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Activator.java Tue Feb 10 23:20:17 2009
@@ -99,4 +99,8 @@
 		} catch (CoreException e) {
 		}
 	}
+
+	public Model getModel() {
+		return new Model();
+	}
 }

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Dependency.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Dependency.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Dependency.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Dependency.java Tue Feb 10 23:20:17 2009
@@ -17,10 +17,12 @@
 
 package org.apache.openejb.builder;
 
+import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
-public class Dependency {
+public class Dependency implements Serializable {
 	private String dependsOn;
 	private List<MethodCall> path = new ArrayList<MethodCall>();
 	
@@ -39,4 +41,20 @@
 	public void addMethodCall(MethodCall methodCall) {
 		path.add(0, methodCall);
 	}
+
+	public boolean touches(String fullyQualifiedName) {
+		Iterator<MethodCall> iterator = path.iterator();
+		while (iterator.hasNext()) {
+			MethodCall methodCall = (MethodCall) iterator.next();
+			if (methodCall.getClassName().equals(fullyQualifiedName)) {
+				return true;
+			}
+		}
+		
+		return false;
+	}
+
+	public Iterator<MethodCall> getMethodCalls() {
+		return path.iterator();
+	}
 }

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/IncrementalProjectBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/IncrementalProjectBuilder.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/IncrementalProjectBuilder.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/IncrementalProjectBuilder.java Tue Feb 10 23:20:17 2009
@@ -18,127 +18,278 @@
 package org.apache.openejb.builder;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.openejb.devtools.core.CompilationUnitCache;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.Path;
+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.ISourceRange;
 import org.eclipse.jdt.core.IType;
 import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jdt.core.dom.CompilationUnit;
 import org.eclipse.jdt.core.dom.IAnnotationBinding;
 import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
 import org.eclipse.jdt.core.dom.TypeDeclaration;
 
 public class IncrementalProjectBuilder extends org.eclipse.core.resources.IncrementalProjectBuilder {
 
+	public static final String MARKER_TYPE_DEPENDS_ON = "org.apache.openejb.builder.dependsonMarker";
+	private Model model;
+	private CompilationUnitCache cache;
+
 	public IncrementalProjectBuilder() {
+		model = Activator.getPlugin().getModel();
+		cache = new CompilationUnitCache(JavaCore.create(getProject()));
 	}
 
 	@SuppressWarnings("unchecked")
 	@Override
 	protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
-		getProject().deleteMarkers("org.apache.openejb.builder.dependsonMarker", true, IResource.DEPTH_INFINITE);
+		cache.clear();
+		ProjectModel projectModel = model.getModel(getProject());
 		
-		CompilationUnitCache cache = new CompilationUnitCache(JavaCore.create(getProject()));
-		try {
-			SingletonDependencyFinder finder = new SingletonDependencyFinder(getProject());
-			finder.findDependencies();
-			
-			String[] singletons = finder.getSingletons();
-			IJavaProject javaProject = JavaCore.create(getProject());
-			
-			for (String singleton : singletons) {
-				IType type = javaProject.findType(singleton);
-				ISourceRange sourceRange = type.getSourceRange();
-				
-				CompilationUnit compilationUnit = cache.getCompilationUnit(type.getCompilationUnit());
-				TypeDeclaration typeDeclaration = cache.getTypeDeclaration(type);
-				IAnnotationBinding[] annotations = typeDeclaration.resolveBinding().getAnnotations();
-				
-				List<String> declaredDependencies = new ArrayList<String>();
+		if (projectModel.getDependencies() == null || projectModel.getDependencies().size() == 0) {
+			performFullBuild();
+			return new IProject[] { getProject() };
+		}
+
+		if (kind != org.eclipse.core.resources.IncrementalProjectBuilder.INCREMENTAL_BUILD && kind != org.eclipse.core.resources.IncrementalProjectBuilder.AUTO_BUILD) {
+			performFullBuild();
+			return new IProject[] { getProject() };
+		}
+
+		performIncrementalBuild();
+		return new IProject[] { getProject() };
+	}
+
+	private void performIncrementalBuild() throws CoreException {
+		final ProjectModel projectModel = model.getModel(getProject());
+		
+		IResourceDelta delta = getDelta(getProject());
+		delta.accept(new IResourceDeltaVisitor() {
+
+			public boolean visit(IResourceDelta delta) throws CoreException {
+				if (delta.getResource() instanceof IFolder) {
+					return true;
+				}
 				
-				for (IAnnotationBinding annotation : annotations) {
-					if ("javax.ejb.DependsOn".equals(annotation.getAnnotationType().getQualifiedName())) {
-						IMemberValuePairBinding[] pairs = annotation.getDeclaredMemberValuePairs();
-						for (int i = 0; i < pairs.length; i++) { 
-							if ("value".equals(pairs[i].getName())) {
-								if (pairs[i].getValue() instanceof Object[]) {
-									Object[] values = (Object[]) pairs[i].getValue();
-									for (int j = 0; j < values.length; j++) {
-										declaredDependencies.add(values[j].toString());
-									}
+				IJavaProject javaProject = JavaCore.create(getProject());
+				IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
+				IPath path = delta.getFullPath();
+
+				for (IClasspathEntry classpathEntry : rawClasspath) {
+					if (IClasspathEntry.CPE_SOURCE == classpathEntry.getEntryKind()) {
+						if (classpathEntry.getPath().isPrefixOf(path)) {
+							StringBuffer pathBuffer = new StringBuffer();
+							for (int i = classpathEntry.getPath().segments().length; i < path.segments().length; i++) {
+								if (i > classpathEntry.getPath().segments().length) {
+									pathBuffer.append(IPath.SEPARATOR);
 								}
+								
+								pathBuffer.append(path.segment(i));
 							}
+							
+							path = Path.fromOSString(pathBuffer.toString());
 						}
 					}
 				}
-
-				Dependency[] dependencies = finder.getDependencies(singleton);
-				List<String> expectedDependencies = new ArrayList<String>();
-
-				if (dependencies != null) {
-					for (Dependency dependency : dependencies) {
-						expectedDependencies.add(dependency.getDependsOn());
-					}
+				// this is the project
+				if (path.segmentCount() == 1) {
+					return true;
 				}
 				
-				boolean matches = expectedDependencies.size() == declaredDependencies.size();
-
-				if (matches) {
-					for (String dependency : declaredDependencies) {
-						if (! expectedDependencies.contains(dependency)) {
-							matches = false;
-							break;
+				try {
+					IJavaElement element = javaProject.findElement(path);
+					
+					if (element instanceof ICompilationUnit) {
+						ICompilationUnit compilationUnit = (ICompilationUnit) element;
+						IType[] types = compilationUnit.getTypes();
+						
+						for (IType type : types) {
+							if (isSingleton(type)) {
+								updateInterfaces(type.getFullyQualifiedName());
+							}
+							
+							List<String> singletons = projectModel.getBeansDependentOn(type.getFullyQualifiedName());
+							for (String singleton : singletons) {
+								try {
+									checkDependency(singleton);
+								} catch (SingletonDependencyFinderException e) {
+								}
+							}
 						}
 					}
+				} catch (Exception e) {
 				}
-				
-				if (! matches) {
-					IMarker marker = type.getUnderlyingResource().createMarker("org.apache.openejb.builder.dependsonMarker");
-					Map attributes = new HashMap();
-					
-					attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
-					attributes.put(IMarker.CHAR_START, sourceRange.getOffset());
-					attributes.put(IMarker.CHAR_END, sourceRange.getOffset() + sourceRange.getLength());
-					attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
-					attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
-					attributes.put(IMarker.MESSAGE, expectedDependencies.size() == 0 ? "This bean should not have the @DependsOn annotation" : "This bean requires the @DependsOn annotation, and depends on: " + getDependencyList(expectedDependencies));
-					attributes.put(ISingletonDependencyMarker.DEPENDENCIES, expectedDependencies.toArray(new String[expectedDependencies.size()]));
-					attributes.put(ISingletonDependencyMarker.BEAN, singleton);
-					marker.setAttributes(attributes);
-				}
+
+				return true;
+			}
+		});
+	}
+
+	protected void updateInterfaces(String singleton) {
+		try {
+			ProjectModel projectModel = model.getModel(getProject());
+			SingletonDependencyFinder finder = new SingletonDependencyFinder(projectModel);
+			List<String> interfaces = finder.getInterfacesFor(singleton);
+			projectModel.setSingletonBeanInterfaces(singleton, interfaces);
+		} catch (SingletonDependencyFinderException e) {
+			e.printStackTrace();
+		}
+	}
+
+	protected boolean isSingleton(IType type) {
+		TypeDeclaration typeDeclaration = cache.getTypeDeclaration(type);
+		ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+		
+		IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+		for (IAnnotationBinding annotation : annotations) {
+			String qualifiedName = annotation.getAnnotationType().getQualifiedName();
+			if ("javax.ejb.Singleton".equals(qualifiedName)) {
+				return true;
+			}
+		}
+		
+		return false;
+	}
+
+	
+	protected void performFullBuild() throws CoreException, JavaModelException {
+		ProjectModel projectModel = model.getModel(getProject());
+		projectModel.clear();
+		
+		getProject().deleteMarkers(MARKER_TYPE_DEPENDS_ON, true, IResource.DEPTH_INFINITE);
+
+		try {
+			SingletonDependencyFinder finder = new SingletonDependencyFinder(projectModel);
+			String[] singletons = finder.findSingletons();
+
+			for (String singleton : singletons) {
+				List<String> interfaces = finder.getInterfacesFor(singleton);
+				projectModel.setSingletonBeanInterfaces(singleton, interfaces);
 			}
 			
+			for (String singleton : singletons) {				
+				checkDependency(singleton);
+			}
+
 		} catch (SingletonDependencyFinderException e) {
-			throw new CoreException(new Status(IStatus.ERROR, "org.apache.openejb.builder", e.getMessage(), e));
 		}
+	}
+
+	private void checkDependency(String singleton) throws JavaModelException, CoreException, SingletonDependencyFinderException {
+		ProjectModel projectModel = model.getModel(getProject());
+		removeMarkersFor(singleton);
 		
-		return new IProject[] { getProject() };
+		List<String> interfacesToSearchFor = projectModel.getInterfacesToSearchFor(singleton);
+		
+		IJavaProject javaProject = JavaCore.create(getProject());
+		SingletonDependencyFinder finder = new SingletonDependencyFinder(projectModel);
+		Dependency[] dependencies = finder.findSingletonDependencies(singleton, interfacesToSearchFor);
+		
+		IType type = javaProject.findType(singleton);
+		ISourceRange sourceRange = type.getSourceRange();
+
+		CompilationUnit compilationUnit = cache.getCompilationUnit(type.getCompilationUnit());
+		TypeDeclaration typeDeclaration = cache.getTypeDeclaration(type);
+		IAnnotationBinding[] annotations = typeDeclaration.resolveBinding().getAnnotations();
+
+		List<String> declaredDependencies = new ArrayList<String>();
+
+		for (IAnnotationBinding annotation : annotations) {
+			if ("javax.ejb.DependsOn".equals(annotation.getAnnotationType().getQualifiedName())) {
+				IMemberValuePairBinding[] pairs = annotation.getDeclaredMemberValuePairs();
+				for (int i = 0; i < pairs.length; i++) {
+					if ("value".equals(pairs[i].getName())) {
+						if (pairs[i].getValue() instanceof Object[]) {
+							Object[] values = (Object[]) pairs[i].getValue();
+							for (int j = 0; j < values.length; j++) {
+								declaredDependencies.add(values[j].toString());
+							}
+						}
+					}
+				}
+			}
+		}
+
+		List<String> expectedDependencies = new ArrayList<String>();
+
+		if (dependencies != null) {
+			for (Dependency dependency : dependencies) {
+				expectedDependencies.add(dependency.getDependsOn());
+			}
+		}
+
+		boolean matches = expectedDependencies.size() == declaredDependencies.size();
+
+		if (matches) {
+			for (String dependency : declaredDependencies) {
+				if (!expectedDependencies.contains(dependency)) {
+					matches = false;
+					break;
+				}
+			}
+		}
+
+		if (!matches) {
+			IMarker marker = type.getUnderlyingResource().createMarker(MARKER_TYPE_DEPENDS_ON);
+			Map attributes = new HashMap();
+
+			attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
+			attributes.put(IMarker.CHAR_START, sourceRange.getOffset());
+			attributes.put(IMarker.CHAR_END, sourceRange.getOffset() + sourceRange.getLength());
+			attributes.put(IMarker.LINE_NUMBER, compilationUnit.getLineNumber(sourceRange.getOffset()));
+			attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+			attributes.put(IMarker.MESSAGE, expectedDependencies.size() == 0 ? "This bean should not have the @DependsOn annotation" : "This bean requires the @DependsOn annotation, and depends on: " + getDependencyList(expectedDependencies));
+			attributes.put(ISingletonDependencyMarker.DEPENDENCIES, expectedDependencies.toArray(new String[expectedDependencies.size()]));
+			attributes.put(ISingletonDependencyMarker.BEAN, singleton);
+			marker.setAttributes(attributes);
+		}
+
+		projectModel.addDependencies(Arrays.asList(dependencies));
+	}
+
+	private void removeMarkersFor(String singleton) throws CoreException {
+		IMarker[] markers = getProject().findMarkers(MARKER_TYPE_DEPENDS_ON, true, IResource.DEPTH_INFINITE);
+		for (IMarker marker : markers) {
+			try {
+				String bean = (String) marker.getAttribute(ISingletonDependencyMarker.BEAN);
+				if (bean.equals(singleton)) {
+					marker.delete();
+				}
+			} catch (Exception e) {
+			}
+		}
 	}
 
 	private String getDependencyList(List<String> dependencies) {
 		StringBuffer buffer = new StringBuffer();
-		
+
 		for (int i = 0; i < dependencies.size(); i++) {
 			if (i > 0) {
 				buffer.append(", ");
 			}
-			
+
 			buffer.append(dependencies.get(i));
 		}
-		
+
 		return buffer.toString();
 	}
-
-
 }

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/MethodCall.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/MethodCall.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/MethodCall.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/MethodCall.java Tue Feb 10 23:20:17 2009
@@ -17,10 +17,13 @@
 
 package org.apache.openejb.builder;
 
-public class MethodCall {
+import java.io.Serializable;
+
+public class MethodCall implements Serializable {
 	private String className;
 	private String methodName;
 	private String[] signature;
+	private String compilationUnit;
 	
 	public String getClassName() {
 		return className;
@@ -45,4 +48,12 @@
 	public void setSignature(String[] signature) {
 		this.signature = signature;
 	}
+
+	public void setCompilationUnit(String compilationUnit) {
+		this.compilationUnit = compilationUnit;
+	}
+
+	public String getCompilationUnit() {
+		return compilationUnit;
+	}
 }

Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java?rev=743162&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java Tue Feb 10 23:20:17 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.builder;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+
+public class Model implements Serializable {
+	private static final long serialVersionUID = 4870818160182347194L;
+
+	private Map<String, ProjectModel> models = new HashMap<String, ProjectModel>();
+	
+	public ProjectModel getModel(IProject project) {
+		return getModel(project.getName());
+	}
+
+	public ProjectModel getModel(String projectName) {
+		ProjectModel projectModel = models.get(projectName);
+		if (projectModel == null) {
+			projectModel = new ProjectModel(projectName);
+			models.put(projectName, projectModel);
+		}
+		
+		return projectModel;
+	}
+}

Propchange: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/Model.java
------------------------------------------------------------------------------
    svn:executable = *

Added: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java?rev=743162&view=auto
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java (added)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java Tue Feb 10 23:20:17 2009
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.builder;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class ProjectModel implements Serializable {
+	private static final long serialVersionUID = -8772710294450537711L;
+	
+	private List<Dependency> dependencies = new ArrayList<Dependency>();
+	private String projectName;
+	private Map<String, List<String>> ifaces;
+	
+	public ProjectModel(String projectName) {
+		super();
+		this.projectName = projectName;
+		ifaces = new HashMap<String, List<String>>();
+	}
+
+	public List<Dependency> getDependencies(String beanName) {
+		List<Dependency> result = new ArrayList<Dependency>();
+		
+		for (Dependency dependency : dependencies) {
+			if (dependency.getDependsOn().equals(beanName)) {
+				result.add(dependency);
+			}
+		}
+		
+		return result;
+	}
+	
+	public List<String> getBeansDependentOn(String typeName) {
+		List<String> beans = new ArrayList<String>();
+		List<Dependency> deps = getDependencies();
+		
+		for (Dependency dep : deps) {
+			if (dep.touches(typeName)) {
+				Iterator<MethodCall> iterator = dep.getMethodCalls();
+				while (iterator.hasNext()) {
+					MethodCall methodCall = (MethodCall) iterator.next();
+					String className = methodCall.getClassName();
+
+					if (ifaces.keySet().contains(className)) {
+						if (! beans.contains(className)) {
+							beans.add(className);
+						}
+					}
+				}
+			}
+		}
+		
+		return beans;
+	}
+
+	public void clear() {
+		dependencies.clear();
+	}
+
+	public void addDependencies(List<Dependency> dependencyList) {
+		for (Dependency dependency : dependencyList) {
+			if (! dependencies.contains(dependency)) {
+				dependencies.add(dependency);
+			}
+		}
+	}
+
+	public List<Dependency> getDependencies() {
+		return dependencies;
+	}
+
+	public void setSingletonBeanInterfaces(String singleton, List<String> interfaces) {
+		ifaces.put(singleton, interfaces);
+	}
+
+	public List<String> getInterfacesToSearchFor(String singleton) {
+		List<String> result = new ArrayList<String>();
+		
+		Iterator<String> iterator = ifaces.keySet().iterator();
+		while (iterator.hasNext()) {
+			String singletonBean = (String) iterator.next();
+			if (! singletonBean.equals(singleton)) {
+				List<String> interfaces = ifaces.get(singletonBean);
+				for (String iface : interfaces) {
+					if (! result.contains(iface)) {
+						result.add(iface);
+					}
+				}
+			}
+		}
+		
+		return result;
+	}
+
+	public String getProjectName() {
+		return projectName;
+	}
+
+	public String getBeanForInterface(String qualifiedName) {
+		Iterator<String> iterator = ifaces.keySet().iterator();
+		while (iterator.hasNext()) {
+			String bean = (String) iterator.next();
+			if (qualifiedName.equals(bean)) {
+				return bean;
+			}
+			
+			List<String> ifaceList = ifaces.get(bean);
+			if (ifaceList.contains(qualifiedName)) {
+				return bean;
+			}
+		}
+		
+		return null;
+	}
+}

Propchange: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/ProjectModel.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/SingletonDependencyFinder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/SingletonDependencyFinder.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/SingletonDependencyFinder.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.builder/src/main/java/org/apache/openejb/builder/SingletonDependencyFinder.java Tue Feb 10 23:20:17 2009
@@ -18,15 +18,12 @@
 package org.apache.openejb.builder;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.Set;
 
 import org.apache.openejb.devtools.core.CompilationUnitCache;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.PlatformObject;
 import org.eclipse.jdt.core.IJavaElement;
@@ -51,6 +48,8 @@
 
 public class SingletonDependencyFinder {
 
+	private final ProjectModel model;
+
 	public class SingletonBeanSearchRequestor extends SearchRequestor {
 		private List<SearchMatch> matches = new ArrayList<SearchMatch>();
 
@@ -67,25 +66,32 @@
 		}
 	}
 
-	public SingletonDependencyFinder(IProject project) {
+	public SingletonDependencyFinder(ProjectModel model) {
 		super();
-		javaProject = JavaCore.create(project);
+		this.model = model;
+		javaProject = getProject();
+	}
+
+	private IJavaProject getProject() {
+		String projectName = model.getProjectName();
+		
+		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+		if (project == null) {
+			return null;
+		}
+		
+		return JavaCore.create(project);
 	}
 
-	protected Map<String, String[]> singletons = new HashMap<String, String[]>();
-	protected Map<String, Dependency[]> dependencies = new HashMap<String, Dependency[]>();
 	private IJavaProject javaProject;
 	private CompilationUnitCache compilationUnitCache = new CompilationUnitCache(javaProject);
 
-	public void findDependencies() throws SingletonDependencyFinderException {
-		findSingletonsAndInterfaces();
-		findSingletonDependencies();
-	}
-
-	protected void findSingletonsAndInterfaces() throws SingletonDependencyFinderException {
+	public String[] findSingletons() throws SingletonDependencyFinderException {
+		List<String> results = new ArrayList<String>();
+		
 		try {
 			IType singleton = javaProject.findType("javax.ejb.Singleton");
-
+			
 			SearchEngine searchEngine = new SearchEngine();
 			SearchPattern pattern = SearchPattern.createPattern(singleton, IJavaSearchConstants.REFERENCES);
 			SearchParticipant[] participants = new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
@@ -99,28 +105,27 @@
 			for (SearchMatch searchMatch : matches) {
 				IType type = (IType) searchMatch.getElement();
 				String singletonBeanClass = type.getFullyQualifiedName();
-
-				String[] interfaces = getInterfacesFor(singletonBeanClass);
-				singletons.put(singletonBeanClass, interfaces);
-
+				
+				results.add(singletonBeanClass);
 			}
 		} catch (Exception e) {
 			throw new SingletonDependencyFinderException("Unable to find singleton beans");
 		}
 
+		return results.toArray(new String[results.size()]);
 	}
 
-	@SuppressWarnings("unchecked")
-	private String[] getInterfacesFor(String singletonBeanClass) throws SingletonDependencyFinderException {
+	public List<String> getInterfacesFor(String singletonBeanClass) throws SingletonDependencyFinderException {
+		List<String> result = new ArrayList<String>();
+		
 		try {
 			IType type = javaProject.findType(singletonBeanClass);
 			TypeDeclaration typeDeclaration = compilationUnitCache.getTypeDeclaration(type);
 
 			ITypeBinding[] interfaces = typeDeclaration.resolveBinding().getInterfaces();
-			String[] result = new String[interfaces.length];
 
-			for (int i = 0; i < result.length; i++) {
-				result[i] = interfaces[i].getQualifiedName();
+			for (int i = 0; i < interfaces.length; i++) {
+				result.add(interfaces[i].getQualifiedName());
 			}
 
 			return result;
@@ -129,52 +134,42 @@
 		}
 	}
 
-	protected void findSingletonDependencies() {
-		Iterator<String> iterator = singletons.keySet().iterator();
-		while (iterator.hasNext()) {
-			String singleton = (String) iterator.next();
-			findSingletonDependencies(singleton);
-		}
-	}
-
-	protected void findSingletonDependencies(String singleton) {
+	public Dependency[] findSingletonDependencies(String singleton, List<String> interfaces) throws SingletonDependencyFinderException {
+		List<Dependency> result = new ArrayList<Dependency>();
+		
 		try {
-			List<String> interfacesToFind = getInterfacesToMatch(singleton);
 			IType type = javaProject.findType(singleton);
 
 			TypeDeclaration declaration = compilationUnitCache.getTypeDeclaration(type);
-
-			List<Dependency> result = new ArrayList<Dependency>();
 			
 			MethodDeclaration[] methodDeclarations = declaration.getMethods();
 			for (MethodDeclaration methodDeclaration : methodDeclarations) {
 				IAnnotationBinding[] annotations = methodDeclaration.resolveBinding().getAnnotations();
 				for (IAnnotationBinding annotationBinding : annotations) {
 					if (annotationBinding.getAnnotationType().getQualifiedName().equals("javax.annotation.PostConstruct") || annotationBinding.getAnnotationType().getQualifiedName().equals("javax.annotation.PreDestroy")) {
-						List<Dependency> dependencies = findReferencesTo(interfacesToFind, methodDeclaration);
+						List<Dependency> dependencies = findReferencesTo(singleton, interfaces, methodDeclaration);
 						result.addAll(dependencies);
 					}
 				}
 			}
 			
-			if (result.size() > 0) {
-				dependencies.put(singleton, result.toArray(new Dependency[result.size()]));
-			}
-			
 		} catch (JavaModelException e) {
 		}
+		
+		return result.toArray(new Dependency[result.size()]);
 	}
 
-	private List<Dependency> findReferencesTo(List<String> interfacesToFind, MethodDeclaration methodDeclaration) {
-		return findReferencesTo(interfacesToFind, methodDeclaration, 0);
+	private List<Dependency> findReferencesTo(String bean, List<String> interfacesToFind, MethodDeclaration methodDeclaration) {
+		return findReferencesTo(bean, interfacesToFind, methodDeclaration, 0);
 	}
 
-	private List<Dependency> findReferencesTo(final List<String> interfacesToFind, MethodDeclaration methodDeclaration, final int currentDepth) {
+	private List<Dependency> findReferencesTo(final String bean, final List<String> interfacesToFind, MethodDeclaration methodDeclaration, final int currentDepth) {
 		final List<Dependency> results = new ArrayList<Dependency>();
 
 		final MethodCall methodCall = new MethodCall();
 		methodCall.setClassName(methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName());
 		methodCall.setMethodName(methodDeclaration.getName().toString());
+		methodCall.setCompilationUnit(getCompilationUnit(methodDeclaration).getElementName());
 		
 		methodDeclaration.accept(new ASTVisitor() {
 
@@ -183,24 +178,27 @@
 				ITypeBinding declaringClass = node.resolveMethodBinding().getDeclaringClass();
 				
 				if (interfacesToFind.contains(declaringClass.getQualifiedName())) {
-					String dependsOn = getBeanForInterface(declaringClass.getQualifiedName());
-
-					if (dependsOn != null) {
-						Dependency dependency = new Dependency();
-						dependency.setDependsOn(dependsOn);
-						
-						dependency.addMethodCall(methodCall);
-						results.add(dependency);
-					}
+					Dependency dependency = new Dependency();
+					
+					// this is wrong!
+					String dependsOn = model.getBeanForInterface(declaringClass.getQualifiedName());
+					dependency.setDependsOn(dependsOn);
+					
+					dependency.addMethodCall(methodCall);
+					results.add(dependency);
 				} else {
-					MethodDeclaration calleeMethodDeclaration = compilationUnitCache.getMethodDeclaration((IMethod) node.resolveMethodBinding().getJavaElement());
-					if (calleeMethodDeclaration != null) {
-						List<Dependency> references = findReferencesTo(interfacesToFind, calleeMethodDeclaration, currentDepth + 1);
-						
-						for (Iterator<Dependency> iterator = references.iterator(); iterator.hasNext();) {
-							Dependency dependency = (Dependency) iterator.next();
-							dependency.addMethodCall(methodCall);
-							results.add(dependency);
+					IMethod method = (IMethod) node.resolveMethodBinding().getJavaElement();
+					if (! method.isBinary()) {
+						MethodDeclaration calleeMethodDeclaration = compilationUnitCache.getMethodDeclaration(method);
+					
+						if (calleeMethodDeclaration != null) {
+							List<Dependency> references = findReferencesTo(bean, interfacesToFind, calleeMethodDeclaration, currentDepth + 1);
+							
+							for (Iterator<Dependency> iterator = references.iterator(); iterator.hasNext();) {
+								Dependency dependency = (Dependency) iterator.next();
+								dependency.addMethodCall(methodCall);
+								results.add(dependency);
+							}
 						}
 					}
 				}
@@ -213,56 +211,18 @@
 		return results;
 	}
 
-	private List<String> getInterfacesToMatch(String singleton) {
-		List<String> result = new ArrayList<String>();
-		Iterator<String> iterator = singletons.keySet().iterator();
-
-		while (iterator.hasNext()) {
-			String bean = (String) iterator.next();
-			if (bean.equals(singleton)) {
-				continue;
-			}
-
-			String[] interfaces = singletons.get(bean);
-			result.addAll(Arrays.asList(interfaces));
-		}
-
-		return result;
-	}
-
-	public String[] getSingletons() {
-		Set<String> singletonBeans = singletons.keySet();
-		return singletonBeans.toArray(new String[singletonBeans.size()]);
-	}
-
-	public Dependency[] getDependencies(String singleton) {
-		return dependencies.get(singleton);
+	private IJavaElement getCompilationUnit(MethodDeclaration methodDeclaration) {
+		IJavaElement javaElement = methodDeclaration.resolveBinding().getJavaElement();
+		return getCompilationUnit(javaElement);
 	}
 
-	public boolean hasDependencies(String singleton) {
-		Dependency[] deps = getDependencies(singleton);
-		return deps != null && deps.length > 0;
-	}
-	
-	protected String getBeanForInterface(String iface) {
-		if (iface == null) {
-			return null;
-		}
+	private IJavaElement getCompilationUnit(IJavaElement javaElement) {
+		if (javaElement == null) return null;
 		
-		for (String singleton : singletons.keySet()) {
-			String[] ifaces = singletons.get(singleton);
-			
-			if (ifaces == null) {
-				continue;
-			}
-			
-			for (int i = 0; i < ifaces.length; i++) {
-				if (iface.equals(ifaces[i])) {
-					return singleton;
-				}
-			}
+		if (javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
+			return javaElement;
 		}
 		
-		return null;
+		return javaElement.getPrimaryElement();
 	}
 }

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/CompilationUnitCache.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/CompilationUnitCache.java?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/CompilationUnitCache.java (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.devtools.core/src/main/java/org/apache/openejb/devtools/core/CompilationUnitCache.java Tue Feb 10 23:20:17 2009
@@ -223,4 +223,8 @@
 		
 		return params.toArray(new String[params.size()]);
 	}
+
+	public void clear() {
+		cache.clear();
+	}
 }

Modified: openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.helper.annotation.test/src/main/resources/org/apache/openejb/helper/annotation/tests/ExpectedSessionBean.txt
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.helper.annotation.test/src/main/resources/org/apache/openejb/helper/annotation/tests/ExpectedSessionBean.txt?rev=743162&r1=743161&r2=743162&view=diff
==============================================================================
--- openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.helper.annotation.test/src/main/resources/org/apache/openejb/helper/annotation/tests/ExpectedSessionBean.txt (original)
+++ openejb/trunk/sandbox/openejb-eclipse-plugin/plugins/org.apache.openejb.helper.annotation.test/src/main/resources/org/apache/openejb/helper/annotation/tests/ExpectedSessionBean.txt Tue Feb 10 23:20:17 2009
@@ -47,8 +47,8 @@
         try {
             Object obj = new InitialContext().lookup("java:comp/env/ejb/Product");
             ProductHome productHome = (ProductHome) PortableRemoteObject.narrow(obj, ProductHome.class);
-            org.superbiz.ProductBean product = new org.superbiz.ProductBean(null, productName,
-					description, productCode);
+            org.superbiz.ProductBean product = new org.superbiz.ProductBean(null, productName, description,
+					productCode);
         } catch (NamingException e) {
             e.printStackTrace();
         } catch (CreateException e) {