summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r--sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java41
-rw-r--r--sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java11
-rw-r--r--sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java13
3 files changed, 37 insertions, 28 deletions
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
index 5f56d843c4..4aa55d658c 100644
--- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
+++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
@@ -75,7 +75,7 @@ public class Shell {
private Map<String, Node> nodes = new HashMap<String, Node>();
private Map<String, Command> commands = new HashMap<String, Command>();
- public static final String[] COMMANDS = new String[] {"addComposite", "bye", "domain", "domains", "domainComposite", "help", "install", "installed", "invoke",
+ public static final String[] COMMANDS = new String[] {"bye", "domain", "domains", "domainComposite", "help", "install", "installed", "invoke",
"load", "nodes", "remove", "run", "save", "services", "start", "started", "stop"};
public static void main(final String[] args) throws Exception {
@@ -144,12 +144,6 @@ public class Shell {
}
}
- boolean addComposite(String curi, String compositeURL) throws ActivationException, ValidationException, ContributionReadException, FileNotFoundException, XMLStreamException, URISyntaxException {
- File f = new File(IOHelper.getLocationAsURL(compositeURL).toURI());
- getNode().addDeploymentComposite(curi, new FileReader(f));
- return true;
- }
-
boolean domain(final String domainURI) {
if (domainURI.length() < 1) {
currentDomain = "";
@@ -552,6 +546,13 @@ public class Shell {
return true;
}
+ public String[] getCommandNames() {
+ List<String> cmds = new ArrayList<String>();
+ cmds.addAll(commands.keySet());
+ cmds.addAll(Arrays.asList(COMMANDS));
+ return cmds.toArray(new String[]{});
+ }
+
public Map<String, Command> getCommands() {
return commands;
}
@@ -615,12 +616,14 @@ public class Shell {
Callable<Boolean> eval(final List<String> toks) {
final String op = toks.size() > 0 ? toks.get(0) : "";
- if (op.equalsIgnoreCase("addComposite"))
+ if (commands.keySet().contains(op)) {
+ toks.remove(0);
return new Callable<Boolean>() {
public Boolean call() throws Exception {
- return addComposite(toks.get(1), toks.get(2));
+ return commands.get(op).invoke(toks.toArray(new String[0]));
}
};
+ }
if (op.equalsIgnoreCase("domain"))
return new Callable<Boolean>() {
public Boolean call() throws Exception {
@@ -797,10 +800,10 @@ public class Shell {
String command = (toks == null || toks.size() < 2) ? null : toks.get(1);
if (command == null) {
helpOverview();
+ } else if (commands.keySet().contains(command)) {
+ out.println(commands.get(command).getHelp());
} else if ("help".equalsIgnoreCase(command)) {
helpHelp();
- } else if ("addComposite".equalsIgnoreCase(command)) {
- helpAddComposite();
} else if ("install".equalsIgnoreCase(command)) {
helpInstall();
} else if ("installed".equalsIgnoreCase(command)) {
@@ -838,7 +841,11 @@ public class Shell {
out.println("Commands:");
out.println();
out.println(" help");
- out.println(" addComposite <contributionURI> <compositeURI");
+
+ for (Command command : commands.values()) {
+ out.println(" " + command.getShortHelp());
+ }
+
out.println(" domain <domainURI>");
out.println(" domains");
out.println(" install [<uri>] <contributionURL> [-metadata <url>] [-duris <uri,uri,...>]");
@@ -862,16 +869,6 @@ public class Shell {
return true;
}
- void helpAddComposite() {
- out.println(" addComposite <contributionURI> <compositeURI");
- out.println();
- out.println(" Adds a deployable composite to an installed contribution.");
- out.println();
- out.println(" Arguments:");
- out.println(" contributionURI - (required) the URI of the installed contribution");
- out.println(" compositeURL - (required) the URL to an external composite file");
- }
-
void helpHelp() {
out.println(" help [<command>]");
out.println();
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java
index fe60ba5c54..1eace59218 100644
--- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java
+++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java
@@ -59,11 +59,11 @@ public class AddComposite implements Command {
@Override
public String getHelp() {
StringBuilder helpText = new StringBuilder();
- helpText.append("Adds a deployable composite to an installed contribution.");
+ helpText.append("Adds a deployable composite to an installed contribution.\n");
helpText.append("\n");
- helpText.append("Arguments:");
- helpText.append(" contributionURI - (required) the URI of the installed contribution");
- helpText.append(" compositeURL - (required) the URL to an external composite file");
+ helpText.append("Arguments:\n");
+ helpText.append(" contributionURI - (required) the URI of the installed contribution\n");
+ helpText.append(" compositeURL - (required) the URL to an external composite file\n");
return helpText.toString();
}
@@ -79,8 +79,9 @@ public class AddComposite implements Command {
System.err.println(getShortHelp());
return true;
}
- if (shell.getNode().getInstalledContributionURIs().contains(args[0])) {
+ if (!!!shell.getNode().getInstalledContributionURIs().contains(args[0])) {
System.err.println("contribution not installed: " + args[0]);
+ return true;
}
File f = new File(IOHelper.getLocationAsURL(args[1]).toURI());
diff --git a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java
index c977bff707..3f38caf1e5 100644
--- a/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java
+++ b/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java
@@ -19,6 +19,7 @@
package org.apache.tuscany.sca.shell.jline;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
@@ -32,6 +33,7 @@ import jline.FileNameCompletor;
import jline.NullCompletor;
import jline.SimpleCompletor;
+import org.apache.tuscany.sca.shell.Command;
import org.apache.tuscany.sca.shell.Shell;
/**
@@ -41,7 +43,7 @@ import org.apache.tuscany.sca.shell.Shell;
public class TShellCompletor extends ArgumentCompletor {
Map<String, Completor[]> completors;
- final Completor commandCompletor = new SimpleCompletor(Shell.COMMANDS);
+ final Completor commandCompletor;
final ArgumentDelimiter delim = new WhitespaceArgumentDelimiter();
final Shell shell;
@@ -51,6 +53,8 @@ public class TShellCompletor extends ArgumentCompletor {
public TShellCompletor(Shell shell) {
super((Completor)null);
this.shell = shell;
+ this.commandCompletor = new SimpleCompletor(shell.getCommandNames());
+
completors = new HashMap<String, Completor[]>();
completors.put("help", new Completor[]{commandCompletor, commandCompletor, new NullCompletor()});
completors.put("install", new Completor[]{commandCompletor, new InstallCompletor(shell)});
@@ -63,6 +67,13 @@ public class TShellCompletor extends ArgumentCompletor {
completors.put("start", new Completor[]{commandCompletor, new ICURICompletor(shell), new CompositeURICompletor(shell), new RemoteNodeCompletor(shell), new NullCompletor()});
completors.put("started", new Completor[]{commandCompletor, new ICURICompletor(shell), new CompositeURICompletor(shell), new NullCompletor()});
completors.put("stop", new Completor[]{commandCompletor, new ICURICompletor(shell), new CompositeURICompletor(shell), new NullCompletor()});
+
+ for (Command c : shell.getCommands().values()) {
+ List<Completor> compleors = new ArrayList<Completor>();
+ compleors.add(commandCompletor);
+ compleors.addAll(Arrays.asList(c.getCompletors()));
+ completors.put(c.getName(), compleors.toArray(new Completor[]{}));
+ }
}
@Override