summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-04 06:09:25 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-04 06:09:25 +0000
commitaa297679a5d888a59209db0a4e1ce3d57b132be7 (patch)
treeb4ac00b9107b96cf8936cc57ae9971882684522e /java/sca
parent0c3b68d0ba3a19ce7b4371d5abda6dd2034b72fc (diff)
Add the command line processing for JSE launcher too
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@740629 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
-rw-r--r--java/sca/modules/node-launcher/META-INF/MANIFEST.MF2
-rw-r--r--java/sca/modules/node-launcher/pom.xml7
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java71
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java30
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java38
5 files changed, 121 insertions, 27 deletions
diff --git a/java/sca/modules/node-launcher/META-INF/MANIFEST.MF b/java/sca/modules/node-launcher/META-INF/MANIFEST.MF
index c0d0f9d222..19e42299b4 100644
--- a/java/sca/modules/node-launcher/META-INF/MANIFEST.MF
+++ b/java/sca/modules/node-launcher/META-INF/MANIFEST.MF
@@ -11,7 +11,7 @@ Bundle-ManifestVersion: 2
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/
diff --git a/java/sca/modules/node-launcher/pom.xml b/java/sca/modules/node-launcher/pom.xml
index c79c993ee8..fd2d0c2afe 100644
--- a/java/sca/modules/node-launcher/pom.xml
+++ b/java/sca/modules/node-launcher/pom.xml
@@ -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>
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
index a0961b5bc3..1e42347d32 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
@@ -21,10 +21,21 @@ package org.apache.tuscany.sca.node.launcher;
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 @@ public class NodeLauncher {
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);
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
index 6b9ed5eae0..0b641c1b84 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
@@ -30,6 +30,8 @@ import java.net.URISyntaxException;
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 @@ import java.util.logging.Logger;
* @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 @@ final class NodeLauncherUtil {
* @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 @@ final class NodeLauncherUtil {
// 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 @@ final class NodeLauncherUtil {
* @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 @@ final class NodeLauncherUtil {
* @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 @@ final class NodeLauncherUtil {
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 @@ final class NodeLauncherUtil {
// 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);
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
index eafe4ddaa0..77751dcc47 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
@@ -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 @@ package org.apache.tuscany.sca.node.launcher;
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