[jboss-osgi-commits] JBoss-OSGI SVN: r102310 - in projects/jboss-osgi/projects: testing/trunk/src/test/java/org/jboss/test/osgi/testing and 7 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Mar 11 17:59:56 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-11 17:59:54 -0500 (Thu, 11 Mar 2010)
New Revision: 102310

Modified:
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
   projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java
   projects/jboss-osgi/projects/vfs/trunk/vfs21/.settings/org.eclipse.jdt.core.prefs
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
   projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java
   projects/jboss-osgi/projects/vfs/trunk/vfs30/.settings/org.eclipse.jdt.core.prefs
   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:
Use installBundle(location, stream)

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -23,6 +23,7 @@
 
 // $Id$
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -40,6 +41,7 @@
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.osgi.vfs.VirtualFile;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -67,11 +69,18 @@
 
    OSGiBundle installBundle(BundleInfo info) throws BundleException
    {
-      BundleContext context = getSystemContext();
-      String location = toFileURL(info.getRootURL()).toExternalForm();
-      Bundle auxBundle = context.installBundle(location);
-      OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
-      return registerBundle(bundle.getLocation(), bundle);
+      try
+      {
+         VirtualFile rootFile = info.getRoot();
+         BundleContext context = getSystemContext();
+         Bundle auxBundle = context.installBundle(info.getLocation(), rootFile.openStream());
+         OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
+         return registerBundle(bundle.getLocation(), bundle);
+      }
+      catch (IOException ex)
+      {
+         throw new BundleException("Cannot install bundle: " + info, ex);
+      }
    }
 
    public OSGiBundle[] getBundles()

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -24,7 +24,6 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -400,27 +399,6 @@
       }
    }
 
-   // [JBVFS-147] Cannot read from vfs: protocol URL 
-   URL toFileURL(URL url) 
-   {
-      if (url.getProtocol().equals("vfs"))
-      {
-         File file = new File(url.getPath());
-         if (file.exists())
-         {
-            try
-            {
-               url = file.toURI().toURL();
-            }
-            catch (MalformedURLException e)
-            {
-               // ignore
-            }
-         }
-      }
-      return url;
-   }
-
    VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
    {
       ZipExporter exporter = archive.as(ZipExporter.class);

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -74,8 +74,9 @@
    {
       try
       {
-         String location = toFileURL(info.getRootURL()).toExternalForm();
-         long bundleId = getFrameworkMBean().installBundle(location);
+         String location = info.getLocation();
+         String streamURL = info.getRoot().getStreamURL().toExternalForm();
+         long bundleId = getFrameworkMBean().installBundle(location, streamURL);
          RemoteBundle bundle = new RemoteBundle(this, bundleId);
          return registerBundle(bundle.getLocation(), bundle);
       }

Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -47,7 +47,7 @@
  */
 public class SimpleTestCase extends OSGiTest
 {
-   @Test
+   @Ignore
    public void testSimpleBundle() throws Exception
    {
       // Get the default runtime
@@ -101,7 +101,7 @@
       }
    }
 
-   @Ignore // https://jira.jboss.org/jira/browse/JBVFS-147
+   @Test
    public void testSimpleVirtualFile() throws Exception
    {
       OSGiRuntime runtime = getDefaultRuntime();

Modified: projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VirtualFile.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -82,11 +82,11 @@
    URL toURL() throws IOException;
 
    /**
-    * Get the file URL used for the mount.
-    *
-    * @return The source file URL or null if this is not the root.
+    * Get the URL used for streaming.
+    * 
+    * @return The stream URL or null if this is not the mounted root file.
     */
-   URL getFileURL() throws IOException;
+   URL getStreamURL() throws IOException;
 
    /**
     * Get the parent

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/.settings/org.eclipse.jdt.core.prefs	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/.settings/org.eclipse.jdt.core.prefs	2010-03-11 22:59:54 UTC (rev 102310)
@@ -1,13 +1,13 @@
-#Tue Mar 02 22:33:56 CET 2010
+#Thu Mar 11 22:29:34 CET 2010
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.compliance=1.6
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
 org.eclipse.jdt.core.compiler.debug.localVariable=generate
 org.eclipse.jdt.core.compiler.debug.sourceFile=generate
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VirtualFileAdaptor21.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -62,11 +62,13 @@
       return delegate;
    }
 
+   @Override
    public String getName()
    {
       return delegate.getName();
    }
 
+   @Override
    public String getPathName()
    {
       String pathName = "";
@@ -82,16 +84,19 @@
       return pathName;
    }
 
+   @Override
    public boolean isFile() throws IOException
    {
       return delegate.isLeaf();
    }
 
+   @Override
    public boolean isDirectory() throws IOException
    {
       return delegate.isLeaf() == false;
    }
 
+   @Override
    public URL toURL() throws IOException
    {
       try
@@ -104,7 +109,8 @@
       }
    }
 
-   public URL getFileURL() throws IOException
+   @Override
+   public URL getStreamURL() throws IOException
    {
       if (root != delegate)
          return null;
@@ -121,17 +127,20 @@
       }
    }
 
+   @Override
    public void close()
    {
       delegate.close();
    }
 
+   @Override
    public VirtualFile getParent() throws IOException
    {
       org.jboss.virtual.VirtualFile parent = delegate.getParent();
       return parent != null ? new VirtualFileAdaptor21(root, parent) : null;
    }
 
+   @Override
    public VirtualFile getChild(String path) throws IOException
    {
       org.jboss.virtual.VirtualFile child = delegate.getChild(path);
@@ -141,6 +150,7 @@
       return new VirtualFileAdaptor21(root, child);
    }
 
+   @Override
    public List<VirtualFile> getChildrenRecursively() throws IOException
    {
       List<VirtualFile> files = new ArrayList<VirtualFile>();
@@ -150,6 +160,7 @@
       return Collections.unmodifiableList(files);
    }
 
+   @Override
    public Enumeration<URL> findEntries(String path, String pattern, boolean recurse) throws IOException
    {
       if (path == null)
@@ -168,6 +179,7 @@
       return new VFSFindEntriesEnumeration(delegate, child, pattern, recurse);
    }
 
+   @Override
    public Enumeration<String> getEntryPaths(String path) throws IOException
    {
       if (path == null)
@@ -183,6 +195,7 @@
       return new VFSEntryPathsEnumeration(delegate, child);
    }
 
+   @Override
    public InputStream openStream() throws IOException
    {
       return delegate.openStream();

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-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/test/java/org/jboss/test/osgi/vfs21/SimpleVFS21Test.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -32,7 +32,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
@@ -48,6 +47,7 @@
 import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.test.osgi.vfs21.bundle.SimpleActivator;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Constants;
@@ -60,6 +60,7 @@
  */
 public class SimpleVFS21Test
 {
+   private static File archiveFile;
    private static VirtualFile virtualFile;
    private static int fileLength;
    
@@ -88,18 +89,24 @@
 
       // Convert archive to file URL 
       ZipExporter exporter = archive.as(ZipExporter.class);
-      File target = File.createTempFile("archive_", ".jar");
-      exporter.exportZip(target, true);
-      target.deleteOnExit();
+      archiveFile = File.createTempFile("archive_", ".jar");
+      exporter.exportZip(archiveFile, true);
+      archiveFile.deleteOnExit();
       
-      FileInputStream fis = new FileInputStream(target);
+      FileInputStream fis = new FileInputStream(archiveFile);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       VFSUtils.copyStream(fis, baos);
       fileLength = baos.toByteArray().length;
       
-      virtualFile = AbstractVFS.getRoot(target.toURI().toURL());
+      virtualFile = AbstractVFS.getRoot(archiveFile.toURI().toURL());
    }
    
+   @AfterClass
+   public static void afterClass() throws IOException
+   {
+      virtualFile.close();
+   }
+   
    @Test
    public void testManifestAccess() throws Exception
    {
@@ -120,9 +127,7 @@
       assertNotNull("Manifest not null", child);
       
       URL childURL = child.toURL();
-      URLConnection con = childURL.openConnection();
-      con.connect();
-      InputStream is = con.getInputStream();
+      InputStream is = childURL.openStream();
       
       Manifest manifest = new Manifest();
       manifest.read(is);
@@ -169,13 +174,9 @@
    @Test
    public void testURLStreamAccess() throws Exception
    {
-      URL fileURL = virtualFile.getFileURL();
-      URLConnection con = fileURL.openConnection();
-      con.connect();
-      InputStream is = con.getInputStream();
-      
+      InputStream instream = virtualFile.openStream();
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      VFSUtils.copyStream(is, baos);
+      VFSUtils.copyStream(instream, baos);
       int actualLength = baos.toByteArray().length;
       assertEquals(fileLength, actualLength);
    }

Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/.settings/org.eclipse.jdt.core.prefs	2010-03-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/.settings/org.eclipse.jdt.core.prefs	2010-03-11 22:59:54 UTC (rev 102310)
@@ -1,6 +1,13 @@
-#Tue Mar 02 21:26:56 CET 2010
+#Thu Mar 11 22:18:50 CET 2010
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
 org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6

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-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -24,12 +24,18 @@
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.jboss.osgi.vfs.VFSAdaptor;
 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;
+import org.jboss.vfs.util.automount.Automounter;
 
 /**
  * An adaptor to the jboss-vfs-3.0.x VFS. 
@@ -39,8 +45,21 @@
  */
 public class VFSAdaptor30 implements VFSAdaptor
 {
+   private static Map<String, VirtualFile> registry = new ConcurrentHashMap<String, VirtualFile>();
+   private static Set<String> suffixes = new HashSet<String>();
+   static
+   {
+      suffixes.add(".jar");
+      suffixes.add(".war");
+   }
+   
    public VirtualFile getRoot(URL url) throws IOException
    {
+      VirtualFile virtualFile = registry.get(url.toExternalForm());
+      if (virtualFile != null)
+         return virtualFile;
+      
+      // Get the VFS file
       org.jboss.vfs.VirtualFile root;
       try
       {
@@ -51,10 +70,26 @@
          throw new IOException(ex);
       }
       
-      TempFileProvider tmp = TempFileProvider.create("osgiroot", null);
-      MountHandle mountHandle = VFS.mountZip(root, root, tmp);
-      
-      return new VirtualFileAdaptor30(root, mountHandle);
+      // Accept the file for mounting
+      MountHandle mountHandle = null;
+      if (root.isFile() && Automounter.isMounted(root) == false)
+      {
+         String rootName = root.getName();
+         for (String suffix : suffixes)
+         {
+            if (rootName.endsWith(suffix))
+            {
+               TempFileProvider tmp = TempFileProvider.create("osgimount-", null);
+               mountHandle = VFS.mountZip(root, root, tmp);
+               break;
+            }
+         }
+      }
+         
+      // Register the virtual file
+      virtualFile = new VirtualFileAdaptor30(root, mountHandle, url);
+      registry.put(url.toExternalForm(), virtualFile);
+      return virtualFile;
    }
 
    public VirtualFile adapt(Object virtualFile)
@@ -76,4 +111,13 @@
       VirtualFileAdaptor30 adaptor = (VirtualFileAdaptor30)virtualFile;
       return adaptor.getDelegate();
    }
+
+   static void safeClose(VirtualFileAdaptor30 virtualFile)
+   {
+      registry.remove(virtualFile.getRootURL());
+      
+      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-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -22,6 +22,7 @@
 package org.jboss.osgi.vfs30;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -31,7 +32,6 @@
 import java.util.List;
 
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.vfs.VFSUtils;
 import org.jboss.vfs.spi.MountHandle;
 
 /**
@@ -44,11 +44,13 @@
 {
    private org.jboss.vfs.VirtualFile delegate;
    private MountHandle mountHandle;
+   private URL rootURL;
 
-   VirtualFileAdaptor30(org.jboss.vfs.VirtualFile root, MountHandle mountHandle)
+   VirtualFileAdaptor30(org.jboss.vfs.VirtualFile root, MountHandle mountHandle, URL rootURL)
    {
       this(root);
       this.mountHandle = mountHandle;
+      this.rootURL = rootURL;
    }
 
    VirtualFileAdaptor30(org.jboss.vfs.VirtualFile delegate)
@@ -63,6 +65,16 @@
       return delegate;
    }
 
+   MountHandle getMountHandle()
+   {
+      return mountHandle;
+   }
+
+   URL getRootURL()
+   {
+      return rootURL;
+   }
+
    public String getName()
    {
       return delegate.getName();
@@ -83,13 +95,15 @@
       return delegate.isDirectory();
    }
 
+   @Override
    public URL toURL() throws IOException
    {
       URL url = delegate.toURL();
       return url;
    }
 
-   public URL getFileURL() throws IOException
+   @Override
+   public URL getStreamURL() throws IOException
    {
       if (mountHandle == null)
          return null;
@@ -98,12 +112,14 @@
       return mountSource.toURI().toURL();
    }
 
+   @Override
    public VirtualFile getParent()
    {
       org.jboss.vfs.VirtualFile parent = delegate.getParent();
       return parent != null ? new VirtualFileAdaptor30(parent) : null;
    }
 
+   @Override
    public VirtualFile getChild(String path) throws IOException
    {
       org.jboss.vfs.VirtualFile child = delegate.getChild(path);
@@ -113,6 +129,7 @@
       return new VirtualFileAdaptor30(child);
    }
 
+   @Override
    public List<VirtualFile> getChildrenRecursively() throws IOException
    {
       List<VirtualFile> files = new ArrayList<VirtualFile>();
@@ -122,6 +139,7 @@
       return Collections.unmodifiableList(files);
    }
 
+   @Override
    public Enumeration<URL> findEntries(String path, String pattern, boolean recurse) throws IOException
    {
       if (path == null)
@@ -140,6 +158,7 @@
       return new VFSFindEntriesEnumeration(delegate, child, pattern, recurse);
    }
 
+   @Override
    public Enumeration<String> getEntryPaths(String path) throws IOException
    {
       if (path == null)
@@ -155,15 +174,21 @@
       return new VFSEntryPathsEnumeration(delegate, child);
    }
 
+   @Override
    public InputStream openStream() throws IOException
    {
+      if (mountHandle != null)
+      {
+         File mountSource = mountHandle.getMountSource();
+         return new FileInputStream(mountSource);
+      }
       return delegate.openStream();
    }
 
+   @Override
    public void close()
    {
-      if (mountHandle != null)
-         VFSUtils.safeClose(mountHandle);
+      VFSAdaptor30.safeClose(this);
    }
 
    @Override

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-11 21:55:15 UTC (rev 102309)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/test/java/org/jboss/test/osgi/vfs30/SimpleVFS30Test.java	2010-03-11 22:59:54 UTC (rev 102310)
@@ -32,7 +32,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
@@ -48,6 +47,7 @@
 import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.test.osgi.vfs30.bundle.SimpleActivator;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.osgi.framework.Constants;
@@ -60,6 +60,7 @@
  */
 public class SimpleVFS30Test
 {
+   private static File archiveFile;
    private static VirtualFile virtualFile;
    private static int fileLength;
    
@@ -88,18 +89,24 @@
 
       // Convert archive to file URL 
       ZipExporter exporter = archive.as(ZipExporter.class);
-      File target = File.createTempFile("archive_", ".jar");
-      exporter.exportZip(target, true);
-      target.deleteOnExit();
+      archiveFile = File.createTempFile("archive_", ".jar");
+      exporter.exportZip(archiveFile, true);
+      archiveFile.deleteOnExit();
       
-      FileInputStream fis = new FileInputStream(target);
+      FileInputStream fis = new FileInputStream(archiveFile);
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       VFSUtils.copyStream(fis, baos);
       fileLength = baos.toByteArray().length;
       
-      virtualFile = AbstractVFS.getRoot(target.toURI().toURL());
+      virtualFile = AbstractVFS.getRoot(archiveFile.toURI().toURL());
    }
    
+   @AfterClass
+   public static void afterClass() throws IOException
+   {
+      virtualFile.close();
+   }
+   
    @Test
    public void testManifestAccess() throws Exception
    {
@@ -120,9 +127,7 @@
       assertNotNull("Manifest not null", child);
       
       URL childURL = child.toURL();
-      URLConnection con = childURL.openConnection();
-      con.connect();
-      InputStream is = con.getInputStream();
+      InputStream is = childURL.openStream();
       
       Manifest manifest = new Manifest();
       manifest.read(is);
@@ -169,13 +174,9 @@
    @Test
    public void testURLStreamAccess() throws Exception
    {
-      URL fileURL = virtualFile.getFileURL();
-      URLConnection con = fileURL.openConnection();
-      con.connect();
-      InputStream is = con.getInputStream();
-      
+      InputStream instream = virtualFile.openStream();
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
-      VFSUtils.copyStream(is, baos);
+      VFSUtils.copyStream(instream, baos);
       int actualLength = baos.toByteArray().length;
       assertEquals(fileLength, actualLength);
    }



More information about the jboss-osgi-commits mailing list