diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-30 10:17:07 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-30 10:17:07 +0000 |
commit | 4bf72d0bbb68be9d8137c3119e9f06cf71091800 (patch) | |
tree | 18258ecd1e63ac87b19d56882585020323a8f443 /sca-java-2.x/trunk/modules/shell/src/main/java/org/apache | |
parent | 8c7b04756d4fb611faca8ffc5beecbe289a293fe (diff) |
Add a run command that runs shell commands saved in a text file
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1002991 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/shell/src/main/java/org/apache')
2 files changed, 44 insertions, 2 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 1f4faf222d..4913a5c5fb 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 @@ -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();
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 98c609d917..616e34b7ad 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 @@ -56,6 +56,7 @@ public class TShellCompletor extends ArgumentCompletor { 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()}); |