tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r692269 - in /tuscany/java/sca/modules/node-launcher-equinox/src: main/java/org/apache/tuscany/sca/node/equinox/launcher/ test/java/org/apache/tuscany/sca/node/equinox/launcher/
Date Thu, 04 Sep 2008 21:56:40 GMT
Author: rfeng
Date: Thu Sep  4 14:56:40 2008
New Revision: 692269

URL: http://svn.apache.org/viewvc?rev=692269&view=rev
Log:
Add the capability to find dependencies jars/folders from the URLClassLoader without building
a mini distro

Modified:
    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/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java

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=692269&r1=692268&r2=692269&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
Thu Sep  4 14:56:40 2008
@@ -27,6 +27,7 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
@@ -267,6 +268,48 @@
         return jarURLs;
 
     }
+    
+    
+    /**
+     * Returns contribution JARs available on the classpath.
+     * 
+     * @return
+     */
+    public static List<URL> getClassPathEntries(ClassLoader classLoader, boolean recursive)
{
+        if (classLoader == null) {
+            classLoader = Thread.currentThread().getContextClassLoader();
+        }
+        Set<URL> entries = new HashSet<URL>();
+        list(entries, classLoader, recursive);
+        return new ArrayList<URL>(entries);
+    }
+
+    /**
+     * Collect JARs on the classpath of a URLClassLoader
+     * @param urls
+     * @param cl
+     */
+    private static void list(Set<URL> urls, ClassLoader cl, boolean recursive) {
+        if (cl == null) {
+            return;
+        }
+
+        // Collect JARs from the URLClassLoader's classpath
+        if (cl instanceof URLClassLoader) {
+            URL[] jarURLs = ((URLClassLoader)cl).getURLs();
+            if (jarURLs != null) {
+                for (URL jarURL : jarURLs) {
+                    urls.add(jarURL);
+                }
+            }
+        }
+
+        // Collect JARs from the parent ClassLoader
+        if (recursive) {
+            list(urls, cl.getParent(), recursive);
+        }
+    }
+
 
     static String getProperty(final String prop) {
         return AccessController.doPrivileged(new PrivilegedAction<String>() {
@@ -281,7 +324,7 @@
         });
     }
 
-    private static File toFile(URL url) {
+    public static File toFile(URL url) {
         if (url == null || !url.getProtocol().equals("file")) {
             return null;
         } else {

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=692269&r1=692268&r2=692269&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
Thu Sep  4 14:56:40 2008
@@ -3,12 +3,11 @@
 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.URI;
 import java.net.URL;
-import java.security.CodeSource;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -137,7 +136,12 @@
             if (urls == null) {
                 File tuscanyInstallDir = findTuscanyInstallDir(bundleContext.getBundle());
 
-                urls = JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter());
+                if (tuscanyInstallDir != null) {
+                    urls =
+                        JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter());
+                } else {
+                    urls = JarFileFinder.getClassPathEntries(JarFileFinder.class.getClassLoader(),
false);
+                }
             }
 
             for (URL url : urls) {
@@ -169,6 +173,7 @@
                 return tuscanyInstallDir;
         }
 
+        /*
         String location = bundle.getLocation();
 
         if (location != null && location.startsWith("file:")) {
@@ -189,6 +194,7 @@
                 }
             }
         }
+        */
         return null;
     }
 
@@ -198,6 +204,26 @@
         }
         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;
+            }
+        }
         Manifest manifest = readManifest(bundleFile);
         boolean isOSGiBundle = manifest != null && manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME)
!= null;
 

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=692269&r1=692268&r2=692269&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
Thu Sep  4 14:56:40 2008
@@ -23,10 +23,6 @@
 
 import org.apache.tuscany.sca.node.SCAClient;
 import org.apache.tuscany.sca.node.SCANode;
-import org.apache.tuscany.sca.node.equinox.launcher.DomainManagerLauncher;
-import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
-import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil;
-import org.apache.tuscany.sca.node.equinox.launcher.OSGiHost;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -40,7 +36,7 @@
 
     @BeforeClass
     public static void setUp() {
-        System.setProperty("TUSCANY_HOME", "target/tuscany");
+        // System.setProperty("TUSCANY_HOME", "target/tuscany");
         host = NodeLauncherUtil.startOSGi();
     }
 



Mime
View raw message