summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java45
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java32
-rw-r--r--java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java6
3 files changed, 74 insertions, 9 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java
index 3bd712161f..eb7edd36b9 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/JarFileFinder.java
@@ -27,6 +27,7 @@ import java.net.MalformedURLException;
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 @@ public class JarFileFinder {
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 @@ public class JarFileFinder {
});
}
- private static File toFile(URL url) {
+ public static File toFile(URL url) {
if (url == null || !url.getProtocol().equals("file")) {
return null;
} else {
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java
index 778eb0f690..d5358726df 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/LauncherBundleActivator.java
@@ -3,12 +3,11 @@ 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.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 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
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 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
return tuscanyInstallDir;
}
+ /*
String location = bundle.getLocation();
if (location != null && location.startsWith("file:")) {
@@ -189,6 +194,7 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
}
}
}
+ */
return null;
}
@@ -198,6 +204,26 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
}
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;
diff --git a/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java b/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
index fa3dfc40aa..2bb45a38be 100644
--- a/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
+++ b/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
@@ -23,10 +23,6 @@ import hello.HelloWorld;
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 @@ public class NodeLauncherTestCase {
@BeforeClass
public static void setUp() {
- System.setProperty("TUSCANY_HOME", "target/tuscany");
+ // System.setProperty("TUSCANY_HOME", "target/tuscany");
host = NodeLauncherUtil.startOSGi();
}