[jboss-cvs] JBossAS SVN: r81287 - in projects/jboss-deployers/trunk/deployers-vfs/src/test: java/org/jboss/test/deployers/vfs/webbeans/test and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 19 07:54:30 EST 2008
Author: alesj
Date: 2008-11-19 07:54:30 -0500 (Wed, 19 Nov 2008)
New Revision: 81287
Modified:
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/support/WebBeanDiscoveryDeployer.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/test/WebBeanDiscoveryTestCase.java
projects/jboss-deployers/trunk/deployers-vfs/src/test/resources/webbeans/simple/META-INF/application.properties
Log:
Complete webbeans test.
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/support/WebBeanDiscoveryDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/support/WebBeanDiscoveryDeployer.java 2008-11-19 12:45:29 UTC (rev 81286)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/support/WebBeanDiscoveryDeployer.java 2008-11-19 12:54:30 UTC (rev 81287)
@@ -21,9 +21,20 @@
*/
package org.jboss.test.deployers.vfs.webbeans.support;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.vfs.spi.deployer.AbstractOptionalVFSRealDeployer;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.virtual.VirtualFile;
/**
* WBD deployer.
@@ -50,14 +61,106 @@
try
{
- if (deployment != null)
+ Module module = unit.getAttachment(Module.class);
+ if (module == null)
+ {
+ VFSDeploymentUnit parent = unit.getParent();
+ while(parent != null && module == null)
+ {
+ module = parent.getAttachment(Module.class);
+ parent = parent.getParent();
+ }
+ if (module == null)
+ throw new IllegalArgumentException("No module in deployment unit's hierarchy: " + unit.getName());
+ }
+
+ if (deployment != null) // do some more
wbdi.addWebBeansXmlURL(deployment.getURL());
- // TODO - check classpath
+ WBDiscoveryVisitor visitor = new WBDiscoveryVisitor(wbdi, unit.getClassLoader());
+
+ Iterable<VirtualFile> classpaths = getClassPaths(unit);
+ for (VirtualFile cp : classpaths)
+ {
+ VirtualFile wbXml = cp.getChild("META-INF/web-beans.xml");
+ if (wbXml != null)
+ {
+ // add url
+ wbdi.addWebBeansXmlURL(wbXml.toURL());
+ // add classes
+ module.visit(visitor, ClassFilter.INSTANCE, null, cp.toURL());
+ }
+ }
+
+ // handle war slightly different
+ VirtualFile warWbXml = unit.getFile("WEB-INF/web-beans.xml");
+ if (warWbXml != null)
+ {
+ VirtualFile classes = unit.getFile("WEB-INF/classes");
+ if (classes != null)
+ module.visit(visitor, ClassFilter.INSTANCE, null, classes.toURL());
+ }
}
catch (Exception e)
{
throw DeploymentException.rethrowAsDeploymentException("Cannot deploy WBD.", e);
}
}
+
+ /**
+ * Get the matching class paths that belong to this deployment unit.
+ *
+ * @param unit the deployment unit
+ * @return matching class paths
+ * @throws Exception for any error
+ */
+ protected Iterable<VirtualFile> getClassPaths(VFSDeploymentUnit unit) throws Exception
+ {
+ List<VirtualFile> classpath = unit.getClassPath();
+ if (classpath != null && classpath.isEmpty() == false)
+ {
+ Set<VirtualFile> matching = new HashSet<VirtualFile>();
+ VirtualFile root = unit.getRoot();
+ for (VirtualFile cp : classpath)
+ {
+ VirtualFile check = cp;
+ while(check != null && check.equals(root) == false)
+ check = check.getParent();
+
+ if (check != null)
+ matching.add(cp);
+ }
+ return matching;
+ }
+ return Collections.emptySet();
+ }
+
+ private class WBDiscoveryVisitor implements ResourceVisitor
+ {
+ private WebBeanDiscoveryImpl wbdi;
+ private ClassLoader cl;
+
+ private WBDiscoveryVisitor(WebBeanDiscoveryImpl wbdi, ClassLoader cl)
+ {
+ this.wbdi = wbdi;
+ this.cl = cl;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ try
+ {
+ wbdi.addWebBeanClass(cl.loadClass(resource.getClassName()));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/test/WebBeanDiscoveryTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/test/WebBeanDiscoveryTestCase.java 2008-11-19 12:45:29 UTC (rev 81286)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/webbeans/test/WebBeanDiscoveryTestCase.java 2008-11-19 12:54:30 UTC (rev 81287)
@@ -64,10 +64,6 @@
WebBeanDiscovery wbDiscovery = topUnit.getAttachment(WebBeanDiscovery.class);
assertNotNull(wbDiscovery);
- // TODO - remove this once WBDDeployer is done
- if (wbDiscovery.discoverWebBeanClasses().iterator().hasNext() == false)
- return;
-
Set<String> expected = new HashSet<String>();
expected.add("ejbs.jar/META-INF");
expected.add("ext.jar/META-INF");
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/resources/webbeans/simple/META-INF/application.properties
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/resources/webbeans/simple/META-INF/application.properties 2008-11-19 12:45:29 UTC (rev 81286)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/resources/webbeans/simple/META-INF/application.properties 2008-11-19 12:54:30 UTC (rev 81287)
@@ -1,3 +1,4 @@
jar-module=simple.jar
ejb-module=ejbs.jar
web-module=simple.war
+crm-module=crm.war
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list