You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/09/08 20:22:15 UTC

svn commit: r693184 - in /tuscany/java/sca/modules/node-launcher-equinox: ./ src/main/java/org/apache/tuscany/sca/node/equinox/launcher/

Author: rfeng
Date: Mon Sep  8 11:22:14 2008
New Revision: 693184

URL: http://svn.apache.org/viewvc?rev=693184&view=rev
Log:
Minor code clean up

Modified:
    tuscany/java/sca/modules/node-launcher-equinox/pom.xml
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
    tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java

Modified: tuscany/java/sca/modules/node-launcher-equinox/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/pom.xml?rev=693184&r1=693183&r2=693184&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/pom.xml (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/pom.xml Mon Sep  8 11:22:14 2008
@@ -90,29 +90,6 @@
 
     <build>
         <plugins>
-        <!-- 
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <version>2.0</version>
-                <executions>
-                    <execution>
-                        <id>copy-dependencies</id>
-                        <phase>process-test-resources</phase>
-                        <goals>
-                            <goal>copy-dependencies</goal>
-                        </goals>
-                        <configuration>
-                            <includeScope>test</includeScope>
-                            <outputDirectory>${project.build.directory}/tuscany/modules</outputDirectory>
-                            <overWriteReleases>true</overWriteReleases>
-                            <overWriteSnapshots>true</overWriteSnapshots>
-                            <excludeArtifactIds></excludeArtifactIds>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>  
-             -->      
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java?rev=693184&r1=693183&r2=693184&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java Mon Sep  8 11:22:14 2008
@@ -32,6 +32,7 @@
 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 @@
             // 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 @@
                     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));
                 }

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java?rev=693184&r1=693183&r2=693184&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java Mon Sep  8 11:22:14 2008
@@ -65,7 +65,7 @@
      * @throws LauncherException
      */
     public <T> 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 @@
      * @throws LauncherException
      */
     public <T> 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 <T> 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 @@
      * @return A newly created SCA node
      */
     public <T> 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 {

Modified: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java?rev=693184&r1=693183&r2=693184&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java (original)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java Mon Sep  8 11:22:14 2008
@@ -47,7 +47,6 @@
 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 @@
  */
 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 @@
 
     /**
      * 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 @@
 
             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 @@
         } catch (Exception e) {
             NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e);
             throw new LauncherException(e);
-        } finally {
-            // 
         }
     }
 
@@ -226,7 +210,7 @@
             return new File(filename);
         }
     }
-    
+
     static Pattern pattern = Pattern.compile("-([0-9.]+)");
 
     private static String version(String jarFile) {
@@ -249,9 +233,11 @@
         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 @@
             StringBuffer classpath = new StringBuffer();
             StringBuffer exports = new StringBuffer();
             StringBuffer imports = new StringBuffer();
-            Set<String> packages = new HashSet<String>(); 
-            for (String jarFile: jarFiles) {
+            Set<String> packages = new HashSet<String>();
+            for (String jarFile : jarFiles) {
                 addPackages(jarFile, packages);
                 classpath.append("\"external:");
                 classpath.append(file(new URL(jarFile)).getAbsolutePath().replace(File.separatorChar, '/'));
                 classpath.append("\",");
             }
-            
+
             Set<String> importPackages = new HashSet<String>();
             for (String pkg : packages) {
                 exports.append(pkg);
@@ -290,32 +276,31 @@
                     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 @@
      * @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 @@
             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 @@
         if ((s & Bundle.ACTIVE) != 0) {
             sb.append(" ACTIVE");
         }
-    
+
         if (verbose) {
             sb.append(" ").append(b.getLocation());
             sb.append(" ").append(b.getHeaders());