You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/09/07 13:25:42 UTC

svn commit: r692820 - in /tuscany/java/sca/modules: extensibility-equinox/ extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/ extensibility-equinox/src/main/resources/ node-launcher-equinox/ node-launcher-equinox/src/main...

Author: jsdelfino
Date: Sun Sep  7 04:25:41 2008
New Revision: 692820

URL: http://svn.apache.org/viewvc?rev=692820&view=rev
Log:
Moved hooks from extensiblity-equinox to node-launcher-equinox. Fixed logic that installs bundles in node-launcher-equinox, which now just installs bundles normally and installs all non-bundle JARs in a single 'library' bundle which exports all the packages that they contain. The startup sequence is now simpler and significantly faster.

Added:
    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/resources/
    tuscany/java/sca/modules/node-launcher-equinox/src/main/resources/hookconfigurators.properties
      - copied, changed from r692687, tuscany/java/sca/modules/extensibility-equinox/src/main/resources/hookconfigurators.properties
Removed:
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/BundleFileWrapperFactory.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxHookConfigurator.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/URLClassLoadingHook.java
    tuscany/java/sca/modules/extensibility-equinox/src/main/resources/hookconfigurators.properties
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHost.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java
Modified:
    tuscany/java/sca/modules/extensibility-equinox/pom.xml
    tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
    tuscany/java/sca/modules/node-launcher-equinox/pom.xml
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.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
    tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java
    tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java

Modified: tuscany/java/sca/modules/extensibility-equinox/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/pom.xml?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/pom.xml (original)
+++ tuscany/java/sca/modules/extensibility-equinox/pom.xml Sun Sep  7 04:25:41 2008
@@ -33,12 +33,14 @@
             <artifactId>tuscany-extensibility</artifactId>
             <version>1.4-SNAPSHOT</version>
         </dependency>
+        
         <dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
             <version>3.3.0-v20070530</version>
             <scope>compile</scope>
         </dependency>
+        
         <dependency>
             <groupId>org.eclipse.core</groupId>
             <artifactId>runtime</artifactId>
@@ -73,18 +75,9 @@
                     <instructions>
                         <Bundle-Version>${tuscany.version}</Bundle-Version>
                         <Bundle-SymbolicName>org.apache.tuscany.sca.extensibility.equinox</Bundle-SymbolicName>
-                        <!-- 
-                        <Fragment-Host>org.eclipse.osgi</Fragment-Host>
-                         -->
                         <Bundle-Description>${pom.name}</Bundle-Description>
                         <Bundle-Activator>org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator</Bundle-Activator>
-                        <!-- This bundle will be the gateway to all exported packages -->
-                        <!-- 
-                        <DynamicImport-Package>*</DynamicImport-Package>
-                         -->
-                        <Import-Package>*</Import-Package>
-                        <Bundle-BuddyPolicy>global,app</Bundle-BuddyPolicy>
-                        <Eclipse-BuddyPolicy>global,app</Eclipse-BuddyPolicy>
+                        <Export-Package>org.apache.tuscany.sca.extensibility.equinox*</Export-Package>
                         <Eclipse-AutoStart>true</Eclipse-AutoStart> 
                     </instructions>
                 </configuration>

Modified: tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java (original)
+++ tuscany/java/sca/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoveryActivator.java Sun Sep  7 04:25:41 2008
@@ -29,19 +29,13 @@
  * @version $Rev: $ $Date: $
  */
 public class EquinoxServiceDiscoveryActivator implements BundleActivator {
-    private static BundleContext bundleContext;
 
     public void start(BundleContext context) throws Exception {
-        if (bundleContext == null) {
-            bundleContext = context;
-            EquinoxServiceDiscoverer discoverer = new EquinoxServiceDiscoverer(bundleContext);
-            ServiceDiscovery.getInstance().setServiceDiscoverer(discoverer);
-        }
+        EquinoxServiceDiscoverer discoverer = new EquinoxServiceDiscoverer(context);
+        ServiceDiscovery.getInstance().setServiceDiscoverer(discoverer);
     }
 
     public void stop(BundleContext context) throws Exception {
-        bundleContext = null;
-        // ServiceDiscovery.setServiceDiscoverer(discoverer);
     }
 
 }

Modified: tuscany/java/sca/modules/node-launcher-equinox/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/pom.xml?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/pom.xml (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/pom.xml Sun Sep  7 04:25:41 2008
@@ -37,24 +37,28 @@
             <version>2.5</version> <!-- To be compatible with Jetty 6 --> 
             <scope>provided</scope>
         </dependency>
+
         <dependency>
             <groupId>org.eclipse</groupId>
             <artifactId>osgi</artifactId>
             <version>3.3.0-v20070530</version>
             <scope>compile</scope>
         </dependency>
+
         <dependency>
             <groupId>org.eclipse.core</groupId>
             <artifactId>runtime</artifactId>
             <version>3.3.100-v20070530</version>
             <scope>runtime</scope>
         </dependency>        
+
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-node-runtime</artifactId>
             <version>1.4-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-extensibility-equinox</artifactId>
@@ -82,7 +86,6 @@
             <version>1.4-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
-              
     </dependencies>
 
     <build>
@@ -122,7 +125,6 @@
                 </configuration>
             </plugin>
 
-<!-- 
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
@@ -132,11 +134,12 @@
                         <Bundle-Version>${tuscany.version}</Bundle-Version>
                         <Bundle-SymbolicName>org.apache.tuscany.sca.node.launcher.equinox</Bundle-SymbolicName>
                         <Bundle-Description>${pom.name}</Bundle-Description>
+                        <Bundle-Activator>org.apache.tuscany.sca.node.equinox.launcher.LauncherBundleActivator</Bundle-Activator>
                         <Export-Package>org.apache.tuscany.sca.node.equinox.launcher*</Export-Package>
+                        <Eclipse-AutoStart>true</Eclipse-AutoStart> 
                     </instructions>
                 </configuration>
             </plugin>
- -->            
         </plugins>
     </build>
 

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java Sun Sep  7 04:25:41 2008
@@ -77,13 +77,13 @@
         // Create a launcher
         DomainManagerLauncher launcher = newInstance();
         
-        EquinoxOSGiHost equinox = null;
+        EquinoxHost equinox = null;
         Object domainManager = null;
         ShutdownThread shutdown = null;
         try {
 
             // Start the OSGi host 
-            equinox = new EquinoxOSGiHost();
+            equinox = new EquinoxHost();
             equinox.start();
 
             // Start the domain manager
@@ -148,9 +148,9 @@
     
     private static class ShutdownThread extends Thread {
         private Object domainManager;
-        private EquinoxOSGiHost equinox;
+        private EquinoxHost equinox;
 
-        public ShutdownThread(Object domainManager, EquinoxOSGiHost equinox) {
+        public ShutdownThread(Object domainManager, EquinoxHost equinox) {
             super();
             this.domainManager = domainManager;
             this.equinox = equinox;

Added: 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=692820&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHookConfigurator.java Sun Sep  7 04:25:41 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.util.jar.Manifest;
+import java.util.logging.Logger;
+
+import org.eclipse.osgi.baseadaptor.HookConfigurator;
+import org.eclipse.osgi.baseadaptor.HookRegistry;
+
+/**
+ * Hook Configurator for Equinox.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class EquinoxHookConfigurator implements HookConfigurator {
+    private static Logger logger = Logger.getLogger(HookConfigurator.class.getName());
+    
+    private String[] jarFiles;
+    private Manifest manifest;
+    
+    public EquinoxHookConfigurator() {
+
+        // Get the list of JAR files to install
+        String jarFilesProperty = System.getProperty("org.apache.tuscany.sca.node.launcher.equinox.jarFiles");
+        jarFiles = jarFilesProperty.split(";");
+        
+        // Create a single 'library' bundle for them
+        long libraryStart = System.currentTimeMillis();
+        manifest = NodeLauncherUtil.libraryManifest(jarFiles);
+        logger.info("Third-party library manifest generated in " + (System.currentTimeMillis() - libraryStart) + " ms");
+        
+    }
+    
+    public void addHooks(HookRegistry registry) {
+        
+        // Register our BundleFileFactory hook 
+        registry.addBundleFileFactoryHook(new LibrariesBundleFileFactoryHook(manifest));
+    }
+
+}

Added: 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=692820&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java Sun Sep  7 04:25:41 2008
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.node.equinox.launcher;
+
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string;
+import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.logging.Logger;
+
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.eclipse.core.runtime.adaptor.LocationManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Wraps the Equinox runtime.
+ */
+public class EquinoxHost {
+    private static Logger logger = Logger.getLogger(EquinoxHost.class.getName());
+
+    private BundleContext context;
+
+    private final static String systemPackages =
+        "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0, "
+            + "org.osgi.service.startlevel; version=1.0.0, "
+            + "org.osgi.service.url; version=1.0.0, "
+            + "org.osgi.util.tracker; version=1.3.2, "
+            + "javax.xml, "
+            + "javax.xml.datatype, "
+            + "javax.xml.namespace, "
+            + "javax.xml.parsers, "
+            + "javax.xml.transform, "
+            + "javax.xml.transform.dom, "
+            + "javax.xml.transform.sax, "
+            + "javax.xml.transform.stream, "
+            + "javax.xml.validation, "
+            + "javax.xml.xpath, "
+            // Force the classes to be imported from the system bundle
+            // + "javax.xml.stream, "
+            // + "javax.xml.stream.util, "
+            + "javax.sql,"
+            + "org.w3c.dom, "
+            + "org.xml.sax, "
+            + "org.xml.sax.ext, "
+            + "org.xml.sax.helpers, "
+            + "javax.security.auth, "
+            + "javax.security.cert, "
+            + "javax.security.auth.login, "
+            + "javax.security.auth.callback, "
+            + "javax.naming, "
+            + "javax.naming.spi, "
+            + "javax.naming.directory, "
+            + "javax.management, "
+            + "javax.imageio, "
+            + "sun.misc, "
+            + "javax.net, "
+            + "javax.net.ssl, "
+            + "javax.crypto, "
+            + "javax.rmi, "
+            + "javax.transaction, "
+            + "javax.transaction.xa";
+
+    public BundleContext start() {
+        try {
+            // Configure Eclipse properties
+            Map<Object, Object> props = new HashMap<Object, Object>();
+            
+            // Set system packages
+            props.put("org.osgi.framework.system.packages", systemPackages);
+
+            // Set the extension bundle
+            props.put("osgi.framework.extensions", "org.apache.tuscany.sca.extensibility.equinox");
+            
+            // Set startup properties
+            props.put(EclipseStarter.PROP_CLEAN, "true");
+            
+            // Set location properties
+            // FIXME Use proper locations
+            props.put(LocationManager.PROP_INSTANCE_AREA, new File("target/workspace").toURI().toString());
+            props.put(LocationManager.PROP_INSTALL_AREA, new File("target/eclipse/install").toURI().toString());
+            props.put(LocationManager.PROP_CONFIG_AREA, new File("target/eclipse/config").toURI().toString());
+            props.put(LocationManager.PROP_USER_AREA, new File("target/eclipse/user").toURI().toString());
+            
+            // Find the Tuscany JARs
+            File tuscanyInstallDir = findTuscanyInstallDir();
+            List<URL> urls;
+            if (tuscanyInstallDir != null) {
+                urls = JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter());
+            } else {
+                urls = JarFileFinder.getClassPathEntries(JarFileFinder.class.getClassLoader(), false);
+            }
+
+            // Sort out which are bundles (and not already installed) and which are just
+            // regular JARs
+            StringBuffer bundleFiles =  new StringBuffer();
+            StringBuffer bundleNames =  new StringBuffer();
+            StringBuffer jarFiles = new StringBuffer();
+            for (URL url : urls) {
+                File file = NodeLauncherUtil.file(url);
+                String bundleName = getBundleName(file);
+                if (bundleName != null) {
+                    bundleFiles.append(url.toString() + ";");
+                    bundleNames.append(bundleName + ";");
+                } else {
+                    if (file.isFile()) {
+                        jarFiles.append(url.toString() + ";");
+                    }
+                }
+            }
+            props.put("org.apache.tuscany.sca.node.launcher.equinox.bundleFiles", bundleFiles.toString());
+            props.put("org.apache.tuscany.sca.node.launcher.equinox.bundleNames", bundleNames.toString());
+            props.put("org.apache.tuscany.sca.node.launcher.equinox.jarFiles", jarFiles.toString());
+            
+            EclipseStarter.setInitialProperties(props);
+            
+            // Start Eclipse
+            context = EclipseStarter.startup(new String[]{}, null);
+            
+            // FIXME use the correct bundle location
+            Bundle launcherBundle = context.installBundle(new File("target/classes").toURI().toURL().toString());
+            logger.info("Starting bundle: " + string(launcherBundle, false));
+            launcherBundle.start();
+            
+            // Start all bundles for now to help diagnose any class loading issues
+            //for (Bundle bundle: context.getBundles()) {
+            //    if ((bundle.getState() & Bundle.ACTIVE) == 0) {
+            //        logger.info("Starting bundle: " + string(bundle, false));
+            //        bundle.start();
+            //    }
+            //}
+            
+            return context;
+            
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+    
+    public void stop() {
+        try {
+            EclipseStarter.shutdown();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    private static File findTuscanyInstallDir() throws IOException {
+        String tuscanyDirName = JarFileFinder.getProperty(JarFileFinder.TUSCANY_HOME);
+        if (tuscanyDirName != null) {
+            File tuscanyInstallDir = new File(tuscanyDirName);
+            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
+                return tuscanyInstallDir;
+        }
+        return null;
+    }
+
+    /**
+     * Returns the name of a bundle, or null if the given file is not a bundle.
+     *  
+     * @param file
+     * @return
+     * @throws IOException
+     */
+    private static String getBundleName(File file) throws IOException {
+        String bundleName = null;
+        if (file.isDirectory()) {
+            File mf = new File(file, "META-INF/MANIFEST.MF");
+            if (mf.isFile()) {
+                Manifest manifest = new Manifest(new FileInputStream(mf));
+                bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
+            }
+        } else {
+            JarFile jar = new JarFile(file, false);
+            Manifest manifest = jar.getManifest();
+            bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
+            jar.close();
+        }
+        if (bundleName == null) {
+            return bundleName;
+        }
+        int sc = bundleName.indexOf(';');
+        if (sc != -1) {
+            bundleName = bundleName.substring(0, sc);
+        }
+        return bundleName;
+    }
+
+}

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java Sun Sep  7 04:25:41 2008
@@ -19,6 +19,8 @@
 
 package org.apache.tuscany.sca.node.equinox.launcher;
 
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.file;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FilenameFilter;
@@ -324,23 +326,6 @@
         });
     }
 
-    public static File toFile(URL url) {
-        if (url == null || !url.getProtocol().equals("file")) {
-            return null;
-        } else {
-            String filename = url.getFile().replace('/', File.separatorChar);
-            int pos = 0;
-            while ((pos = filename.indexOf('%', pos)) >= 0) {
-                if (pos + 2 < filename.length()) {
-                    String hexStr = filename.substring(pos + 1, pos + 3);
-                    char ch = (char)Integer.parseInt(hexStr, 16);
-                    filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
-                }
-            }
-            return new File(filename);
-        }
-    }
-
     private static URL getContainer(URL resourceURL, String resourceName) {
         URL root = null;
         // "jar:file://....../something.jar!/a/b/c/app.composite"
@@ -358,7 +343,7 @@
                     try {
                         root = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {
                             public URL run() throws IOException {
-                                return toFile(new URL(location)).toURI().toURL();
+                                return file(new URL(location)).toURI().toURL();
                             }
                         });
                     } catch (PrivilegedActionException e) {
@@ -370,14 +355,14 @@
                 // jar contribution
                 String location = url.substring(4, url.lastIndexOf("!/"));
                 // workaround for evil URL/URI from Maven
-                root = toFile(new URL(location)).toURI().toURL();
+                root = file(new URL(location)).toURI().toURL();
 
             } else if ("wsjar".equals(protocol)) {
                 // See https://issues.apache.org/jira/browse/TUSCANY-2219
                 // wsjar contribution 
                 String location = url.substring(6, url.lastIndexOf("!/"));
                 // workaround for evil url/uri from maven 
-                root = toFile(new URL(location)).toURI().toURL();
+                root = file(new URL(location)).toURI().toURL();
 
             } else if (protocol != null && (protocol.equals("bundle") || protocol.equals("bundleresource"))) {
                 root = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), "/");

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java Sun Sep  7 04:25:41 2008
@@ -1,26 +1,12 @@
 package org.apache.tuscany.sca.node.equinox.launcher;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.zip.ZipEntry;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
@@ -30,463 +16,88 @@
 import org.osgi.framework.Constants;
 
 /**
- * Bundle activator which installs Tuscany modules and 3rd party jars into an OSGi runtime.
+ * Bundle activator which installs Tuscany modules into an OSGi runtime.
  *
  */
 public class LauncherBundleActivator implements BundleActivator, Constants, BundleListener {
     private static Logger logger = Logger.getLogger(LauncherBundleActivator.class.getName());
-    private static final String[] immutableJars = {"bcprov"};
 
+    private List<Bundle> installedBundles = new ArrayList<Bundle>();
     private BundleContext bundleContext;
-    private List<Bundle> tuscanyBundles = new ArrayList<Bundle>();
-
-    private List<URL> jarFiles;
 
     public LauncherBundleActivator() {
         super();
     }
 
-    public LauncherBundleActivator(List<URL> jarFiles) {
-        super();
-        this.jarFiles = jarFiles;
-    }
-
-    public static String toString(Bundle b, boolean verbose) {
-        StringBuffer sb = new StringBuffer();
-        sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
-        int s = b.getState();
-        if ((s & Bundle.UNINSTALLED) != 0) {
-            sb.append(" UNINSTALLED");
-        }
-        if ((s & Bundle.INSTALLED) != 0) {
-            sb.append(" INSTALLED");
-        }
-        if ((s & Bundle.RESOLVED) != 0) {
-            sb.append(" RESOLVED");
-        }
-        if ((s & Bundle.STARTING) != 0) {
-            sb.append(" STARTING");
-        }
-        if ((s & Bundle.STOPPING) != 0) {
-            sb.append(" STOPPING");
-        }
-        if ((s & Bundle.ACTIVE) != 0) {
-            sb.append(" ACTIVE");
-        }
-
-        if (verbose) {
-            sb.append(" ").append(b.getLocation());
-            sb.append(" ").append(b.getHeaders());
-        }
-        return sb.toString();
-    }
-
     public void start(BundleContext bundleContext) throws Exception {
         this.bundleContext = bundleContext;
         this.bundleContext.addBundleListener(this);
-        installTuscany(bundleContext);
-
-        for (Bundle b : bundleContext.getBundles()) {
-            try {
-                if ("org.apache.tuscany.sca.contribution.osgi".equals(b.getSymbolicName()) || "org.apache.tuscany.sca.extensibility.equinox"
-                    .equals(b.getSymbolicName())) {
-                    if (b.getHeaders().get("Fragment-Host") == null) {
-                        b.start();
-                        logger.info(toString(b, false) + " " + b.getState());
-                    }
-                }
-            } catch (Exception e) {
-                logger.log(Level.SEVERE, e.getMessage(), e);
-            }
-        }
-    }
-
-    public void stop(BundleContext bundleContext) throws Exception {
-        /*
-        for (Bundle bundle : tuscanyBundles) {
-            try {
-                bundle.stop();
-            } catch (Exception e) {
-                logger.log(Level.SEVERE, e.getMessage(), e);
-            }
-        }
-        */
 
-        for (Bundle bundle : tuscanyBundles) {
-            try {
-                if (logger.isLoggable(Level.FINE)) {
-                    logger.fine("Uninstalling bundle: " + toString(bundle, false));
-                }
-                bundle.uninstall();
-            } catch (Exception e) {
-                logger.log(Level.SEVERE, e.getMessage(), e);
-            }
-        }
-        this.bundleContext.removeBundleListener(this);
-        tuscanyBundles.clear();
-        this.bundleContext = null;
-    }
-
-    public void installTuscany(BundleContext bundleContext) {
+        // Install the Tuscany bundles
         long start = System.currentTimeMillis();
 
-        try {
+        // FIXME: SDO bundles dont have the correct dependencies
+        System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");
 
-            // FIXME: SDO bundles dont have the correct dependencies
-            System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");
-            List<URL> urls = jarFiles;
-            if (urls == null) {
-                File tuscanyInstallDir = findTuscanyInstallDir(bundleContext.getBundle());
-
-                if (tuscanyInstallDir != null) {
-                    urls =
-                        JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter());
-                } else {
-                    urls = JarFileFinder.getClassPathEntries(JarFileFinder.class.getClassLoader(), false);
-                }
-            }
-
-            for (URL url : urls) {
-                File file = new File(url.toURI());
-                if (file.getName().startsWith("org.apache.felix.") || file.getName().startsWith("osgi-")
-                    || file.getName().startsWith("org.osgi.")) {
+        // Get the list of JAR files to install
+        String jarFilesProperty = System.getProperty("org.apache.tuscany.sca.node.launcher.equinox.jarFiles");
+        String[] jarFiles = jarFilesProperty.split(";");
+        
+        // Create a single 'library' bundle for them
+        long libraryStart = System.currentTimeMillis();
+        //InputStream library = NodeLauncherUtil.libraryBundle(jarFiles);
+        Bundle libraryBundle = bundleContext.installBundle("org.apache.tuscany.sca.node.launcher.equinox.libraries", new ByteArrayInputStream(new byte[0]));
+        installedBundles.add(libraryBundle);
+        logger.info("Third-party library bundle installed in " + (System.currentTimeMillis() - libraryStart) + " ms: " + NodeLauncherUtil.string(libraryBundle, false));
+        
+        // Get the set of already installed bundles
+        Set<String> alreadyInstalledBundleNames = new HashSet<String>();
+        for (Bundle bundle: bundleContext.getBundles()) {
+            alreadyInstalledBundleNames.add(bundle.getSymbolicName());
+        }
+
+        // Get the list of bundle files and names to install
+        String bundleFilesProperty = System.getProperty("org.apache.tuscany.sca.node.launcher.equinox.bundleFiles");
+        String[] bundleFiles = bundleFilesProperty.split(";");
+        String bundleNamesProperty = System.getProperty("org.apache.tuscany.sca.node.launcher.equinox.bundleNames");
+        String[] bundleNames = bundleNamesProperty.split(";");
+        
+        // Install all the bundles that are not already installed
+        for (int i =0, n = bundleFiles.length; i < n; i++) {
+            String bundleFile = bundleFiles[i];
+            String bundleName = bundleNames[i];
+            if (!alreadyInstalledBundleNames.contains(bundleName)) {
+                if (bundleName.contains("org.eclipse.jdt.junit")) {
                     continue;
                 }
-                try {
-                    Bundle bundle = createAndInstallBundle(bundleContext, url);
-                } catch (Exception e) {
-                    logger.log(Level.SEVERE, e.getMessage(), e);
-                }
+                long installStart = System.currentTimeMillis();
+                Bundle bundle = bundleContext.installBundle(bundleFile);
+                //logger.info("Bundle installed in " + (System.currentTimeMillis() - installStart) + " ms: " + NodeLauncherUtil.string(bundle, false));
+                installedBundles.add(bundle);
             }
-
-            long end = System.currentTimeMillis();
-            logger.info("Tuscany bundles are installed in " + (end - start) + " ms.");
-
-        } catch (Exception e) {
-            e.printStackTrace();
         }
-    }
-
-    private File findTuscanyInstallDir(Bundle bundle) throws IOException {
-        String tuscanyDirName = JarFileFinder.getProperty(JarFileFinder.TUSCANY_HOME);
-        if (tuscanyDirName != null) {
-            File tuscanyInstallDir = new File(tuscanyDirName);
-            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
-                return tuscanyInstallDir;
-        }
-
-        /*
-        String location = bundle.getLocation();
 
-        if (location != null && location.startsWith("file:")) {
-            File file = new File(URI.create(location));
-            File tuscanyInstallDir = file.getParentFile();
-            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
-                return tuscanyInstallDir;
-        }
-        if (this.getClass().getProtectionDomain() != null) {
-            CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
-            if (codeSource != null) {
-                try {
-                    File tuscanyInstallDir = new File(codeSource.getLocation().toURI());
-                    if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
-                        return tuscanyInstallDir;
-                } catch (Exception e) {
-                    // ignore
-                }
-            }
-        }
-        */
-        return null;
+        long end = System.currentTimeMillis();
+        logger.info("Tuscany bundles are installed in " + (end - start) + " ms.");
     }
 
-    public Bundle createAndInstallBundle(BundleContext bundleContext, URL bundleFile) throws Exception {
-        if (logger.isLoggable(Level.FINE)) {
-            logger.fine("Installing bundle: " + bundleFile);
-        }
-        long start = System.currentTimeMillis();
-
-        File file = JarFileFinder.toFile(bundleFile);
-        if (file != null && file.isDirectory()) {
-            boolean isOSGiBundle = false;
-            File mf = new File(file, "META-INF/MANIFEST.MF");
-            if (mf.isFile()) {
-                Manifest manifest = new Manifest();
-                manifest.read(new FileInputStream(mf));
-                isOSGiBundle = manifest != null && manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME) != null;
-            }
-            if (isOSGiBundle) {
-                Bundle bundle = bundleContext.installBundle(bundleFile.toString());
-                if (logger.isLoggable(Level.FINE)) {
-                    logger.fine("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleFile);
-                }
-                tuscanyBundles.add(bundle);
-                return bundle;
-            } else {
-                return null;
-            }
-        } else if (file != null && !file.exists()) {
-            return null;
-        }
-        Manifest manifest = readManifest(bundleFile);
-        boolean isOSGiBundle = manifest != null && manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME) != null;
-
-        if (!isOSGiBundle) {
-            // return null;
-            manifest = updateBundleManifest(bundleFile, manifest);
-        }
-
-        String symbolicName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
-        if (symbolicName != null) {
-            int index = symbolicName.indexOf(';');
-            if (index != -1) {
-                symbolicName = symbolicName.substring(0, index);
-            }
-        }
-        String version = manifest.getMainAttributes().getValue(BUNDLE_VERSION);
-        Bundle bundle = findBundle(bundleContext, symbolicName, version);
-        if (bundle != null) {
-            if (logger.isLoggable(Level.FINE)) {
-                logger.fine("Bundle is already installed: " + symbolicName);
-            }
-            return bundle;
-        }
-
-        String bundleLocation = bundleFile.toString();
-        InputStream inStream = null;
-        if (!isOSGiBundle) {
-            // We need to repackage the bundle
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            JarOutputStream jarOut = new JarOutputStream(out, manifest);
-
-            String classpath = manifest.getMainAttributes().getValue("Bundle-ClassPath");
-            boolean embedded = classpath != null && !classpath.trim().equals(".");
-            if (embedded) {
-                addFileToJar(bundleFile, jarOut);
-            } else {
-                copyJar(bundleFile, jarOut);
-            }
-
-            jarOut.close();
-            inStream = new ByteArrayInputStream(out.toByteArray());
-        } else {
-            // The file itself is already a bundle
-            inStream = bundleFile.openStream();
-        }
-
-        try {
-            bundle = bundleContext.installBundle(bundleLocation, inStream);
-            if (logger.isLoggable(Level.FINE)) {
-                logger.fine("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleLocation);
-            }
-            tuscanyBundles.add(bundle);
-            return bundle;
-        } finally {
-            inStream.close();
-        }
-
-    }
-
-    private Bundle findBundle(BundleContext bundleContext, String symbolicName, String version) {
-        Bundle[] bundles = bundleContext.getBundles();
-        if (version == null) {
-            version = "0.0.0";
-        }
-        for (Bundle b : bundles) {
-            String v = (String)b.getHeaders().get(BUNDLE_VERSION);
-            if (v == null) {
-                v = "0.0.0";
-            }
-            if (b.getSymbolicName().equals(symbolicName) && (version.equals("0.0.0") || v.equals(version))) {
-                return b;
-            }
-        }
-        return null;
-    }
-
-    private String getFileName(URL url) {
-        String name = url.getPath();
-        int index = name.lastIndexOf('/');
-        return name.substring(index + 1);
-    }
-
-    private void addFileToJar(URL file, JarOutputStream jarOut) throws IOException {
-        JarEntry ze = new JarEntry(getFileName(file));
-        jarOut.putNextEntry(ze);
-        InputStream inStream = file.openStream();
-        copy(inStream, jarOut);
-        inStream.close();
-    }
-
-    private void copy(InputStream in, OutputStream out) throws IOException {
-        byte[] readBuf = new byte[4096];
-        int bytesRead;
-        while ((bytesRead = in.read(readBuf)) > 0) {
-            out.write(readBuf, 0, bytesRead);
-        }
-    }
-
-    private void copyJar(URL in, JarOutputStream jarOut) throws IOException {
-        JarInputStream jarIn = new JarInputStream(in.openStream());
-        ZipEntry ze;
-        while ((ze = jarIn.getNextEntry()) != null) {
-            // Skip the MANIFEST.MF
-            if (ze.getName().equals("META-INF/MANIFEST.MF"))
-                continue;
-            jarOut.putNextEntry(ze);
-            copy(jarIn, jarOut);
-        }
-        jarIn.close();
-    }
-
-    private Manifest readManifest(URL jarFile) throws IOException {
-        JarInputStream jar = new JarInputStream(jarFile.openStream());
-        // Read the Manifest from the jar file
-        Manifest manifest = jar.getManifest();
-        jar.close();
-
-        if (manifest == null) {
-            // Create a new one if no Manifest is found
-            manifest = new Manifest();
-        }
-        return manifest;
-    }
-
-    private Manifest updateBundleManifest(URL jarFile, Manifest manifest) throws Exception {
-
-        // Check if we have an associated .mf file
-        String name = jarFile.toString();
-        int index = name.lastIndexOf('.');
-        if (index != -1) {
-            URL mf = new URL(name.substring(0, index) + ".mf");
+    public void stop(BundleContext bundleContext) throws Exception {
+        
+        // Uninstall all the bundles we've installed
+        for (Bundle bundle : installedBundles) {
             try {
-                InputStream in = mf.openStream();
-                manifest.read(in);
-                in.close();
-            } catch (IOException e) {
-                // Ignore
-            }
-        }
-
-        String jarFileName = getFileName(jarFile);
-        boolean isImmutableJar = false;
-        for (String immutableJar : immutableJars) {
-            if (jarFileName.startsWith(immutableJar)) {
-                isImmutableJar = true;
-                break;
-            }
-        }
-
-        Attributes attributes = manifest.getMainAttributes();
-        if (attributes.getValue(BUNDLE_SYMBOLICNAME) == null) {
-            String bundleSymbolicName = jarFileName;
-            if (bundleSymbolicName.endsWith(".jar")) {
-                bundleSymbolicName = bundleSymbolicName.substring(0, bundleSymbolicName.length() - 4);
-            }
-            attributes.putValue(BUNDLE_SYMBOLICNAME, bundleSymbolicName);
-        } else {
-            // Assume the jar is already a bundle
-            return null;
-        }
-
-        if (attributes.getValue("Manifest-Version") == null) {
-            attributes.putValue("Manifest-Version", "1.0");
-        }
-
-        if (attributes.getValue(BUNDLE_MANIFESTVERSION) == null) {
-            attributes.putValue(BUNDLE_MANIFESTVERSION, "2");
-        }
-
-        if (isImmutableJar && attributes.getValue(BUNDLE_CLASSPATH) == null) {
-            attributes.putValue(BUNDLE_CLASSPATH, ".," + jarFileName);
-        }
-
-        JarInputStream jar = new JarInputStream(jarFile.openStream());
-        HashSet<String> packages = getPackagesInJar(jarFileName, jar);
-        jar.close();
-        String version = getJarVersion(jarFileName);
-
-        //        attributes.remove(new Attributes.Name("Require-Bundle"));
-        //        attributes.remove(new Attributes.Name("Import-Package"));
-
-        if (attributes.getValue(BUNDLE_VERSION) == null) {
-            attributes.putValue(BUNDLE_VERSION, version);
-        }
-        // Existing export statements in bundles may contain versions, so they should be used as is
-        // SDO exports are not sufficient, and should be changed
-        if (attributes.getValue(EXPORT_PACKAGE) == null || jarFileName.startsWith("tuscany-sdo-impl")) {
-            String pkgs = packagesToString(packages, version);
-            if (pkgs.length() > 0) {
-                attributes.putValue(EXPORT_PACKAGE, pkgs);
-                attributes.putValue(IMPORT_PACKAGE, packagesToString(packages, null));
-            }
-            // attributes.putValue("Import-Package", packagesToString(packages, null));
-        }
-
-        attributes.putValue(DYNAMICIMPORT_PACKAGE, "*");
-        return manifest;
-    }
-
-    private HashSet<String> getPackagesInJar(String bundleName, JarInputStream jar) throws Exception {
-        HashSet<String> packages = new HashSet<String>();
-        ZipEntry entry;
-        while ((entry = jar.getNextEntry()) != null) {
-            String entryName = entry.getName();
-            if (!entry.isDirectory() && entryName != null && entryName.length() > 0 && !entryName.startsWith(".")
-            // && !entryName.startsWith("META-INF")
-                && entryName.lastIndexOf("/") > 0) {
-                String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.');
-                packages.add(pkg);
-
-            }
-        }
-        // FIXME: Split package
-        if (bundleName.startsWith("axis2-adb")) {
-            packages.remove("org.apache.axis2.util");
-        } else if (bundleName.startsWith("axis2-codegen")) {
-            packages.remove("org.apache.axis2.wsdl");
-            packages.remove("org.apache.axis2.wsdl.util");
-        } else if (bundleName.startsWith("bsf-all")) {
-            packages.remove("org.mozilla.javascript");
-        }
-
-        return packages;
-    }
-
-    private String packagesToString(HashSet<String> packages, String version) {
-
-        StringBuilder pkgBuf = new StringBuilder();
-        for (String pkg : packages) {
-            if (pkgBuf.length() > 0) {
-                pkgBuf.append(',');
-            }
-            pkgBuf.append(pkg);
-            if (version != null && !pkg.startsWith("META-INF.")) {
-                pkgBuf.append(";version=\"");
-                pkgBuf.append(version);
-                pkgBuf.append('\"');
-            }
-        }
-        return pkgBuf.toString();
-    }
-
-    private String getJarVersion(String bundleName) {
-        Pattern pattern = Pattern.compile("-([0-9.]+)");
-        Matcher matcher = pattern.matcher(bundleName);
-        String version = "1.0.0";
-        if (matcher.find()) {
-            version = matcher.group();
-            if (version.endsWith(".")) {
-                version = version.substring(1, version.length() - 1);
-            } else {
-                version = version.substring(1);
+                //if (logger.isLoggable(Level.FINE)) {
+                // logger.info("Uninstalling bundle: " + NodeLauncherUtil.string(bundle, false));
+                //}
+                bundle.uninstall();
+            } catch (Exception e) {
+                logger.log(Level.SEVERE, e.getMessage(), e);
             }
         }
-        return version;
-    }
+        installedBundles.clear();
 
-    public BundleContext getBundleContext() {
-        return bundleContext;
+        this.bundleContext.removeBundleListener(this);
+        this.bundleContext = null;
     }
 
     public void bundleChanged(BundleEvent event) {

Added: 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=692820&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LibrariesBundleFileFactoryHook.java Sun Sep  7 04:25:41 2008
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.jar.Manifest;
+
+import org.eclipse.osgi.baseadaptor.BaseData;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
+import org.eclipse.osgi.baseadaptor.bundlefile.BundleFile;
+
+/**
+ * A bundle file factory hook that.
+ *
+ * @version $Rev: $ $Date: $
+*/
+public class LibrariesBundleFileFactoryHook implements org.eclipse.osgi.baseadaptor.hooks.BundleFileFactoryHook {
+    
+    private Manifest manifest;
+    
+    private static class LibrariesBundleFile extends BundleFile {
+        
+        private static class ManifestBundleEntry extends BundleEntry {
+            
+            private byte[] bytes;
+            
+            public ManifestBundleEntry(Manifest manifest) {
+                ByteArrayOutputStream bos = new ByteArrayOutputStream();
+                try {
+                    manifest.write(bos);
+                    bytes = bos.toByteArray();
+                } catch (IOException e) {
+                    throw new IllegalStateException(e);
+                }
+            }
+
+            @Override
+            public URL getFileURL() {
+                return null;
+            }
+            
+            @Override
+            public InputStream getInputStream() throws IOException {
+                return new ByteArrayInputStream(bytes);
+            }
+            
+            @Override
+            public URL getLocalURL() {
+                return null;
+            }
+            
+            @Override
+            public String getName() {
+                return "META-INF/MANIFEST.MF";
+            }
+            
+            @Override
+            public long getSize() {
+                return bytes.length;
+            }
+            
+            @Override
+            public long getTime() {
+                return -1;
+            }
+            
+            @Override
+            public byte[] getBytes() throws IOException {
+                return bytes;
+            }
+        }
+        
+        private Manifest manifest;
+        
+        public LibrariesBundleFile(Object baseFile, Manifest manifest) {
+            super((File)baseFile);
+            this.manifest = manifest;
+        }
+
+        @Override
+        public void close() throws IOException {
+        }
+
+        @Override
+        public boolean containsDir(String dir) {
+            return false;
+        }
+
+        @Override
+        public BundleEntry getEntry(String path) {
+            if ("META-INF/MANIFEST.MF".equals(path)) {
+                return new ManifestBundleEntry(manifest);
+            }
+            return null;
+        }
+
+        @Override
+        public Enumeration getEntryPaths(String path) {
+            return null;
+        }
+
+        @Override
+        public File getFile(String path, boolean nativeCode) {
+            return null;
+        }
+
+        @Override
+        public void open() throws IOException {
+        }
+    }
+    
+    public LibrariesBundleFileFactoryHook(Manifest manifest) {
+        this.manifest = manifest;
+    }
+
+    public BundleFile createBundleFile(Object content, BaseData data, boolean base) throws IOException {
+        if ("org.apache.tuscany.sca.node.launcher.equinox.libraries".equals(data.getLocation())) {
+            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/NodeDaemonLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java Sun Sep  7 04:25:41 2008
@@ -66,13 +66,13 @@
         // Create a node launcher
         NodeDaemonLauncher launcher = newInstance();
 
-        EquinoxOSGiHost equinox = null;
+        EquinoxHost equinox = null;
         Object node = null;
         ShutdownThread shutdown = null;
         try {
 
             // Start the OSGi host 
-            equinox = new EquinoxOSGiHost();
+            equinox = new EquinoxHost();
             equinox.start();
 
             // Start the node
@@ -135,9 +135,9 @@
     
     private static class ShutdownThread extends Thread {
         private Object node;
-        private EquinoxOSGiHost equinox;
+        private EquinoxHost equinox;
 
-        public ShutdownThread(Object node, EquinoxOSGiHost equinox) {
+        public ShutdownThread(Object node, EquinoxHost equinox) {
             super();
             this.node = node;
             this.equinox = equinox;

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=692820&r1=692819&r2=692820&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 Sun Sep  7 04:25:41 2008
@@ -33,13 +33,13 @@
 public class NodeLauncher {
 
     static final Logger logger = Logger.getLogger(NodeLauncher.class.getName());
-    private EquinoxOSGiHost host;
+    private EquinoxHost host;
 
     /**
      * Constructs a new node launcher.
      */
     private NodeLauncher() {
-        host = new EquinoxOSGiHost();
+        host = new EquinoxHost();
         host.start();
     }
 
@@ -118,7 +118,7 @@
         // Create a node launcher
         NodeLauncher launcher = newInstance();
 
-        EquinoxOSGiHost equinox = launcher.host;
+        EquinoxHost equinox = launcher.host;
         Object node = null;
         ShutdownThread shutdown = null;
         try {
@@ -204,9 +204,9 @@
     
     private static class ShutdownThread extends Thread {
         private Object node;
-        private EquinoxOSGiHost equinox;
+        private EquinoxHost equinox;
 
-        public ShutdownThread(Object node, EquinoxOSGiHost equinox) {
+        public ShutdownThread(Object node, EquinoxHost equinox) {
             super();
             this.node = node;
             this.equinox = equinox;

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=692820&r1=692819&r2=692820&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 Sun Sep  7 04:25:41 2008
@@ -19,8 +19,32 @@
 
 package org.apache.tuscany.sca.node.equinox.launcher;
 
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.file;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 import java.util.logging.Level;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
 
 /**
  * Common functions and constants used by the admin components.
@@ -172,4 +196,114 @@
         }
     }
 
+    static File file(URL url) {
+        if (url == null || !url.getProtocol().equals("file")) {
+            return null;
+        } else {
+            String filename = url.getFile().replace('/', File.separatorChar);
+            int pos = 0;
+            while ((pos = filename.indexOf('%', pos)) >= 0) {
+                if (pos + 2 < filename.length()) {
+                    String hexStr = filename.substring(pos + 1, pos + 3);
+                    char ch = (char)Integer.parseInt(hexStr, 16);
+                    filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
+                }
+            }
+            return new File(filename);
+        }
+    }
+    
+    static Pattern pattern = Pattern.compile("-([0-9.]+)");
+
+    private static String version(String jarFile) {
+        Matcher matcher = pattern.matcher(jarFile);
+        String version = "1.0.0";
+        if (matcher.find()) {
+            version = matcher.group();
+            if (version.endsWith(".")) {
+                version = version.substring(1, version.length() - 1);
+            } else {
+                version = version.substring(1);
+            }
+        }
+        return version;
+    }
+
+    private static void addPackages(String jarFile, Set<String> packages) throws IOException {
+        String version = ";version=" + version(jarFile);
+        ZipInputStream is = new ZipInputStream(new FileInputStream(file(new URL(jarFile))));
+        ZipEntry entry;
+        while ((entry = is.getNextEntry()) != null) {
+            String entryName = entry.getName();
+            if (!entry.isDirectory() && entryName != null && entryName.length() > 0 &&
+                !entryName.startsWith(".") && !entryName.startsWith("META-INF") &&
+                entryName.lastIndexOf("/") > 0) {
+                String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.') + version;
+                packages.add(pkg);
+            }
+        }
+        is.close();
+    }
+
+    static Manifest libraryManifest(String[] jarFiles) throws IllegalStateException {
+        try {
+
+            // List exported packages and bundle classpath entries
+            StringBuffer classpath = new StringBuffer();
+            StringBuffer exports = new StringBuffer();
+            Set<String> packages = new HashSet<String>(); 
+            for (String jarFile: jarFiles) {
+                addPackages(jarFile, packages);
+                classpath.append(jarFile);
+                classpath.append(',');
+            }
+            for (String pkg: packages) {
+                exports.append(pkg);
+                exports.append(',');
+            }
+    
+            // Create a manifest
+            Manifest manifest = new Manifest();
+            Attributes attributes = manifest.getMainAttributes();
+            attributes.putValue("Manifest-Version", "1.0");
+            attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
+            attributes.putValue(Constants.BUNDLE_SYMBOLICNAME, "org.apache.tuscany.sca.node.launcher.equinox.libraries");
+            attributes.putValue(Constants.EXPORT_PACKAGE, exports.substring(0, exports.length() -1));
+            attributes.putValue(Constants.BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() -1));
+            
+            return manifest;
+        } catch (IOException e) {
+            throw new IllegalStateException(e);
+        }
+    }
+    
+    static String string(Bundle b, boolean verbose) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
+        int s = b.getState();
+        if ((s & Bundle.UNINSTALLED) != 0) {
+            sb.append(" UNINSTALLED");
+        }
+        if ((s & Bundle.INSTALLED) != 0) {
+            sb.append(" INSTALLED");
+        }
+        if ((s & Bundle.RESOLVED) != 0) {
+            sb.append(" RESOLVED");
+        }
+        if ((s & Bundle.STARTING) != 0) {
+            sb.append(" STARTING");
+        }
+        if ((s & Bundle.STOPPING) != 0) {
+            sb.append(" STOPPING");
+        }
+        if ((s & Bundle.ACTIVE) != 0) {
+            sb.append(" ACTIVE");
+        }
+    
+        if (verbose) {
+            sb.append(" ").append(b.getLocation());
+            sb.append(" ").append(b.getHeaders());
+        }
+        return sb.toString();
+    }
 }

Copied: tuscany/java/sca/modules/node-launcher-equinox/src/main/resources/hookconfigurators.properties (from r692687, tuscany/java/sca/modules/extensibility-equinox/src/main/resources/hookconfigurators.properties)
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/resources/hookconfigurators.properties?p2=tuscany/java/sca/modules/node-launcher-equinox/src/main/resources/hookconfigurators.properties&p1=tuscany/java/sca/modules/extensibility-equinox/src/main/resources/hookconfigurators.properties&r1=692687&r2=692820&rev=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/extensibility-equinox/src/main/resources/hookconfigurators.properties (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/resources/hookconfigurators.properties Sun Sep  7 04:25:41 2008
@@ -13,4 +13,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License. 
-hook.configurators=org.apache.tuscany.sca.extensibility.equinox.EquinoxHookConfigurator
\ No newline at end of file
+hook.configurators=org.apache.tuscany.sca.node.equinox.launcher.EquinoxHookConfigurator
\ No newline at end of file

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java Sun Sep  7 04:25:41 2008
@@ -35,7 +35,7 @@
 public class EquinoxOSGiHostTestCase {
     @Test
     public void testStartThenStop() {
-        EquinoxOSGiHost host = new EquinoxOSGiHost();
+        EquinoxHost host = new EquinoxHost();
         BundleContext context = host.start();
         Assert.assertNotNull(context);
         for (Bundle b : context.getBundles()) {
@@ -46,7 +46,7 @@
 
     @Test
     public void testStartTwice() {
-        EquinoxOSGiHost host = new EquinoxOSGiHost();
+        EquinoxHost host = new EquinoxHost();
         host.start();
         try {
             host.start();

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java?rev=692820&r1=692819&r2=692820&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java Sun Sep  7 04:25:41 2008
@@ -36,7 +36,11 @@
 
     @BeforeClass
     public static void setUp() {
-        launcher = NodeLauncher.newInstance();
+        try {
+            launcher = NodeLauncher.newInstance();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     @AfterClass