[jboss-osgi-commits] JBoss-OSGI SVN: r102515 - in projects/jboss-osgi/projects/vfs/trunk: vfs30 and 2 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Mar 17 09:21:24 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-17 09:21:21 -0400 (Wed, 17 Mar 2010)
New Revision: 102515

Modified:
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java
Log:
Copy VirtualJarInputStream

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java	2010-03-17 13:13:04 UTC (rev 102514)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java	2010-03-17 13:21:21 UTC (rev 102515)
@@ -37,6 +37,7 @@
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
 import org.jboss.osgi.vfs.AbstractVFS;
@@ -62,7 +63,6 @@
 {
    private static File archiveFile;
    private static VirtualFile virtualFile;
-   private static int fileLength;
    
    @BeforeClass
    public static void beforeClass() throws IOException
@@ -96,7 +96,6 @@
       FileInputStream fis = new FileInputStream(archiveFile);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       VFSUtils.copyStream(fis, baos);
-      fileLength = baos.toByteArray().length;
       
       virtualFile = AbstractVFS.getRoot(archiveFile.toURI().toURL());
    }
@@ -172,12 +171,24 @@
    }
    
    @Test
-   public void testURLStreamAccess() throws Exception
+   public void testStreamURLAccess() throws Exception
    {
+      URL streamURL = virtualFile.getStreamURL();
+      JarInputStream jarIn = new JarInputStream(streamURL.openStream());
+      Manifest manifest = jarIn.getManifest();
+      Attributes attributes = manifest.getMainAttributes();
+      String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+      assertEquals("example-simple", symbolicName);
+   }
+   
+   @Test
+   public void testStreamAccess() throws Exception
+   {
       InputStream instream = virtualFile.openStream();
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      VFSUtils.copyStream(instream, baos);
-      int actualLength = baos.toByteArray().length;
-      assertEquals(fileLength, actualLength);
+      JarInputStream jarIn = new JarInputStream(instream);
+      Manifest manifest = jarIn.getManifest();
+      Attributes attributes = manifest.getMainAttributes();
+      String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+      assertEquals("example-simple", symbolicName);
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml	2010-03-17 13:13:04 UTC (rev 102514)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/pom.xml	2010-03-17 13:21:21 UTC (rev 102515)
@@ -31,7 +31,7 @@
   <!-- Properties -->
   <properties>
     <version.jboss.shrinkwrap>1.0.0-SNAPSHOT</version.jboss.shrinkwrap>
-    <version.jboss.vfs>3.0.0-SNAPSHOT</version.jboss.vfs>
+    <version.jboss.vfs>3.0.0.CR5</version.jboss.vfs>
     <version.osgi>4.2.0</version.osgi>
   </properties>
   
@@ -47,6 +47,10 @@
       <artifactId>jboss-vfs</artifactId>
       <version>${version.jboss.vfs}</version>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
     
     <dependency>
       <groupId>junit</groupId>

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-17 13:13:04 UTC (rev 102514)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-17 13:21:21 UTC (rev 102515)
@@ -21,6 +21,7 @@
 */
 package org.jboss.osgi.vfs30;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -33,8 +34,6 @@
 import org.jboss.osgi.vfs.VirtualFile;
 import org.jboss.vfs.TempFileProvider;
 import org.jboss.vfs.VFS;
-import org.jboss.vfs.VFSUtils;
-import org.jboss.vfs.spi.MountHandle;
 
 /**
  * An adaptor to the jboss-vfs-3.0.x VFS. 
@@ -78,13 +77,13 @@
          return abstractFile;
 
       // Accept the file for mounting
-      MountHandle mountHandle = null;
+      Closeable closeable = null;
       if (acceptForMount((org.jboss.vfs.VirtualFile)other) == true)
       {
          try
          {
             TempFileProvider tmp = TempFileProvider.create("osgimount-", null);
-            mountHandle = VFS.mountZip(nativeFile, nativeFile, tmp);
+            closeable = VFS.mountZip(nativeFile, nativeFile, tmp);
          }
          catch (IOException ex)
          {
@@ -93,7 +92,7 @@
       }
 
       // Register the VirtualFile abstraction
-      abstractFile = new VirtualFileAdaptor30(nativeFile, mountHandle);
+      abstractFile = new VirtualFileAdaptor30(nativeFile, closeable);
       registry.put(nativeFile, abstractFile);
       return abstractFile;
    }
@@ -128,9 +127,5 @@
    static void safeClose(VirtualFileAdaptor30 virtualFile)
    {
       registry.remove(virtualFile.getDelegate());
-
-      MountHandle mountHandle = virtualFile.getMountHandle();
-      if (mountHandle != null)
-         VFSUtils.safeClose(mountHandle);
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java	2010-03-17 13:13:04 UTC (rev 102514)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java	2010-03-17 13:21:21 UTC (rev 102515)
@@ -21,8 +21,9 @@
 */
 package org.jboss.osgi.vfs30;
 
+import java.io.Closeable;
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -30,9 +31,14 @@
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
+import java.util.jar.JarOutputStream;
+import java.util.zip.ZipEntry;
 
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.vfs.spi.MountHandle;
+import org.jboss.vfs.TempDir;
+import org.jboss.vfs.TempFileProvider;
+import org.jboss.vfs.VFSUtils;
+import org.jboss.vfs.VirtualJarInputStream;
 
 /**
  * An adaptor to the jboss-vfs-3.0.x VirtualFile. 
@@ -43,12 +49,13 @@
 class VirtualFileAdaptor30 implements VirtualFile
 {
    private org.jboss.vfs.VirtualFile delegate;
-   private MountHandle mountHandle;
+   private Closeable closeable;
+   private URL streamURL;
 
-   VirtualFileAdaptor30(org.jboss.vfs.VirtualFile root, MountHandle mountHandle)
+   VirtualFileAdaptor30(org.jboss.vfs.VirtualFile root, Closeable closeable)
    {
       this(root);
-      this.mountHandle = mountHandle;
+      this.closeable = closeable;
    }
 
    VirtualFileAdaptor30(org.jboss.vfs.VirtualFile delegate)
@@ -63,11 +70,6 @@
       return delegate;
    }
 
-   MountHandle getMountHandle()
-   {
-      return mountHandle;
-   }
-
    public String getName()
    {
       return delegate.getName();
@@ -98,11 +100,33 @@
    @Override
    public URL getStreamURL() throws IOException
    {
-      if (mountHandle == null)
-         return null;
-      
-      File mountSource = mountHandle.getMountSource();
-      return mountSource.toURI().toURL();
+      if (streamURL == null)
+      {
+         if (delegate.isFile() == true)
+         {
+            streamURL = delegate.toURL();
+         }
+         else
+         {
+            TempFileProvider tmpProvider = TempFileProvider.create("osgiurl-", null);
+            TempDir tmpDir = tmpProvider.createTempDir(getName());
+            File file = tmpDir.getFile(getName());
+            JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(file));
+            
+            VirtualJarInputStream jarIn = (VirtualJarInputStream)delegate.openStream();
+            ZipEntry nextEntry = jarIn.getNextEntry();
+            while(nextEntry != null)
+            {
+               jarOut.putNextEntry(nextEntry);
+               VFSUtils.copyStream(jarIn, jarOut);
+               nextEntry = jarIn.getNextEntry();
+            }
+            jarOut.close();
+            jarIn.close();
+            streamURL = file.toURI().toURL();
+         }
+      }
+      return streamURL;
    }
 
    @Override
@@ -170,17 +194,16 @@
    @Override
    public InputStream openStream() throws IOException
    {
-      if (mountHandle != null)
-      {
-         File mountSource = mountHandle.getMountSource();
-         return new FileInputStream(mountSource);
-      }
+      if (closeable != null)
+         return getStreamURL().openStream();
+      
       return delegate.openStream();
    }
 
    @Override
    public void close()
    {
+      VFSUtils.safeClose(closeable);
       VFSAdaptor30.safeClose(this);
    }
 

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java	2010-03-17 13:13:04 UTC (rev 102514)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java	2010-03-17 13:21:21 UTC (rev 102515)
@@ -37,6 +37,7 @@
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 
 import org.jboss.osgi.vfs.AbstractVFS;
@@ -62,7 +63,6 @@
 {
    private static File archiveFile;
    private static VirtualFile virtualFile;
-   private static int fileLength;
    
    @BeforeClass
    public static void beforeClass() throws IOException
@@ -96,7 +96,6 @@
       FileInputStream fis = new FileInputStream(archiveFile);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       VFSUtils.copyStream(fis, baos);
-      fileLength = baos.toByteArray().length;
       
       virtualFile = AbstractVFS.getRoot(archiveFile.toURI().toURL());
    }
@@ -172,12 +171,24 @@
    }
    
    @Test
-   public void testURLStreamAccess() throws Exception
+   public void testStreamURLAccess() throws Exception
    {
+      URL streamURL = virtualFile.getStreamURL();
+      JarInputStream jarIn = new JarInputStream(streamURL.openStream());
+      Manifest manifest = jarIn.getManifest();
+      Attributes attributes = manifest.getMainAttributes();
+      String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+      assertEquals("example-simple", symbolicName);
+   }
+   
+   @Test
+   public void testStreamAccess() throws Exception
+   {
       InputStream instream = virtualFile.openStream();
-      ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      VFSUtils.copyStream(instream, baos);
-      int actualLength = baos.toByteArray().length;
-      assertEquals(fileLength, actualLength);
+      JarInputStream jarIn = new JarInputStream(instream);
+      Manifest manifest = jarIn.getManifest();
+      Attributes attributes = manifest.getMainAttributes();
+      String symbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
+      assertEquals("example-simple", symbolicName);
    }
 }
\ No newline at end of file



More information about the jboss-osgi-commits mailing list