[jboss-svn-commits] JBoss Common SVN: r3510 - in tmpdpl/trunk: api/src/main/java/org/jboss/tmpdpl/api/deployable and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Sep 8 23:25:20 EDT 2009


Author: ALRubinger
Date: 2009-09-08 23:25:20 -0400 (Tue, 08 Sep 2009)
New Revision: 3510

Modified:
   tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java
   tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java
   tmpdpl/trunk/impl-vdf/src/main/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImpl.java
   tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java
   tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java
Log:
[TMPDPL-4] Refactoring to latest archives work

Modified: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java	2009-09-09 01:39:45 UTC (rev 3509)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/container/Container.java	2009-09-09 03:25:20 UTC (rev 3510)
@@ -51,7 +51,7 @@
     * @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;
+   void deploy(Archive<?>... archives) throws DeploymentException, IllegalArgumentException;
 
    /**
     * Undeploys the specified deployables from the server as one atomic operation.
@@ -73,5 +73,5 @@
     * @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;
+   void undeploy(Archive<?>... archives) throws DeploymentException, IllegalArgumentException;
 }

Modified: tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java
===================================================================
--- tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java	2009-09-09 01:39:45 UTC (rev 3509)
+++ tmpdpl/trunk/api/src/main/java/org/jboss/tmpdpl/api/deployable/VfsVdfDeployableFactory.java	2009-09-09 03:25:20 UTC (rev 3510)
@@ -27,7 +27,7 @@
  * VfsVdfDeployableFactory
  * 
  * Factory to create {@link Deployable} instances from 
- * {@link VfsArchive}s.  This removes the API
+ * {@link Archive}s.  This removes the API
  * dependency upon internals for the client view and additionally
  * acts as a convenience mechanism.
  *
@@ -54,21 +54,13 @@
    /**
     * FQN of the archive type actually supported by {@link VfsVdfDeployableFactory#createDeployable(VirtualArchive)}
     */
-   private static final String CLASS_NAME_ARCHIVE_TYPE = "org.jboss.declarchive.spi.vfs.VfsArchive";
+   private static final String CLASS_NAME_ARCHIVE_TYPE = "org.jboss.declarchive.api.Archive";
 
    /**
     * Constructor used in creating new {@link Deployable} instances
     */
    private static Constructor<?> constructor;
 
-   /**
-    * The actual type expected of archives passed to 
-    * {@link VfsVdfDeployableFactory#createDeployable(Archive)};
-    * used here to do runtime type checking so we hide the internals and don't
-    * leak out APIs to the client.  Will have FQN of {@link VfsVdfDeployableFactory#CLASS_NAME_ARCHIVE_TYPE}.
-    */
-   private static Class<?> supportedArchiveType;
-
    //-------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -89,20 +81,14 @@
     * Creates a {@link Deployable} from the specified archive
     * 
     * @param archive
-    * @throws IllegalArgumentException If the archive is not specified or an unsupported type
+    * @throws IllegalArgumentException If the archive is not specified 
     */
-   public static Deployable createDeployable(final Archive archive) throws IllegalArgumentException
+   public static Deployable createDeployable(final Archive<?> archive) throws IllegalArgumentException
    {
       // Precondition check
-      final Class<?> supportedArchiveType = getSupportedArchiveType();
-      if (!supportedArchiveType.isAssignableFrom(archive.getClass()))
+      if (archive == null)
       {
-         final ClassLoader archiveCl = archive.getClass().getClassLoader();
-         final ClassLoader supportedCl = supportedArchiveType.getClassLoader();
-         log.log(Level.WARNING, "Archive CL: " + archiveCl);
-         log.log(Level.WARNING, "Expected CL: " + supportedCl);
-         throw new IllegalArgumentException("Specified archive must be of type " + supportedArchiveType.getName()
-               + "; was instead: " + archive);
+         throw new IllegalArgumentException("Archive must be specified");
       }
 
       // Get the implementation ctor
@@ -203,21 +189,4 @@
       }
    }
 
-   /**
-    * Obtains the Class representing supported archive types to be used 
-    * in creation of new Deployables
-    * @return
-    */
-   private synchronized static Class<?> getSupportedArchiveType()
-   {
-      // If not yet initialized/cached
-      if (supportedArchiveType == null)
-      {
-         // Load and set
-         supportedArchiveType = getClass(CLASS_NAME_ARCHIVE_TYPE);
-      }
-
-      // Return
-      return supportedArchiveType;
-   }
 }

Modified: tmpdpl/trunk/impl-vdf/src/main/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImpl.java
===================================================================
--- tmpdpl/trunk/impl-vdf/src/main/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImpl.java	2009-09-09 01:39:45 UTC (rev 3509)
+++ tmpdpl/trunk/impl-vdf/src/main/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImpl.java	2009-09-09 03:25:20 UTC (rev 3510)
@@ -16,12 +16,24 @@
  */
 package org.jboss.tmpdpl.impl.vdf;
 
+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.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.jboss.declarchive.spi.vfs.VfsArchive;
+import org.jboss.declarchive.api.Archive;
+import org.jboss.declarchive.api.export.ZipExporter;
 import org.jboss.deployers.client.spi.Deployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.tmpdpl.spi.vdf.VdfDeployable;
+import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -45,6 +57,11 @@
     */
    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 -------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -57,7 +74,7 @@
    /**
     * The underlying archive; used in calculating equals() and hashCode() only
     */
-   private VfsArchive archive;
+   private Archive<?> archive;
 
    //-------------------------------------------------------------------------------------||
    // Constructor ------------------------------------------------------------------------||
@@ -69,7 +86,7 @@
     * Creates a new Deployable from the specified archive
     * @throws IllegalArgumentException If the archive is not specified 
     */
-   public VfsVdfDeployableImpl(final VfsArchive archive) throws IllegalArgumentException
+   public VfsVdfDeployableImpl(final Archive<?> archive) throws IllegalArgumentException
    {
       // Precondition check
       if (archive == null)
@@ -77,15 +94,89 @@
          throw new IllegalArgumentException("archive must be specified");
       }
 
-      // Obtain file
-      final VirtualFile file = archive.getRoot();
+      // Export to ZIP
+      final InputStream zipStream = ZipExporter.exportZip(archive);
+      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 mus tbe a directory: " + tmpDir.getAbsolutePath());
+      }
+      final String fileName = archive.getName();
+      final File tmpFile = new File(tmpDir, fileName);
 
-      // Check
-      if (file == null)
+      // Write the ZIP to the temp file
+      final OutputStream out;
+      try
       {
-         throw new IllegalArgumentException("file must be obtained from the specified archive");
+         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 = zipStream.read(buffer)) != -1))
+         {
+            out.write(buffer, 0, read);
+         }
+      }
+      catch (final IOException ioe)
+      {
+         throw new RuntimeException("Error in obtainting bytes from " + zipStream, ioe);
+      }
+      finally
+      {
+         try
+         {
+            zipStream.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());
+      }
+
+      // Obtain as a VFS VirtualFile
+      final URI uri = tmpFile.toURI();
+      final VirtualFile file;
+      try
+      {
+         file = VFS.createNewRoot(uri);
+      }
+      catch (final IOException e)
+      {
+         throw new RuntimeException("Could not create new VFS root from " + tmpFile, e);
+      }
+
       // Create Deployment
       final Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
       log.fine("Created deployment: " + deployment);
@@ -123,7 +214,7 @@
    /**
     * @return the archive
     */
-   private VfsArchive getArchive()
+   private Archive<?> getArchive()
    {
       return archive;
    }
@@ -131,7 +222,7 @@
    /**
     * @param archive the archive to set
     */
-   private void setArchive(final VfsArchive archive)
+   private void setArchive(final Archive<?> archive)
    {
       this.archive = archive;
    }
@@ -170,12 +261,12 @@
          return false;
       // Equal refs to underlying archives are equal
       final VfsVdfDeployableImpl other = (VfsVdfDeployableImpl) obj;
-      final VfsArchive ourArchive = this.getArchive();
+      final Archive<?> ourArchive = this.getArchive();
       if (ourArchive == null)
       {
          throw new IllegalStateException("Underlying archive can never be null");
       }
-      final VfsArchive otherArchive = other.getArchive();
+      final Archive<?> otherArchive = other.getArchive();
       if (ourArchive == otherArchive)
       {
          return true;

Modified: tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java
===================================================================
--- tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java	2009-09-09 01:39:45 UTC (rev 3509)
+++ tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableFactoryTestCase.java	2009-09-09 03:25:20 UTC (rev 3510)
@@ -20,8 +20,9 @@
 
 import junit.framework.Assert;
 
-import org.jboss.declarchive.api.Archive;
-import org.jboss.declarchive.impl.vfs.MemoryArchiveImpl;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.spec.JavaArchiveImpl;
 import org.jboss.tmpdpl.api.deployable.Deployable;
 import org.jboss.tmpdpl.api.deployable.VfsVdfDeployableFactory;
 import org.jboss.virtual.VFS;
@@ -78,7 +79,8 @@
       log.info("testDeployableFactory");
 
       // Make an archive
-      final Archive archive = new MemoryArchiveImpl("test.jar").addClass(this.getClass());
+      final JavaArchive archive = new JavaArchiveImpl(new MemoryMapArchiveImpl("test.jar")); // TODO Use factory
+      archive.addClass(this.getClass());
 
       // Make a Deployable
       final Deployable deployable = VfsVdfDeployableFactory.createDeployable(archive);

Modified: tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java
===================================================================
--- tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java	2009-09-09 01:39:45 UTC (rev 3509)
+++ tmpdpl/trunk/impl-vdf/src/test/java/org/jboss/tmpdpl/impl/vdf/VfsVdfDeployableImplTestCase.java	2009-09-09 03:25:20 UTC (rev 3510)
@@ -18,8 +18,9 @@
 
 import java.util.logging.Logger;
 
-import org.jboss.declarchive.impl.vfs.MemoryArchiveImpl;
-import org.jboss.declarchive.spi.vfs.VfsArchive;
+import org.jboss.declarchive.api.spec.JavaArchive;
+import org.jboss.declarchive.impl.base.MemoryMapArchiveImpl;
+import org.jboss.declarchive.impl.base.spec.JavaArchiveImpl;
 import org.jboss.tmpdpl.api.deployable.Deployable;
 import org.jboss.virtual.VFS;
 import org.junit.Assert;
@@ -77,8 +78,8 @@
       log.info("testEquals");
 
       // Make some test archives
-      final VfsArchive archive1 = new MemoryArchiveImpl("archive1");
-      final VfsArchive archive2 = new MemoryArchiveImpl("archive2");
+      final JavaArchive archive1 = new JavaArchiveImpl(new MemoryMapArchiveImpl("archive1")); // TODO Use factory
+      final JavaArchive archive2 = new JavaArchiveImpl(new MemoryMapArchiveImpl("archive2")); // TODO Use factory
 
       // Make some test Deployables from the archives
       final Deployable deployable1 = new VfsVdfDeployableImpl(archive1);



More information about the jboss-svn-commits mailing list