[jboss-cvs] JBossAS SVN: r105598 - in projects/embedded/trunk: core and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 2 17:07:05 EDT 2010


Author: ALRubinger
Date: 2010-06-02 17:07:04 -0400 (Wed, 02 Jun 2010)
New Revision: 105598

Removed:
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/DeployableArchive.java
Modified:
   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
   projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/deployable/DeployableImplementationsUnitTest.java
Log:
[EMB-87] Remove ShrinkWrap Archive file serialization and use the new SW/VDF integration component ShrinkWrapDeployer to view Archives as VFS and send along to AS for deployment

Modified: projects/embedded/trunk/build/pom.xml
===================================================================
--- projects/embedded/trunk/build/pom.xml	2010-06-02 20:58:13 UTC (rev 105597)
+++ projects/embedded/trunk/build/pom.xml	2010-06-02 21:07:04 UTC (rev 105598)
@@ -28,7 +28,7 @@
 
     <!-- Versioning -->
     <version.junit_junit>4.7</version.junit_junit>
-    <version.org.jboss.shrinkwrap>1.0.0-alpha-9</version.org.jboss.shrinkwrap>
+    <version.org.jboss.shrinkwrap>1.0.0-alpha-10</version.org.jboss.shrinkwrap>
     <version.org.jboss.bootstrap>2.1.0-alpha-4</version.org.jboss.bootstrap>
 
   </properties>
@@ -147,6 +147,11 @@
       </dependency>
       <dependency>
         <groupId>org.jboss.shrinkwrap</groupId>
+        <artifactId>shrinkwrap-extension-vdf</artifactId>
+        <version>${version.org.jboss.shrinkwrap}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.shrinkwrap</groupId>
         <artifactId>shrinkwrap-impl-base</artifactId>
         <version>${version.org.jboss.shrinkwrap}</version>
       </dependency>

Modified: projects/embedded/trunk/core/pom.xml
===================================================================
--- projects/embedded/trunk/core/pom.xml	2010-06-02 20:58:13 UTC (rev 105597)
+++ projects/embedded/trunk/core/pom.xml	2010-06-02 21:07:04 UTC (rev 105598)
@@ -70,6 +70,10 @@
       <groupId>org.jboss.shrinkwrap</groupId>
       <artifactId>shrinkwrap-impl-base</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-extension-vdf</artifactId>
+    </dependency>
     
     <!-- org.jboss.logmanager -->
     <dependency>

Deleted: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/DeployableArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/DeployableArchive.java	2010-06-02 20:58:13 UTC (rev 105597)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/deployable/DeployableArchive.java	2010-06-02 21:07:04 UTC (rev 105598)
@@ -1,206 +0,0 @@
-/*
- * 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.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.logging.Logger;
-
-import org.jboss.embedded.api.Deployable;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-
-/**
- * {@link Deployable} view backed by a ShrinkWrap
- * {@link Archive}.  Immutable and Thread-safe.
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public final class DeployableArchive implements Deployable
-{
-   //-------------------------------------------------------------------------------------||
-   // Class Members ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Logger
-    */
-   private static final Logger log = Logger.getLogger(DeployableArchive.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 serialized view of this archive which
-    * will act as the delegate
-    */
-   private final Deployable serializedView;
-
-   /**
-    * Archive from which this Deployable was created; we use
-    * this in determining value equality
-    */
-   private final Archive<?> createdFrom;
-
-   //-------------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Creates a new {@link Deployable} backed by the specified
-    * {@link Archive}
-    * 
-    * @param archive
-    * @throws IllegalArgumentException If the archive is not specified
-    */
-   public DeployableArchive(final Archive<?> archive) throws IllegalArgumentException
-   {
-      if (archive == null)
-      {
-         throw new IllegalArgumentException("archive must be specified");
-      }
-
-      /*
-       * Make a temp file
-       */
-
-      // Get location for the new temp dir, and validate
-      final String tempDirLocation = AccessController.doPrivileged(GetTempDirAction.INSTANCE);
-      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());
-      }
-
-      // Make the new temp file
-      final String name = archive.getName();
-      final File tmpFile = new File(tmpDir, name);
-      tmpFile.deleteOnExit();
-
-      // Write the ZIP to the temp file
-      archive.as(ZipExporter.class).exportZip(tmpFile, true);
-
-      // Create a Deployable from the File
-      final Deployable deployableFile = new DeployableFile(tmpFile);
-
-      // Set
-      this.createdFrom = archive;
-      this.serializedView = deployableFile;
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Required Implementations -----------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * {@inheritDoc}
-    * @see org.jboss.embedded.api.Deployable#getTarget()
-    */
-   @Override
-   public URL getTarget()
-   {
-      return serializedView.getTarget();
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // Inner Classes ----------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Privileged action to obtain the temp directory
-    */
-   private static enum GetTempDirAction implements PrivilegedAction<String> {
-      INSTANCE;
-      @Override
-      public String run()
-      {
-         return System.getProperty(SYS_PROP_TMP_DIR);
-      }
-   }
-
-   //-------------------------------------------------------------------------------------||
-   // OVerridden Implementations ---------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * {@inheritDoc}
-    * @see java.lang.Object#hashCode()
-    */
-   @Override
-   public int hashCode()
-   {
-      final int prime = 31;
-      int result = 1;
-      result = prime * result + ((createdFrom == null) ? 0 : createdFrom.hashCode());
-      return result;
-   }
-
-   /**
-    * {@inheritDoc}
-    * Value equality is based upon the underlying archive; 
-    * if the referents are equal, so are we. 
-    * 
-    * @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 DeployableArchive other = (DeployableArchive) obj;
-      if (createdFrom == null)
-      {
-         // Should never be null
-         throw new IllegalStateException("Created from archive must never be null");
-      }
-      // If the underlying archives created from are equal, so are we
-      else if (createdFrom == other.createdFrom)
-      {
-         return true;
-      }
-
-      return false;
-   }
-
-   /**
-    * {@inheritDoc}
-    * @see java.lang.Object#toString()
-    */
-   @Override
-   public String toString()
-   {
-      return this.getClass().getSimpleName() + " [archive=" + createdFrom.toString(true) + "]";
-   }
-
-}

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	2010-06-02 20:58:13 UTC (rev 105597)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/server/JBossASEmbeddedServerImpl.java	2010-06-02 21:07:04 UTC (rev 105598)
@@ -47,7 +47,6 @@
 import org.jboss.embedded.api.Deployable;
 import org.jboss.embedded.api.DeploymentException;
 import org.jboss.embedded.api.server.JBossASEmbeddedServer;
-import org.jboss.embedded.core.deployable.DeployableArchive;
 import org.jboss.embedded.core.deployable.DeployableFile;
 import org.jboss.embedded.core.deployable.DeployableUrl;
 import org.jboss.embedded.core.lifecycle.IgnoreXbUnorderedSequenceLifecycleEventHandler;
@@ -60,6 +59,7 @@
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
 import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.vdf.api.ShrinkWrapDeployer;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
@@ -100,6 +100,11 @@
     * Name under which the MainDeployer is registered with MC
     */
    private static final String MC_NAME_MAIN_DEPLOYER = "MainDeployer";
+   
+   /**
+    * Deployer for ShrinkWrap {@link Archive} types
+    */
+   private ShrinkWrapDeployer shrinkWrapDeployer;
 
    //-------------------------------------------------------------------------------------||
    // Instance Members -------------------------------------------------------------------||
@@ -206,11 +211,22 @@
    @Override
    public void deploy(final Archive<?>... archives) throws DeploymentException, IllegalArgumentException
    {
-      // Make new Deployables
-      final Collection<Deployable> deployables = this.asDeployables(archives);
+      // Precondition checks
+      if (archives == null)
+      {
+         throw new IllegalArgumentException("Archives for deployment must be specified");
+      }
 
-      // Deploy
-      deploy(deployables);
+      try
+      {
+         // Delegate
+         this.getShrinkWrapDeployer().deploy(archives);
+      }
+      catch (final org.jboss.deployers.spi.DeploymentException e)
+      {
+         // Translate
+         throw new DeploymentException("Error in deploying " + Arrays.asList(archives), e);
+      }
    }
 
    /**
@@ -307,11 +323,22 @@
    @Override
    public void undeploy(final Archive<?>... archives) throws DeploymentException, IllegalArgumentException
    {
-      // Make new Deployables
-      final Collection<Deployable> deployables = this.asDeployables(archives);
+      // Precondition checks
+      if (archives == null)
+      {
+         throw new IllegalArgumentException("Archives for undeployment must be specified");
+      }
 
-      // Undeploy
-      undeploy(deployables);
+      try
+      {
+         // Delegate
+         this.getShrinkWrapDeployer().undeploy(archives);
+      }
+      catch (final org.jboss.deployers.spi.DeploymentException e)
+      {
+         // Translate
+         throw new DeploymentException("Error in undeploying " + Arrays.asList(archives), e);
+      }
    }
 
    /**
@@ -469,32 +496,6 @@
    }
 
    /**
-    * Represents the specified {@link Archive}s as a {@link Collection} of
-    * {@link Deployable}s
-    * 
-    * @param archives
-    * @return
-    * @throws IllegalArgumentException If the URLs are not specified
-    */
-   private Collection<Deployable> asDeployables(final Archive<?>... archives) throws IllegalArgumentException
-   {
-      // Precondition checks
-      if (archives == null)
-      {
-         throw new IllegalArgumentException("archives must not be null");
-      }
-
-      // Make new Deployables
-      final Collection<Deployable> deployables = new ArrayList<Deployable>(archives.length);
-      for (final Archive<?> archive : archives)
-      {
-         final Deployable deployable = new DeployableArchive(archive);
-         deployables.add(deployable);
-      }
-      return deployables;
-   }
-
-   /**
     * Represents the specified {@link File}s as a {@link Collection} of
     * {@link Deployable}s
     * 
@@ -574,6 +575,27 @@
       // Return
       return mainDeployer;
    }
+   
+   /**
+    * Obtains the {@link ShrinkWrapDeployer} for deploying archives
+    * @return
+    */
+   protected final ShrinkWrapDeployer getShrinkWrapDeployer()
+   {
+      if (shrinkWrapDeployer == null)
+      {
+         // Lookup by type 
+         final Kernel kernel = this.getKernel();
+         final KernelController controller = kernel.getController();
+         final ControllerContext context = controller.getContextByClass(ShrinkWrapDeployer.class);
+         if (context == null)
+         {
+            throw new IllegalStateException(ShrinkWrapDeployer.class.getSimpleName() + " could not be found");
+         }
+         shrinkWrapDeployer = (ShrinkWrapDeployer) context.getTarget();
+      }
+      return shrinkWrapDeployer;
+   }
 
    /**
     * Processes and checks the specified MainDeployer

Modified: projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/deployable/DeployableImplementationsUnitTest.java
===================================================================
--- projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/deployable/DeployableImplementationsUnitTest.java	2010-06-02 20:58:13 UTC (rev 105597)
+++ projects/embedded/trunk/core/src/test/java/org/jboss/embedded/core/deployable/DeployableImplementationsUnitTest.java	2010-06-02 21:07:04 UTC (rev 105598)
@@ -24,10 +24,6 @@
 import junit.framework.TestCase;
 
 import org.jboss.embedded.api.Deployable;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.junit.Test;
 
 /**
@@ -59,35 +55,6 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Ensures that {@link Deployable} types backed by an
-    * {@link Archive} are working
-    */
-   @Test
-   public void testDeployableArchive() throws Exception
-   {
-      // Create an archive
-      final JavaArchive archive = ShrinkWrap.create("archive.jar", JavaArchive.class).addClass(this.getClass());
-
-      // Make a Deployable
-      final Deployable deployable = new DeployableArchive(archive);
-
-      // Get the Deployable target
-      final URL target = deployable.getTarget();
-
-      // Test the streams for equal contents
-      final InputStream expectedStream = archive.as(ZipExporter.class).exportZip();
-      final InputStream roundtripStream = target.openStream();
-      this.assertEqualStreamContents(expectedStream, roundtripStream);
-
-      // Test Equality
-      final JavaArchive unequalArchive = ShrinkWrap.create("unequal.jar", JavaArchive.class).addClass(this.getClass());
-      final Deployable unequalDeployable = new DeployableArchive(unequalArchive);
-      final Deployable equalDeployable = new DeployableArchive(archive);
-      this.assertEquality(deployable, equalDeployable, unequalDeployable);
-
-   }
-
-   /**
     * Ensures that {@link Deployable} types backed by a
     * {@link File} are working
     */




More information about the jboss-cvs-commits mailing list