[jboss-cvs] JBossAS SVN: r103901 - in projects/scanning/trunk: plugins and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 13 08:41:30 EDT 2010
Author: alesj
Date: 2010-04-13 08:41:28 -0400 (Tue, 13 Apr 2010)
New Revision: 103901
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPlugin.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPluginFactory.java
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/VoidScanningHandle.java
Modified:
projects/scanning/trunk/plugins/pom.xml
projects/scanning/trunk/pom.xml
projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
Log:
Add Weld scanning plugin support.
Modified: projects/scanning/trunk/plugins/pom.xml
===================================================================
--- projects/scanning/trunk/plugins/pom.xml 2010-04-13 12:12:48 UTC (rev 103900)
+++ projects/scanning/trunk/plugins/pom.xml 2010-04-13 12:41:28 UTC (rev 103901)
@@ -55,6 +55,16 @@
<artifactId>jboss-classloading-vfs</artifactId>
</dependency>
<dependency>
+ <groupId>org.jboss.weld.integration</groupId>
+ <artifactId>weld-jboss-int-deployer</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPlugin.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPlugin.java 2010-04-13 12:41:28 UTC (rev 103901)
@@ -0,0 +1,126 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.weld;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.List;
+
+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.scanning.plugins.helpers.VoidScanningHandle;
+import org.jboss.scanning.spi.helpers.AbstractScanningPlugin;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
+
+/**
+ * Weld scanning plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeldScanningPlugin extends AbstractScanningPlugin<VoidScanningHandle, Object>
+{
+ private ResourceVisitor visitor;
+ private Collection<VirtualFile> cpFiles;
+
+ public WeldScanningPlugin(WeldDiscoveryEnvironment environment, Collection<VirtualFile> cpFiles)
+ {
+ this.visitor = new WBDiscoveryVisitor(environment);
+ this.cpFiles = cpFiles;
+ }
+
+ @Override
+ protected VoidScanningHandle doCreateHandle()
+ {
+ return VoidScanningHandle.INSTANCE;
+ }
+
+ public Class<Object> getHandleInterface()
+ {
+ return Object.class;
+ }
+
+ @Override
+ public void cleanupHandle(Object handle)
+ {
+ visitor = null;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return new ResourceFilter()
+ {
+ public boolean accepts(ResourceContext resource)
+ {
+ try
+ {
+ URL url = resource.getUrl();
+ VirtualFile file = VFS.getChild(url);
+ List<VirtualFile> parents = file.getParentFileList();
+ // let's go from the end, usually we'll know from 2nd token -- the root
+ for (int i = parents.size() - 1; i >= 0; i--)
+ {
+ // is our resource part of weld's classpath
+ if (cpFiles.contains(parents.get(i)))
+ return true;
+ }
+ return false;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ visitor.visit(resource);
+ }
+
+ private static class WBDiscoveryVisitor implements ResourceVisitor
+ {
+ private Collection<Class<?>> classes;
+
+ private WBDiscoveryVisitor(WeldDiscoveryEnvironment wbdi)
+ {
+ // TODO -- fix this once we have new Weld-int release
+ this.classes = wbdi.getWeldClasses();
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ classes.add(resource.loadClass());
+ }
+ }
+
+}
\ No newline at end of file
Added: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPluginFactory.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPluginFactory.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/weld/WeldScanningPluginFactory.java 2010-04-13 12:41:28 UTC (rev 103901)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.weld;
+
+import java.net.URL;
+import java.util.Collection;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
+import org.jboss.scanning.plugins.helpers.VoidScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.deployer.env.WeldDiscoveryEnvironment;
+
+/**
+ * Add Weld scanning plugin.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class WeldScanningPluginFactory implements DeploymentScanningPluginFactory<VoidScanningHandle, Object>
+{
+ public boolean isRelevant(DeploymentUnit unit)
+ {
+ @SuppressWarnings("unchecked")
+ Collection<VirtualFile> wbFiles = unit.getAttachment(DeployersUtils.WELD_FILES, Collection.class);
+ boolean hasWB = (wbFiles != null && wbFiles.isEmpty() == false);
+
+ @SuppressWarnings("unchecked")
+ Collection<VirtualFile> cpFiles = unit.getAttachment(DeployersUtils.WELD_CLASSPATH, Collection.class);
+ boolean hasCp = (cpFiles != null && cpFiles.isEmpty() == false);
+
+ WeldDiscoveryEnvironment environment = null;
+ if (hasWB || hasCp)
+ {
+ DeploymentUnit topUnit = unit.getTopLevel();
+ environment = topUnit.getAttachment(WeldDiscoveryEnvironment.class);
+ if (environment == null)
+ {
+ environment = new WeldDiscoveryEnvironment();
+ topUnit.addAttachment(WeldDiscoveryEnvironment.class, environment);
+ }
+ }
+
+ if (hasWB)
+ {
+ // TODO -- fix this once we have new Weld-int release
+ Collection<URL> xmls = environment.getWeldXml();
+ try
+ {
+ for (VirtualFile file : wbFiles)
+ xmls.add(file.toURL());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return hasCp;
+ }
+
+ public ScanningPlugin<VoidScanningHandle, Object> create(DeploymentUnit unit)
+ {
+ @SuppressWarnings("unchecked")
+ Collection<VirtualFile> cpFiles = unit.getAttachment(DeployersUtils.WELD_CLASSPATH, Collection.class);
+ WeldDiscoveryEnvironment environment = unit.getTopLevel().getAttachment(WeldDiscoveryEnvironment.class);
+ return new WeldScanningPlugin(environment, cpFiles);
+ }
+}
Modified: projects/scanning/trunk/pom.xml
===================================================================
--- projects/scanning/trunk/pom.xml 2010-04-13 12:12:48 UTC (rev 103900)
+++ projects/scanning/trunk/pom.xml 2010-04-13 12:41:28 UTC (rev 103901)
@@ -35,6 +35,7 @@
<version.org.jboss.man>2.1.1.SP1</version.org.jboss.man>
<version.org.jboss.classloader>2.2.0.Alpha4</version.org.jboss.classloader>
<version.org.jboss.deployers>2.2.0.Alpha4</version.org.jboss.deployers>
+ <version.org.jboss.weld-int>6.0.0.Beta11</version.org.jboss.weld-int>
<version.javassist>3.11.0.GA</version.javassist>
<version.ant>1.7.1</version.ant>
<version.hibernate>3.5.0-CR-2</version.hibernate>
@@ -197,6 +198,11 @@
<type>test-jar</type>
</dependency>
<dependency>
+ <groupId>org.jboss.weld.integration</groupId>
+ <artifactId>weld-jboss-int-deployer</artifactId>
+ <version>${version.org.jboss.weld-int}</version>
+ </dependency>
+ <dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>${version.javassist}</version>
Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java 2010-04-13 12:12:48 UTC (rev 103900)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java 2010-04-13 12:41:28 UTC (rev 103901)
@@ -31,6 +31,7 @@
import org.jboss.deployers.spi.deployer.helpers.AttachmentLocator;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.scanning.plugins.helpers.DelegateResourceFilter;
+import org.jboss.scanning.plugins.helpers.VoidScanningHandle;
import org.jboss.scanning.spi.ScanningHandle;
import org.jboss.scanning.spi.ScanningPlugin;
import org.jboss.scanning.spi.helpers.UrlScanner;
@@ -104,7 +105,8 @@
protected ScanningHandle createHandle(ScanningPlugin plugin)
{
ScanningHandle handle = plugin.createHandle();
- unit.addAttachment(plugin.getHandleKey(), handle, plugin.getHandleInterface());
+ if (handle != VoidScanningHandle.INSTANCE) // ignore helper dummy/void handle
+ unit.addAttachment(plugin.getHandleKey(), handle, plugin.getHandleInterface());
return handle;
}
}
\ No newline at end of file
Added: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/VoidScanningHandle.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/VoidScanningHandle.java (rev 0)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/helpers/VoidScanningHandle.java 2010-04-13 12:41:28 UTC (rev 103901)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.plugins.helpers;
+
+import org.jboss.scanning.spi.ScanningHandle;
+
+/**
+ * No op scanning handle.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VoidScanningHandle implements ScanningHandle<VoidScanningHandle>
+{
+ public static final VoidScanningHandle INSTANCE = new VoidScanningHandle();
+
+ private VoidScanningHandle()
+ {
+ }
+
+ public void merge(VoidScanningHandle subHandle)
+ {
+ }
+}
More information about the jboss-cvs-commits
mailing list