diff --git a/gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java b/gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java
index 11b1143..cd6f265 100644
--- a/gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java
+++ b/gclc/src/main/java/fr/bigeon/gclc/command/ScriptExecution.java
@@ -1,3 +1,37 @@
+/*
+ * 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
@@ -18,18 +52,22 @@ import fr.bigeon.gclc.exception.CommandParsingException;
import fr.bigeon.gclc.exception.CommandRunException;
import fr.bigeon.gclc.exception.CommandRunExceptionType;
-/**
- * TODO
+/** A command that will laucnh a series of command from a file
+ *
+ * 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
- * @param application
- * @param 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);
@@ -39,11 +77,12 @@ public class ScriptExecution extends Command {
/* (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);
+ "Expecting a file", this); //$NON-NLS-1$
}
List argsList = Arrays.asList(args);
String scriptFile = argsList.remove(0);
@@ -55,9 +94,11 @@ public class ScriptExecution extends Command {
params[i - 1] = args[i];
}
while ((cmd = reader.readLine()) != null) {
- if (cmd.startsWith(" ") || cmd.startsWith("\t")) {
+ 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)",
+ "Invalid command in script (line starts with space character)", //$NON-NLS-1$
this);
}
if (cmd.isEmpty() || cmd.startsWith(commentPrefix)) {
@@ -69,12 +110,12 @@ public class ScriptExecution extends Command {
application.executeSub(command, ps.toArray(new String[0]));
}
} catch (CommandParsingException e) {
- throw new CommandRunException("Invalid command in script (" +
- e.getLocalizedMessage() + ")",
+ 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() + ")",
+ "Unable to read script (" + e.getLocalizedMessage() + ")", //$NON-NLS-1$ //$NON-NLS-2$
e, this);
}
}
@@ -85,17 +126,17 @@ public class ScriptExecution extends Command {
protected String usageDetail() {
StringBuilder builder = new StringBuilder();
builder.append(
- " scriptfile: path to the file containing the script to execute.");
+ " 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");
+ " 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");
+ "start with whitespace characters. The lines starting with"); //$NON-NLS-1$
builder.append(System.lineSeparator());
- builder.append("\"" + commentPrefix +
- "\" will be ignored as well as empty lines.");
+ builder.append("\"" + commentPrefix + //$NON-NLS-1$
+ "\" will be ignored as well as empty lines."); //$NON-NLS-1$
builder.append(System.lineSeparator());
return builder.toString();
@@ -105,7 +146,7 @@ public class ScriptExecution extends Command {
* @see fr.bigeon.gclc.command.ICommand#tip() */
@Override
public String tip() {
- return "Execute a script";
+ return "Execute a script"; //$NON-NLS-1$
}
}
diff --git a/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunException.java b/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunException.java
index c28a8d1..c9bf497 100644
--- a/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunException.java
+++ b/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunException.java
@@ -51,11 +51,13 @@ public class CommandRunException extends Exception {
*/
private static final long serialVersionUID = 1L;
+ /** The type of run exception */
private final CommandRunExceptionType type;
/** The command that caused the error */
private final ICommand source;
- /** @param message a message */
+ /** @param message a message
+ * @param source the source */
public CommandRunException(String message, ICommand source) {
super(message);
type = CommandRunExceptionType.EXECUTION;
@@ -63,7 +65,8 @@ public class CommandRunException extends Exception {
}
/** @param message a message
- * @param cause the cause */
+ * @param cause the cause
+ * @param source the source */
public CommandRunException(String message, Throwable cause,
ICommand source) {
super(message, cause);
@@ -72,7 +75,8 @@ public class CommandRunException extends Exception {
}
/** @param type the type of exception
- * @param message the message */
+ * @param message the message
+ * @param source the source */
public CommandRunException(CommandRunExceptionType type, String message,
ICommand source) {
super(message);
@@ -82,7 +86,8 @@ public class CommandRunException extends Exception {
/** @param type the type of exception
* @param message a message
- * @param cause the cause */
+ * @param cause the cause
+ * @param source the source */
public CommandRunException(CommandRunExceptionType type, String message,
Throwable cause, ICommand source) {
super(message, cause);
diff --git a/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunExceptionType.java b/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunExceptionType.java
index bbe04d8..f7d9701 100644
--- a/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunExceptionType.java
+++ b/gclc/src/main/java/fr/bigeon/gclc/exception/CommandRunExceptionType.java
@@ -1,3 +1,37 @@
+/*
+ * 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
diff --git a/gclc/src/main/java/fr/bigeon/gclc/manager/SystemConsoleManager.java b/gclc/src/main/java/fr/bigeon/gclc/manager/SystemConsoleManager.java
index e985b75..a8986ca 100644
--- a/gclc/src/main/java/fr/bigeon/gclc/manager/SystemConsoleManager.java
+++ b/gclc/src/main/java/fr/bigeon/gclc/manager/SystemConsoleManager.java
@@ -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$
}
diff --git a/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java b/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java
index 0c55f1f..437e86d 100644
--- a/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java
+++ b/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java
@@ -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() {