tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r740629 - in /tuscany/java/sca/modules/node-launcher: ./ META-INF/ src/main/java/org/apache/tuscany/sca/node/launcher/
Date Wed, 04 Feb 2009 06:09:25 GMT
Author: rfeng
Date: Wed Feb  4 06:09:25 2009
New Revision: 740629

URL: http://svn.apache.org/viewvc?rev=740629&view=rev
Log:
Add the command line processing for JSE launcher too

Modified:
    tuscany/java/sca/modules/node-launcher/META-INF/MANIFEST.MF
    tuscany/java/sca/modules/node-launcher/pom.xml
    tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
    tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
    tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java

Modified: tuscany/java/sca/modules/node-launcher/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/META-INF/MANIFEST.MF?rev=740629&r1=740628&r2=740629&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/META-INF/MANIFEST.MF (original)
+++ tuscany/java/sca/modules/node-launcher/META-INF/MANIFEST.MF Wed Feb  4 06:09:25 2009
@@ -11,7 +11,7 @@
 Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
 Bundle-Description: Apache Tuscany SCA Node Launcher
 Import-Package: javax.servlet,org.apache.tuscany.sca.node.launcher;ver
- sion="2.0.0"
+ sion="2.0.0",org.apache.commons.cli;resolution:=optional
 Bundle-SymbolicName: org.apache.tuscany.sca.node.launcher
 Bundle-DocURL: http://www.apache.org/
 

Modified: tuscany/java/sca/modules/node-launcher/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/pom.xml?rev=740629&r1=740628&r2=740629&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/pom.xml (original)
+++ tuscany/java/sca/modules/node-launcher/pom.xml Wed Feb  4 06:09:25 2009
@@ -36,6 +36,13 @@
             <artifactId>servlet-api</artifactId>
             <version>2.5</version>
         </dependency>
+        
+        <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+            <version>1.1</version>
+        </dependency>
+           
     </dependencies>
 
     <build>

Modified: tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java?rev=740629&r1=740628&r2=740629&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
(original)
+++ tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
Wed Feb  4 06:09:25 2009
@@ -21,10 +21,21 @@
 
 import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.node;
 
+import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+
 /**
  * A launcher for SCA nodes.
  *  
@@ -108,32 +119,70 @@
         return (T)node(null, compositeURI, null, null, classLoader);
     }
     
-    public static void main(String[] args) throws Exception {
-        logger.info("Apache Tuscany SCA Node is starting...");
-
-        // Create a node launcher
-        NodeLauncher launcher = newInstance();
+    static Options getCommandLineOptions() {
+        Options options = new Options();
+        Option opt1 = new Option("c", "composite", true, "URI for the composite");
+        opt1.setArgName("compositeURI");
+        options.addOption(opt1);
+        Option opt2 = new Option("n", "node", true, "URI for the node configuration");
+        opt2.setArgName("nodeConfigurationURI");
+        options.addOption(opt2);
+        return options;
+    }
 
+    public static void main(String[] args) throws Exception {
+        CommandLineParser parser = new PosixParser();
+        Options options = getCommandLineOptions();
+        CommandLine cli = parser.parse(options, args);
+        
         Object node = null;
         ShutdownThread shutdown = null;
         try {
             while (true) {
-                if (args.length ==1) {
+                if (cli.hasOption("node")) {
                     
                     // Create a node from a configuration URI
-                    String configurationURI = args[0];
+                    String configurationURI = cli.getOptionValue("node");
                     logger.info("SCA Node configuration: " + configurationURI);
+                    // Create a node launcher
+                    NodeLauncher launcher = newInstance();
                     node = launcher.createNodeFromURL(configurationURI);
                 } else {
                     
                     // Create a node from a composite URI and a contribution location
-                    String compositeURI = args[0];
-                    String contributionLocation = args[1];
+                    String compositeURI = cli.getOptionValue("composite");
+                    List<String> contribs = cli.getArgList();
+                    Contribution[] contributions = null;
+                    if (!contribs.isEmpty()) {
+                        contributions = new Contribution[contribs.size()];
+                        int index = 0;
+                        for (String contrib : contribs) {
+                            logger.info("SCA contribution: " + contrib);
+                            URL url = null;
+                            try {
+                                url = new URL(contrib);
+                            } catch(MalformedURLException e) {
+                                url = new File(contrib).toURI().toURL();
+                            }
+                            contributions[index] = new Contribution("contribution-" + index,
url.toString());
+                            index++;
+                        }
+                    } else {
+                        HelpFormatter formatter = new HelpFormatter();
+                        formatter.setSyntaxPrefix("Usage: ");
+                        formatter.printHelp("java " + NodeLauncher.class.getName()
+                            + " [-c <compositeURI>] contribution1 ... contributionN",
options);
+                        return;
+                    }
+                    // Create a node launcher
                     logger.info("SCA composite: " + compositeURI);
-                    logger.info("SCA contribution: " + contributionLocation);
-                    node = launcher.createNode(compositeURI, new Contribution("default",
contributionLocation));
+                    NodeLauncher launcher = newInstance();
+                    
+                    node = launcher.createNode(compositeURI, contributions);
                 }
                 
+                logger.info("Apache Tuscany SCA Node is starting...");
+
                 // Start the node
                 try {
                     node.getClass().getMethod("start").invoke(node);

Modified: tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java?rev=740629&r1=740628&r2=740629&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
(original)
+++ tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
Wed Feb  4 06:09:25 2009
@@ -30,6 +30,8 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashSet;
@@ -45,6 +47,8 @@
  * @version $Rev$ $Date$
  */
 final class NodeLauncherUtil {
+    private static final String NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP = "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap";
+
     private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
     
     private static final String TUSCANY_HOME = "TUSCANY_HOME";
@@ -84,10 +88,17 @@
      * @return
      */
     private static ClassLoader runtimeClassLoader(ClassLoader parentClassLoader, FilenameFilter
filter) throws FileNotFoundException, URISyntaxException, MalformedURLException {
-        
+        // First try to see if the runtime classes are already on the classpath
+        // If yes, skip the discovery to avoid duplicate jars
+        try {
+            Class.forName(NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP, false, parentClassLoader);
+            return parentClassLoader;
+        } catch (ClassNotFoundException e) {
+            // Ignore;
+        }
         // Build list of runtime JARs
         Set<URL> jarDirectoryURLs = new HashSet<URL>();
-        List<URL> jarURLs = new ArrayList<URL>();
+        Set<URL> jarURLs = new HashSet<URL>();
         
         // First determine the path to the launcher class
         String resource = NodeLauncherUtil.class.getName().replace('.', '/') + ".class";

@@ -150,6 +161,11 @@
     
         // Return the runtime class loader
         if (!jarURLs.isEmpty()) {
+            // Remove the URLs which are already in the parent classloader
+            if (parentClassLoader instanceof URLClassLoader) {
+                URLClassLoader cl = (URLClassLoader)parentClassLoader;
+                jarURLs.removeAll(Arrays.asList(cl.getURLs()));
+            }            
             
             // Return a ClassLoader configured with the runtime JARs
             ClassLoader classLoader = new RuntimeClassLoader(jarURLs.toArray(new URL[jarURLs.size()]),
parentClassLoader);
@@ -169,7 +185,7 @@
      * @param filter
      * @throws MalformedURLException
      */
-    private static void collectJARFiles(String directory, Set<URL> jarDirectoryURLs,
List<URL> jarURLs, FilenameFilter filter)
+    private static void collectJARFiles(String directory, Set<URL> jarDirectoryURLs,
Collection<URL> jarURLs, FilenameFilter filter)
         throws MalformedURLException {
         File directoryFile = new File(directory);
         URL directoryURL = directoryFile.toURI().toURL(); 
@@ -205,7 +221,7 @@
      * @param recursive 
      * @throws MalformedURLException
      */
-    private static void collectJARFiles(File directory, List<URL> urls, FilenameFilter
filter, boolean recursive) throws MalformedURLException {
+    private static void collectJARFiles(File directory, Collection<URL> urls, FilenameFilter
filter, boolean recursive) throws MalformedURLException {
         File[] files = directory.listFiles(filter);
         if (files != null) {
             int count = 0;
@@ -243,6 +259,10 @@
                 return false;
             }
             
+            if ("features".equals(dir.getName()) && name.startsWith("equinox-manifest"))
{
+                return false;
+            }
+            
             // Filter out the Tomcat and Webapp hosts
             if (name.startsWith("tuscany-host-tomcat") ||
                 name.startsWith("tuscany-host-webapp")) {
@@ -309,7 +329,7 @@
     
             // Use Java reflection to create the node as only the runtime class
             // loader knows the runtime classes required by the node
-            String className = "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap";
+            String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP;
             Class<?> bootstrapClass;
             if (runtimeClassLoader != null) {
                 bootstrapClass = Class.forName(className, true, runtimeClassLoader);

Modified: tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java?rev=740629&r1=740628&r2=740629&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
(original)
+++ tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
Wed Feb  4 06:09:25 2009
@@ -19,11 +19,18 @@
 
 package org.apache.tuscany.sca.node.launcher;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+
 
 /**
  * Main class for this JAR.
- * With no arguments this class launches the SCA Node Daemon.
- * With a "domain" argument it launches the SCA domain admin node.
+ * With a "-nodeDaemon or -nd" this class launches the SCA Node Daemon.
+ * With a "-domainManager or -dm" argument it launches the SCA domain admin node.
  * With any other argument it launches an SCA Node. 
  *  
  * @version $Rev$ $Date$
@@ -31,14 +38,25 @@
 public class NodeMain {
 
     public static void main(String[] args) throws Exception {
-        if (args.length != 0) {
-            if (args[0].equals("domain")) {
-                DomainManagerLauncher.main(args);
-            } else {
-                NodeLauncher.main(args);
-            }
-        } else {
+        CommandLineParser parser = new PosixParser();
+        Options options = new Options();
+        OptionGroup group = new OptionGroup();
+        group.addOption(new Option("dm", "domainManager", false, "Domain Manager"));
+        group.addOption(new Option("nd", "nodeDaemon", false, "Node Domain"));
+        options.addOptionGroup(group);
+        
+        // Add options from NodeLauncher to avoid UnrecognizedOptionException
+        for (Object o : NodeLauncher.getCommandLineOptions().getOptions()) {
+            options.addOption((Option)o);
+        }
+        
+        CommandLine cli = parser.parse(options, args);
+        if (cli.hasOption("nd")) {
             NodeDaemonLauncher.main(args);
+        } else if (cli.hasOption("dm")) {
+            DomainManagerLauncher.main(args);
+        } else {
+            NodeLauncher.main(args);
         }
     }
-}
+}
\ No newline at end of file



Mime
View raw message