[jboss-cvs] JBossAS SVN: r102977 - in projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing: internal and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 25 17:01:42 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-25 17:01:42 -0400 (Thu, 25 Mar 2010)
New Revision: 102977

Modified:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
Log:
Add better support for installBundle

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java	2010-03-25 20:07:30 UTC (rev 102976)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java	2010-03-25 21:01:42 UTC (rev 102977)
@@ -29,7 +29,8 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
+import java.io.IOException;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -43,12 +44,12 @@
 import org.jboss.osgi.vfs.AbstractVFS;
 import org.jboss.osgi.vfs.VirtualFile;
 import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.ServiceEvent;
@@ -104,21 +105,22 @@
       return (PackageAdmin)systemContext.getService(sref);
    }
    
-   protected Bundle installBundle(Archive<?> archive) throws Exception
+   protected Bundle installBundle(String location) throws BundleException, IOException
    {
-      ZipExporter exporter = archive.as(ZipExporter.class);
-      File target = File.createTempFile("archive_", ".jar");
-      exporter.exportZip(target, true);
-      target.deleteOnExit();
-      
-      VirtualFile virtualFile = AbstractVFS.getRoot(target.toURI().toURL());
+      URL bundleURL = getTestHelper().getTestArchiveURL(location);
+      return installBundle(AbstractVFS.getRoot(bundleURL));
+   }
+   
+   protected Bundle installBundle(Archive<?> archive) throws BundleException, IOException
+   {
+      VirtualFile virtualFile = OSGiTestHelper.toVirtualFile(archive);
       return installBundle(virtualFile);
    }
    
-   protected Bundle installBundle(VirtualFile archive) throws Exception
+   protected Bundle installBundle(VirtualFile virtualFile) throws BundleException, IOException
    {
-      String location = archive.getPathName();
-      return systemContext.installBundle(location, archive.openStream());
+      String location = virtualFile.getPathName();
+      return systemContext.installBundle(location, virtualFile.openStream());
    }
    
    protected void assertLoadClass(Bundle bundle, String className, Bundle exporter)

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java	2010-03-25 20:07:30 UTC (rev 102976)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java	2010-03-25 21:01:42 UTC (rev 102977)
@@ -37,6 +37,7 @@
 import org.jboss.osgi.spi.util.ConstantsHelper;
 import org.jboss.osgi.vfs.AbstractVFS;
 import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.Archives;
 import org.jboss.shrinkwrap.api.Asset;
 import org.jboss.shrinkwrap.api.exporter.ZipExporter;
@@ -98,10 +99,20 @@
    {
       try
       {
-         return getTestArchiveFile(archive).toURI().toURL();
+         URL archiveURL = new URL(archive);
+         return archiveURL;
       }
       catch (MalformedURLException ex)
       {
+         // ignore
+      }
+      try
+      {
+         File file = getTestArchiveFile(archive);
+         return file.toURI().toURL();
+      }
+      catch (MalformedURLException ex)
+      {
          throw new IllegalStateException(ex);
       }
    }
@@ -109,7 +120,8 @@
    /** Try to discover the absolute path for the deployment archive */
    public String getTestArchivePath(String archive)
    {
-      return getTestArchiveFile(archive).getAbsolutePath();
+      File archiveFile = getTestArchiveFile(archive);
+      return archiveFile.getAbsolutePath();
    }
 
    /** Try to discover the File for the deployment archive */
@@ -203,11 +215,17 @@
       }
 
       // Convert archive to file URL 
+      VirtualFile virtualFile = toVirtualFile(archive);
+      return virtualFile;
+   }
+
+   @SuppressWarnings("rawtypes")
+   public static VirtualFile toVirtualFile(Archive archive) throws IOException, MalformedURLException
+   {
       ZipExporter exporter = archive.as(ZipExporter.class);
       File target = File.createTempFile("archive_", ".jar");
       exporter.exportZip(target, true);
       target.deleteOnExit();
-
       return AbstractVFS.getRoot(target.toURI().toURL());
    }
 

Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2010-03-25 20:07:30 UTC (rev 102976)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2010-03-25 21:01:42 UTC (rev 102977)
@@ -21,9 +21,7 @@
  */
 package org.jboss.osgi.testing.internal;
 
-import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -49,10 +47,9 @@
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiRuntimeHelper;
 import org.jboss.osgi.testing.OSGiServiceReference;
-import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.testing.OSGiTestHelper;
 import org.jboss.osgi.vfs.VirtualFile;
 import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.exporter.ZipExporter;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
 import org.osgi.jmx.framework.BundleStateMBean;
@@ -151,7 +148,7 @@
 
    public OSGiBundle installBundle(Archive<?> archive) throws BundleException, IOException
    {
-      VirtualFile virtualFile = toVirtualFile(archive);
+      VirtualFile virtualFile = OSGiTestHelper.toVirtualFile(archive);
       BundleInfo info = BundleInfo.createBundleInfo(virtualFile);
       return installBundle(info);
    }
@@ -343,16 +340,6 @@
          tuple.uninstall();
    }
 
-   private VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
-   {
-      ZipExporter exporter = archive.as(ZipExporter.class);
-      File target = File.createTempFile("archive_", ".jar");
-      exporter.exportZip(target, true);
-      target.deleteOnExit();
-      
-      return AbstractVFS.getRoot(target.toURI().toURL());
-   }
-   
    class BundleTuple
    {
       BundleInfo info;




More information about the jboss-cvs-commits mailing list