[jboss-cvs] JBossAS SVN: r81424 - in projects/jboss-deployers/trunk/deployers-vfs/src: test/java/org/jboss/test/deployers/vfs/classloader/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 21 06:48:40 EST 2008


Author: alesj
Date: 2008-11-21 06:48:39 -0500 (Fri, 21 Nov 2008)
New Revision: 81424

Added:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/DeploymentHostNameCreator.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/HostNameCreator.java
Modified:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classloader/test/InMemoryClasesUnitTestCase.java
Log:
[JBDEPLOY-133]; allow for reproduceable url

Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/DeploymentHostNameCreator.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/DeploymentHostNameCreator.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/DeploymentHostNameCreator.java	2008-11-21 11:48:39 UTC (rev 81424)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.vfs.plugins.classloader;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * Join all deployment names.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DeploymentHostNameCreator implements HostNameCreator
+{
+   /**The prefix */
+   private String prefix = "in-memory";
+
+   public String createHostName(VFSDeploymentUnit unit)
+   {
+      StringBuilder builder = new StringBuilder(prefix);
+      VFSDeploymentUnit vdu = unit;
+      while (vdu != null)
+      {
+         builder.append("-").append(vdu.getSimpleName());
+         vdu = vdu.getParent();
+      }
+      return builder.toString();
+   }
+
+   /**
+    * Set prefix.
+    *
+    * @param prefix the prefix
+    */
+   public void setPrefix(String prefix)
+   {
+      this.prefix = prefix;
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/HostNameCreator.java (from rev 81169, projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/HostNameCreator.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/HostNameCreator.java	2008-11-21 11:48:39 UTC (rev 81424)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.vfs.plugins.classloader;
+
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * Create host name for in-memory url.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface HostNameCreator
+{
+   /**
+    * Create host name.
+    *
+    * It should not contain any '/' due to VFS Memory context limitations.
+    * See JBDEPLOY-75.
+    *
+    * @param unit the vfs deployment unit
+    * @return host name
+    */
+   String createHostName(VFSDeploymentUnit unit);
+}
\ No newline at end of file


Property changes on: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/HostNameCreator.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java	2008-11-21 10:53:28 UTC (rev 81423)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/InMemoryClassesDeployer.java	2008-11-21 11:48:39 UTC (rev 81424)
@@ -48,6 +48,9 @@
    /** The name of the dynamic class root */
    public static final String DYNAMIC_CLASS_KEY = "DYNAMIC_CLASS_KEY";
 
+   /** The host name creator */
+   private HostNameCreator hostNameCreator;
+
    /**
     * Create a new TempURLDeployer.
     */
@@ -58,13 +61,24 @@
       setOutput(ClassLoadingMetaData.class);
       setTopLevelOnly(true);
    }
-   
+
+   /**
+    * Create host name.
+    *
+    * @param unit the deployment unit
+    * @return the host name
+    */
+   protected String createHost(VFSDeploymentUnit unit)
+   {
+      return (hostNameCreator != null) ? hostNameCreator.createHostName(unit) : GUID.asString();
+   }
+
    @Override
    public void deploy(VFSDeploymentUnit unit) throws DeploymentException
    {
       try
       {
-         URL dynamicClassRoot = new URL("vfsmemory", GUID.asString(), "");
+         URL dynamicClassRoot = new URL("vfsmemory", createHost(unit), "");
          VirtualFile classes = MemoryFileFactory.createRoot(dynamicClassRoot).getRoot();
          unit.addAttachment(DYNAMIC_CLASS_URL_KEY, dynamicClassRoot);
          unit.addAttachment(DYNAMIC_CLASS_KEY, classes);
@@ -108,4 +122,14 @@
          }
       }
    }
+
+   /**
+    * Set host name creator.
+    *
+    * @param hostNameCreator the host name creator
+    */
+   public void setHostNameCreator(HostNameCreator hostNameCreator)
+   {
+      this.hostNameCreator = hostNameCreator;
+   }
 }

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classloader/test/InMemoryClasesUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classloader/test/InMemoryClasesUnitTestCase.java	2008-11-21 10:53:28 UTC (rev 81423)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/test/java/org/jboss/test/deployers/vfs/classloader/test/InMemoryClasesUnitTestCase.java	2008-11-21 11:48:39 UTC (rev 81424)
@@ -38,6 +38,7 @@
 import org.jboss.deployers.vfs.plugins.classloader.InMemoryClassesDeployer;
 import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderClassPathDeployer;
 import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderDescribeDeployer;
+import org.jboss.deployers.vfs.plugins.classloader.DeploymentHostNameCreator;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.test.deployers.vfs.classloader.support.TestLevelClassLoaderSystemDeployer;
 import org.jboss.test.deployers.vfs.classloader.support.a.A;
@@ -48,10 +49,13 @@
  * InMemoryClasesUnitTestCase.
  * 
  * @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 InMemoryClasesUnitTestCase extends VFSClassLoaderDependenciesTest
 {
+   private InMemoryClassesDeployer inMemoryClassesDeployer = new InMemoryClassesDeployer();
+
    public InMemoryClasesUnitTestCase(String name)
    {
       super(name);
@@ -101,6 +105,32 @@
       assertFalse("dynamic classes should NOT be in the classpath", unit.getClassPath().contains(file));
    }
 
+   public void testHostNameCreator() throws Exception
+   {
+      DeployerClient mainDeployer = getMainDeployer();
+      MainDeployerStructure main = (MainDeployerStructure) mainDeployer;
+
+      Deployment ad = createDeployment("A");
+      Version v1 = Version.parseVersion("1");
+      ClassLoadingMetaData clmd = addClassLoadingMetaData(ad, v1, true, A.class);
+      clmd.setBlackListable(false);
+
+      inMemoryClassesDeployer.setHostNameCreator(new DeploymentHostNameCreator());
+      try
+      {
+         assertDeploy(mainDeployer, ad);
+
+         VFSDeploymentUnit unit = (VFSDeploymentUnit) main.getDeploymentUnit("A");
+         URL root = unit.getAttachment(InMemoryClassesDeployer.DYNAMIC_CLASS_URL_KEY, URL.class);
+         assertNotNull(root);
+         assertEquals("vfsmemory://in-memory-test-classes", root.toExternalForm());
+      }
+      finally
+      {
+         inMemoryClassesDeployer.setHostNameCreator(null);
+      }
+   }
+
    protected DeployerClient getMainDeployer()
    {
       AbstractJDKChecker.getExcluded().add(VFSClassLoaderDependenciesTest.class);
@@ -116,10 +146,8 @@
       deployer2.setClassLoading(classLoading);
       deployer2.setSystem(system);
       
-      Deployer deployer3 = new InMemoryClassesDeployer();
-
       Deployer deployer4 = new VFSClassLoaderClassPathDeployer();
       
-      return createMainDeployer(deployer1, deployer2, deployer3, deployer4);
+      return createMainDeployer(deployer1, deployer2, inMemoryClassesDeployer, deployer4);
    }
 }




More information about the jboss-cvs-commits mailing list