felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r954601 - /felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
Date Mon, 14 Jun 2010 19:28:10 GMT
Author: rickhall
Date: Mon Jun 14 19:28:10 2010
New Revision: 954601

URL: http://svn.apache.org/viewvc?rev=954601&view=rev
Log:
Retrieve embedded bundle from resource URL rather than hard-coded location.

Modified:
    felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java

Modified: felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java?rev=954601&r1=954600&r2=954601&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
(original)
+++ felix/sandbox/rickhall/vb-bnd-test/org.apache.felix.framework.vb/src/org/apache/felix/framework/vb/b001/Activator.java
Mon Jun 14 19:28:10 2010
@@ -18,12 +18,19 @@
  */
 package org.apache.felix.framework.vb.b001;
 
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
 import org.apache.felix.framework.ext.FelixBundleContext;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -37,8 +44,16 @@ public class Activator implements Bundle
             FelixBundleContext fbc = (FelixBundleContext) bc;
             try
             {
-                JarFile jarFile = new JarFile("/Users/rickhall/Projects/felix-sandbox/vb-bnd-test/org.apache.felix.framework.vb/vb.b002.jar");
-                // Get the embedded resource.
+                // Copy the embedded bundle from our parent test bundle into
+                // our private data area so we can wrap it.
+                Bundle parentBundle = getBundle(bc, "org.apache.felix.framework.vb");
+                URL url = parentBundle.getResource("vb.b002.jar");
+                File outputFile = bc.getDataFile("vb.b002.jar");
+                copyStreamToFile(url.openStream(), outputFile);
+
+                // Create a JarFile for the embedded bundle.
+                JarFile jarFile = new JarFile(outputFile);
+                // Get the embedded bundle's manifest.
                 Manifest mf = jarFile.getManifest();
                 // Use an empty map if there is no manifest.
                 Map headers = (mf == null) ? new HashMap() : mf.getMainAttributes();
@@ -74,4 +89,40 @@ public class Activator implements Bundle
     public void stop(BundleContext bc)
     {
     }
-}
+
+    private static Bundle getBundle(BundleContext bc, String symName)
+    {
+
+        for (Bundle bundle : bc.getBundles())
+        {
+            if (bundle.getSymbolicName().equals(symName))
+            {
+                return bundle;
+            }
+        }
+        return null;
+    }
+
+    private static void copyStreamToFile(InputStream is, File outputFile)
+        throws IOException
+    {
+        OutputStream os = null;
+
+        try
+        {
+            os = new FileOutputStream(outputFile);
+            os = new BufferedOutputStream(os, 2048);
+            byte[] b = new byte[2048];
+            int len = 0;
+            while ((len = is.read(b)) != -1)
+            {
+                os.write(b, 0, len);
+            }
+        }
+        finally
+        {
+            if (is != null) is.close();
+            if (os != null) os.close();
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message