[jboss-osgi-commits] JBoss-OSGI SVN: r102132 - in projects/jboss-osgi/projects/testing/trunk: src/main/java/org/jboss/osgi/testing and 4 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Mar 9 09:59:28 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-09 09:59:26 -0500 (Tue, 09 Mar 2010)
New Revision: 102132

Added:
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java
   projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/
   projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF
Modified:
   projects/jboss-osgi/projects/testing/trunk/pom.xml
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
   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/SimpleAssemblyTestCase.java
   projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
Log:
Add support for shrinkwrap

Modified: projects/jboss-osgi/projects/testing/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/pom.xml	2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/pom.xml	2010-03-09 14:59:26 UTC (rev 102132)
@@ -10,6 +10,14 @@
   <!-- ====================================================================== -->
 
   <!-- $Id$ -->
+  
+  <!-- 
+    Set these VM properties in your IDE debugger
+     
+    -Djava.protocol.handler.pkgs=org.jboss.net.protocol|org.jboss.virtual.protocol|org.jboss.vfs.protocol
+    -Dlog4j.output.dir=${workspace_loc:jboss-osgi-testing/target}
+    -Dtest.archive.directory=${workspace_loc:jboss-osgi-testing/target}/test-libs
+   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
@@ -42,7 +50,7 @@
   <properties>
     <version.apache.aries.jmx>1.0.0-incubating-SNAPSHOT</version.apache.aries.jmx>
     <version.apache.felix.log>1.0.0</version.apache.felix.log>
-    <version.jboss.shrinkwrap>1.0.0-alpha-6</version.jboss.shrinkwrap>
+    <version.jboss.shrinkwrap>1.0.0-SNAPSHOT</version.jboss.shrinkwrap>
     <version.jboss.osgi.common>1.0.4-SNAPSHOT</version.jboss.osgi.common>
     <version.jboss.osgi.felix>2.0.2.SP1-SNAPSHOT</version.jboss.osgi.felix>
     <version.jboss.osgi.jmx>1.0.4-SNAPSHOT</version.jboss.osgi.jmx>
@@ -75,7 +83,7 @@
     <dependency>
       <groupId>org.jboss.shrinkwrap</groupId>
       <artifactId>shrinkwrap-api</artifactId>
-    <version>${version.jboss.shrinkwrap}</version>
+      <version>${version.jboss.shrinkwrap}</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
@@ -141,10 +149,16 @@
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.vfs</groupId>
-      <artifactId>jboss-osgi-vfs21</artifactId>
+      <artifactId>jboss-osgi-vfs30</artifactId>
       <version>${version.jboss.osgi.vfs}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-impl-base</artifactId>
+      <version>${version.jboss.shrinkwrap}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -211,7 +225,7 @@
           <systemProperties>
             <property>
               <name>java.protocol.handler.pkgs</name>
-              <value>org.jboss.net.protocol|org.jboss.virtual.protocol</value>
+              <value>org.jboss.net.protocol|org.jboss.virtual.protocol|org.jboss.vfs.protocol</value>
             </property>
             <property>
               <name>log4j.output.dir</name>

Copied: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java (from rev 102117, projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/ManifestBuilder.java)
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java	                        (rev 0)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -0,0 +1,157 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.testing;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.osgi.framework.Constants;
+
+/**
+ * A simple OSGi manifest builder.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 08-Mar-2010
+ */
+public final class ManifestBuilder implements Asset
+{
+   private StringWriter sw;
+   private PrintWriter pw;
+   private List<String> importPackages = new ArrayList<String>();
+   private List<String> exportPackages = new ArrayList<String>();
+
+   public static ManifestBuilder newInstance()
+   {
+      return new ManifestBuilder();
+   }
+
+   private ManifestBuilder()
+   {
+      sw = new StringWriter();
+      pw = new PrintWriter(sw);
+      pw.println(Attributes.Name.MANIFEST_VERSION + ": 1.0");
+   }
+
+   public ManifestBuilder addBundleManifestVersion(int version)
+   {
+      pw.println(Constants.BUNDLE_MANIFESTVERSION + ": " + version);
+      return this;
+   }
+
+   public ManifestBuilder addBundleSymbolicName(String symbolicName)
+   {
+      pw.println(Constants.BUNDLE_SYMBOLICNAME + ": " + symbolicName);
+      return this;
+   }
+
+   public ManifestBuilder addBundleActivator(String bundleActivator)
+   {
+      pw.println(Constants.BUNDLE_ACTIVATOR + ": " + bundleActivator);
+      return this;
+   }
+
+   public ManifestBuilder addImportPackages(String... packages)
+   {
+      for (String aux : packages)
+         importPackages.add(aux);
+
+      return this;
+   }
+
+   public ManifestBuilder addExportPackages(String... packages)
+   {
+      for (String aux : packages)
+         exportPackages.add(aux);
+
+      return this;
+   }
+
+   public ManifestBuilder addManifestHeader(String key, String value)
+   {
+      pw.println(key + ": " + value);
+      return this;
+   }
+
+   public Manifest getManifest()
+   {
+      if (exportPackages.size() > 0)
+      {
+         pw.print(Constants.EXPORT_PACKAGE + ": ");
+         for (int i = 0; i < exportPackages.size(); i++)
+         {
+            if (i > 0)
+               pw.print(",");
+            
+            pw.print(exportPackages.get(i));
+         }
+         pw.println();
+      }
+      
+      if (importPackages.size() > 0)
+      {
+         pw.print(Constants.IMPORT_PACKAGE + ": ");
+         for (int i = 0; i < importPackages.size(); i++)
+         {
+            if (i > 0)
+               pw.print(",");
+            
+            pw.print(importPackages.get(i));
+         }
+         pw.println();
+      }
+      
+      try
+      {
+         Manifest manifest = new Manifest(new ByteArrayInputStream(sw.toString().getBytes()));
+         return manifest;
+      }
+      catch (IOException ex)
+      {
+         throw new IllegalStateException("Cannot create manifest", ex);
+      }
+   }
+
+   @Override
+   public InputStream openStream()
+   {
+      Manifest manifest = getManifest();
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      try
+      {
+         manifest.write(baos);
+         return new ByteArrayInputStream(baos.toByteArray());
+      }
+      catch (IOException ex)
+      {
+         throw new IllegalStateException("Cannot provide manifest InputStream", ex);
+      }
+   }
+}

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java	2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -29,6 +29,7 @@
 
 import org.jboss.osgi.spi.capability.Capability;
 import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archive;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
 import org.osgi.jmx.framework.BundleStateMBean;
@@ -60,6 +61,11 @@
    void removeCapability(Capability capability);
 
    /**
+    * Install an {@link OSGiBundle} from the given archive.
+    */
+   OSGiBundle installBundle(Archive<?> archive) throws BundleException, IOException;
+
+   /**
     * Install an {@link OSGiBundle} from the given virtual file.
     */
    OSGiBundle installBundle(VirtualFile vfsfile) throws BundleException, IOException;

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java	2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -25,6 +25,8 @@
 import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Hashtable;
@@ -32,8 +34,6 @@
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import junit.framework.AssertionFailedError;
-
 import org.jboss.osgi.spi.framework.OSGiBootstrap;
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.osgi.spi.util.ConstantsHelper;
@@ -41,7 +41,10 @@
 import org.jboss.osgi.testing.internal.RemoteRuntime;
 import org.jboss.osgi.vfs.AbstractVFS;
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.osgi.framework.Bundle;
 
 /**
@@ -218,16 +221,86 @@
       return assembleBundle(name, new String[] { resource }, packages);
    }
 
-   public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws Exception
+   public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws IOException
    {
-      VirtualFileAssembly assembly = AbstractVFS.createVirtualFileAssembly(name);
-      for (String path : resources)
-         addPath(assembly, path, "");
-      for (Class<?> reference : packages)
-         addPackage(assembly, reference);
-      return assembly;
+      JavaArchive archive = Archives.create(name + ".jar", JavaArchive.class);
+      if (resources != null)
+      {
+         for (String res : resources)
+         {
+            URL url = getClass().getResource(res);
+            if (url == null)
+               throw new IllegalArgumentException("Cannot load resource: " + res);
+            
+            final VirtualFile file = AbstractVFS.getChild(url);
+            if (file.isDirectory())
+            {
+               addResources(archive, file, file);
+            }
+            else
+            {
+               addResource(archive, res, file);
+            }
+         }
+      }
+      if (packages != null)
+      {
+         for(Class<?> clazz : packages)
+         {
+            URL url = clazz.getResource("/");
+            VirtualFile base = AbstractVFS.getChild(url);
+            
+            String path = clazz.getName().replace('.', '/');
+            path = path.substring(0, path.lastIndexOf("/"));
+            
+            VirtualFile classes = base.getChild(path);
+            addResources(archive, base, classes);
+         }
+      }
+      
+      // Convert archive to file URL 
+      ZipExporter exporter = archive.as(ZipExporter.class);
+      File target = File.createTempFile("archive_", ".jar");
+      exporter.exportZip(target, true);
+      target.deleteOnExit();
+      
+      return AbstractVFS.getChild(target.toURI().toURL());
    }
 
+   private void addResources(JavaArchive archive, VirtualFile basedir, VirtualFile resdir) throws IOException
+   {
+      String basepath = basedir.getPathName();
+      for (final VirtualFile child : resdir.getChildrenRecursively())
+      {
+         if (child.isDirectory())
+            continue;
+         
+         String path = child.getPathName();
+         path = path.substring(basepath.length());
+         
+         addResource(archive, path, child);
+      }
+   }
+
+   private void addResource(JavaArchive archive, String path, final VirtualFile file)
+   {
+      Asset asset = new Asset()
+      {
+         public InputStream openStream()
+         {
+            try
+            {
+               return file.openStream();
+            }
+            catch (IOException ex)
+            {
+               throw new IllegalStateException("Cannot open stream for: " + file, ex);
+            }
+         }
+      };
+      archive.add(asset, path);
+   }
+
    public void assertBundleState(int expState, int wasState)
    {
       String expstr = ConstantsHelper.bundleState(expState);
@@ -258,32 +331,4 @@
             fail("Unexpected ClassNotFoundException for: " + message);
       }
    }
-   
-   private void addPath(VirtualFileAssembly dir, String path, String name) throws Exception
-   {
-      URL url = getClass().getResource(path);
-      if (url == null)
-         throw new AssertionFailedError(path + " not found");
-
-      VirtualFile root = AbstractVFS.getChild(url);
-      VirtualFile file = root.getChild(name);
-      dir.addPath(file);
-   }
-
-   private void addPackage(VirtualFileAssembly dir, Class<?> reference) throws Exception
-   {
-      String packagePath = packageNameToPath(reference.getName());
-      dir.addResources(reference, new String[] { packagePath + "/*.class" }, new String[0]);
-   }
-
-   // Convert a class's package name into a path
-   private String packageNameToPath(final String className)
-   {
-      int end = className.lastIndexOf('.');
-      if (end == -1)
-         return "";
-
-      String packageName = className.substring(0, end);
-      return packageName.replace('.', '/');
-   }
 }

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-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,7 +23,6 @@
 
 // $Id$
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -41,7 +40,6 @@
 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,28 +65,15 @@
       super(helper);
    }
 
-   public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+   OSGiBundle installBundle(BundleInfo info) throws BundleException
    {
-      BundleInfo info = BundleInfo.createBundleInfo(file);
-
       BundleContext context = getSystemContext();
-      Bundle auxBundle = context.installBundle(info.getLocation(), file.openStream());
+      String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+      Bundle auxBundle = context.installBundle(location);
       OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
-      
       return registerBundle(bundle.getLocation(), bundle);
    }
 
-   public OSGiBundle installBundle(String location) throws BundleException
-   {
-      BundleInfo info = BundleInfo.createBundleInfo(location);
-
-      BundleContext context = getSystemContext();
-      Bundle auxBundle = context.installBundle(info.getLocation());
-      OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
-      
-      return registerBundle(bundle.getLocation(), bundle);
-   }
-
    public OSGiBundle[] getBundles()
    {
       List<OSGiBundle> absBundles = new ArrayList<OSGiBundle>();

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-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,6 +23,8 @@
 
 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;
@@ -53,6 +55,10 @@
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTestHelper;
+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.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
@@ -160,6 +166,47 @@
          removeCapability(dependency);
    }
 
+   public OSGiBundle installBundle(String location) throws BundleException
+   {
+      BundleInfo info = BundleInfo.createBundleInfo(location);
+      return installBundle(info);
+   }
+
+   public OSGiBundle installBundle(Archive<?> archive) throws BundleException, IOException
+   {
+      VirtualFile file = toVirtualFile(archive);
+      return installBundle(file);
+   }
+
+   public OSGiBundle installBundle(VirtualFile virtualFile) throws BundleException
+   {
+      BundleInfo info = BundleInfo.createBundleInfo(virtualFile);
+      return installBundle(info);
+   }
+
+   abstract OSGiBundle installBundle(BundleInfo info) throws BundleException;
+   
+   // [JBVFS-147] Cannot read from vfs: protocol URL 
+   URL fixVirtualFileURL(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;
+   }
+
    public void shutdown()
    {
       log.debug("Start Shutdown");
@@ -327,7 +374,7 @@
       return value;
    }
 
-   private Manifest getManifest(String location)
+   Manifest getManifest(String location)
    {
       Manifest manifest;
       try
@@ -374,6 +421,16 @@
       }
    }
 
+   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.getChild(target.toURI().toURL());
+   }
+   
    private void failsafeUninstall(OSGiBundle bundle)
    {
       if (bundle != null)

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-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -43,13 +43,11 @@
 import org.jboss.osgi.jmx.MBeanProxy;
 import org.jboss.osgi.jmx.ObjectNameFactory;
 import org.jboss.osgi.jmx.ServiceStateMBeanExt;
-import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.util.BundleInfo;
 import org.jboss.osgi.testing.OSGiBundle;
 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.BundleException;
 import org.osgi.jmx.framework.BundleStateMBean;
 import org.osgi.jmx.framework.ServiceStateMBean;
@@ -72,21 +70,12 @@
       super(helper);
    }
 
-   public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+   OSGiBundle installBundle(BundleInfo info) throws BundleException
    {
-      throw new NotImplementedException();
-   }
-   
-   public OSGiBundle installBundle(String location) throws BundleException
-   {
       try
       {
-         // Get the bundle info from the location
-         BundleInfo info = BundleInfo.createBundleInfo(location);
-         String rootURL = info.getRootURL().toExternalForm();
-
-         long bundleId = getFrameworkMBean().installBundle(rootURL);
-
+         String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+         long bundleId = getFrameworkMBean().installBundle(location);
          RemoteBundle bundle = new RemoteBundle(this, bundleId);
          return registerBundle(bundle.getLocation(), bundle);
       }
@@ -94,13 +83,9 @@
       {
          throw rte;
       }
-      catch (BundleException ex)
-      {
-         throw ex;
-      }
       catch (Exception ex)
       {
-         throw new BundleException("Cannot install: " + location, ex);
+         throw new BundleException("Cannot install: " + info, ex);
       }
    }
 

Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java	2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,24 +23,13 @@
 
 //$Id: SimpleTestCase.java 101150 2010-02-19 10:50:46Z thomas.diesler at jboss.com $
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
+import org.jboss.osgi.testing.ManifestBuilder;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiTest;
-import org.jboss.osgi.vfs.AbstractVFS;
-import org.jboss.osgi.vfs.ManifestBuilder;
 import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
 import org.jboss.test.osgi.testing.bundle.SimpleActivator;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
@@ -54,24 +43,22 @@
 public class SimpleAssemblyTestCase extends OSGiTest
 {
    @Test
-   public void testSimpleAssembly() throws Exception
+   public void testAssembleArchive() throws Exception
    {
       OSGiRuntime runtime = getDefaultRuntime();
       try
       {
-         VirtualFileAssembly assembly = AbstractVFS.createVirtualFileAssembly("example-simple.jar");
-         assembly.addClass(SimpleActivator.class);
+         JavaArchive archive = Archives.create("example-simple.jar", JavaArchive.class);
+         archive.addClass(SimpleActivator.class);
 
          ManifestBuilder mb = ManifestBuilder.newInstance();
          mb.addBundleManifestVersion(2);
          mb.addBundleSymbolicName("example-simple");
          mb.addBundleActivator(SimpleActivator.class.getName());
          mb.addImportPackages("org.jboss.osgi.common.log", "org.osgi.framework", "org.osgi.service.log");
+         archive.setManifest(mb);
          
-         Manifest manifest = mb.getManifest();
-         assembly.addManifest(manifest);
-
-         OSGiBundle bundle = runtime.installBundle(assembly);
+         OSGiBundle bundle = runtime.installBundle(archive);
          assertBundleState(Bundle.INSTALLED, bundle.getState());
       }
       finally
@@ -79,4 +66,20 @@
          runtime.shutdown();
       }
    }
+   
+   @Test
+   public void testAssembleBundle() throws Exception
+   {
+      OSGiRuntime runtime = getDefaultRuntime();
+      try
+      {
+         VirtualFile virtualFile = assembleBundle("example-simple", "/simple", SimpleActivator.class);
+         OSGiBundle bundle = runtime.installBundle(virtualFile);
+         assertBundleState(Bundle.INSTALLED, bundle.getState());
+      }
+      finally
+      {
+         runtime.shutdown();
+      }
+   }
 }
\ No newline at end of file

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-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java	2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,13 +23,19 @@
 
 //$Id$
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
+import java.net.URL;
+
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VirtualFile;
 import org.jboss.test.osgi.testing.bundle.SimpleService;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 
@@ -78,4 +84,36 @@
          runtime.shutdown();
       }
    }
+
+   @Test
+   public void testSimpleArchiveURL() throws Exception
+   {
+      OSGiRuntime runtime = getDefaultRuntime();
+      try
+      {
+         URL archiveURL = getTestArchiveURL("example-simple.jar");
+         OSGiBundle bundle = runtime.installBundle(archiveURL.toExternalForm());
+         assertBundleState(Bundle.INSTALLED, bundle.getState());
+      }
+      finally
+      {
+         runtime.shutdown();
+      }
+   }
+
+   @Ignore // https://jira.jboss.org/jira/browse/JBVFS-147
+   public void testSimpleVirtualFile() throws Exception
+   {
+      OSGiRuntime runtime = getDefaultRuntime();
+      try
+      {
+         VirtualFile archive = AbstractVFS.getChild(getTestArchiveURL("example-simple.jar"));
+         OSGiBundle bundle = runtime.installBundle(archive);
+         assertBundleState(Bundle.INSTALLED, bundle.getState());
+      }
+      finally
+      {
+         runtime.shutdown();
+      }
+   }
 }
\ No newline at end of file

Added: projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF	                        (rev 0)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF	2010-03-09 14:59:26 UTC (rev 102132)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: example-simple
+Bundle-Activator: org.jboss.test.osgi.testing.bundle.SimpleActivator
+Import-Package: org.jboss.osgi.common.log,org.osgi.framework,org.osgi.service.log



More information about the jboss-osgi-commits mailing list