diff --git a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java index 77da3b0..2981948 100644 --- a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java +++ b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java @@ -198,7 +198,10 @@ public class SocketConsoleApplicationShell implements Runnable { } communicate(writer, in); } catch (SocketException e) { - LOGGER.log(Level.INFO, "Socket closed", e); //$NON-NLS-1$ + LOGGER.log(Level.INFO, "Socket closed"); //$NON-NLS-1$ + LOGGER.log(Level.FINE, + "Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$ + e); } } } diff --git a/gclc-socket/src/test/java/fr/bigeon/gclc/socket/ConsoleRunnableTest.java b/gclc-socket/src/test/java/fr/bigeon/gclc/socket/ConsoleRunnableTest.java index af4fa31..e44b04c 100644 --- a/gclc-socket/src/test/java/fr/bigeon/gclc/socket/ConsoleRunnableTest.java +++ b/gclc-socket/src/test/java/fr/bigeon/gclc/socket/ConsoleRunnableTest.java @@ -61,7 +61,7 @@ public class ConsoleRunnableTest { int i = 0; String[] cmds; - /** @param cmds */ + /** @param cmds the commands to run */ public ConsoleManagerTestImplementation(String[] cmds) { super(); this.cmds = cmds; diff --git a/gclc-socket/src/test/java/fr/bigeon/gclc/socket/TestServer.java b/gclc-socket/src/test/java/fr/bigeon/gclc/socket/TestServer.java index 0df3e3f..82cca37 100644 --- a/gclc-socket/src/test/java/fr/bigeon/gclc/socket/TestServer.java +++ b/gclc-socket/src/test/java/fr/bigeon/gclc/socket/TestServer.java @@ -60,7 +60,6 @@ public class TestServer { return server; } - /** @return */ private static SocketConsoleApplicationShell getShell() { if (SHELL == null) { SHELL = new SocketConsoleApplicationShell(3300, "close", diff --git a/gclc-swt/src/main/java/fr/bigeon/gclc/swt/HistoryTextKeyListener.java b/gclc-swt/src/main/java/fr/bigeon/gclc/swt/HistoryTextKeyListener.java index e5edaaa..d595f7b 100644 --- a/gclc-swt/src/main/java/fr/bigeon/gclc/swt/HistoryTextKeyListener.java +++ b/gclc-swt/src/main/java/fr/bigeon/gclc/swt/HistoryTextKeyListener.java @@ -77,7 +77,7 @@ public final class HistoryTextKeyListener extends KeyAdapter { pressedKeyCode(e.keyCode); } - /** @param keyCode */ + /** @param keyCode the pressed key code */ public void pressedKeyCode(int keyCode) { // Enter validates the command if prompting if (keyCode == '\r') { diff --git a/gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java b/gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java index 3d6591a..a104d43 100644 --- a/gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java +++ b/gclc-swt/src/main/java/fr/bigeon/gclc/swt/SWTConsole.java @@ -225,6 +225,8 @@ public class SWTConsole extends Composite implements ConsoleManager { promptLock.notifyAll(); promptLock.wait(); } catch (final InterruptedException e) { + LOGGER.log(Level.WARNING, + "Error in synchronization of prompting", e); //$NON-NLS-1$ command = null; } } @@ -260,6 +262,8 @@ public class SWTConsole extends Composite implements ConsoleManager { throw new IOException(); } } catch (final InterruptedException e) { + LOGGER.log(Level.WARNING, + "Error in synchronization of prompting", e); //$NON-NLS-1$ command = null; } finally { Display.getDefault().syncExec(new Runnable() { diff --git a/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java b/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java index e3965c4..d57364b 100644 --- a/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java +++ b/gclc-swt/src/test/java/fr/bigeon/gclc/swt/SWTConsoleShellTest.java @@ -55,6 +55,7 @@ import fr.bigeon.gclc.exception.InvalidCommandName; * TODO * * @author Emmanuel Bigeon */ +@SuppressWarnings({"javadoc", "static-method", "nls", "deprecation"}) public class SWTConsoleShellTest { protected static final long TWO_SECONDS = 2000; diff --git a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java index 81a86c6..a152c87 100644 --- a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java +++ b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java @@ -23,53 +23,63 @@ import fr.bigeon.gclc.manager.ConsoleManager; * @author Emmanuel Bigeon */ public class ExecSystemCommand extends Command { + /** The command default name */ + private static final String COMMAND_DEFAULT_NAME = "exec"; //$NON-NLS-1$ + /** The end of line separator */ private static final String EOL = System.lineSeparator(); /** The class logger */ private static final Logger LOGGER = Logger .getLogger(ExecSystemCommand.class.getName()); + /** The manager for the application's user interface */ private final ConsoleManager manager; - /** @param name - * @param manager */ + /** @param name the name of the command (the input from the manager that + * should trigger this command) + * @param manager the console manager for input and outputs */ public ExecSystemCommand(String name, ConsoleManager manager) { super(name); this.manager = manager; } - /** @param name - * @param manager */ + /** @param manager the console manager for input and outputs */ public ExecSystemCommand(ConsoleManager manager) { - super("exec"); + super(COMMAND_DEFAULT_NAME); this.manager = manager; } /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(java.lang.String[]) */ + @SuppressWarnings("resource") @Override public void execute(String... args) throws CommandRunException { Process proc; try { proc = Runtime.getRuntime().exec(args); } catch (IOException e2) { - LOGGER.log(Level.SEVERE, "Unable to run process", e2); + LOGGER.log(Level.SEVERE, "Unable to run process", e2); //$NON-NLS-1$ return; } - final InputStream is = proc.getInputStream(); + final InputStream is = proc + .getInputStream(); Thread th = new Thread(new Runnable() { + @SuppressWarnings("synthetic-access") @Override public void run() { try { readToEnd(is); + is.close(); } catch (CommandRunException e) { LOGGER.log(Level.WARNING, - "Manager was closed in the meantime...", e); + "Manager was closed in the meantime...", e); //$NON-NLS-1$ + } catch (IOException e) { + LOGGER.log(Level.WARNING, "Input stream was closed...", e); //$NON-NLS-1$ } } }); th.start(); - manager.setPrompt(""); + manager.setPrompt(new String()); final OutputStream os = proc.getOutputStream(); try (BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os))) { @@ -80,18 +90,19 @@ public class ExecSystemCommand extends Command { } catch (IOException e) { throw new CommandRunException( CommandRunExceptionType.INTERACTION, - "manager was closed", e, this); + "manager was closed", e, this); //$NON-NLS-1$ } writer.write(user + EOL); } } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + throw new CommandRunException(CommandRunExceptionType.INTERACTION, + "manager was closed", e1, this); //$NON-NLS-1$ } } /** @param is the input stream - * @throws CommandRunException */ + * @throws CommandRunException if the manager was closed while writing the + * stream */ protected void readToEnd(InputStream is) throws CommandRunException { int c; try { @@ -101,11 +112,11 @@ public class ExecSystemCommand extends Command { } catch (IOException e) { throw new CommandRunException( CommandRunExceptionType.INTERACTION, - "manager was closed", e, this); + "manager was closed", e, this); //$NON-NLS-1$ } } } catch (IOException e) { - LOGGER.log(Level.INFO, "input stream reading failed", e); + LOGGER.log(Level.INFO, "input stream reading failed", e); //$NON-NLS-1$ } } @@ -113,12 +124,12 @@ public class ExecSystemCommand extends Command { * @see fr.bigeon.gclc.command.Command#usageDetail() */ @Override protected String usageDetail() { - return " The system command is a system dependend command like sh on linux or" + - System.lineSeparator() + "powershell on windows." + + return " The system command is a system dependend command like sh on linux or" + //$NON-NLS-1$ + System.lineSeparator() + "powershell on windows." + //$NON-NLS-1$ System.lineSeparator() + System.lineSeparator() + - " As an example if you give \"cat /etc/hostname\" as argument, on a linux" + + " As an example if you give \"cat /etc/hostname\" as argument, on a linux" + //$NON-NLS-1$ System.lineSeparator() + - "system, you would get the computer name." + + "system, you would get the computer name." + //$NON-NLS-1$ System.lineSeparator(); } @@ -126,14 +137,14 @@ public class ExecSystemCommand extends Command { * @see fr.bigeon.gclc.command.Command#usagePattern() */ @Override protected String usagePattern() { - return " CMD "; + return " CMD "; //$NON-NLS-1$ } /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#tip() */ @Override public String tip() { - return "Execute a system command"; + return "Execute a system command"; //$NON-NLS-1$ } } diff --git a/gclc.system/src/test/java/net/bigeon/gclc/system/AppTest.java b/gclc.system/src/test/java/net/bigeon/gclc/system/AppTest.java deleted file mode 100644 index 543473d..0000000 --- a/gclc.system/src/test/java/net/bigeon/gclc/system/AppTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package net.bigeon.gclc.system; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } - - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } - - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } -} diff --git a/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java b/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java index d84cf98..268c78d 100644 --- a/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java +++ b/gclc/src/main/java/fr/bigeon/gclc/prompt/CLIPrompter.java @@ -198,6 +198,8 @@ public class CLIPrompter { } } catch (final NumberFormatException e) { + LOGGER.log(Level.FINER, + "Unrecognized number. Prompting user again.", e); //$NON-NLS-1$ keepOn = true; manager.println(CLIPrompterMessages .getString(PROMPTCHOICE_FORMATERR, 0, index)); @@ -384,6 +386,8 @@ public class CLIPrompter { try { added = addUserChoice(val, chs, index); } catch (final NumberFormatException e) { + LOGGER.log(Level.FINER, + "Unrecognized number. Prompting user again.", e); //$NON-NLS-1$ keepOn = true; manager.println(CLIPrompterMessages .getString(PROMPTCHOICE_FORMATERR, 0, index)); diff --git a/gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java b/gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java index 0ce9402..0c2c322 100644 --- a/gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java +++ b/gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java @@ -55,6 +55,7 @@ import fr.bigeon.gclc.manager.SystemConsoleManager; * @author Emmanuel Bigeon * */ +@SuppressWarnings("javadoc") public class CommandTestingApplication { private final PrintWriter writer; @@ -62,6 +63,7 @@ public class CommandTestingApplication { private final Thread th; /** @throws IOException if the streams cannot be build */ + @SuppressWarnings("resource") public CommandTestingApplication() throws IOException { final PipedOutputStream src = new PipedOutputStream(); InputStream in = new PipedInputStream(src); @@ -70,6 +72,7 @@ public class CommandTestingApplication { new SystemConsoleManager(System.out, in)); th = new Thread(new Runnable() { + @SuppressWarnings("synthetic-access") @Override public void run() { application.start(); diff --git a/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java b/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java index d4aa070..4ea782d 100644 --- a/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java +++ b/gclc/src/test/java/fr/bigeon/gclc/ConsoleApplicationTest.java @@ -124,7 +124,7 @@ public class ConsoleApplicationTest { e.printStackTrace(); } } catch (IOException e) { - fail("pipe creation"); //$NON-NLS-1$ + fail("pipe creation " + e.getLocalizedMessage()); //$NON-NLS-1$ } } } diff --git a/gclc/src/test/java/fr/bigeon/gclc/GCLCConstantsTest.java b/gclc/src/test/java/fr/bigeon/gclc/GCLCConstantsTest.java index 9641011..01ac901 100644 --- a/gclc/src/test/java/fr/bigeon/gclc/GCLCConstantsTest.java +++ b/gclc/src/test/java/fr/bigeon/gclc/GCLCConstantsTest.java @@ -62,7 +62,7 @@ public class GCLCConstantsTest { try { res = GCLCConstants.splitCommand("aCommand"); } catch (CommandParsingException e) { - fail("Unable to parse simple command"); //$NON-NLS-1$ + fail("Unable to parse simple command " + e.getLocalizedMessage()); //$NON-NLS-1$ return; } assertTrue(res.size() == 1); @@ -71,7 +71,8 @@ public class GCLCConstantsTest { try { res = GCLCConstants.splitCommand("aCommand with some arguments"); } catch (CommandParsingException e) { - fail("Unable to parse command with arguments"); //$NON-NLS-1$ + fail("Unable to parse command with arguments " + //$NON-NLS-1$ + e.getLocalizedMessage()); return; } assertTrue(res.size() == 4); @@ -82,7 +83,8 @@ public class GCLCConstantsTest { try { res = GCLCConstants.splitCommand("aCommand with some arguments"); } catch (CommandParsingException e) { - fail("Unable to parse command with arguments and double whitspaces"); //$NON-NLS-1$ + fail("Unable to parse command with arguments and double whitspaces " + //$NON-NLS-1$ + e.getLocalizedMessage()); return; } assertTrue(res.size() == 4); @@ -94,7 +96,8 @@ public class GCLCConstantsTest { res = GCLCConstants .splitCommand("aCommand \"with some\" arguments"); } catch (CommandParsingException e) { - fail("Unable to parse command with string argument"); //$NON-NLS-1$ + fail("Unable to parse command with string argument " + //$NON-NLS-1$ + e.getLocalizedMessage()); return; } assertTrue(res.size() == 3); @@ -104,7 +107,8 @@ public class GCLCConstantsTest { try { res = GCLCConstants.splitCommand("aCommand with\\ some arguments"); } catch (CommandParsingException e) { - fail("Unable to parse command with arguments with escaped whitspaces"); //$NON-NLS-1$ + fail("Unable to parse command with arguments with escaped whitspaces " + //$NON-NLS-1$ + e.getLocalizedMessage()); return; } assertTrue(res.size() == 3); @@ -115,7 +119,8 @@ public class GCLCConstantsTest { res = GCLCConstants .splitCommand("aCommand wi\\\"th some arguments"); } catch (CommandParsingException e) { - fail("Unable to parse command with string argument"); //$NON-NLS-1$ + fail("Unable to parse command with string argument " + //$NON-NLS-1$ + e.getLocalizedMessage()); return; } assertTrue(res.size() == 4); @@ -131,6 +136,7 @@ public class GCLCConstantsTest { fail("Parsing argument with string cut"); } catch (CommandParsingException e) { // OK + assertTrue(e.getLocalizedMessage(), true); } } diff --git a/gclc/src/test/java/fr/bigeon/gclc/command/ScriptExecutionTest.java b/gclc/src/test/java/fr/bigeon/gclc/command/ScriptExecutionTest.java index f667dea..53bc6ae 100644 --- a/gclc/src/test/java/fr/bigeon/gclc/command/ScriptExecutionTest.java +++ b/gclc/src/test/java/fr/bigeon/gclc/command/ScriptExecutionTest.java @@ -54,6 +54,7 @@ import fr.bigeon.gclc.exception.InvalidCommandName; * @author Emmanuel Bigeon * */ +@SuppressWarnings("static-method") public class ScriptExecutionTest { /** @@ -64,20 +65,20 @@ public class ScriptExecutionTest { try { CommandTestingApplication application = new CommandTestingApplication(); - application.add(new ScriptExecution("script", - application.getApplication(), "#")); + application.add(new ScriptExecution("script", //$NON-NLS-1$ + application.getApplication(), "#")); //$NON-NLS-1$ - application.sendCommand("script src/test/resources/script1.txt"); - application.sendCommand("script src/test/resources/script2.txt"); - application.sendCommand("script src/test/resources/script3.txt"); - application.sendCommand("script src/test/resources/script4.txt"); + application.sendCommand("script src/test/resources/script1.txt"); //$NON-NLS-1$ + application.sendCommand("script src/test/resources/script2.txt"); //$NON-NLS-1$ + application.sendCommand("script src/test/resources/script3.txt"); //$NON-NLS-1$ + application.sendCommand("script src/test/resources/script4.txt"); //$NON-NLS-1$ application - .sendCommand("script src/test/resources/script5.txt test"); + .sendCommand("script src/test/resources/script5.txt test"); //$NON-NLS-1$ application.waitAndStop(); } catch (IOException | InvalidCommandName e) { - fail("Unexpected exception"); + fail("Unexpected exception " + e.getLocalizedMessage()); //$NON-NLS-1$ } }