You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2011/07/08 10:40:18 UTC

svn commit: r1144192 - in /tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell: Shell.java commands/AddComposite.java jline/TShellCompletor.java

Author: antelder
Date: Fri Jul  8 08:40:17 2011
New Revision: 1144192

URL: http://svn.apache.org/viewvc?rev=1144192&view=rev
Log:
Update the Shell to use the AddComposite class and have no code within Shell for that command

Modified:
    tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
    tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java
    tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java

Modified: tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java?rev=1144192&r1=1144191&r2=1144192&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/Shell.java Fri Jul  8 08:40:17 2011
@@ -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();

Modified: tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java?rev=1144192&r1=1144191&r2=1144192&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/commands/AddComposite.java Fri Jul  8 08:40:17 2011
@@ -59,11 +59,11 @@ public class AddComposite implements Com
     @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 Com
             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());

Modified: tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java?rev=1144192&r1=1144191&r2=1144192&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/shell/src/main/java/org/apache/tuscany/sca/shell/jline/TShellCompletor.java Fri Jul  8 08:40:17 2011
@@ -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.Shel
 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 Arg
     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 Arg
         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