summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-launcher-equinox/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-04 01:31:18 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-02-04 01:31:18 +0000
commit54bec0b997ffd6d92efdd209071ce230b2e24099 (patch)
tree657bbfd2ff8ddb8994031c07f0995a7069655048 /java/sca/modules/node-launcher-equinox/src
parentb6a7235c65cf4aed9dbb8037118e7839c689a070 (diff)
Add command-line parsing to the node launcher
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@740567 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/NodeLauncher.java92
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java35
2 files changed, 99 insertions, 28 deletions
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 462246f37c..510fe62c71 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
@@ -21,10 +21,20 @@ package org.apache.tuscany.sca.node.equinox.launcher;
import static org.apache.tuscany.sca.node.equinox.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;
import org.osgi.framework.BundleContext;
/**
@@ -98,32 +108,72 @@ public class NodeLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA Node is starting...");
+ CommandLineParser parser = new PosixParser();
+ 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);
+ Option opt3 = new Option("config", "configuration", true, "Configuration");
+ opt3.setArgName("equinoxConfiguration");
+ options.addOption(opt3);
+ CommandLine cli = parser.parse(options, args);
- // Create a node launcher
- NodeLauncher launcher = newInstance();
-
- EquinoxHost equinox = launcher.equinoxHost;
Object node = null;
ShutdownThread shutdown = null;
+ EquinoxHost equinox = null;
try {
- if (args.length ==1) {
-
+ if (cli.hasOption("config")) {
+ System.setProperty("osgi.configuration.area", cli.getOptionValue("config"));
+ }
+ 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();
+ equinox = launcher.equinoxHost;
+
node = launcher.createNode(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> contributionURL1 ... contributionURLN", 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();
+ equinox = launcher.equinoxHost;
+ node = launcher.createNode(compositeURI, contributions);
}
-
+
+ logger.info("Apache Tuscany SCA Node is starting...");
+
// Start the node
try {
node.getClass().getMethod("start").invoke(node);
@@ -132,19 +182,19 @@ public class NodeLauncher {
throw e;
}
logger.info("SCA Node is now started.");
-
+
// Install a shutdown hook
shutdown = new ShutdownThread(node, equinox);
Runtime.getRuntime().addShutdownHook(shutdown);
-
+
logger.info("Press enter to shutdown.");
try {
System.in.read();
} catch (IOException e) {
-
+
// Wait forever
Object lock = new Object();
- synchronized(lock) {
+ synchronized (lock) {
lock.wait();
}
}
@@ -154,7 +204,7 @@ public class NodeLauncher {
if (shutdown != null) {
Runtime.getRuntime().removeShutdownHook(shutdown);
}
-
+
// Stop the node
if (node != null) {
destroyNode(node);
@@ -164,7 +214,7 @@ public class NodeLauncher {
}
}
}
-
+
public void destroy() {
if (equinoxHost != null) {
equinoxHost.stop();
@@ -188,7 +238,7 @@ public class NodeLauncher {
throw e;
}
}
-
+
private static class ShutdownThread extends Thread {
private Object node;
private EquinoxHost equinox;
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
index 17172dbd5e..44f92dee7d 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
@@ -19,6 +19,12 @@
package org.apache.tuscany.sca.node.equinox.launcher;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.PosixParser;
+
/**
* Main class for this JAR.
@@ -31,14 +37,29 @@ package org.apache.tuscany.sca.node.equinox.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();
+ options.addOption("dm", "domainManager", false, "Domain Manager");
+ options.addOption("nd", "nodeDaemon", false, "Node Domain");
+
+ // Add options from NodeLauncher to avoid UnrecognizedOptionException
+ 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);
+ Option opt3 = new Option("config", "configuration", true, "Configuration");
+ opt3.setArgName("equinoxConfiguration");
+ options.addOption(opt3);
+
+ CommandLine cli = parser.parse(options, args, false);
+ if (cli.hasOption("nd")) {
NodeDaemonLauncher.main(args);
+ } else if (cli.hasOption("dm")) {
+ DomainManagerLauncher.main(args);
+ } else {
+ NodeLauncher.main(args);
}
}
}