[jboss-cvs] JBossAS SVN: r102872 - projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 24 08:16:55 EDT 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-24 08:16:54 -0400 (Wed, 24 Mar 2010)
New Revision: 102872

Added:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java
Removed:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java
Modified:
   projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
Log:
Add shrinkwrap support to OSGiFrameworkTest

Deleted: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java	2010-03-24 12:10:40 UTC (rev 102871)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java	2010-03-24 12:16:54 UTC (rev 102872)
@@ -1,157 +0,0 @@
-/*
-* 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/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-24 12:10:40 UTC (rev 102871)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java	2010-03-24 12:16:54 UTC (rev 102872)
@@ -29,6 +29,7 @@
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.File;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -39,7 +40,10 @@
 import org.jboss.osgi.spi.framework.OSGiBootstrap;
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 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.exporter.ZipExporter;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.osgi.framework.Bundle;
@@ -100,6 +104,17 @@
       return (PackageAdmin)systemContext.getService(sref);
    }
    
+   protected Bundle installBundle(Archive<?> archive) throws Exception
+   {
+      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());
+      return installBundle(virtualFile);
+   }
+   
    protected Bundle installBundle(VirtualFile archive) throws Exception
    {
       String location = archive.getPathName();

Copied: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java (from rev 102863, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java)
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java	                        (rev 0)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java	2010-03-24 12:16:54 UTC (rev 102872)
@@ -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 OSGiManifestBuilder implements Asset
+{
+   private StringWriter sw;
+   private PrintWriter pw;
+   private List<String> importPackages = new ArrayList<String>();
+   private List<String> exportPackages = new ArrayList<String>();
+
+   public static OSGiManifestBuilder newInstance()
+   {
+      return new OSGiManifestBuilder();
+   }
+
+   private OSGiManifestBuilder()
+   {
+      sw = new StringWriter();
+      pw = new PrintWriter(sw);
+      pw.println(Attributes.Name.MANIFEST_VERSION + ": 1.0");
+   }
+
+   public OSGiManifestBuilder addBundleManifestVersion(int version)
+   {
+      pw.println(Constants.BUNDLE_MANIFESTVERSION + ": " + version);
+      return this;
+   }
+
+   public OSGiManifestBuilder addBundleSymbolicName(String symbolicName)
+   {
+      pw.println(Constants.BUNDLE_SYMBOLICNAME + ": " + symbolicName);
+      return this;
+   }
+
+   public OSGiManifestBuilder addBundleActivator(String bundleActivator)
+   {
+      pw.println(Constants.BUNDLE_ACTIVATOR + ": " + bundleActivator);
+      return this;
+   }
+
+   public OSGiManifestBuilder addImportPackages(String... packages)
+   {
+      for (String aux : packages)
+         importPackages.add(aux);
+
+      return this;
+   }
+
+   public OSGiManifestBuilder addExportPackages(String... packages)
+   {
+      for (String aux : packages)
+         exportPackages.add(aux);
+
+      return this;
+   }
+
+   public OSGiManifestBuilder 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);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list