From 0ff94f30af0ff0e6fce6b52f7c16ca35ac482a24 Mon Sep 17 00:00:00 2001 From: rfeng Date: Mon, 8 Sep 2008 18:22:14 +0000 Subject: Minor code clean up git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693184 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/modules/node-launcher-equinox/pom.xml | 23 -------- .../sca/node/equinox/launcher/EquinoxHost.java | 8 ++- .../sca/node/equinox/launcher/NodeLauncher.java | 8 +-- .../node/equinox/launcher/NodeLauncherUtil.java | 65 +++++++++------------- 4 files changed, 34 insertions(+), 70 deletions(-) (limited to 'java/sca') diff --git a/java/sca/modules/node-launcher-equinox/pom.xml b/java/sca/modules/node-launcher-equinox/pom.xml index 12095cefc5..654f7c8fcf 100644 --- a/java/sca/modules/node-launcher-equinox/pom.xml +++ b/java/sca/modules/node-launcher-equinox/pom.xml @@ -90,29 +90,6 @@ - org.apache.maven.plugins maven-jar-plugin 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 93b8936ae9..74e7d6ac4a 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 @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.jar.JarFile; import java.util.jar.Manifest; +import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.core.runtime.adaptor.EclipseStarter; @@ -101,7 +102,9 @@ public class EquinoxHost { // Set startup properties props.put(EclipseStarter.PROP_CLEAN, "true"); - props.put("osgi.console", "8085"); + if (logger.isLoggable(Level.FINE)) { + props.put("osgi.console", "8085"); + } // Set location properties // FIXME Use proper locations @@ -160,8 +163,7 @@ public class EquinoxHost { try { bundle.start(); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.log(Level.SEVERE, e.getMessage(), e); } logger.info("Bundle: " + string(bundle, false)); } diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java index f3bb8c04ae..807b5cd8f7 100644 --- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java +++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java @@ -65,7 +65,7 @@ public class NodeLauncher { * @throws LauncherException */ public T createNodeFromURL(String configurationURL) throws LauncherException { - return (T)node(configurationURL, null, null, null, null, bundleContext); + return (T)node(configurationURL, null, null, null, null); } /** @@ -80,7 +80,7 @@ public class NodeLauncher { * @throws LauncherException */ public T createNode(String compositeURI, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, null, contributions, null, bundleContext); + return (T)node(null, compositeURI, null, contributions, null); } /** @@ -94,7 +94,7 @@ public class NodeLauncher { */ public T createNode(String compositeURI, String compositeContent, Contribution... contributions) throws LauncherException { - return (T)node(null, compositeURI, compositeContent, contributions, null, bundleContext); + return (T)node(null, compositeURI, compositeContent, contributions, null); } /** @@ -112,7 +112,7 @@ public class NodeLauncher { * @return A newly created SCA node */ public T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException { - return (T)node(null, compositeURI, null, null, classLoader, bundleContext); + return (T)node(null, compositeURI, null, null, classLoader); } public static void main(String[] args) throws Exception { 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 7310356c72..e2b457b62c 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 @@ -47,7 +47,6 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; /** * Common functions and constants used by the admin components. @@ -56,6 +55,8 @@ import org.osgi.framework.BundleContext; */ final class NodeLauncherUtil { + private static final String SCANODE_FACTORY = "org.apache.tuscany.sca.node.SCANodeFactory"; + private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP = "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap"; @@ -67,33 +68,18 @@ final class NodeLauncherUtil { /** * Collect JAR files under the given directory. + * @param contributions * - * @p @param contributions - * @param bundleContext TODO * @throws LauncherException */ static Object node(String configurationURI, String compositeURI, String compositeContent, Contribution[] contributions, - ClassLoader contributionClassLoader, - BundleContext bundleContext) throws LauncherException { + ClassLoader contributionClassLoader) throws LauncherException { try { - -// Bundle bundle = null; -// for (Bundle b : bundleContext.getBundles()) { -// if ("org.apache.tuscany.sca.implementation.node.runtime".equals(b.getSymbolicName())) { -// bundle = b; -// break; -// } -// } -// if (bundle == null) { -// throw new IllegalStateException( -// "Bundle org.apache.tuscany.sca.implementation.node.runtime is not installed"); -// } // Use Java reflection to create the node as only the runtime class // loader knows the runtime classes required by the node - String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP; Class bootstrapClass = Class.forName(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP); Object bootstrap; @@ -139,7 +125,7 @@ final class NodeLauncherUtil { Object node = bootstrapClass.getMethod("getNode").invoke(bootstrap); try { - Class type = Class.forName("org.apache.tuscany.sca.node.SCANodeFactory"); + Class type = Class.forName(SCANODE_FACTORY); type = type.getDeclaredClasses()[0]; return type.getMethod("createProxy", Class.class, Object.class).invoke(null, type, node); } catch (ClassNotFoundException e) { @@ -150,8 +136,6 @@ final class NodeLauncherUtil { } catch (Exception e) { NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e); throw new LauncherException(e); - } finally { - // } } @@ -226,7 +210,7 @@ final class NodeLauncherUtil { return new File(filename); } } - + static Pattern pattern = Pattern.compile("-([0-9.]+)"); private static String version(String jarFile) { @@ -249,9 +233,11 @@ final class NodeLauncherUtil { 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) { + 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); } @@ -266,14 +252,14 @@ final class NodeLauncherUtil { StringBuffer classpath = new StringBuffer(); StringBuffer exports = new StringBuffer(); StringBuffer imports = new StringBuffer(); - Set packages = new HashSet(); - for (String jarFile: jarFiles) { + Set packages = new HashSet(); + for (String jarFile : jarFiles) { addPackages(jarFile, packages); classpath.append("\"external:"); classpath.append(file(new URL(jarFile)).getAbsolutePath().replace(File.separatorChar, '/')); classpath.append("\","); } - + Set importPackages = new HashSet(); for (String pkg : packages) { exports.append(pkg); @@ -290,32 +276,31 @@ final class NodeLauncherUtil { importPackages.add(importPackage); } } - - + // Create a manifest Manifest manifest = new Manifest(); Attributes attributes = manifest.getMainAttributes(); attributes.putValue("Manifest-Version", "1.0"); attributes.putValue(BUNDLE_MANIFESTVERSION, "2"); attributes.putValue(BUNDLE_SYMBOLICNAME, "org.apache.tuscany.sca.node.launcher.equinox.libraries"); - attributes.putValue(EXPORT_PACKAGE, exports.substring(0, exports.length() -1)); - attributes.putValue(IMPORT_PACKAGE, imports.substring(0, imports.length() -1)); - attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() -1)); + attributes.putValue(EXPORT_PACKAGE, exports.substring(0, exports.length() - 1)); + attributes.putValue(IMPORT_PACKAGE, imports.substring(0, imports.length() - 1)); + attributes.putValue(BUNDLE_CLASSPATH, classpath.substring(0, classpath.length() - 1)); attributes.putValue(DYNAMICIMPORT_PACKAGE, "*"); - + return manifest; } catch (IOException e) { throw new IllegalStateException(e); } } - + static byte[] generateBundle(Manifest mf) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); JarOutputStream jos = new JarOutputStream(bos, mf); jos.close(); return bos.toByteArray(); } - + /** * Returns the location of this bundle. * @@ -323,13 +308,13 @@ final class NodeLauncherUtil { * @throws IOException */ static String bundleLocation() throws IOException, URISyntaxException { - String resource = NodeLauncherUtil.class.getName().replace('.', '/') + ".class"; + String resource = NodeLauncherUtil.class.getName().replace('.', '/') + ".class"; URL url = NodeLauncherUtil.class.getClassLoader().getResource(resource); if (url == null) { throw new FileNotFoundException(resource); } URI uri = url.toURI(); - + String scheme = uri.getScheme(); if (scheme.equals("jar")) { String path = uri.toString().substring(4); @@ -342,7 +327,7 @@ final class NodeLauncherUtil { return path; } } - + static String string(Bundle b, boolean verbose) { StringBuffer sb = new StringBuffer(); sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); @@ -365,7 +350,7 @@ final class NodeLauncherUtil { if ((s & Bundle.ACTIVE) != 0) { sb.append(" ACTIVE"); } - + if (verbose) { sb.append(" ").append(b.getLocation()); sb.append(" ").append(b.getHeaders()); -- cgit v1.2.3