Author: rfeng
Date: Mon Sep  8 00:33:14 2008
New Revision: 693007

URL: http://svn.apache.org/viewvc?rev=693007&view=rev
Log:
Fix the Bundle-ClassPath syntax and make sure the classpath is resolved against 
the base bundle correctly
Use the bundle to load implementation-node classes

Modified:
    
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java
    
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
    
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java
    
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
    
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java

Modified: 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java?rev=693007&r1=693006&r2=693007&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java
 (original)
+++ 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java
 Mon Sep  8 00:33:14 2008
@@ -19,7 +19,10 @@
 
 package org.apache.tuscany.sca.node.equinox.launcher;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.util.jar.Manifest;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.eclipse.osgi.baseadaptor.HookConfigurator;
@@ -45,6 +48,17 @@
         // Create a single 'library' bundle for them
         long libraryStart = System.currentTimeMillis();
         manifest = NodeLauncherUtil.libraryManifest(jarFiles);
+        
+        if (logger.isLoggable(Level.FINE)) {
+            try {
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                manifest.write(bos);
+                bos.close();
+                logger.fine(new String(bos.toByteArray()));
+            } catch (IOException e) {
+            }
+        }
+
         logger.info("Third-party library manifest generated in " + 
(System.currentTimeMillis() - libraryStart) + " ms");
         
     }

Modified: 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java?rev=693007&r1=693006&r2=693007&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
 (original)
+++ 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
 Mon Sep  8 00:33:14 2008
@@ -101,6 +101,8 @@
             // Set startup properties
             props.put(EclipseStarter.PROP_CLEAN, "true");
             
+            props.put("osgi.console", "8085");
+            
             // Set location properties
             // FIXME Use proper locations
             props.put(LocationManager.PROP_INSTANCE_AREA, new 
File("target/workspace").toURI().toString());
@@ -155,11 +157,16 @@
             for (Bundle bundle: context.getBundles()) {
                 if ((bundle.getState() & Bundle.ACTIVE) == 0) {
                     logger.info("Starting bundle: " + string(bundle, false));
-                    bundle.start();
+                    try {
+                        bundle.start();
+                    } catch (Exception e) {
+                        // TODO Auto-generated catch block
+                        e.printStackTrace();
+                    }
+                    logger.info("Bundle: " + string(bundle, false));
                 }
             }
             logger.info("Tuscany bundles are started in " + 
(System.currentTimeMillis() - activateStart) + " ms.");
-            
             return context;
             
         } catch (Exception e) {

Modified: 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java?rev=693007&r1=693006&r2=693007&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java
 (original)
+++ 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java
 Mon Sep  8 00:33:14 2008
@@ -64,7 +64,6 @@
             
             @Override
             public InputStream getInputStream() throws IOException {
-                System.out.println(new String(bytes));
                 return new ByteArrayInputStream(bytes);
             }
             
@@ -138,7 +137,8 @@
     }
 
     public BundleFile createBundleFile(Object content, BaseData data, boolean 
base) throws IOException {
-        if 
("org.apache.tuscany.sca.node.launcher.equinox.libraries".equals(data.getLocation()))
 {
+        // Equinox will resolve external classpath against the base bundle
+        if 
("org.apache.tuscany.sca.node.launcher.equinox.libraries".equals(data.getLocation())
 && base) {
             return new LibrariesBundleFile(content, manifest);
         } else {
             return null;

Modified: 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java?rev=693007&r1=693006&r2=693007&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
 (original)
+++ 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
 Mon Sep  8 00:33:14 2008
@@ -25,6 +25,8 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.osgi.framework.BundleContext;
+
 /**
  * A launcher for SCA nodes.
  *  
@@ -34,13 +36,14 @@
 
     static final Logger logger = 
Logger.getLogger(NodeLauncher.class.getName());
     private EquinoxHost host;
+    private BundleContext bundleContext;
 
     /**
      * Constructs a new node launcher.
      */
     private NodeLauncher() {
         host = new EquinoxHost();
-        host.start();
+        bundleContext = host.start();
     }
 
     /**
@@ -62,7 +65,7 @@
      * @throws LauncherException
      */
     public <T> T createNodeFromURL(String configurationURL) throws 
LauncherException {
-        return (T)node(configurationURL, null, null, null, null);
+        return (T)node(configurationURL, null, null, null, null, 
bundleContext);
     }
 
     /**
@@ -77,7 +80,7 @@
      * @throws LauncherException
      */
     public <T> T createNode(String compositeURI, Contribution... 
contributions) throws LauncherException {
-        return (T)node(null, compositeURI, null, contributions, null);
+        return (T)node(null, compositeURI, null, contributions, null, 
bundleContext);
     }
 
     /**
@@ -91,7 +94,7 @@
      */
     public <T> T createNode(String compositeURI, String compositeContent, 
Contribution... contributions)
         throws LauncherException {
-        return (T)node(null, compositeURI, compositeContent, contributions, 
null);
+        return (T)node(null, compositeURI, compositeContent, contributions, 
null, bundleContext);
     }
 
     /**
@@ -109,7 +112,7 @@
      * @return A newly created SCA node
      */
     public <T> T createNodeFromClassLoader(String compositeURI, ClassLoader 
classLoader) throws LauncherException {
-        return (T)node(null, compositeURI, null, null, classLoader);
+        return (T)node(null, compositeURI, null, null, classLoader, 
bundleContext);
     }
 
     public static void main(String[] args) throws Exception {
@@ -183,6 +186,7 @@
     public void destroy() {
         if (host != null) {
             host.stop();
+            bundleContext = null;
         }
     }
 

Modified: 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java?rev=693007&r1=693006&r2=693007&view=diff
==============================================================================
--- 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
 (original)
+++ 
tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
 Mon Sep  8 00:33:14 2008
@@ -25,6 +25,7 @@
 import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE;
 import static org.osgi.framework.Constants.EXPORT_PACKAGE;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -33,9 +34,11 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.logging.Level;
 import java.util.regex.Matcher;
@@ -43,8 +46,10 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+import org.eclipse.osgi.util.ManifestElement;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 
 /**
  * Common functions and constants used by the admin components.
@@ -66,21 +71,32 @@
      * Collect JAR files under the given directory.
      * 
      * @p @param contributions
+     * @param bundleContext TODO
      * @throws LauncherException
      */
     static Object node(String configurationURI,
                        String compositeURI,
                        String compositeContent,
                        Contribution[] contributions,
-                       ClassLoader contributionClassLoader) throws 
LauncherException {
-        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+                       ClassLoader contributionClassLoader,
+                       BundleContext bundleContext) throws LauncherException {
         try {
 
+            Bundle bundle = null;
+            for (Bundle b : bundleContext.getBundles()) {
+                if 
("org.apache.tuscany.sca.implementation.node.runtime".equals(b.getSymbolicName()))
 {
+                    bundle = b;
+                    break;
+                }
+            }
+            if (bundle == null) {
+                throw new IllegalStateException(
+                                                "Bundle 
org.apache.tuscany.sca.implementation.node.runtime is not installed");
+            }
             // Use Java reflection to create the node as only the runtime class
             // loader knows the runtime classes required by the node
             String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP;
-            Class<?> bootstrapClass;
-            bootstrapClass = Class.forName(className, false, tccl);
+            Class<?> bootstrapClass = 
bundle.loadClass(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP);
 
             Object bootstrap;
             if (configurationURI != null) {
@@ -137,7 +153,7 @@
             NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be 
created", e);
             throw new LauncherException(e);
         } finally {
-            Thread.currentThread().setContextClassLoader(tccl);
+            // 
         }
     }
 
@@ -254,8 +270,9 @@
             Set<String> packages = new HashSet<String>(); 
             for (String jarFile: jarFiles) {
                 addPackages(jarFile, packages);
-                classpath.append(jarFile);
-                classpath.append(',');
+                classpath.append("\"external:");
+                classpath.append(file(new 
URL(jarFile)).getAbsolutePath().replace(File.separatorChar, '/'));
+                classpath.append("\",");
             }
             for (String pkg: packages) {
                 exports.append(pkg);
@@ -272,12 +289,28 @@
             attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, 
classpath.length() -1));
             attributes.putValue(DYNAMICIMPORT_PACKAGE, "*");
             
+            try {
+                ManifestElement[] elements = 
ManifestElement.parseHeader(BUNDLE_CLASSPATH, classpath.substring(0, 
classpath.length() -1));
+                for(ManifestElement e: elements) {
+                    System.out.println(Arrays.asList(e.getValueComponents()));
+                }
+            } catch (BundleException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
             return manifest;
         } catch (IOException e) {
             throw new IllegalStateException(e);
         }
     }
     
+    static byte[] generateBundle(Manifest mf) throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        JarOutputStream jos = new JarOutputStream(bos, mf);
+        jos.close();
+        return bos.toByteArray();
+    }
+    
     /**
      * Returns the location of this bundle.
      * 


Reply via email to