summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java78
-rw-r--r--java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java6
-rw-r--r--java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java7
3 files changed, 87 insertions, 4 deletions
diff --git a/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
index 7d10bd8fc5..ffe0407a68 100644
--- a/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
+++ b/java/sca/modules/extensibility-eclipse/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
@@ -28,6 +28,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.security.SecureClassLoader;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -48,9 +50,11 @@ import org.osgi.framework.BundleContext;
public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
private static final Logger logger = Logger.getLogger(EquinoxServiceDiscoverer.class.getName());
private BundleContext context;
+ private ClassLoader classLoader;
public EquinoxServiceDiscoverer(BundleContext context) {
this.context = context;
+ this.classLoader = new ClassLoaderImpl();
}
public static class ServiceDeclarationImpl implements ServiceDeclaration {
@@ -112,6 +116,72 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
}
+ public class ClassLoaderImpl extends SecureClassLoader {
+
+ public ClassLoaderImpl() {
+ super(EquinoxServiceDiscoverer.class.getClassLoader());
+ }
+
+ /**
+ * Open a back-door to expose the META-INF/services resources
+ */
+ @Override
+ protected URL findResource(String name) {
+ int index = name.lastIndexOf('/');
+ if (index == -1) {
+ return null;
+ }
+ String path = name.substring(0, index);
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+
+ if (!path.startsWith("META-INF/services")) {
+ return null;
+ }
+
+ for (Bundle bundle : context.getBundles()) {
+ URL url = bundle.getEntry(name);
+ if (url != null) {
+ return url;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Open a back-door to expose the META-INF/services resources
+ */
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException {
+ int index = name.lastIndexOf('/');
+ if (index == -1) {
+ return null;
+ }
+ String path = name.substring(0, index);
+ String file = name.substring(index + 1);
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+
+ if (!path.startsWith("META-INF/services")) {
+ return null;
+ }
+
+ Set<URL> urlSet = new HashSet<URL>();
+
+ for (Bundle bundle : context.getBundles()) {
+ Enumeration<URL> urls = bundle.findEntries(path, file, false);
+ if (urls != null) {
+ urlSet.addAll(Collections.list(urls));
+ }
+ }
+ return Collections.enumeration(urlSet);
+ }
+
+ }
+
private static String toString(Bundle b) {
StringBuffer sb = new StringBuffer();
sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
@@ -252,4 +322,12 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer {
}
+ /**
+ * This class loader can be set as the thread context class loader for non-OSGi code
+ * @return
+ */
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
}
diff --git a/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java b/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java
index e90ded0901..1b07753f3d 100644
--- a/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java
+++ b/java/sca/modules/extensibility-osgi/src/main/java/org/apache/tuscany/sca/extensibility/osgi/OSGiServiceDiscoverer.java
@@ -57,6 +57,12 @@ public class OSGiServiceDiscoverer implements ServiceDiscoverer {
this.classLoader = new ClassLoaderImpl();
}
+ /**
+ * This class loader provides resource access to META-INF/services/... which is used by
+ * many frameworks. OSGi Import-Package and DynmaicImport-Package headers do not support
+ * split packages. Another option is to use Require-Bundle header. We can collect the list
+ * of bundles and add them as required bundles to a special gateway bundle.
+ */
public class ClassLoaderImpl extends SecureClassLoader {
public ClassLoaderImpl() {
diff --git a/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java b/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java
index 015ef5741d..0739e3d1ab 100644
--- a/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java
+++ b/java/sca/modules/implementation-node-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/osgi/launcher/LauncherBundleActivator.java
@@ -96,6 +96,7 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
}
}
this.bundleContext.removeBundleListener(this);
+ tuscanyBundles.clear();
this.bundleContext = null;
}
@@ -118,9 +119,6 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
}
try {
Bundle bundle = createAndInstallBundle(bundleContext, file);
- if (bundle != null) {
- tuscanyBundles.add(bundle);
- }
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
}
@@ -181,7 +179,7 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
Bundle bundle = findBundle(bundleContext, symbolicName, version);
if (bundle != null) {
logger.info("Bundle is already installed: " + symbolicName);
- return null;
+ return bundle;
}
String bundleLocation = bundleFile.toURI().toString();
@@ -209,6 +207,7 @@ public class LauncherBundleActivator implements BundleActivator, Constants, Bund
try {
bundle = bundleContext.installBundle(bundleLocation, inStream);
logger.info("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleLocation);
+ tuscanyBundles.add(bundle);
return bundle;
} finally {
inStream.close();