[jboss-cvs] JBossAS SVN: r71484 - in projects/jboss-deployers/trunk: deployers-vfs/src/resources/tests/bean and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 31 09:17:49 EDT 2008


Author: alesj
Date: 2008-03-31 09:17:49 -0400 (Mon, 31 Mar 2008)
New Revision: 71484

Added:
   projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/
   projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/
   projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/
   projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/first-beans.xml
   projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/snd-beans.xml
Modified:
   projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/AliasDeploymentDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/Properties2BeansDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerUnitTestCase.java
Log:
[JBDEPLOY-4] handling multiple matching metadata files.

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/AliasDeploymentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/AliasDeploymentDeployer.java	2008-03-31 13:17:40 UTC (rev 71483)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/AliasDeploymentDeployer.java	2008-03-31 13:17:49 UTC (rev 71484)
@@ -31,6 +31,8 @@
 import org.jboss.kernel.spi.deployment.KernelDeployment;
 
 /**
+ * Handle alias components.
+ *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
 public class AliasDeploymentDeployer extends AbstractComponentDeployer<KernelDeployment, NamedAliasMetaData>

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanDeployer.java	2008-03-31 13:17:40 UTC (rev 71483)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanDeployer.java	2008-03-31 13:17:49 UTC (rev 71484)
@@ -51,7 +51,8 @@
       setSuffix("-beans.xml");
       setJarExtension(".beans");
       // Enable ManagedObject creation based on annotations by default
-      setBuildManagedObject(true);
+      setBuildManagedObject(true);      
+      setAllowMultipleFiles(true);
    }
 
    @Override

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/Properties2BeansDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/Properties2BeansDeployer.java	2008-03-31 13:17:40 UTC (rev 71483)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/Properties2BeansDeployer.java	2008-03-31 13:17:49 UTC (rev 71484)
@@ -50,6 +50,7 @@
       setSuffix("-beans.properties");
       // Enable ManagedObject creation based on annotations by default
       setBuildManagedObject(true);
+      setAllowMultipleFiles(true);
    }
 
    @Override

Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/first-beans.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/first-beans.xml	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/first-beans.xml	2008-03-31 13:17:49 UTC (rev 71484)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="Test1" class="org.jboss.test.deployers.vfs.deployer.bean.support.Simple"/>
+</deployment>

Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/snd-beans.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/snd-beans.xml	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bean/multiple/test.jar/META-INF/snd-beans.xml	2008-03-31 13:17:49 UTC (rev 71484)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+   <bean name="Test2" class="org.jboss.test.deployers.vfs.deployer.bean.support.Simple"/>
+</deployment>

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerUnitTestCase.java	2008-03-31 13:17:40 UTC (rev 71483)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerUnitTestCase.java	2008-03-31 13:17:49 UTC (rev 71484)
@@ -33,6 +33,7 @@
  * BeanDeployerUnitTestCase.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public class BeanDeployerUnitTestCase extends AbstractDeployerUnitTestCase
@@ -77,4 +78,15 @@
       assertNull(controller.getContext("Test", null));
    }
 
+   public void testMultipleMatchingFiles() throws Exception
+   {
+      VFSDeployment context = createDeployment("/bean", "multiple/test.jar");
+      assertDeploy(context);
+      assertNotNull(controller.getInstalledContext("Test1"));
+      assertNotNull(controller.getInstalledContext("Test2"));
+
+      assertUndeploy(context);
+      assertNull(controller.getContext("Test2", null));
+      assertNull(controller.getContext("Test1", null));
+   }
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2008-03-31 13:17:40 UTC (rev 71483)
+++ projects/jboss-deployers/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractVFSParsingDeployer.java	2008-03-31 13:17:49 UTC (rev 71484)
@@ -36,10 +36,14 @@
  *
  * @param <T> the type of output
  * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractVFSParsingDeployer<T> extends AbstractParsingDeployerWithOutput<T> implements FileMatcher
 {
+   /** The allow multiple fiels flag */
+   private boolean allowMultipleFiles;
+
    /**
     * Create a new AbstractVFSParsingDeployer.
     * 
@@ -131,22 +135,69 @@
       // Try to find the metadata
       VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
       List<VirtualFile> files = vfsDeploymentUnit.getMetaDataFiles(name, suffix);
+
       if (files.size() == 0)
+      {
          return null;
-      
-      // TODO JBMICROCONT-184 remove this limitation
-      if (files.size() > 1)
-         throw new DeploymentException("Only one file is allowed, found=" + files);
+      }
+      else if (files.size() > 1)
+      {
+         return handleMultipleFiles(vfsDeploymentUnit, root, files);
+      }
+      else
+      {
+         VirtualFile file = files.get(0);
 
-      VirtualFile file = files.get(0);
-      
-      T result = parse(vfsDeploymentUnit, file, root);
-      if (result != null)
-         init(vfsDeploymentUnit, result, file);
-      return result;
+         T result = parse(vfsDeploymentUnit, file, root);
+         if (result != null)
+            init(vfsDeploymentUnit, result, file);
+         return result;
+      }
    }
 
    /**
+    * Handle multiple files.
+    *
+    * @param unit the vfs deployment unit
+    * @param root possibly null pre-existing root
+    * @param files the matching files
+    * @return null or merged single result
+    * @throws Exception for any error
+    */
+   protected T handleMultipleFiles(VFSDeploymentUnit unit, T root, List<VirtualFile> files) throws Exception
+   {
+      if (allowsMultipleFiles(files) == false)
+         throw new IllegalArgumentException("Multiple matching files not allowed: " + files);
+
+      for (VirtualFile file : files)
+      {
+         T result = parse(unit, file, root);
+         if (result != null)
+         {
+            init(unit, result, file);
+            unit.addAttachment(file.toURL().toString(), result, getOutput());
+         }
+      }
+
+      return null;
+   }
+
+   /**
+    * Check if we allow multiple files.
+    *
+    * Make sure you have deployers down
+    * the chain that will handle generated
+    * multiple attachments if this method returns true.
+    * 
+    * @param files the matching files
+    * @return true if we allow, false otherwise
+    */
+   protected boolean allowsMultipleFiles(List<VirtualFile> files)
+   {
+      return allowMultipleFiles;
+   }
+
+   /**
     * Parse a deployment
     * 
     * @param unit the deployment unit
@@ -168,4 +219,14 @@
    protected void init(VFSDeploymentUnit unit, T metaData, VirtualFile file) throws Exception
    {
    }
+
+   /**
+    * Set allow multiple files.
+    *
+    * @param allowMultipleFiles the allow multiple files flag
+    */
+   public void setAllowMultipleFiles(boolean allowMultipleFiles)
+   {
+      this.allowMultipleFiles = allowMultipleFiles;
+   }
 }




More information about the jboss-cvs-commits mailing list