[jboss-cvs] JBossAS SVN: r110069 - in projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers: cp and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 21 07:25:03 EST 2010


Author: alesj
Date: 2010-12-21 07:25:03 -0500 (Tue, 21 Dec 2010)
New Revision: 110069

Added:
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ClasspathSelector.java
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DefaultDeploymentUnitScannerFactory.java
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DeploymentUnitScannerFactory.java
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/DeploymentOnlyClasspathSelector.java
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/ManifestIncludedClasspathSelector.java
Modified:
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/VFSDeploymentUnitScanner.java
Log:
Allow for more cp selection control.

Added: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ClasspathSelector.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ClasspathSelector.java	                        (rev 0)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ClasspathSelector.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -0,0 +1,44 @@
+/*
+ * 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.deployers;
+
+import java.net.URL;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * Get classpath urls from vfs deployment unit.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ClasspathSelector
+{
+   /**
+    * Select classpath urls from vfs deployment unit.
+    *
+    * @param unit the vfs deployment unit
+    * @return classpath urls
+    * @throws Exception for any error
+    */
+   URL[] select(VFSDeploymentUnit unit) throws Exception;
+}

Added: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DefaultDeploymentUnitScannerFactory.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DefaultDeploymentUnitScannerFactory.java	                        (rev 0)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DefaultDeploymentUnitScannerFactory.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -0,0 +1,55 @@
+/*
+ * 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.deployers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.scanning.plugins.DeploymentUnitScanner;
+
+/**
+ * Default deployment unit scanner factory.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DefaultDeploymentUnitScannerFactory implements DeploymentUnitScannerFactory
+{
+   public DeploymentUnitScanner create(DeploymentUnit unit) throws Exception
+   {
+      if (unit instanceof VFSDeploymentUnit)
+         return createVFSDeploymentUnitScanner((VFSDeploymentUnit) unit);
+      else
+         return new DeploymentUnitScanner(unit);
+   }
+
+   /**
+    * Create VFS DU scanner.
+    *
+    * @param unit the vfs deployment unit
+    * @return new VFS DU scanner
+    * @throws Exception for any error
+    */
+   protected VFSDeploymentUnitScanner createVFSDeploymentUnitScanner(VFSDeploymentUnit unit) throws Exception
+   {
+      return new VFSDeploymentUnitScanner(unit);
+   }
+}

Added: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DeploymentUnitScannerFactory.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DeploymentUnitScannerFactory.java	                        (rev 0)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/DeploymentUnitScannerFactory.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -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.deployers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.plugins.DeploymentUnitScanner;
+
+/**
+ * Create deployment unit scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface DeploymentUnitScannerFactory
+{
+   /**
+    * Create deployment unit.
+    *
+    * @param unit the deployment unit
+    * @return new deployment unit scanner
+    * @throws Exception for any error
+    */
+   DeploymentUnitScanner create(DeploymentUnit unit) throws Exception;
+}

Modified: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java	2010-12-21 12:18:12 UTC (rev 110068)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -31,9 +31,7 @@
 import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.DeploymentUnitFilter;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
-import org.jboss.scanning.plugins.DeploymentUnitScanner;
 import org.jboss.scanning.spi.ScanningPlugin;
 import org.jboss.scanning.spi.helpers.UrlScanner;
 import org.jboss.scanning.spi.metadata.ScanningMetaData;
@@ -51,6 +49,8 @@
    private DeploymentUnitFilter filter;
    /** The plugin factories */
    private Set<DeploymentScanningPluginFactory> factories = new CopyOnWriteArraySet<DeploymentScanningPluginFactory>();
+   /** The DU scanner factory*/
+   private DeploymentUnitScannerFactory factory = new DefaultDeploymentUnitScannerFactory();
 
    public ScanningDeployer()
    {
@@ -58,6 +58,15 @@
       addInput(ScanningMetaData.class);
    }
 
+   /**
+    * Do a create state check.
+    */
+   public void create()
+   {
+      if (factory == null)
+         throw new IllegalArgumentException("Null DU scanner factory");
+   }
+
    public void deploy(DeploymentUnit unit) throws DeploymentException
    {
       // running this deployer is costly, check if it should be run
@@ -73,13 +82,9 @@
 
       if (plugins.isEmpty() == false)
       {
-         VFSDeploymentUnit vdu = null;
-         if (unit instanceof VFSDeploymentUnit)
-            vdu = VFSDeploymentUnit.class.cast(unit);
-
          try
          {
-            UrlScanner scanner = (vdu != null) ? new VFSDeploymentUnitScanner(vdu) : new DeploymentUnitScanner(unit);
+            UrlScanner scanner = factory.create(unit);
             if (scanner.doScan())
             {
                scanner.setPlugins(plugins);
@@ -138,4 +143,14 @@
    {
       this.filter = filter;
    }
+
+   /**
+    * Set DU scanner factory.
+    *
+    * @param factory the factory
+    */
+   public void setFactory(DeploymentUnitScannerFactory factory)
+   {
+      this.factory = factory;
+   }
 }

Modified: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/VFSDeploymentUnitScanner.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/VFSDeploymentUnitScanner.java	2010-12-21 12:18:12 UTC (rev 110068)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/VFSDeploymentUnitScanner.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -22,9 +22,13 @@
 
 package org.jboss.scanning.deployers;
 
-import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.scanning.plugins.DeploymentUnitScanner;
+import org.jboss.vfs.VirtualFile;
 
 /**
  * Scanning deployer.
@@ -33,11 +37,26 @@
  */
 public class VFSDeploymentUnitScanner extends DeploymentUnitScanner
 {
+   private static final ClasspathSelector DEFAULT = new DefaultClasspathSelector();
+
+   private static ClasspathSelector check(ClasspathSelector selector)
+   {
+      if (selector == null)
+         selector = DEFAULT;
+
+      return selector;
+   }
+
    public VFSDeploymentUnitScanner(VFSDeploymentUnit unit) throws Exception
    {
-      super(unit, ClasspathUtils.getUrls(unit));
+      this(unit, DEFAULT);
    }
 
+   public VFSDeploymentUnitScanner(VFSDeploymentUnit unit, ClasspathSelector selector) throws Exception
+   {
+      super(unit, check(selector).select(unit));
+   }
+
    /**
     * Mostly there is no sense in scanning
     * if there is no explicit roots; e.g. file based sub-deployment.
@@ -49,4 +68,19 @@
    {
       return (getRoots().length > 0);
    }
+
+   private static class DefaultClasspathSelector implements ClasspathSelector
+   {
+      public URL[] select(VFSDeploymentUnit unit) throws Exception
+      {
+         List<URL> urls = new ArrayList<URL>();
+         List<VirtualFile> cps = unit.getClassPath();
+         if (cps != null && cps.size() > 0)
+         {
+            for (VirtualFile cp : cps)
+               urls.add(cp.toURL());
+         }
+         return urls.toArray(new URL[urls.size()]);
+      }
+   }
 }
\ No newline at end of file

Added: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/DeploymentOnlyClasspathSelector.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/DeploymentOnlyClasspathSelector.java	                        (rev 0)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/DeploymentOnlyClasspathSelector.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -0,0 +1,42 @@
+/*
+ * 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.deployers.cp;
+
+import java.net.URL;
+
+import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.scanning.deployers.ClasspathSelector;
+
+/**
+ * Get classpath urls from vfs deployment unit only.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeploymentOnlyClasspathSelector implements ClasspathSelector
+{
+   public URL[] select(VFSDeploymentUnit unit) throws Exception
+   {
+      return ClasspathUtils.getUrls(unit);
+   }
+}

Added: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/ManifestIncludedClasspathSelector.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/ManifestIncludedClasspathSelector.java	                        (rev 0)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/cp/ManifestIncludedClasspathSelector.java	2010-12-21 12:25:03 UTC (rev 110069)
@@ -0,0 +1,85 @@
+/*
+ * 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.deployers.cp;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.scanning.deployers.ClasspathSelector;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * Get classpath urls from vfs deployment unit, including any from manifest.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ManifestIncludedClasspathSelector implements ClasspathSelector
+{
+   public URL[] select(VFSDeploymentUnit unit) throws Exception
+   {
+      List<VirtualFile> classpath = unit.getClassPath();
+      if (classpath != null && classpath.isEmpty() == false)
+      {
+         List<URL> urls = new ArrayList<URL>();
+         VirtualFile root = unit.getRoot();
+         List<VirtualFile> missing = new ArrayList<VirtualFile>();
+
+         for (VirtualFile cp : classpath)
+         {
+            VirtualFile check = cp;
+            while(check != null && check.equals(root) == false)
+               check = check.getParent();
+
+            if (check != null)
+               urls.add(cp.toURL());
+            else
+               missing.add(cp);
+         }
+
+         if (missing.isEmpty() == false)
+         {
+            List<VirtualFile> cps = new ArrayList<VirtualFile>();
+            for (VirtualFile cp : classpath)
+            {
+               if (missing.contains(cp) == false)
+                  VFSUtils.addManifestLocations(cp, cps);
+            }
+
+            for (VirtualFile cp : missing)
+            {
+               if (cps.contains(cp))
+                  urls.add(cp.toURL());
+            }
+         }
+
+         if (urls.isEmpty() == false)
+         {
+            return urls.toArray(new URL[urls.size()]);
+         }
+      }
+      return new URL[0];
+   }
+}



More information about the jboss-cvs-commits mailing list