[jboss-cvs] JBossAS SVN: r96397 - in projects/embedded/trunk: api/src/main/java/org/jboss/embedded/api and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 15 22:56:21 EST 2009


Author: ALRubinger
Date: 2009-11-15 22:56:20 -0500 (Sun, 15 Nov 2009)
New Revision: 96397

Added:
   projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/DeploymentException.java
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/VfsVdfDeployableImpl.java
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/spi/
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/spi/VdfDeployable.java
   projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/VfsVdfDeployableImplTestCase.java
Modified:
   projects/embedded/trunk/api/pom.xml
   projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServer.java
   projects/embedded/trunk/build/pom.xml
   projects/embedded/trunk/core/pom.xml
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
Log:
[EMB-64] Bring the TMPDPL logic into EmbeddedAS

Modified: projects/embedded/trunk/api/pom.xml
===================================================================
--- projects/embedded/trunk/api/pom.xml	2009-11-16 03:12:46 UTC (rev 96396)
+++ projects/embedded/trunk/api/pom.xml	2009-11-16 03:56:20 UTC (rev 96397)
@@ -2,7 +2,8 @@
   <!--
   vi:ts=2:sw=2:expandtab:
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
   <!-- Parent -->
   <parent>
@@ -40,10 +41,10 @@
       <version>${version.org.jboss.bootstrap_jboss.bootstrap.api.as}</version>
     </dependency>
 
-    <!-- org.jboss.tmpdpl:tmpdpl-api-shrinkwrap -->
+    <!-- org.jboss.shrinkwrap:shrinkwrap-api -->
     <dependency>
-      <groupId>org.jboss.tmpdpl</groupId>
-      <artifactId>tmpdpl-api-shrinkwrap</artifactId>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-api</artifactId>
     </dependency>
 
   </dependencies>

Added: projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/DeploymentException.java
===================================================================
--- projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/DeploymentException.java	                        (rev 0)
+++ projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/DeploymentException.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.embedded.api;
+
+/**
+ * DeploymentException
+ *
+ * Indicates a problem encountered during deployment to the target {@link Container}
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class DeploymentException extends Exception
+{
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * serialVersionUID
+    */
+   private static final long serialVersionUID = 1L;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructors -----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * 
+    */
+   public DeploymentException()
+   {
+      super();
+   }
+
+   /**
+    * @param message
+    * @param cause
+    */
+   public DeploymentException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+
+   /**
+    * @param message
+    */
+   public DeploymentException(String message)
+   {
+      super(message);
+   }
+
+   /**
+    * @param cause
+    */
+   public DeploymentException(Throwable cause)
+   {
+      super(cause);
+   }
+}

Modified: projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServer.java
===================================================================
--- projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServer.java	2009-11-16 03:12:46 UTC (rev 96396)
+++ projects/embedded/trunk/api/src/main/java/org/jboss/embedded/api/server/JBossASEmbeddedServer.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -23,8 +23,8 @@
 
 import org.jboss.bootstrap.api.as.config.JBossASServerConfig;
 import org.jboss.bootstrap.api.as.server.JBossASBasedServer;
-import org.jboss.tmpdpl.api.container.Container;
-import org.jboss.tmpdpl.api.shrinkwrap.container.ArchiveContainer;
+import org.jboss.embedded.api.DeploymentException;
+import org.jboss.shrinkwrap.api.Archive;
 
 /**
  * JBossASEmbeddedServer
@@ -35,11 +35,30 @@
  * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
  * @version $Revision: $
  */
-public interface JBossASEmbeddedServer
-      extends
-         JBossASBasedServer<JBossASEmbeddedServer, JBossASServerConfig>,
-         Container,
-         ArchiveContainer
+public interface JBossASEmbeddedServer extends JBossASBasedServer<JBossASEmbeddedServer, JBossASServerConfig>
 {
+   //-------------------------------------------------------------------------------||
+   // Contracts --------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
 
+   /**
+    * Deploys the specified archives into the server as one atomic operation. 
+    * 
+    * @param archives
+    * @throws DeploymentException
+    * @throws IllegalArgumentException If no archives were specified or the type of archive
+    * is not supported by this server
+    */
+   void deploy(Archive<?>... archives) throws DeploymentException, IllegalArgumentException;
+
+   /**
+    * Undeploys the specified archives from the server as one atomic operation.
+    * The archives must have been previously deployed.
+    * 
+    * @param archives
+    * @throws DeploymentException
+    * @throws IllegalArgumentException If no archives were specified or the type of archive
+    * is not supported by this server
+    */
+   void undeploy(Archive<?>... archives) throws DeploymentException, IllegalArgumentException;
 }

Modified: projects/embedded/trunk/build/pom.xml
===================================================================
--- projects/embedded/trunk/build/pom.xml	2009-11-16 03:12:46 UTC (rev 96396)
+++ projects/embedded/trunk/build/pom.xml	2009-11-16 03:56:20 UTC (rev 96397)
@@ -31,10 +31,6 @@
     <version.org.jboss.bootstrap_jboss.bootstrap.impl.emeddded>2.0.0-SNAPSHOT</version.org.jboss.bootstrap_jboss.bootstrap.impl.emeddded>
     <version.org.jboss.jbossas>5.2.0-SNAPSHOT</version.org.jboss.jbossas>
     <version.org.jboss.shrinkwrap>1.0.0-alpha-2</version.org.jboss.shrinkwrap>
-    <version.org.jboss.tmpdpl_tmpdpl.api>0.1.1-SNAPSHOT</version.org.jboss.tmpdpl_tmpdpl.api>
-    <version.org.jboss.tmpdpl_tmpdpl.api.shrinkwrap>0.1.1-SNAPSHOT</version.org.jboss.tmpdpl_tmpdpl.api.shrinkwrap>
-    <version.org.jboss.tmpdpl_tmpdpl.impl.vdf>0.1.1-SNAPSHOT</version.org.jboss.tmpdpl_tmpdpl.impl.vdf>
-    <version.org.jboss.tmpdpl_tmpdpl.impl.shrinkwrap>0.1.1-SNAPSHOT</version.org.jboss.tmpdpl_tmpdpl.impl.shrinkwrap>
 
   </properties>
 
@@ -125,7 +121,7 @@
         <configuration>
           <rules>
             <requireMavenVersion>
-              <version>[2.0.9,2.1)</version> <!-- Must be Maven 2.0.9 >= x > 2.1  -->
+              <version>[2.0.9,2.2.1)</version> <!-- Must be Maven 2.0.9 >= x > 2.2.1  -->
             </requireMavenVersion>
             <requireJavaVersion>
               <version>1.6.0</version> <!-- Must be JDK6 -->
@@ -150,7 +146,7 @@
         <scope>test</scope>
       </dependency>
 
-      <!-- ShrinkWrap (Declarative Archives) -->
+      <!-- ShrinkWrap -->
       <dependency>
         <groupId>org.jboss.shrinkwrap</groupId>
         <artifactId>shrinkwrap-api</artifactId>
@@ -166,36 +162,7 @@
         <artifactId>shrinkwrap-spi</artifactId>
         <version>${version.org.jboss.shrinkwrap}</version>
       </dependency>
-      
-      <!-- Deployable Containers (groupId and artifactId will change) -->
-      <dependency>
-        <groupId>org.jboss.tmpdpl</groupId>
-        <artifactId>tmpdpl-impl-shrinkwrap</artifactId>
-        <version>${version.org.jboss.tmpdpl_tmpdpl.impl.shrinkwrap}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.jboss.tmpdpl</groupId>
-        <artifactId>tmpdpl-impl-vdf</artifactId>
-        <version>${version.org.jboss.tmpdpl_tmpdpl.impl.vdf}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.jboss.tmpdpl</groupId>
-        <artifactId>tmpdpl-api</artifactId>
-        <version>${version.org.jboss.tmpdpl_tmpdpl.api}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.jboss.tmpdpl</groupId>
-        <artifactId>tmpdpl-api-shrinkwrap</artifactId>
-        <version>${version.org.jboss.tmpdpl_tmpdpl.api.shrinkwrap}</version>
-      </dependency>
 
-      <!-- Embedded Bootstrap -->
-      <dependency>
-        <groupId>org.jboss.bootstrap</groupId>
-        <artifactId>jboss-bootstrap-impl-embedded</artifactId>
-        <version>${version.org.jboss.bootstrap_jboss.bootstrap.impl.emeddded}</version>
-      </dependency>
-
       <!-- AS modules and 3rdparty deps -->
       <dependency>
         <groupId>org.jboss.jbossas</groupId>

Modified: projects/embedded/trunk/core/pom.xml
===================================================================
--- projects/embedded/trunk/core/pom.xml	2009-11-16 03:12:46 UTC (rev 96396)
+++ projects/embedded/trunk/core/pom.xml	2009-11-16 03:56:20 UTC (rev 96397)
@@ -49,12 +49,29 @@
       <version>${version.org.jboss.bootstrap_jboss.bootstrap.impl.as}</version>
     </dependency>
 
-    <!-- org.jboss.tmpdpl:tmpdpl-impl-shrinkwrap -->
+    <!-- org.jboss.deployers:jboss-deployers-vfs-spi -->
     <dependency>
-      <groupId>org.jboss.tmpdpl</groupId>
-      <artifactId>tmpdpl-impl-shrinkwrap</artifactId>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-vfs-spi</artifactId>
     </dependency>
 
+    <!-- org.jboss:jboss-common-core -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+    </dependency>
+
+    <!-- 
+    Test Dependencies (anything in AS is OK here)
+     -->
+
+    <dependency>
+      <groupId>org.jboss.jbossas</groupId>
+      <artifactId>jboss-as-build</artifactId>
+      <scope>test</scope>
+      <type>pom</type>
+    </dependency>
+
     <!-- JUnit -->
     <dependency>
       <groupId>junit</groupId>

Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/VfsVdfDeployableImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/VfsVdfDeployableImpl.java	                        (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/VfsVdfDeployableImpl.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -0,0 +1,348 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.embedded.core.deployable;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.embedded.spi.VdfDeployable;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VfsVdfDeployableImpl
+ * 
+ * A Deployable entity backed by a Virtual Deployer's Framework Deployment
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsVdfDeployableImpl implements VdfDeployable
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(VfsVdfDeployableImpl.class.getName());
+
+   /**
+    * System property denoting the location of the temp dir
+    */
+   private static final String SYS_PROP_TMP_DIR = "java.io.tmpdir";
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * The underlying deployment
+    */
+   private Deployment deployment;
+
+   //-------------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Internal Constructor
+    */
+   protected VfsVdfDeployableImpl(final Deployment deployment) throws IllegalArgumentException
+   {
+      // Precondition check
+      assert deployment != null : "Deployment must be specified";
+
+      // Set
+      this.setDeployment(deployment);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Factory Methods --------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Creates a new {@link VdfDeployable} from the specified archive
+    * 
+    * @param archive The archive to be created into a {@link VdfDeployable}
+    * @throws IllegalArgumentException If the archive or name is not specified 
+    */
+   public static VdfDeployable create(final Archive<?> archive) throws IllegalArgumentException
+   {
+      // Obtain name and Stream
+      final String name = archive.getName();
+      final InputStream in = archive.as(ZipExporter.class).exportZip();
+
+      // Create and return
+      return create(name, in);
+   }
+
+   /**
+    * Creates a new {@link VdfDeployable} from the specified archive and name 
+    * 
+    * @param name The name to assign the deployment
+    * @param archive an InputStream representing a series of bytes deployable by the container (eg, JAR, EAR, XML, etc)
+    * @throws IllegalArgumentException If the archive or name is not specified 
+    */
+   public static VdfDeployable create(final String name, final InputStream archive) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (name == null || name.length() == 0)
+      {
+         throw new IllegalArgumentException("name must be specified");
+      }
+      if (archive == null)
+      {
+         throw new IllegalArgumentException("archive must be specified");
+      }
+
+      // Make a temp file
+      final String tempDirLocation = AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         @Override
+         public String run()
+         {
+            return System.getProperty(SYS_PROP_TMP_DIR);
+         }
+      });
+      final File tmpDir = new File(tempDirLocation);
+      if (!tmpDir.exists())
+      {
+         throw new IllegalStateException("Could not obtain valid temp directory: " + tmpDir.getAbsolutePath());
+      }
+      if (!tmpDir.isDirectory())
+      {
+         throw new IllegalStateException("Temp location must be a directory: " + tmpDir.getAbsolutePath());
+      }
+      final File tmpFile = new File(tmpDir, name);
+      tmpFile.deleteOnExit();
+
+      // Write the ZIP to the temp file
+      final OutputStream out;
+      try
+      {
+         out = new FileOutputStream(tmpFile);
+      }
+      catch (final FileNotFoundException fnfe)
+      {
+         throw new RuntimeException("Created temp file could not be found: " + tmpFile);
+      }
+      final int len = 1024;
+      final byte[] buffer = new byte[len];
+      int read = 0;
+      try
+      {
+
+         while (((read = archive.read(buffer)) != -1))
+         {
+            out.write(buffer, 0, read);
+         }
+      }
+      catch (final IOException ioe)
+      {
+         throw new RuntimeException("Error in obtainting bytes from " + archive, ioe);
+      }
+      finally
+      {
+         try
+         {
+            archive.close();
+         }
+         catch (final IOException ignore)
+         {
+
+         }
+         try
+         {
+            out.close();
+         }
+         catch (final IOException ignore)
+         {
+
+         }
+      }
+      if (log.isLoggable(Level.FINE))
+      {
+         log.fine("Using temporary file to back deployable: " + tmpFile.getAbsolutePath());
+      }
+
+      // Delegate
+      return create(tmpFile);
+   }
+
+   /**
+    * Creates a new {@link VdfDeployable} from the specified archive
+    * 
+    * @throws IllegalArgumentException If the archive is not specified or does not exist
+    */
+   public static VdfDeployable create(final File archive) throws IllegalArgumentException
+   {
+      // Precondition checks
+      if (archive == null)
+      {
+         throw new IllegalArgumentException("archive must be specified");
+      }
+      if (!archive.exists())
+      {
+         throw new IllegalArgumentException("archive must exist: " + archive.getAbsolutePath());
+      }
+
+      // Obtain as a VFS VirtualFile
+      final URI uri = archive.toURI();
+      final VirtualFile file;
+      try
+      {
+         file = VFS.createNewRoot(uri);
+      }
+      catch (final IOException e)
+      {
+         throw new RuntimeException("Could not create new VFS root from " + archive, e);
+      }
+
+      // Create Deployment
+      final Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+      log.fine("Created deployment: " + deployment);
+
+      // Create Deployable
+      final VdfDeployable deployable = new VfsVdfDeployableImpl(deployment);
+      return deployable;
+   }
+
+   /**
+    * Constructor
+    * 
+    * Creates a new Deployable from the specified URL, 
+    * @throws IllegalArgumentException If the archive is not specified, or is not a valid archive 
+    */
+   public static VdfDeployable create(final URL archive) throws IllegalArgumentException
+   {
+      // Precondition check
+      if (archive == null)
+      {
+         throw new IllegalArgumentException("archive must be specified");
+      }
+
+      // Obtain InputStream
+      final InputStream in;
+      try
+      {
+         in = archive.openConnection().getInputStream();
+      }
+      catch (final IOException ioe)
+      {
+         throw new RuntimeException("Could not get stream from archive: " + archive, ioe);
+      }
+
+      // Obtain the name
+      final String name = archive.getPath();
+
+      // Create from stream
+      return create(name, in);
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Required Implementations -----------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.tmpdpl.spi.vdf.VdfDeployable#getDeployment()
+    */
+   @Override
+   public Deployment getDeployment()
+   {
+      return this.deployment;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Delegates to the underlying deployment for hash code
+    * {@inheritDoc}
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+
+      // Use the deployment hash code
+      result = prime * result + ((deployment == null) ? 0 : deployment.hashCode());
+      return result;
+   }
+
+   /**
+    * Deployables with equal underlying deployments, or
+    * created from archives are equal
+    * {@inheritDoc}
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(final Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      final VfsVdfDeployableImpl other = (VfsVdfDeployableImpl) obj;
+
+      // Equal if the underlying deployments are equal
+      if (deployment == null)
+      {
+         if (other.deployment != null)
+            return false;
+      }
+      else if (!deployment.equals(other.deployment))
+         return false;
+
+      return true;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @param deployment the deployment to set
+    */
+   private void setDeployment(final Deployment deployment)
+   {
+      this.deployment = deployment;
+   }
+
+}

Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java	2009-11-16 03:12:46 UTC (rev 96396)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -38,19 +38,18 @@
 import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.embedded.api.DeploymentException;
 import org.jboss.embedded.api.server.JBossASEmbeddedServer;
+import org.jboss.embedded.core.deployable.VfsVdfDeployableImpl;
 import org.jboss.embedded.core.lifecycle.IgnoreXbUnorderedSequenceLifecycleEventHandler;
 import org.jboss.embedded.core.lifecycle.InitLoggingManagerLifecycleEventHandler;
 import org.jboss.embedded.core.lifecycle.SetIPv4LifecycleEventHandler;
 import org.jboss.embedded.core.lifecycle.SetRmiHostnameLifecycleEventHandler;
+import org.jboss.embedded.spi.VdfDeployable;
 import org.jboss.kernel.Kernel;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
 import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.tmpdpl.api.container.DeploymentException;
-import org.jboss.tmpdpl.api.deployable.Deployable;
-import org.jboss.tmpdpl.api.shrinkwrap.container.deployable.DeployableArchiveFactory;
-import org.jboss.tmpdpl.spi.vdf.VdfDeployable;
 
 /**
  * JBossASEmbeddedServer
@@ -97,12 +96,12 @@
    /**
     * A mapping of deployable types to their resultant deployments (so we can undeploy)
     */
-   private final Map<Deployable, Deployment> deployableToDeploymentMap = new ConcurrentHashMap<Deployable, Deployment>();
+   private final Map<VdfDeployable, Deployment> deployableToDeploymentMap = new ConcurrentHashMap<VdfDeployable, Deployment>();
 
    /**
     * A mapping of archives to their resultant Deployables (so we can undeploy)
     */
-   private final Map<Archive<?>, Deployable> archiveToDeployableMap = new ConcurrentHashMap<Archive<?>, Deployable>();
+   private final Map<Archive<?>, VdfDeployable> archiveToDeployableMap = new ConcurrentHashMap<Archive<?>, VdfDeployable>();
 
    //-------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
@@ -134,7 +133,7 @@
     * @param Absolute location of JBOSS_HOME on the filesystem
     * @throws IllegalArgumentException If jbossHome is not specified
     */
-   public JBossASEmbeddedServerImpl(String jbossHome) throws IllegalArgumentException
+   public JBossASEmbeddedServerImpl(final String jbossHome) throws IllegalArgumentException
    {
       // Call super
       super(JBossASEmbeddedServer.class);
@@ -154,10 +153,11 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * @see org.jboss.tmpdpl.api.container.Container#deploy(org.jboss.tmpdpl.api.deployable.Deployable[])
+    * TODO
     */
-   @Override
-   public void deploy(final Deployable... deployables) throws DeploymentException, IllegalArgumentException
+   //@Override 
+   //TODO Required?
+   private void deploy(final VdfDeployable... deployables) throws DeploymentException, IllegalArgumentException
    {
       // Precondition checks and obtain as VDF impls
       final Collection<VdfDeployable> vdfDeployables = this.asVdfDeployables(deployables);
@@ -200,10 +200,11 @@
    }
 
    /**
-    * @see org.jboss.tmpdpl.api.container.Container#undeploy(org.jboss.tmpdpl.api.deployable.Deployable[])
+    * TODO
     */
-   @Override
-   public void undeploy(final Deployable... deployables) throws DeploymentException, IllegalArgumentException
+   //@Override
+   //TODO Required?
+   private void undeploy(final VdfDeployable... deployables) throws DeploymentException, IllegalArgumentException
    {
       /*
        * Precondition checks
@@ -220,7 +221,7 @@
       final MainDeployer mainDeployer = this.getMainDeployer();
 
       // Get the deployments for each deployable
-      for (final Deployable deployable : deployables)
+      for (final VdfDeployable deployable : deployables)
       {
          final Deployment deployment = this.getDeployablesToDeploymentsMap().get(deployable);
          if (deployment == null)
@@ -266,7 +267,7 @@
    public void deploy(final Archive<?>... archives) throws DeploymentException, IllegalArgumentException
    {
       // Precondition checks and obtain as array of Deployables
-      final Deployable[] deployables = this.asDeployableArray(archives);
+      final VdfDeployable[] deployables = this.asDeployableArray(archives);
 
       // Deploy
       this.deploy(deployables);
@@ -279,7 +280,7 @@
    public void undeploy(final Archive<?>... archives) throws DeploymentException, IllegalArgumentException
    {
       // Precondition checks and obtain as array of Deployables
-      final Deployable[] deployables = this.asDeployableArray(archives);
+      final VdfDeployable[] deployables = this.asDeployableArray(archives);
 
       // Undeploy
       this.undeploy(deployables);
@@ -362,7 +363,7 @@
     * @throws IllegalArgumentException If the specified archives are not specified or not of acceptable
     * (VFS) backing type
     */
-   private Deployable[] asDeployableArray(final Archive<?>... archives) throws IllegalArgumentException
+   private VdfDeployable[] asDeployableArray(final Archive<?>... archives) throws IllegalArgumentException
    {
       // Precondition check
       if (archives == null || archives.length == 0)
@@ -371,17 +372,17 @@
       }
 
       // Make a deployable from each archive
-      final Collection<Deployable> deployables = new ArrayList<Deployable>();
+      final Collection<VdfDeployable> deployables = new ArrayList<VdfDeployable>();
       for (final Archive<?> archive : archives)
       {
          // First check the mapping cache
-         final Map<Archive<?>, Deployable> archiveToDeployableMap = this.getArchiveToDeployableMap();
-         Deployable deployable = archiveToDeployableMap.get(archive);
+         final Map<Archive<?>, VdfDeployable> archiveToDeployableMap = this.getArchiveToDeployableMap();
+         VdfDeployable deployable = archiveToDeployableMap.get(archive);
          // If not in the cache
          if (deployable == null)
          {
             // Make a Deployable from the archive 
-            deployable = DeployableArchiveFactory.createDeployable(archive);
+            deployable = VfsVdfDeployableImpl.create(archive);
             // Add to the cache
             this.getArchiveToDeployableMap().put(archive, deployable);
          }
@@ -391,7 +392,7 @@
       }
 
       // Return
-      return deployables.toArray(new Deployable[]
+      return deployables.toArray(new VdfDeployable[]
       {});
    }
 
@@ -426,7 +427,8 @@
     * @throws IllegalArgumentException If the deployables are either null, empty, or
     *   contain any non-VDF types
     */
-   private Collection<VdfDeployable> asVdfDeployables(final Deployable... deployables) throws IllegalArgumentException
+   private Collection<VdfDeployable> asVdfDeployables(final VdfDeployable... deployables)
+         throws IllegalArgumentException
    {
       return this.asExpectedTypeCollection(VdfDeployable.class, deployables);
    }
@@ -522,7 +524,7 @@
     * Returns an immutable view of the deployables/deployments map
     * @return the Deployments
     */
-   protected final Map<Deployable, Deployment> getDeployablesToDeploymentsMap()
+   protected final Map<VdfDeployable, Deployment> getDeployablesToDeploymentsMap()
    {
       return Collections.unmodifiableMap(deployableToDeploymentMap);
    }
@@ -530,7 +532,7 @@
    /**
     * @return the archiveToDeployableMap
     */
-   private Map<Archive<?>, Deployable> getArchiveToDeployableMap()
+   private Map<Archive<?>, VdfDeployable> getArchiveToDeployableMap()
    {
       return archiveToDeployableMap;
    }

Added: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/spi/VdfDeployable.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/spi/VdfDeployable.java	                        (rev 0)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/spi/VdfDeployable.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.embedded.spi;
+
+import org.jboss.deployers.client.spi.Deployment;
+
+/**
+ * VdfDeployable
+ *
+ * Represents a deployable entity which may be exposed
+ * as a JBoss Virtual Deployers Framework (VDF) implementation
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface VdfDeployable
+{
+   /**
+    * Returns the VDF view of this deployment
+    * 
+    * @return
+    */
+   Deployment getDeployment();
+}

Added: projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/VfsVdfDeployableImplTestCase.java
===================================================================
--- projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/VfsVdfDeployableImplTestCase.java	                        (rev 0)
+++ projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/VfsVdfDeployableImplTestCase.java	2009-11-16 03:56:20 UTC (rev 96397)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.embedded.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.logging.Logger;
+
+import org.jboss.embedded.core.deployable.VfsVdfDeployableImpl;
+import org.jboss.embedded.spi.VdfDeployable;
+import org.jboss.virtual.VFS;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * VfsVdfDeployableImplTestCase
+ * 
+ * Test Cases to ensure that that {@link VfsVdfDeployableImpl} 
+ * is working as contracted
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class VfsVdfDeployableImplTestCase
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Logger
+    */
+   private static final Logger log = Logger.getLogger(VfsVdfDeployableImplTestCase.class.getName());
+
+   //-------------------------------------------------------------------------------------||
+   // Lifecycle --------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Initializes the Virtual File System
+    */
+   @BeforeClass
+   public static void initVfs() throws Exception
+   {
+      VFS.init();
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that the equals() contract is correct; archive types 
+    * are equal if and only if they have equal references to backing 
+    * archives.
+    * @throws Exception
+    */
+   @Test
+   public void testEqualsAndHashCode() throws Exception
+   {
+      // Log
+      log.info("testEquals");
+
+      // Make names
+      final String name1 = "archive1";
+      final String name2 = "archive2";
+
+      // Make some test archives
+      final File root = new File(this.getRoot().toURI());
+      final File archive1 = new File(root, name1);
+      final File archive2 = new File(root, name2);
+      createIfNecessary(archive1);
+      createIfNecessary(archive2);
+
+      // Make some test Deployables from the archives
+      final VdfDeployable deployable1 = VfsVdfDeployableImpl.create(archive1);
+      final VdfDeployable deployable2 = VfsVdfDeployableImpl.create(archive2);
+
+      // Test equals
+      Assert.assertTrue("Deployable must be equal to itself by value", deployable1.equals(deployable1));
+      Assert.assertFalse("Different deployables should not be equal by value", deployable1.equals(deployable2));
+
+      // Get hashCodes
+      final int deployable1HashCode = deployable1.hashCode();
+      final int deployable1HashCodeAgain = deployable1.hashCode();
+
+      // Test hashCodes
+      Assert.assertEquals("hash code op must be indempotent", deployable1HashCode, deployable1HashCodeAgain);
+
+      /*
+       * Note we don't check for inequal hash codes between deployable1 and deployable2 because technically
+       * they could collide
+       */
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Internal Helper Methods ------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Returns the root of these tests
+    */
+   private final URL getRoot()
+   {
+      return this.getClass().getProtectionDomain().getCodeSource().getLocation();
+   }
+
+   /**
+    * Creates the new specified file if necessary, erring if unable
+    * @param file
+    * @throws IOException
+    */
+   private static void createIfNecessary(final File file) throws IOException
+   {
+      if (!file.exists())
+      {
+         Assert.assertTrue("archive could not be created", file.createNewFile());
+         log.info("Created tmp file: " + file);
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list