diff --git a/src/main/java/AeshExample.java b/src/main/java/AeshExample.java
index ae13af531..a4950494d 100644
--- a/src/main/java/AeshExample.java
+++ b/src/main/java/AeshExample.java
@@ -72,6 +72,7 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
/**
* @author Ståle W. Pedersen
@@ -170,7 +171,7 @@ public void handleInterrupt(Console console) {
public static class ExitCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.stop();
return CommandResult.SUCCESS;
}
@@ -183,15 +184,19 @@ public static class RunCommand implements Command {
private List arguments;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.putProcessInBackground();
- if(arguments != null && arguments.size() > 0 && arguments.get(0).isLeaf()) {
- List script = readScriptFile(arguments.get(0));
+ if (arguments != null && arguments.size() > 0 && arguments.get(0).isLeaf()) {
+ try {
+ List script = readScriptFile(arguments.get(0));
- for (String line : script) {
- commandInvocation.executeCommand(line + Config.getLineSeparator());
+ for (String line : script) {
+ commandInvocation.executeCommand(line + Config.getLineSeparator());
+ }
+ } catch (IOException ex) {
+ throw new CommandException(ex);
}
}
@@ -221,7 +226,7 @@ public static class FooCommand implements Command {
private String foo;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(bar == null)
commandInvocation.getShell().out().println("NO BAR!");
else {
@@ -251,14 +256,18 @@ public static class TestConsoleCommand implements Command {
private Shell shell;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
this.shell = commandInvocation.getShell();
if(help) {
shell.out().println(commandInvocation.getHelpInfo("test"));
}
else {
- //display();
- processOperation(commandInvocation);
+ try {
+ //display();
+ processOperation(commandInvocation);
+ } catch (IOException ex) {
+ throw new CommandException(ex);
+ }
}
return CommandResult.SUCCESS;
@@ -335,7 +344,7 @@ public static class LsCommand implements Command {
private List arguments;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(help) {
commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("ls"));
}
@@ -385,7 +394,7 @@ public static class PromptCommand implements Command {
private Shell shell;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
this.shell = commandInvocation.getShell();
if(bar) {
shell.out().print("are you sure you want bar? (y/n) ");
@@ -401,7 +410,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
return CommandResult.SUCCESS;
}
- public void processOperation(CommandOperation operation) throws IOException {
+ public void processOperation(CommandOperation operation) {
if(operation.getInputKey() == Key.y) {
shell.out().println(Config.getLineSeparator()+"you wanted bar!");
}
@@ -524,7 +533,7 @@ public static class GroupCommand implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(help)
commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("group"));
else
@@ -542,7 +551,7 @@ public static class Child1 implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(help)
commandInvocation.getShell().out().println(commandInvocation.getHelpInfo("group child1"));
else
@@ -557,7 +566,7 @@ public static class Child2 implements Command {
private boolean bar;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("bar is set to: "+bar);
return CommandResult.SUCCESS;
}
diff --git a/src/main/java/AeshGraphicsExample.java b/src/main/java/AeshGraphicsExample.java
index dd9e0ac01..dd17a9be2 100644
--- a/src/main/java/AeshGraphicsExample.java
+++ b/src/main/java/AeshGraphicsExample.java
@@ -36,7 +36,7 @@
import org.jboss.aesh.terminal.Key;
import org.jboss.aesh.terminal.TerminalColor;
-import java.io.IOException;
+import org.jboss.aesh.console.command.CommandException;
/**
* @author Ståle W. Pedersen
@@ -65,7 +65,7 @@ public static void main(String[] args) {
public static class ExitCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.stop();
return CommandResult.SUCCESS;
}
@@ -78,7 +78,7 @@ public static class GraphicsCommand implements Command {
private Graphics g;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
invocation = commandInvocation;
invocation.getShell().enableAlternateBuffer();
doGfx();
diff --git a/src/main/java/org/jboss/aesh/cl/result/NullResultHandler.java b/src/main/java/org/jboss/aesh/cl/result/NullResultHandler.java
index 3aeff6c8d..07fea76cb 100644
--- a/src/main/java/org/jboss/aesh/cl/result/NullResultHandler.java
+++ b/src/main/java/org/jboss/aesh/cl/result/NullResultHandler.java
@@ -19,6 +19,7 @@
*/
package org.jboss.aesh.cl.result;
+import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandResult;
/**
@@ -37,4 +38,8 @@ public void onFailure(CommandResult result) {
@Override
public void onValidationFailure(CommandResult result, Exception exception) {
}
+
+ @Override
+ public void onExecutionFailure(CommandResult result, CommandException exception) {
+ }
}
diff --git a/src/main/java/org/jboss/aesh/cl/result/ResultHandler.java b/src/main/java/org/jboss/aesh/cl/result/ResultHandler.java
index 217bb2241..c70a040e2 100644
--- a/src/main/java/org/jboss/aesh/cl/result/ResultHandler.java
+++ b/src/main/java/org/jboss/aesh/cl/result/ResultHandler.java
@@ -19,6 +19,7 @@
*/
package org.jboss.aesh.cl.result;
+import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandResult;
/**
@@ -31,4 +32,6 @@ public interface ResultHandler {
void onFailure(CommandResult result);
void onValidationFailure(CommandResult result, Exception exception);
+
+ void onExecutionFailure(CommandResult result, CommandException exception);
}
\ No newline at end of file
diff --git a/src/main/java/org/jboss/aesh/console/AeshConsoleImpl.java b/src/main/java/org/jboss/aesh/console/AeshConsoleImpl.java
index 5506addc7..d33a16e4e 100644
--- a/src/main/java/org/jboss/aesh/console/AeshConsoleImpl.java
+++ b/src/main/java/org/jboss/aesh/console/AeshConsoleImpl.java
@@ -32,6 +32,7 @@
import org.jboss.aesh.cl.validator.OptionValidatorException;
import org.jboss.aesh.complete.CompleteOperation;
import org.jboss.aesh.complete.Completion;
+import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandNotFoundException;
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.activator.AeshOptionActivatorProvider;
@@ -352,8 +353,13 @@ else if(resultHandler != null)
result = CommandResult.FAILURE;
if(commandNotFoundHandler != null)
commandNotFoundHandler.handleCommandNotFound(output.getBuffer(), getShell());
- }
- catch (Exception e) {
+ } catch (CommandException cmd) {
+ getShell().out().println(cmd.getMessage());
+ result = CommandResult.FAILURE;
+ if (resultHandler != null) {
+ resultHandler.onExecutionFailure(result, cmd);
+ }
+ } catch (Exception e) {
if(e instanceof InterruptedException)
throw (InterruptedException) e;
else {
diff --git a/src/main/java/org/jboss/aesh/console/command/Command.java b/src/main/java/org/jboss/aesh/console/command/Command.java
index 42de71467..bbd02d09e 100644
--- a/src/main/java/org/jboss/aesh/console/command/Command.java
+++ b/src/main/java/org/jboss/aesh/console/command/Command.java
@@ -33,8 +33,9 @@ public interface Command {
*
* @param commandInvocation invocation
* @return success or failure depending on how the execution went.
- * @throws IOException
- * @throws InterruptedException
+ * @throws CommandException In case an exception occurs during execution
+ * @throws InterruptedException In case the current thread is being
+ * interrupted.
*/
- CommandResult execute(T commandInvocation) throws IOException, InterruptedException;
+ CommandResult execute(T commandInvocation) throws CommandException, InterruptedException;
}
diff --git a/src/main/java/org/jboss/aesh/console/command/CommandException.java b/src/main/java/org/jboss/aesh/console/command/CommandException.java
new file mode 100644
index 000000000..11a713ea7
--- /dev/null
+++ b/src/main/java/org/jboss/aesh/console/command/CommandException.java
@@ -0,0 +1,34 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.jboss.aesh.console.command;
+
+/**
+ *
+ * An exception thrown by Commands when exception occurs
+ *
+ * @author jdenise@redhat.com
+ */
+public final class CommandException extends Exception {
+
+ private static final long serialVersionUID = -1098155769714455108L;
+
+ public CommandException() {
+ super();
+ }
+
+ public CommandException(String message) {
+ super(message);
+ }
+
+ public CommandException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public CommandException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/org/jboss/aesh/console/command/container/CommandContainer.java b/src/main/java/org/jboss/aesh/console/command/container/CommandContainer.java
index 4cd3386d3..05d4291ff 100644
--- a/src/main/java/org/jboss/aesh/console/command/container/CommandContainer.java
+++ b/src/main/java/org/jboss/aesh/console/command/container/CommandContainer.java
@@ -30,6 +30,7 @@
import org.jboss.aesh.parser.AeshLine;
import java.io.IOException;
+import org.jboss.aesh.console.command.CommandException;
/**
* A CommandContainer hold reference to the Command and
@@ -65,5 +66,7 @@ public interface CommandContainer extends AutoCloseable {
CommandContainerResult executeCommand(AeshLine line, InvocationProviders invocationProviders,
AeshContext aeshContext,
- CommandInvocation commandInvocation) throws CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException, InterruptedException;
+ CommandInvocation commandInvocation)
+ throws CommandLineParserException, OptionValidatorException,
+ CommandValidatorException, CommandException, InterruptedException;
}
diff --git a/src/main/java/org/jboss/aesh/console/command/container/DefaultCommandContainer.java b/src/main/java/org/jboss/aesh/console/command/container/DefaultCommandContainer.java
index 04fa79750..05ee82e90 100644
--- a/src/main/java/org/jboss/aesh/console/command/container/DefaultCommandContainer.java
+++ b/src/main/java/org/jboss/aesh/console/command/container/DefaultCommandContainer.java
@@ -32,6 +32,7 @@
import org.jboss.aesh.parser.AeshLine;
import java.io.IOException;
+import org.jboss.aesh.console.command.CommandException;
/**
* @author Ståle W. Pedersen
@@ -42,7 +43,7 @@ public abstract class DefaultCommandContainer implements Comm
public CommandContainerResult executeCommand(AeshLine line, InvocationProviders invocationProviders,
AeshContext aeshContext,
CommandInvocation commandInvocation)
- throws CommandLineParserException, OptionValidatorException, CommandValidatorException, IOException, InterruptedException {
+ throws CommandLineParserException, OptionValidatorException, CommandValidatorException, CommandException, InterruptedException {
CommandLine commandLine = getParser().parse(line, false);
commandLine.getParser().getCommandPopulator().populateObject(commandLine, invocationProviders, aeshContext, true);
diff --git a/src/main/java/org/jboss/aesh/console/man/Man.java b/src/main/java/org/jboss/aesh/console/man/Man.java
index ac35b856e..259c9c128 100644
--- a/src/main/java/org/jboss/aesh/console/man/Man.java
+++ b/src/main/java/org/jboss/aesh/console/man/Man.java
@@ -34,6 +34,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
/**
* A Man implementation for Aesh. ref: http://en.wikipedia.org/wiki/Man_page
@@ -86,7 +87,7 @@ else if(getSearchStatus() == TerminalPage.Search.NO_SEARCH ||
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(manPages == null || manPages.size() == 0) {
commandInvocation.getShell().out().println("What manual page do you want?");
return CommandResult.SUCCESS;
@@ -100,8 +101,12 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
InputStream inputStream = manProvider.getManualDocument(manPages.get(0));
if(inputStream != null) {
setCommandInvocation(commandInvocation);
- fileParser.setInput(inputStream);
- afterAttach();
+ try {
+ fileParser.setInput(inputStream);
+ afterAttach();
+ } catch (IOException ex) {
+ throw new CommandException(ex);
+ }
}
return CommandResult.SUCCESS;
diff --git a/src/test/java/org/jboss/aesh/cl/CommandLineParserTest.java b/src/test/java/org/jboss/aesh/cl/CommandLineParserTest.java
index 51ff6bb67..afd321c72 100644
--- a/src/test/java/org/jboss/aesh/cl/CommandLineParserTest.java
+++ b/src/test/java/org/jboss/aesh/cl/CommandLineParserTest.java
@@ -27,9 +27,9 @@
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.junit.Test;
-import java.io.IOException;
import java.util.List;
import java.util.Map;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -355,7 +355,7 @@ public class GroupCommandTest extends TestingCommand {
public class TestingCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -374,7 +374,7 @@ public class SubHelp extends HelpClass implements Command {
private String foo;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/cl/ParseCompleteObjectTest.java b/src/test/java/org/jboss/aesh/cl/ParseCompleteObjectTest.java
index fea5b3777..a0d9e0550 100644
--- a/src/test/java/org/jboss/aesh/cl/ParseCompleteObjectTest.java
+++ b/src/test/java/org/jboss/aesh/cl/ParseCompleteObjectTest.java
@@ -28,8 +28,8 @@
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.junit.Test;
-import java.io.IOException;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -357,7 +357,7 @@ public class ParseCompleteGroupChild2 extends TestCommand {
public class TestCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/cl/ParserGeneratorTest.java b/src/test/java/org/jboss/aesh/cl/ParserGeneratorTest.java
index 7f6565818..88afb9435 100644
--- a/src/test/java/org/jboss/aesh/cl/ParserGeneratorTest.java
+++ b/src/test/java/org/jboss/aesh/cl/ParserGeneratorTest.java
@@ -28,10 +28,10 @@
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.junit.Test;
-import java.io.IOException;
import java.util.List;
import static junit.framework.TestCase.assertTrue;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -83,7 +83,7 @@ public class Test1 implements Command {
private Boolean bar;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -98,7 +98,7 @@ public class Test2 implements Command {
private String version;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -113,7 +113,7 @@ public class Test3 implements Command {
private String test;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/cl/SubHelp.java b/src/test/java/org/jboss/aesh/cl/SubHelp.java
index 6efe5289d..b64d21327 100644
--- a/src/test/java/org/jboss/aesh/cl/SubHelp.java
+++ b/src/test/java/org/jboss/aesh/cl/SubHelp.java
@@ -23,7 +23,7 @@
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
-import java.io.IOException;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "subhelp", description = "a simple help")
public class SubHelp extends HelpPopulator implements Command {
@@ -32,7 +32,7 @@ public class SubHelp extends HelpPopulator implements Command {
public String equal;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
\ No newline at end of file
diff --git a/src/test/java/org/jboss/aesh/cl/TestPopulator1.java b/src/test/java/org/jboss/aesh/cl/TestPopulator1.java
index efd6da2d6..3c12cdafc 100644
--- a/src/test/java/org/jboss/aesh/cl/TestPopulator1.java
+++ b/src/test/java/org/jboss/aesh/cl/TestPopulator1.java
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "test", description = "a simple test")
public class TestPopulator1 implements Command {
@@ -71,7 +72,7 @@ public Integer getInt1() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
\ No newline at end of file
diff --git a/src/test/java/org/jboss/aesh/cl/TestPopulator2.java b/src/test/java/org/jboss/aesh/cl/TestPopulator2.java
index c23a0eff2..528170b54 100644
--- a/src/test/java/org/jboss/aesh/cl/TestPopulator2.java
+++ b/src/test/java/org/jboss/aesh/cl/TestPopulator2.java
@@ -23,10 +23,10 @@
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "test", description = "a simple test")
public class TestPopulator2 implements Command {
@@ -61,7 +61,7 @@ public List getImplList() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
\ No newline at end of file
diff --git a/src/test/java/org/jboss/aesh/cl/TestPopulator3.java b/src/test/java/org/jboss/aesh/cl/TestPopulator3.java
index 7b64c67bb..b487cb19c 100644
--- a/src/test/java/org/jboss/aesh/cl/TestPopulator3.java
+++ b/src/test/java/org/jboss/aesh/cl/TestPopulator3.java
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "test", description = "a simple test")
public class TestPopulator3 implements Command {
@@ -48,7 +49,7 @@ public Map getIntegerMap() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/cl/TestPopulator4.java b/src/test/java/org/jboss/aesh/cl/TestPopulator4.java
index 455f4629b..7142e3761 100644
--- a/src/test/java/org/jboss/aesh/cl/TestPopulator4.java
+++ b/src/test/java/org/jboss/aesh/cl/TestPopulator4.java
@@ -24,10 +24,10 @@
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import java.io.File;
-import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "test", description = "a simple test")
public class TestPopulator4 implements Command {
@@ -60,7 +60,7 @@ public Set getArguments() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/cl/TestPopulator5.java b/src/test/java/org/jboss/aesh/cl/TestPopulator5.java
index a8fe5ee81..117c6dd6c 100644
--- a/src/test/java/org/jboss/aesh/cl/TestPopulator5.java
+++ b/src/test/java/org/jboss/aesh/cl/TestPopulator5.java
@@ -27,12 +27,12 @@
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.aesh.console.command.validator.ValidatorInvocation;
-import java.io.IOException;
import java.util.Currency;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import org.jboss.aesh.console.command.CommandException;
@CommandDefinition(name = "test", description = "a simple test")
public class TestPopulator5 implements Command {
@@ -97,7 +97,7 @@ public Boolean getBar() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCompletionTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCompletionTest.java
index 3d4009e07..20be85afa 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCompletionTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCompletionTest.java
@@ -52,6 +52,7 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -264,7 +265,7 @@ public static class FooCommand implements Command {
private List arguments;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
@@ -280,7 +281,7 @@ public static class BarCommand implements Command {
private String bar;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -319,7 +320,7 @@ public static class ArqCommand implements Command {
private String containerOption;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return null;
}
}
@@ -350,7 +351,7 @@ public static class GitCommand implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -362,7 +363,7 @@ public static class GitCommit implements Command {
private boolean all;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -377,7 +378,7 @@ public static class GitRebase implements Command {
private String test;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertTrue(force);
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCustomCommand.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCustomCommand.java
index 0ca9b6c80..5a849c9bb 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCustomCommand.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandCustomCommand.java
@@ -47,7 +47,6 @@
import org.junit.Test;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
@@ -55,6 +54,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -134,7 +134,7 @@ public CustomCommand(CustomPopulator populator) {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertEquals(populator.getValue("bar"), "YES");
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandDynamicTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandDynamicTest.java
index a18b04fab..797230c18 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandDynamicTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandDynamicTest.java
@@ -39,11 +39,11 @@
import org.junit.Test;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.HashMap;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -114,7 +114,7 @@ private CommandBuilder createGroupCommand() throws OptionParserException {
public class GroupCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -124,7 +124,7 @@ public class Child1Command implements Command {
private String foo;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertEquals("BAR", foo);
return CommandResult.SUCCESS;
}
@@ -143,7 +143,7 @@ public CommandAdapter(String name, HashMap fields) {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
StringBuilder builder = new StringBuilder();
commandInvocation.getShell().out().println("creating data packet we're sending over the wire:");
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandEndOperatorTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandEndOperatorTest.java
index bef941436..8c3a0f56f 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandEndOperatorTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandEndOperatorTest.java
@@ -40,6 +40,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -89,7 +90,7 @@ public void testEnd() throws IOException, InterruptedException {
private static class FooCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
counter++;
return CommandResult.SUCCESS;
}
@@ -102,7 +103,7 @@ private static class BarCommand implements Command {
private String info;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertEquals("yup", info);
counter++;
return CommandResult.SUCCESS;
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandInvocationServiceTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandInvocationServiceTest.java
index 024aea474..1e1d38a44 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandInvocationServiceTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandInvocationServiceTest.java
@@ -46,6 +46,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertTrue;
@@ -100,7 +101,7 @@ public void testCommandInvocationExtension() throws IOException, InterruptedExce
class BarCommand implements Command {
@Override
- public CommandResult execute(FooCommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(FooCommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println(commandInvocation.getFoo());
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionActivatorTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionActivatorTest.java
index be4381fb3..52716b6de 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionActivatorTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionActivatorTest.java
@@ -46,6 +46,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -117,7 +118,7 @@ private static class ValCommand implements Command {
private String bar;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return null;
}
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionValidatorTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionValidatorTest.java
index a206b0cc8..4cb0b195a 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionValidatorTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOptionValidatorTest.java
@@ -46,6 +46,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -196,7 +197,7 @@ public static class ValCommand implements Command {
private String foo;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("VAL");
return CommandResult.SUCCESS;
}
@@ -208,7 +209,7 @@ public static class IntCommand implements Command {
private Integer num;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("NUM");
return CommandResult.SUCCESS;
}
@@ -238,7 +239,7 @@ public static class Val2Command implements Command {
private String foo;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("VAL2");
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOverrideRequiredTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOverrideRequiredTest.java
index 3fa57bf4f..53b8e6321 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOverrideRequiredTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandOverrideRequiredTest.java
@@ -42,6 +42,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -95,7 +96,7 @@ public class FooCommand implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(help)
commandInvocation.getShell().out().println("OVERRIDDEN");
return CommandResult.SUCCESS;
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPasteTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPasteTest.java
index 6bc5dd2a0..82b4b5e02 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPasteTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPasteTest.java
@@ -34,6 +34,7 @@
import org.jboss.aesh.console.Config;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.Command;
+import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.aesh.console.command.registry.AeshCommandRegistryBuilder;
@@ -122,7 +123,7 @@ public void testPasteWhileACommandIsRunning() throws IOException, InterruptedExc
private static class FooCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
try {
Thread.sleep(100);
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPipelineTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPipelineTest.java
index ac0157caa..b7c7b3863 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPipelineTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandPipelineTest.java
@@ -39,6 +39,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -89,7 +90,7 @@ public static class PipeCommand implements Command {
private int counter = 0;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(commandInvocation.getControlOperator().isPipe()) {
counter++;
}
@@ -105,7 +106,7 @@ public int getCounter() {
public static class FooCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandResultHandlerTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandResultHandlerTest.java
index 0ac5c7fbb..0a2f6f7d0 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandResultHandlerTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandResultHandlerTest.java
@@ -43,6 +43,7 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -88,6 +89,10 @@ public void testResultHandler() throws IOException, InterruptedException {
outputStream.flush();
Thread.sleep(80);
+ outputStream.write(("foo --foo 1 --exception" + Config.getLineSeparator()).getBytes());
+ outputStream.flush();
+ Thread.sleep(80);
+
}
@@ -100,14 +105,21 @@ public static class FooCommand implements Command {
@Option
private String name;
+ @Option(hasValue = false)
+ private boolean exception;
+
@Arguments
private List arguments;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
- if(name == null)
- return CommandResult.FAILURE;
- else
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
+ if (name == null) {
+ if (exception) {
+ throw new CommandException("Exception occured, please fix options");
+ } else {
+ return CommandResult.FAILURE;
+ }
+ } else
return CommandResult.SUCCESS;
}
@@ -135,6 +147,12 @@ public void onFailure(CommandResult result) {
@Override
public void onValidationFailure(CommandResult result, Exception exception) {
assertEquals(2, resultCounter);
+ resultCounter++;
+ }
+
+ @Override
+ public void onExecutionFailure(CommandResult result, CommandException exception) {
+ assertEquals(3, resultCounter);
}
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandValidatorTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandValidatorTest.java
index 487290488..ec9a6148e 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshCommandValidatorTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshCommandValidatorTest.java
@@ -48,6 +48,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -134,7 +135,7 @@ public static class FooCommand implements Command {
private int high;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("you got foooed");
return CommandResult.SUCCESS;
}
@@ -156,7 +157,7 @@ public static class GitCommand implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -171,7 +172,7 @@ public static class GitCommit implements Command {
private String message;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -194,7 +195,7 @@ public static class GitRebase implements Command {
private String test;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertTrue(force);
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshConsoleTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshConsoleTest.java
index be57c428c..0797a34fc 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshConsoleTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshConsoleTest.java
@@ -56,6 +56,7 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
@@ -120,7 +121,7 @@ public static class FooTestCommand implements Command {
private String bar;
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertEquals("en", bar);
return CommandResult.SUCCESS;
}
@@ -149,7 +150,7 @@ public class LsCommand implements Command {
private java.util.List arguments;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
assertEquals(2, files.size());
return CommandResult.SUCCESS;
}
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshConverterInvocationProviderTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshConverterInvocationProviderTest.java
index 97e469953..7ec2090de 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshConverterInvocationProviderTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshConverterInvocationProviderTest.java
@@ -45,6 +45,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertTrue;
@@ -101,7 +102,7 @@ public ConCommand() {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println(foo);
commandInvocation.getShell().out().flush();
return CommandResult.SUCCESS;
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshNestedCommandTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshNestedCommandTest.java
index c343166b8..3a0348f35 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshNestedCommandTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshNestedCommandTest.java
@@ -20,6 +20,7 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertTrue;
@@ -78,7 +79,7 @@ public void testNestedCommand() throws IOException, InterruptedException {
class CustomCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
try {
commandInvocation.putProcessInBackground();
@@ -107,7 +108,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
class CustomCommandInternal implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
try {
assertTrue(fooInBackground);
diff --git a/src/test/java/org/jboss/aesh/console/aesh/AeshScriptTest.java b/src/test/java/org/jboss/aesh/console/aesh/AeshScriptTest.java
index ff11ad09e..b0bd2455d 100644
--- a/src/test/java/org/jboss/aesh/console/aesh/AeshScriptTest.java
+++ b/src/test/java/org/jboss/aesh/console/aesh/AeshScriptTest.java
@@ -49,6 +49,7 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -140,16 +141,20 @@ public RunCommand(CommandResultHandler resultHandler) {
}
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.putProcessInBackground();
- List script = readScriptFile();
+ List script;
+ try {
+ script = readScriptFile();
- for(String line : script) {
- commandInvocation.executeCommand(line + Config.getLineSeparator());
+ for (String line : script) {
+ commandInvocation.executeCommand(line + Config.getLineSeparator());
+ }
+ } catch (IOException ex) {
+ throw new CommandException(ex);
}
-
return CommandResult.SUCCESS;
}
}
@@ -158,7 +163,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
private static class ExitCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
commandInvocation.getShell().out().println("EXITING");
commandInvocation.stop();
return CommandResult.SUCCESS;
@@ -169,7 +174,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
private static class FooCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(counter < 2) {
commandInvocation.getShell().out().println("computing...." + Config.getLineSeparator() + "finished computing, returning...");
counter++;
@@ -186,7 +191,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
private static class BarCommand implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
if(counter < 3) {
commandInvocation.getShell().out().println("baring...." + Config.getLineSeparator() + "finished baring, returning...");
counter++;
@@ -237,6 +242,12 @@ public void handleCommandNotFound(String line, Shell shell) {
failed = true;
failedString = line;
}
+
+ @Override
+ public void onExecutionFailure(CommandResult result, CommandException exception) {
+ failed = true;
+ failedString = exception.toString();
+ }
}
}
diff --git a/src/test/java/org/jboss/aesh/console/registry/MutableCommandRegistryTest.java b/src/test/java/org/jboss/aesh/console/registry/MutableCommandRegistryTest.java
index 511ce186d..600a8d81a 100644
--- a/src/test/java/org/jboss/aesh/console/registry/MutableCommandRegistryTest.java
+++ b/src/test/java/org/jboss/aesh/console/registry/MutableCommandRegistryTest.java
@@ -30,7 +30,7 @@
import org.jboss.aesh.terminal.TerminalString;
import org.junit.Test;
-import java.io.IOException;
+import org.jboss.aesh.console.command.CommandException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -90,7 +90,7 @@ public void testFindCommandNames() {
@CommandDefinition(name = "foo", description = "")
public class Command1 implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -98,7 +98,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
@CommandDefinition(name = "bar", description = "")
public class Command2 implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -106,7 +106,7 @@ public CommandResult execute(CommandInvocation commandInvocation) throws IOExcep
@CommandDefinition(name = "help", description = "")
public class Command3 implements Command {
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}
@@ -118,7 +118,7 @@ public class GroupCommand1 implements Command {
private boolean help;
@Override
- public CommandResult execute(CommandInvocation commandInvocation) throws IOException, InterruptedException {
+ public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException {
return CommandResult.SUCCESS;
}
}