summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-launcher-equinox/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-31 03:42:17 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-07-31 03:42:17 +0000
commit6e481c109faf970288bae780bea01c236571e277 (patch)
treef73fae7d20d1f15b4ec4ed6ece36b975455d97a5 /java/sca/modules/node-launcher-equinox/src
parentdb0695c47f85c0d8a57966110bfb5b70fbb9f5e0 (diff)
Generate a gateway bundle that aggregate split META-INF/services resources
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@799510 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-launcher-equinox/src')
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java62
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java93
2 files changed, 138 insertions, 17 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
index e730333cd2..24a8b368dc 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
@@ -21,6 +21,7 @@ package org.apache.tuscany.sca.node.equinox.launcher;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.setProperty;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.GATEWAY_BUNDLE;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.LAUNCHER_EQUINOX_LIBRARIES;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.artifactId;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.bundleName;
@@ -33,6 +34,7 @@ import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thir
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.thisBundleLocation;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -57,6 +59,7 @@ import java.util.logging.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.launch.Framework;
/**
@@ -155,6 +158,11 @@ public class EquinoxHost {
if (injectedBundleContext == null) {
String version = getSystemProperty("java.specification.version");
+
+ /**
+ * [rfeng] I have to remove javax.transaction.* packages from the system bundle
+ * See: http://www.mail-archive.com/dev@geronimo.apache.org/msg70761.html
+ */
String profile = "J2SE-1.5.profile";
if (version.startsWith("1.6")) {
profile = "JavaSE-1.6.profile";
@@ -197,6 +205,23 @@ public class EquinoxHost {
put(props, PROP_CONFIG_AREA_DEFAULT, new File(root, "config").toURI().toString());
put(props, PROP_USER_AREA_DEFAULT, new File(root, "user").toURI().toString());
+ // Test if the configuration/config.ini or osgi.bundles has been set
+ // If yes, try to avoid discovery of bundles
+ if (bundleLocations == null) {
+ if (props.getProperty("osgi.bundles") != null) {
+ bundleLocations = Collections.emptySet();
+ } else {
+ String config = props.getProperty(PROP_CONFIG_AREA);
+ File ini = new File(config, "config.ini");
+ if (ini.isFile()) {
+ Properties iniProps = new Properties();
+ iniProps.load(new FileInputStream(ini));
+ if (iniProps.getProperty("osgi.bundles") != null) {
+ bundleLocations = Collections.emptySet();
+ }
+ }
+ }
+ }
startFramework(props);
} else {
@@ -259,13 +284,20 @@ public class EquinoxHost {
logger.fine("Generating third-party library bundle.");
}
long libraryStart = currentTimeMillis();
+
+ Set<String> serviceProviders = new HashSet<String>();
if (!aggregateThirdPartyJars) {
for (URL jarFile : jarFiles) {
- installAsBundle(jarFile, null);
+ Bundle bundle = installAsBundle(jarFile, null);
+ isServiceProvider(bundle, serviceProviders);
}
} else {
- installAsBundle(jarFiles, LAUNCHER_EQUINOX_LIBRARIES);
+ Bundle bundle = installAsBundle(jarFiles, LAUNCHER_EQUINOX_LIBRARIES);
+ isServiceProvider(bundle, serviceProviders);
}
+
+ installGatewayBundle(serviceProviders);
+
if (logger.isLoggable(Level.FINE)) {
logger
.fine("Third-party library bundle installed in " + (currentTimeMillis() - libraryStart) + " ms: ");
@@ -320,6 +352,32 @@ public class EquinoxHost {
}
}
+ private boolean isServiceProvider(Bundle bundle, Set<String> serviceProviders) {
+ if (bundle != null) {
+ String export = (String)bundle.getHeaders().get(Constants.EXPORT_PACKAGE);
+ if (export != null && export.contains("META-INF.services")) {
+ serviceProviders.add(bundle.getSymbolicName());
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void installGatewayBundle(Set<String> bundles) throws IOException, BundleException {
+ if (allBundles.containsKey(GATEWAY_BUNDLE)) {
+ return;
+ }
+ if (bundles == null) {
+ bundles = allBundles.keySet();
+ }
+ InputStream gateway = NodeLauncherUtil.generateGatewayBundle(bundles, null, false);
+ if (gateway != null) {
+ Bundle gatewayBundle = bundleContext.installBundle(GATEWAY_BUNDLE, gateway);
+ allBundles.put(NodeLauncherUtil.GATEWAY_BUNDLE, gatewayBundle);
+ installedBundles.add(gatewayBundle);
+ }
+ }
+
/**
* Start all the bundles as a check for class loading issues
* @param bundleContext - the bundle context
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
index d958cda0cf..47480635f0 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
@@ -19,12 +19,22 @@
package org.apache.tuscany.sca.node.equinox.launcher;
+import static org.osgi.framework.Constants.ACTIVATION_LAZY;
+import static org.osgi.framework.Constants.BUNDLE_ACTIVATIONPOLICY;
import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
import static org.osgi.framework.Constants.BUNDLE_MANIFESTVERSION;
+import static org.osgi.framework.Constants.BUNDLE_NAME;
import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
+import static org.osgi.framework.Constants.BUNDLE_VENDOR;
+import static org.osgi.framework.Constants.BUNDLE_VERSION;
import static org.osgi.framework.Constants.DYNAMICIMPORT_PACKAGE;
import static org.osgi.framework.Constants.EXPORT_PACKAGE;
import static org.osgi.framework.Constants.IMPORT_PACKAGE;
+import static org.osgi.framework.Constants.REQUIRE_BUNDLE;
+import static org.osgi.framework.Constants.RESOLUTION_DIRECTIVE;
+import static org.osgi.framework.Constants.RESOLUTION_OPTIONAL;
+import static org.osgi.framework.Constants.VISIBILITY_DIRECTIVE;
+import static org.osgi.framework.Constants.VISIBILITY_REEXPORT;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -81,7 +91,8 @@ final class NodeLauncherUtil {
private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
static final String LAUNCHER_EQUINOX_LIBRARIES = "org.apache.tuscany.sca.node.launcher.equinox.libraries";
-
+ static final String GATEWAY_BUNDLE = "org.apache.tuscany.sca.gateway";
+
private static final String NODE_FACTORY = "org.apache.tuscany.sca.node.NodeFactory";
private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP =
@@ -335,13 +346,22 @@ final class NodeLauncherUtil {
}
String pkg = cls.substring(0, index);
pkg = pkg.replace('/', '.') + version;
- packages.add(pkg);
+ // Export META-INF.services
+ if ("META-INF.services".equals(pkg)) {
+ packages.add("META-INF.services" + ";partial=true;mandatory:=partial");
+ } else {
+ packages.add(pkg);
+ }
}
} else if (file.isFile()) {
ZipInputStream is = new ZipInputStream(new FileInputStream(file));
ZipEntry entry;
while ((entry = is.getNextEntry()) != null) {
String entryName = entry.getName();
+ // Export split packages for META-INF/services
+ if(entryName.startsWith("META-INF/services/")) {
+ packages.add("META-INF.services" + ";partial=true;mandatory:=partial");
+ }
if (!entry.isDirectory() && entryName != null
&& entryName.length() > 0
&& !entryName.startsWith(".")
@@ -358,6 +378,10 @@ final class NodeLauncherUtil {
private static List<String> listClassFiles(File directory) {
List<String> artifacts = new ArrayList<String>();
traverse(artifacts, directory, directory);
+ // Add META-INF/services to be exported
+ if (new File(directory, "META-INF/services").isDirectory()) {
+ artifacts.add("META-INF/services/");
+ }
return artifacts;
}
@@ -426,16 +450,6 @@ final class NodeLauncherUtil {
String bundleSymbolicName,
String bundleVersion) throws IllegalStateException {
try {
- // Added by Mike Edwards, 12/04/2009 - to handle the third party JAR files in the distribution that
- // have separate OSGi manifest files provided alongside them
- // In some cases a single JAR file is already accompanied by a MANIFEST.MF file, sitting in
- // a META-INF directory alongside the JAR
- //if( jarFiles.size() == 1 ){
- // URL theJar = jarFiles.iterator().next();
- // Manifest theManifest = findOSGiManifest( theJar );
- // if( theManifest != null ) return theManifest;
- //} // end if
- // End of addition
// List exported packages and bundle classpath entries
StringBuffer classpath = new StringBuffer();
@@ -459,8 +473,11 @@ final class NodeLauncherUtil {
importPackage = pkg.substring(0, index);
}
if (!importPackages.contains(importPackage)) {
- imports.append(pkg);
- imports.append(',');
+ // Exclude META-INF.services
+ if (!"META-INF.services".equals(importPackage)) {
+ imports.append(pkg);
+ imports.append(',');
+ }
importPackages.add(importPackage);
exports.append(pkg);
exports.append(',');
@@ -492,7 +509,8 @@ final class NodeLauncherUtil {
if (classpath.length() > 0) {
attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() - 1));
}
- attributes.putValue(DYNAMICIMPORT_PACKAGE, "*");
+ // The system bundle has incomplete javax.transaction* packages exported
+ attributes.putValue(DYNAMICIMPORT_PACKAGE, "javax.transaction;version=\"1.1\",javax.transaction.xa;version=\"1.1\",*");
return manifest;
} catch (IOException e) {
@@ -1259,4 +1277,49 @@ final class NodeLauncherUtil {
} // end if
} // end collectDevelopmentLibraryEntries
+ /**
+ * Generate a gateway bundle that aggregate other bundles to handle split packages
+ * @param bundleSymbolicNames
+ * @throws FileNotFoundException
+ * @throws IOException
+ */
+ static InputStream generateGatewayBundle(Collection<String> bundleSymbolicNames, String bundleVersion, boolean reexport)
+ throws IOException {
+ Manifest manifest = new Manifest();
+ Attributes attrs = manifest.getMainAttributes();
+ StringBuffer requireBundle = new StringBuffer();
+ for (String name : new HashSet<String>(bundleSymbolicNames)) {
+ requireBundle.append(name).append(";").append(RESOLUTION_DIRECTIVE).append(":=")
+ .append(RESOLUTION_OPTIONAL);
+ if (reexport) {
+ requireBundle.append(";").append(VISIBILITY_DIRECTIVE).append(":=").append(VISIBILITY_REEXPORT);
+ }
+ requireBundle.append(",");
+ }
+ int len = requireBundle.length();
+ if (len > 0 && requireBundle.charAt(len - 1) == ',') {
+ requireBundle.deleteCharAt(len - 1);
+ attrs.putValue(REQUIRE_BUNDLE, requireBundle.toString());
+ attrs.putValue("Manifest-Version", "1.0");
+ attrs.putValue("Implementation-Vendor", "The Apache Software Foundation");
+ attrs.putValue("Implementation-Vendor-Id", "org.apache");
+ if (bundleVersion != null) {
+ attrs.putValue(BUNDLE_VERSION, bundleVersion);
+ }
+ attrs.putValue(BUNDLE_MANIFESTVERSION, "2");
+ attrs.putValue(BUNDLE_SYMBOLICNAME, GATEWAY_BUNDLE);
+ attrs.putValue(BUNDLE_NAME, "Apache Tuscany SCA Gateway Bundle");
+ attrs.putValue(BUNDLE_VENDOR, "The Apache Software Foundation");
+ attrs.putValue(EXPORT_PACKAGE, "META-INF.services");
+ attrs.putValue(DYNAMICIMPORT_PACKAGE, "*");
+ attrs.putValue(BUNDLE_ACTIVATIONPOLICY, ACTIVATION_LAZY);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ JarOutputStream jos = new JarOutputStream(bos, manifest);
+ jos.close();
+ return new ByteArrayInputStream(bos.toByteArray());
+ } else {
+ return null;
+ }
+ }
+
}