From 769618664f43fdfaa793f61ec5024be404eff8e8 Mon Sep 17 00:00:00 2001 From: antelder Date: Fri, 8 Jul 2011 08:40:17 +0000 Subject: Update the Shell to use the AddComposite class and have no code within Shell for that command git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1144192 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/tuscany/sca/shell/Shell.java | 41 ++++++++++------------ .../tuscany/sca/shell/commands/AddComposite.java | 11 +++--- .../tuscany/sca/shell/jline/TShellCompletor.java | 13 ++++++- 3 files changed, 37 insertions(+), 28 deletions(-) (limited to 'sca-java-2.x/trunk/modules') 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 nodes = new HashMap(); private Map commands = new HashMap(); - 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 cmds = new ArrayList(); + cmds.addAll(commands.keySet()); + cmds.addAll(Arrays.asList(COMMANDS)); + return cmds.toArray(new String[]{}); + } + public Map getCommands() { return commands; } @@ -615,12 +616,14 @@ public class Shell { Callable eval(final List 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() { 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() { 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 "); out.println(" domains"); out.println(" install [] [-metadata ] [-duris ]"); @@ -862,16 +869,6 @@ public class Shell { return true; } - void helpAddComposite() { - out.println(" addComposite ]"); 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 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(); 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 compleors = new ArrayList(); + compleors.add(commandCompletor); + compleors.addAll(Arrays.asList(c.getCompletors())); + completors.put(c.getName(), compleors.toArray(new Completor[]{})); + } } @Override -- cgit v1.2.3