Compare commits
4 Commits
gclc-socke
...
gclc-1.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| f95d2f114a | |||
| e04e7ceaa5 | |||
| 3c1c8e85c8 | |||
| 095a363520 |
@@ -70,7 +70,7 @@ of Emmanuel Bigeon. -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>gclc-socket</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<version>1.0.7-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.bigeon.fr/emmanuel</url>
|
||||
<properties>
|
||||
@@ -104,6 +104,6 @@ of Emmanuel Bigeon. -->
|
||||
<description>Socket implementation of GCLC</description>
|
||||
<scm>
|
||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||
<tag>gclc-socket-1.0.6</tag>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
</project>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<version>1.2.3</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.bigeon.fr/emmanuel</url>
|
||||
<properties>
|
||||
@@ -83,6 +83,6 @@
|
||||
<scm>
|
||||
|
||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<tag>gclc-1.2.3</tag>
|
||||
</scm>
|
||||
</project>
|
||||
|
||||
@@ -48,9 +48,9 @@ import fr.bigeon.gclc.command.HelpExecutor;
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
import fr.bigeon.gclc.command.ICommandProvider;
|
||||
import fr.bigeon.gclc.command.SubedCommand;
|
||||
import fr.bigeon.gclc.command.UnrecognizedCommand;
|
||||
import fr.bigeon.gclc.exception.CommandParsingException;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.i18n.Messages;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
@@ -100,7 +100,7 @@ public class ConsoleApplication implements ICommandProvider {
|
||||
this.header = welcome;
|
||||
this.footer = goodbye;
|
||||
this.manager = manager;
|
||||
root = new SubedCommand(new String(), new UnrecognizedCommand(manager));
|
||||
root = new SubedCommand(new String());
|
||||
}
|
||||
|
||||
/** @param manager the manager
|
||||
@@ -208,6 +208,9 @@ public class ConsoleApplication implements ICommandProvider {
|
||||
manager.println(Messages
|
||||
.getString("ConsoleApplication.cmd.failed", cmd)); //$NON-NLS-1$
|
||||
manager.println(e.getLocalizedMessage());
|
||||
if (e.getType() == CommandRunExceptionType.USAGE) {
|
||||
e.getSource().help(getManager());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CommandProvider implements ICommandProvider {
|
||||
}
|
||||
}
|
||||
throw new CommandRunException(
|
||||
Messages.getString("CommandProvider.unrecognized", cmd)); //$NON-NLS-1$
|
||||
Messages.getString("CommandProvider.unrecognized", cmd), null); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -41,6 +41,7 @@ package fr.bigeon.gclc.command;
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.prompt.CLIPrompterMessages;
|
||||
|
||||
@@ -77,7 +78,8 @@ public class HelpExecutor extends Command {
|
||||
try {
|
||||
cmd.help(consoleManager, args);
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("Console manager closed", e); //$NON-NLS-1$
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
"Console manager closed", e, this); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
|
||||
/** <p>
|
||||
@@ -122,7 +123,8 @@ public abstract class ParametrizedCommand extends Command {
|
||||
boolParams.keySet(), stringParams.keySet(), strict);
|
||||
if (!parameters.parseArgs(args)) {
|
||||
// ERROR the parameters could not be correctly parsed
|
||||
throw new CommandRunException("Unable to read arguments"); //$NON-NLS-1$
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
"Unable to read arguments", this); //$NON-NLS-1$
|
||||
}
|
||||
final List<String> toProvide = new ArrayList<>();
|
||||
for (final String string : params.keySet()) {
|
||||
@@ -152,7 +154,8 @@ public abstract class ParametrizedCommand extends Command {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
"Interactive command but manager closed...", e); //$NON-NLS-1$
|
||||
CommandRunExceptionType.INTERACTION,
|
||||
"Interactive command but manager closed...", e, this); //$NON-NLS-1$
|
||||
}
|
||||
parameters.set(string, value);
|
||||
}
|
||||
|
||||
152
gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java
Normal file
152
gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a generic framework for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.command.ScriptExecution.java
|
||||
* Created on: Jun 12, 2016
|
||||
*/
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.GCLCConstants;
|
||||
import fr.bigeon.gclc.exception.CommandParsingException;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
|
||||
/** A command that will laucnh a series of command from a file
|
||||
* <p>
|
||||
* This command will read a file and execute each non empty non commented line
|
||||
* as a command of the application.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ScriptExecution extends Command {
|
||||
|
||||
/** The application */
|
||||
private final ConsoleApplication application;
|
||||
/** The commenting prefix */
|
||||
private final String commentPrefix;
|
||||
|
||||
/** @param name the name of the command
|
||||
* @param application the application
|
||||
* @param commentPrefix the comment prefix in the script files */
|
||||
public ScriptExecution(String name, ConsoleApplication application,
|
||||
String commentPrefix) {
|
||||
super(name);
|
||||
this.application = application;
|
||||
this.commentPrefix = commentPrefix;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#execute(java.lang.String[]) */
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
if (args.length == 0) {
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
"Expecting a file", this); //$NON-NLS-1$
|
||||
}
|
||||
List<String> argsList = Arrays.asList(args);
|
||||
String scriptFile = argsList.remove(0);
|
||||
Object[] params = argsList.toArray();
|
||||
try (FileReader fReader = new FileReader(new File(scriptFile));
|
||||
BufferedReader reader = new BufferedReader(fReader)) {
|
||||
String cmd;
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
params[i - 1] = args[i];
|
||||
}
|
||||
while ((cmd = reader.readLine()) != null) {
|
||||
if (cmd.startsWith(" ") || cmd.startsWith("\t")) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
reader.close();
|
||||
fReader.close();
|
||||
throw new CommandRunException(
|
||||
"Invalid command in script (line starts with space character)", //$NON-NLS-1$
|
||||
this);
|
||||
}
|
||||
if (cmd.isEmpty() || cmd.startsWith(commentPrefix)) {
|
||||
continue;
|
||||
}
|
||||
String cmdLine = MessageFormat.format(cmd, params);
|
||||
List<String> ps = GCLCConstants.splitCommand(cmdLine);
|
||||
String command = ps.remove(0);
|
||||
application.executeSub(command, ps.toArray(new String[0]));
|
||||
}
|
||||
} catch (CommandParsingException e) {
|
||||
throw new CommandRunException("Invalid command in script (" + //$NON-NLS-1$
|
||||
e.getLocalizedMessage() + ")", //$NON-NLS-1$
|
||||
e, this);
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
"Unable to read script (" + e.getLocalizedMessage() + ")", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
e, this);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(
|
||||
" scriptfile: path to the file containing the script to execute."); //$NON-NLS-1$
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append(
|
||||
" The script file must contain one line commands. The lines must never"); //$NON-NLS-1$
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append(
|
||||
"start with whitespace characters. The lines starting with"); //$NON-NLS-1$
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append("\"" + commentPrefix + //$NON-NLS-1$
|
||||
"\" will be ignored as well as empty lines."); //$NON-NLS-1$
|
||||
builder.append(System.lineSeparator());
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@Override
|
||||
public String tip() {
|
||||
return "Execute a script"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
|
||||
@@ -114,10 +115,16 @@ public class SubedCommand implements ICommandProvider, ICommand {
|
||||
if (noArgCommand != null) {
|
||||
noArgCommand.execute(args);
|
||||
} else {
|
||||
throw new CommandRunException("Unrecognized command"); //$NON-NLS-1$
|
||||
throw new CommandRunException("Unrecognized command", this); //$NON-NLS-1$
|
||||
}
|
||||
} else {
|
||||
executeSub(args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
|
||||
try {
|
||||
executeSub(args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
} catch (CommandRunException e) {
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
e.getLocalizedMessage(), e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a generic framework for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.UnrecognizedCommand.java
|
||||
* Created on: Dec 23, 2014
|
||||
*/
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
import fr.bigeon.gclc.prompt.CLIPrompterMessages;
|
||||
|
||||
/** <p>
|
||||
* The error message for unrecognized commands
|
||||
*
|
||||
* @author Emmanuel BIGEON */
|
||||
public final class UnrecognizedCommand implements ICommand {
|
||||
/** The unrecognized command key */
|
||||
private static final String UNRECOGNIZED_CMD = "unrecognized.cmd"; //$NON-NLS-1$
|
||||
/** The unrecognized command key */
|
||||
private static final String EXPECTED_CMD = "expected.cmd"; //$NON-NLS-1$
|
||||
/** The manager */
|
||||
private final ConsoleManager manager;
|
||||
|
||||
/** @param manager the console manager to use */
|
||||
public UnrecognizedCommand(ConsoleManager manager) {
|
||||
if (manager == null) {
|
||||
throw new NullPointerException("The argument cannot be null"); //$NON-NLS-1$
|
||||
}
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String... args) throws CommandRunException {
|
||||
|
||||
try {
|
||||
if (args.length > 0) {
|
||||
manager.println(CLIPrompterMessages.getString(UNRECOGNIZED_CMD,
|
||||
(Object[]) args));
|
||||
} else {
|
||||
manager.println(CLIPrompterMessages.getString(EXPECTED_CMD));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("Manager closed", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#getCommandName() */
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void help(@SuppressWarnings("hiding") ConsoleManager manager,
|
||||
String... args) {
|
||||
// Nothing to do (no help provided as this is not a user command
|
||||
// (usually)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tip() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,6 @@
|
||||
* {@link fr.bigeon.gclc.command.SubedCommand} for a command that is declined in
|
||||
* a set of sub commands, the {@link fr.bigeon.gclc.command.HelpExecutor} for
|
||||
* help display of other commands and the
|
||||
* {@link fr.bigeon.gclc.command.UnrecognizedCommand} that should not be
|
||||
* directly accessible to the user, but will be used in case of error in typing.
|
||||
*
|
||||
* @author Emmanuel BIGEON */
|
||||
package fr.bigeon.gclc.command;
|
||||
@@ -38,6 +38,8 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.exception;
|
||||
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
|
||||
/** <p>
|
||||
* An exception thrown when a command failed to run correctly.
|
||||
*
|
||||
@@ -49,15 +51,48 @@ public class CommandRunException extends Exception {
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** @param message a message */
|
||||
public CommandRunException(String message) {
|
||||
/** The type of run exception */
|
||||
private final CommandRunExceptionType type;
|
||||
/** The command that caused the error */
|
||||
private final ICommand source;
|
||||
|
||||
/** @param message a message
|
||||
* @param source the source */
|
||||
public CommandRunException(String message, ICommand source) {
|
||||
super(message);
|
||||
type = CommandRunExceptionType.EXECUTION;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/** @param message a message
|
||||
* @param cause the cause */
|
||||
public CommandRunException(String message, Throwable cause) {
|
||||
* @param cause the cause
|
||||
* @param source the source */
|
||||
public CommandRunException(String message, Throwable cause,
|
||||
ICommand source) {
|
||||
super(message, cause);
|
||||
type = CommandRunExceptionType.EXECUTION;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/** @param type the type of exception
|
||||
* @param message the message
|
||||
* @param source the source */
|
||||
public CommandRunException(CommandRunExceptionType type, String message,
|
||||
ICommand source) {
|
||||
super(message);
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/** @param type the type of exception
|
||||
* @param message a message
|
||||
* @param cause the cause
|
||||
* @param source the source */
|
||||
public CommandRunException(CommandRunExceptionType type, String message,
|
||||
Throwable cause, ICommand source) {
|
||||
super(message, cause);
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -71,4 +106,13 @@ public class CommandRunException extends Exception {
|
||||
return super.getLocalizedMessage();
|
||||
}
|
||||
|
||||
/** @return the source */
|
||||
public ICommand getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
/** @return the type */
|
||||
public CommandRunExceptionType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a generic framework for console applications.
|
||||
*
|
||||
* This software is governed by the CeCILL license under French law and
|
||||
* abiding by the rules of distribution of free software. You can use,
|
||||
* modify and/or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.exception.CommandRunExceptionType.java
|
||||
* Created on: Jun 12, 2016
|
||||
*/
|
||||
package fr.bigeon.gclc.exception;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
public enum CommandRunExceptionType {
|
||||
/** Type of exception due to a wrong usage */
|
||||
USAGE,
|
||||
/** Type of exception due to a problem in execution */
|
||||
EXECUTION,
|
||||
/** Type of exception due to the impossibility to interact with user */
|
||||
INTERACTION;
|
||||
}
|
||||
@@ -137,17 +137,8 @@ public class SystemConsoleManager implements ConsoleManager { // NOSONAR
|
||||
}
|
||||
String result = new String();
|
||||
out.print(message + ' ');
|
||||
char c;
|
||||
try {
|
||||
result = in.readLine();
|
||||
// c = (char) in.read();
|
||||
// while (c != System.lineSeparator().charAt(0)) {
|
||||
// result += c;
|
||||
// c = (char) in.read();
|
||||
// }
|
||||
// while (in.available() != 0) {
|
||||
// in.read();
|
||||
// }
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.SEVERE, "Unable to read prompt", e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -54,9 +53,10 @@ import fr.bigeon.gclc.manager.SystemConsoleManager;
|
||||
/** Test class for ConsoleApplication
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@SuppressWarnings("static-method")
|
||||
@SuppressWarnings({"resource", "javadoc", "nls", "static-method"})
|
||||
public class ConsoleApplicationTest {
|
||||
|
||||
/** 3 seconds in milliseconds */
|
||||
protected static final long THREE_SECONDS = 3000;
|
||||
|
||||
/** Test the base of a console application */
|
||||
@@ -73,8 +73,6 @@ public class ConsoleApplicationTest {
|
||||
final PipedOutputStream src = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(src);
|
||||
|
||||
final PipedInputStream snk = new PipedInputStream();
|
||||
PrintStream out = new PrintStream(new PipedOutputStream(snk));
|
||||
final ConsoleTestApplication app = new ConsoleTestApplication(
|
||||
new SystemConsoleManager(System.out, in));
|
||||
Thread th = new Thread(new Runnable() {
|
||||
|
||||
@@ -36,7 +36,6 @@ package fr.bigeon.gclc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fr.bigeon.gclc.ConsoleApplication;
|
||||
import fr.bigeon.gclc.command.Command;
|
||||
import fr.bigeon.gclc.command.ExitCommand;
|
||||
import fr.bigeon.gclc.command.HelpExecutor;
|
||||
@@ -74,7 +73,8 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
try {
|
||||
manager.println("Test command ran fine");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("manager closed", e);
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -92,9 +92,11 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
Thread.sleep(TWO_SECONDS);
|
||||
manager.println("done!");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("manager closed", e);
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
} catch (InterruptedException e) {
|
||||
throw new CommandRunException("wait interrupted", e);
|
||||
throw new CommandRunException("wait interrupted", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user