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 2010/09/30 12:17:08 UTC

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

Author: antelder
Date: Thu Sep 30 10:17:07 2010
New Revision: 1002991

URL: http://svn.apache.org/viewvc?rev=1002991&view=rev
Log:
Add a run command that runs shell commands saved in a text file

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/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=1002991&r1=1002990&r2=1002991&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 Thu Sep 30 10:17:07 2010
@@ -59,7 +59,7 @@ public class Shell {
     private Map<String, Node> nodes = new HashMap<String, Node>();
 
     public static final String[] COMMANDS = new String[] {"bye", "domain", "domains", "help", "install", "installed",
-                                                          "load", "printDomainLevelComposite", "remove", "start", "status",
+                                                          "load", "printDomainLevelComposite", "remove", "run", "start", "status",
                                                           "stop"};
 
     public static void main(final String[] args) throws Exception {
@@ -219,6 +219,27 @@ public class Shell {
         return true;
     }
 
+    boolean run(final String commandsFileURL) throws IOException {
+        BufferedReader r = new BufferedReader(new InputStreamReader(IOHelper.getLocationAsURL(commandsFileURL).openStream()));
+        String l;
+        try {
+            while ((l = r.readLine()) != null) {
+                out.println(l);
+                String[] toks = l != null ? l.trim().split(" ") : "".split(" ");
+                List<String> toksList = new ArrayList<String>();
+                for (String s : toks) {
+                    if (s != null && s.trim().length() > 0) {
+                        toksList.add(s);
+                    }
+                }
+                apply(eval(toksList));
+            }
+        } finally {
+            r.close();
+        }
+        return true;
+    }
+
     public boolean stop(List<String> toks) throws ActivationException {
         String curi = toks.get(1);
         if (toks.size() > 2) {
@@ -410,6 +431,12 @@ public class Shell {
                     return remove(toks.get(1));
                 }
             };
+        if (op.equalsIgnoreCase("run"))
+            return new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return run(toks.get(1));
+                }
+            };
         if (op.equalsIgnoreCase("help"))
             return new Callable<Boolean>() {
                 public Boolean call() {
@@ -466,7 +493,7 @@ public class Shell {
                     return history();
                 }
             };
-        if (op.equalsIgnoreCase(""))
+        if (op.equalsIgnoreCase("") || op.startsWith("#"))
             return new Callable<Boolean>() {
                 public Boolean call() {
                     return true;
@@ -515,6 +542,8 @@ public class Shell {
             helpLoad();
         } else if ("remove".equalsIgnoreCase(command)) {
             helpRemove();
+        } else if ("run".equalsIgnoreCase(command)) {
+            helpRun();
         } else if ("printDomainLevelComposite".equalsIgnoreCase(command)) {
             helpPrintDomainLevelComposite();
         } else if ("start".equalsIgnoreCase(command)) {
@@ -547,6 +576,7 @@ public class Shell {
         out.println("   installed [<contributionURI>]");
         out.println("   load <configXmlURL>");
         out.println("   remove <contributionURI>");
+        out.println("   run <commandsFileURL>");
         out.println("   printDomainLevelComposite");
         out.println("   start <curi> <compositeUri>|<contentURL>");
         out.println("   start <name> [<compositeUri>] <contributionURL> [-duris <uri,uri,...>]");
@@ -641,6 +671,17 @@ public class Shell {
         out.println("      contributionURI - (required) the URI of an installed contribution");
     }
 
+    void helpRun() {
+        out.println("   run <commandsFileURL>");
+        out.println();
+        out.println("   Runs shell commands stored in file.");
+        out.println("   The file should be a text file with one shell command per line. Blank lines and ");
+        out.println("   lines starting with # will be ignored.");
+        out.println();
+        out.println("   Arguments:");
+        out.println("      commandsFileURL - (required) the URL of the commands file to run");
+    }
+
     void helpPrintDomainLevelComposite() {
         out.println("   printDomainLevelComposite");
         out.println();

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=1002991&r1=1002990&r2=1002991&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 Thu Sep 30 10:17:07 2010
@@ -56,6 +56,7 @@ public class TShellCompletor extends Arg
         completors.put("installed", new Completor[]{commandCompletor, new ICURICompletor(shell), new NullCompletor()});    
         completors.put("load", new Completor[]{commandCompletor, new FileNameCompletor(), new NullCompletor()});    
         completors.put("remove", new Completor[]{commandCompletor, new ICURICompletor(shell), new NullCompletor()});    
+        completors.put("run", new Completor[]{commandCompletor, new FileNameCompletor(), new NullCompletor()});    
         completors.put("addDeploymentComposite", new Completor[]{commandCompletor, new ICURICompletor(shell), new FileNameCompletor(), new NullCompletor()});    
         completors.put("printDomainLevelComposite", new Completor[]{commandCompletor, new NullCompletor()});    
         completors.put("start", new Completor[]{commandCompletor, new ICURICompletor(shell), new CompositeURICompletor(shell), new NullCompletor()});