From 93589c750eda84ed73ddd41f765d3f3f1a35099a Mon Sep 17 00:00:00 2001 From: Emmanuel Bigeon Date: Sun, 14 Oct 2018 23:07:41 -0400 Subject: [PATCH] Reformatting Signed-off-by: Emmanuel Bigeon --- .../gclc/process/CommandForeground.java | 18 ++-- .../net/bigeon/gclc/process/CommandFork.java | 18 ++-- .../bigeon/gclc/process/ForkCommandTask.java | 43 +++++----- .../net/bigeon/gclc/process/ForkTask.java | 50 +++++------ .../gclc/process/InterruptionListener.java | 18 ++-- .../gclc/process/ProcessAttachement.java | 29 +++---- .../net/bigeon/gclc/process/ProcessClear.java | 23 +++--- .../net/bigeon/gclc/process/ProcessKill.java | 23 +++--- .../net/bigeon/gclc/process/ProcessList.java | 26 +++--- .../gclc/process/ScreenAttachement.java | 20 ++--- .../java/net/bigeon/gclc/process/Task.java | 26 +++--- .../net/bigeon/gclc/process/TaskPool.java | 38 ++++----- .../net/bigeon/gclc/process/TaskSpawner.java | 29 ++++--- .../process/io/ConnectingConsoleInput.java | 76 ++++++++--------- .../process/io/ConnectingConsoleOutput.java | 58 ++++++------- .../bigeon/gclc/socket/ConnexionManager.java | 18 ++-- .../bigeon/gclc/socket/DConnexionManager.java | 73 ++++++++--------- .../gclc/socket/PluggableConsoleInput.java | 82 +++++++++---------- .../gclc/socket/PluggableConsoleOutput.java | 23 +++--- .../gclc/socket/RemoteDisconnectCommand.java | 50 ++++++----- .../socket/SocketConsoleApplicationShell.java | 49 ++++++----- .../gclc/socket/SocketConsoleInterface.java | 28 +++---- .../net/bigeon/gclc/socket/package-info.java | 18 ++-- .../gclc/socket/ConsoleTestApplication.java | 51 +++++------- .../socket/PluggableConsoleInputTest.java | 37 +++++---- .../socket/RemoteDisconnectCommandTest.java | 26 +++--- .../socket/SocketConsoleApplicationTest.java | 64 +++++++-------- .../bigeon/gclc/socket/TestConsoleClient.java | 33 ++++---- .../net/bigeon/gclc/socket/TestServer.java | 30 +++---- .../net/bigeon/gclc/swt/ConsoleDelayIO.java | 21 ++--- .../gclc/swt/HistoryTextKeyListener.java | 30 ++++--- .../java/net/bigeon/gclc/swt/SWTConsole.java | 32 ++++---- .../net/bigeon/gclc/swt/SWTConsoleShell.java | 18 ++-- .../net/bigeon/gclc/swt/SWTConsoleView.java | 43 +++++----- .../net/bigeon/gclc/swt/package-info.java | 18 ++-- .../gclc/swt/HistoryTextKeyListenerTest.java | 29 +++---- .../bigeon/gclc/swt/SWTConsoleShellTest.java | 55 ++++++------- .../bigeon/gclc/swt/SWTConsoleViewTest.java | 43 +++++----- .../bigeon/gclc/system/ExecSystemCommand.java | 65 +++++++-------- 39 files changed, 689 insertions(+), 742 deletions(-) diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/CommandForeground.java b/gclc-process/src/main/java/net/bigeon/gclc/process/CommandForeground.java index e58c46a..8a423fd 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/CommandForeground.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/CommandForeground.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/CommandFork.java b/gclc-process/src/main/java/net/bigeon/gclc/process/CommandFork.java index 3d12015..c46d81a 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/CommandFork.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/CommandFork.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ForkCommandTask.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ForkCommandTask.java index a449986..be6d03f 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ForkCommandTask.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ForkCommandTask.java @@ -30,7 +30,7 @@ * knowledge of the CeCILL license and that you accept its terms. */ /** - * + * */ package net.bigeon.gclc.process; @@ -41,17 +41,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -59,10 +59,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -72,13 +72,10 @@ import java.util.Arrays; import net.bigeon.gclc.command.ICommand; import net.bigeon.gclc.exception.CommandRunException; -/** - * @author Emmanuel Bigeon - * - */ +/** @author Emmanuel Bigeon */ public class ForkCommandTask extends ForkTask { - private final ICommand command; - private final String[] args; + private final ICommand command; + private final String[] args; /** @param cmd the command * @param args the arguements @@ -89,13 +86,6 @@ public class ForkCommandTask extends ForkTask { this.args = Arrays.copyOf(args, args.length); } - /* (non-Javadoc) - * @see net.bigeon.gclc.process.Task#getName() */ - @Override - public String getName() { - return command.getCommandName(); - } - /* (non-Javadoc) * @see net.bigeon.gclc.process.ForkTask#doRun() */ @Override @@ -103,4 +93,11 @@ public class ForkCommandTask extends ForkTask { command.execute(out, in, args); } + /* (non-Javadoc) + * @see net.bigeon.gclc.process.Task#getName() */ + @Override + public String getName() { + return command.getCommandName(); + } + } diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ForkTask.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ForkTask.java index 1557a5c..c47ab78 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ForkTask.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ForkTask.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -89,8 +89,8 @@ public abstract class ForkTask implements Task { protected final ConnectingConsoleInput in = new ConnectingConsoleInput(); protected final ConnectingConsoleOutput out; - private CommandRunException exception; - private final Object runLock = new Object(); + private CommandRunException exception; + private final Object runLock = new Object(); /** @param lines the number of print to store in the output */ public ForkTask(int lines) { @@ -105,6 +105,20 @@ public abstract class ForkTask implements Task { listeners.add(listener); } + /** Actually run the fork. */ + protected abstract void doRun() throws CommandRunException; + + /** Get the excepion that caused a failure. + * + * @return the exception */ + public final CommandRunException getException() { + return exception; + } + + protected final Object getRunningLock() { + return runLock; + } + /* (non-Javadoc) * @see net.bigeon.gclc.process.Task#isRunning() */ @Override @@ -162,16 +176,6 @@ public abstract class ForkTask implements Task { } } - /** Actually run the fork. */ - protected abstract void doRun() throws CommandRunException; - - /** Get the excepion that caused a failure. - * - * @return the exception */ - public final CommandRunException getException() { - return exception; - } - /* (non-Javadoc) * @see net.bigeon.gclc.process.Task#setRunning(boolean) */ @Override @@ -181,8 +185,4 @@ public abstract class ForkTask implements Task { runLock.notifyAll(); } } - - protected final Object getRunningLock() { - return runLock; - } } diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/InterruptionListener.java b/gclc-process/src/main/java/net/bigeon/gclc/process/InterruptionListener.java index 66d5e0a..f28674a 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/InterruptionListener.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/InterruptionListener.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessAttachement.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessAttachement.java index 060b423..4b7ee25 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessAttachement.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessAttachement.java @@ -30,7 +30,7 @@ * knowledge of the CeCILL license and that you accept its terms. */ /** - * + * */ package net.bigeon.gclc.process; @@ -41,17 +41,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -59,10 +59,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -71,10 +71,7 @@ import net.bigeon.gclc.ApplicationAttachement; import net.bigeon.gclc.command.ICommandProvider; import net.bigeon.gclc.exception.InvalidCommandName; -/** - * @author Emmanuel Bigeon - * - */ +/** @author Emmanuel Bigeon */ public class ProcessAttachement implements ApplicationAttachement { private final TaskPool pool; @@ -86,8 +83,8 @@ public class ProcessAttachement implements ApplicationAttachement { } /* (non-Javadoc) - * @see fr.bigeon.gclc.ApplicationAttachement#attach(fr.bigeon.gclc.ConsoleApplication) - */ + * @see fr.bigeon.gclc.ApplicationAttachement#attach(fr.bigeon.gclc. + * ConsoleApplication) */ @Override public void attach(ICommandProvider application) throws InvalidCommandName { application.add(new ProcessKill("kill", pool)); diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessClear.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessClear.java index 5b0ed64..2a5cdee 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessClear.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessClear.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -89,11 +89,10 @@ public final class ProcessClear extends Command { /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { for (final String id : pool.getPIDs()) { if (!pool.get(id).isRunning()) { pool.remove(id); diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessKill.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessKill.java index a9cf30a..a376e9f 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessKill.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessKill.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -89,11 +89,10 @@ public final class ProcessKill extends Command { /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { pool.get(args[0]).setRunning(false); } diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessList.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessList.java index 229dbd3..1a048b2 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessList.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ProcessList.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -95,11 +95,10 @@ public final class ProcessList extends Command { /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { final ArrayList pids = new ArrayList<>(pool.getPIDs()); Collections.sort(pids); for (final String string : pids) { @@ -107,8 +106,7 @@ public final class ProcessList extends Command { out.println(MessageFormat.format("{0}\t{1}", string, //$NON-NLS-1$ pool.get(string).getName())); } catch (final IOException e) { - throw new CommandRunException( - CommandRunExceptionType.INTERACTION, + throw new CommandRunException(CommandRunExceptionType.INTERACTION, "Unable to communicate with user", e); //$NON-NLS-1$ } } diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/ScreenAttachement.java b/gclc-process/src/main/java/net/bigeon/gclc/process/ScreenAttachement.java index 8d69eb9..500c486 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/ScreenAttachement.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/ScreenAttachement.java @@ -30,7 +30,7 @@ * knowledge of the CeCILL license and that you accept its terms. */ /** - * + * */ package net.bigeon.gclc.process; @@ -41,17 +41,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -59,10 +59,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/Task.java b/gclc-process/src/main/java/net/bigeon/gclc/process/Task.java index 0581ca7..4da701f 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/Task.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/Task.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -86,12 +86,12 @@ public interface Task extends Runnable { void addInterruptionListener(InterruptionListener listener); /** Get the task name. - * + * * @return the task name */ String getName(); /** Test the running status of the task. - * + * * @return if the command is supposed to be running */ boolean isRunning(); @@ -103,8 +103,8 @@ public interface Task extends Runnable { /** Set the running state. *

* This method should be only called by external objects with the false - * argument. Calling this method with true has unspecified behavior and - * could do nothing as well as restart the command for example. + * argument. Calling this method with true has unspecified behavior and could do + * nothing as well as restart the command for example. * * @param running the running state */ void setRunning(boolean running); diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/TaskPool.java b/gclc-process/src/main/java/net/bigeon/gclc/process/TaskPool.java index 941a460..6b1a9e3 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/TaskPool.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/TaskPool.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -95,16 +95,6 @@ public final class TaskPool { this.autoClear = autoClear; } - /** Remove a task from the pool - * - * @param pid the task id */ - public void remove(String pid) { - synchronized (lock) { - running.remove(pid); - count = Math.min(count, Integer.parseInt(pid)); - } - } - /** Add a process in the pool. * * @param cmd the process @@ -168,6 +158,16 @@ public final class TaskPool { return autoClear; } + /** Remove a task from the pool + * + * @param pid the task id */ + public void remove(String pid) { + synchronized (lock) { + running.remove(pid); + count = Math.min(count, Integer.parseInt(pid)); + } + } + /** Request all task to stop running. *

* This call does not guaranty end of execution, it is up to the task diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/TaskSpawner.java b/gclc-process/src/main/java/net/bigeon/gclc/process/TaskSpawner.java index 48202f8..b915336 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/TaskSpawner.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/TaskSpawner.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.process; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.process; * 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. - * + * 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. * #L% @@ -80,7 +80,7 @@ import net.bigeon.gclc.manager.ConsoleOutput; * @author Emmanuel Bigeon */ public abstract class TaskSpawner extends Command { /** The process pool */ - private final TaskPool pool; + private final TaskPool pool; private final ExecutorService threadPool; /** @param name the command name @@ -97,16 +97,15 @@ public abstract class TaskSpawner extends Command { * @param args the arguments * @return the process to start and add to the pool * @throws CommandRunException if the task creation failed */ - protected abstract Task createTask(ConsoleOutput out, ConsoleInput in, - String... args) throws CommandRunException; + protected abstract Task createTask(ConsoleOutput out, ConsoleInput in, String... args) + throws CommandRunException; /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public final void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { final Task task = createTask(out, in, args); final Thread th = new Thread(task); pool.add(task); diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java index eaf6bfa..b62cc75 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleInput.java @@ -30,7 +30,7 @@ * knowledge of the CeCILL license and that you accept its terms. */ /** - * + * */ package net.bigeon.gclc.process.io; @@ -41,17 +41,17 @@ package net.bigeon.gclc.process.io; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -59,10 +59,10 @@ package net.bigeon.gclc.process.io; * 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. - * + * 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. * #L% @@ -77,9 +77,9 @@ import net.bigeon.gclc.tools.StringProvider; /** @author Emmanuel Bigeon */ public final class ConnectingConsoleInput implements ConsoleInput { - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(ConnectingConsoleInput.class.getName()); - private boolean close = false; + private boolean close = false; private StringProvider prompt; private boolean prompting; private final Object promptLock = new Object(); @@ -94,6 +94,26 @@ public final class ConnectingConsoleInput implements ConsoleInput { close = true; } + public void connect(ConsoleInput input) { + disconnect(); + synchronized (promptLock) { + connected = input; + promptLock.notifyAll(); + } + } + + public void disconnect() { + synchronized (connectionLock) { + if (connected != null) { + disconnection = true; + synchronized (promptLock) { + connected.interruptPrompt(); + } + connected = null; + } + } + } + /* (non-Javadoc) * @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */ @Override @@ -128,14 +148,6 @@ public final class ConnectingConsoleInput implements ConsoleInput { return prompt(prompt.apply()); } - /* (non-Javadoc) - * @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools. - * StringProvider) */ - @Override - public void setPrompt(StringProvider string) { - prompt = string; - } - /* (non-Javadoc) * @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */ @Override @@ -222,23 +234,11 @@ public final class ConnectingConsoleInput implements ConsoleInput { }; } - public void connect(ConsoleInput input) { - disconnect(); - synchronized (promptLock) { - connected = input; - promptLock.notifyAll(); - } - } - - public void disconnect() { - synchronized (connectionLock) { - if (connected != null) { - disconnection = true; - synchronized (promptLock) { - connected.interruptPrompt(); - } - connected = null; - } - } + /* (non-Javadoc) + * @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools. + * StringProvider) */ + @Override + public void setPrompt(StringProvider string) { + prompt = string; } } diff --git a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleOutput.java b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleOutput.java index b64b3c7..5268986 100644 --- a/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleOutput.java +++ b/gclc-process/src/main/java/net/bigeon/gclc/process/io/ConnectingConsoleOutput.java @@ -30,7 +30,7 @@ * knowledge of the CeCILL license and that you accept its terms. */ /** - * + * */ package net.bigeon.gclc.process.io; @@ -41,17 +41,17 @@ package net.bigeon.gclc.process.io; * Copyright (C) 2014 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -59,10 +59,10 @@ package net.bigeon.gclc.process.io; * 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. - * + * 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. * #L% @@ -130,6 +130,25 @@ public class ConnectingConsoleOutput implements ConsoleOutput { close = true; } + public synchronized void connect(ConsoleOutput output) { + this.output = output; + for (final String string : messages) { + try { + output.print(string); + } catch (final IOException e) { + LOGGER.severe("nable to print to connecting console"); + LOGGER.log(Level.FINE, "Console error", e); + } + } + if (!persistent) { + messages.clear(); + } + } + + public synchronized void disconnect() { + output = null; + } + /* (non-Javadoc) * @see fr.bigeon.gclc.manager.ConsoleOutput#isClosed() */ @Override @@ -157,23 +176,4 @@ public class ConnectingConsoleOutput implements ConsoleOutput { public void println(String message) { addMessage(message + System.lineSeparator()); } - - public synchronized void connect(ConsoleOutput output) { - this.output = output; - for (final String string : messages) { - try { - output.print(string); - } catch (final IOException e) { - LOGGER.severe("nable to print to connecting console"); - LOGGER.log(Level.FINE, "Console error", e); - } - } - if (!persistent) { - messages.clear(); - } - } - - public synchronized void disconnect() { - output = null; - } } diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/ConnexionManager.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/ConnexionManager.java index afd802d..155d49b 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/ConnexionManager.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/ConnexionManager.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/DConnexionManager.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/DConnexionManager.java index f6af241..38c79ce 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/DConnexionManager.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/DConnexionManager.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -50,23 +50,24 @@ import java.util.logging.Logger; public final class DConnexionManager implements ConnexionManager { /** Class logger. */ - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(DConnexionManager.class.getName()); /** The connected objects. */ - private final Map connecteds = new HashMap<>(); + private final Map connecteds = new HashMap<>(); /** The locks for the connexions. */ - private final Map locks = new HashMap<>(); + private final Map locks = new HashMap<>(); /** The counter for the disconnexion locks. */ - private final Map counters = new HashMap<>(); + private final Map counters = new HashMap<>(); /** The lock for modification of {@link #counters}. */ - private final Object counterLock = new Object(); + private final Object counterLock = new Object(); /** The count of connexions. */ - private int count = 0; + private int count; /** Default.constructor. */ public DConnexionManager() { // } + /* (non-Javadoc) * @see * net.bigeon.gclc.socket.ConnexionManager#addConnexion(java.lang.Object) */ @@ -80,29 +81,28 @@ public final class DConnexionManager implements ConnexionManager { } /* (non-Javadoc) - * @see - * net.bigeon.gclc.socket.ConnexionManager#disconnect(java.lang.String) */ + * @see net.bigeon.gclc.socket.ConnexionManager#disconnect(java.lang.String) */ @Override public T disconnect(final String id) { - if (connecteds.containsKey(id)) { - final T disc = connecteds.remove(id); - final Object lock = locks.get(id); - synchronized (lock) { - lock.notifyAll(); - } - synchronized (counterLock) { - while (counters.get(id).intValue() > 0) { - try { - counterLock.wait(); - } catch (final InterruptedException e) { - LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$ - Thread.currentThread().interrupt(); - } + if (!connecteds.containsKey(id)) { + return null; + } + final T disc = connecteds.remove(id); + final Object lock = locks.get(id); + synchronized (lock) { + lock.notifyAll(); + } + synchronized (counterLock) { + while (counters.get(id).intValue() > 0) { + try { + counterLock.wait(); + } catch (final InterruptedException e) { + LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$ + Thread.currentThread().interrupt(); } } - return disc; } - return null; + return disc; } /* (non-Javadoc) @@ -120,8 +120,7 @@ public final class DConnexionManager implements ConnexionManager { } /* (non-Javadoc) - * @see - * net.bigeon.gclc.socket.ConnexionManager#isConnected(java.lang.String) */ + * @see net.bigeon.gclc.socket.ConnexionManager#isConnected(java.lang.String) */ @Override public boolean isConnected(final String id) { return connecteds.containsKey(id); @@ -154,8 +153,8 @@ public final class DConnexionManager implements ConnexionManager { @Override public void releaseDisconnexionLock(final String id) { synchronized (counterLock) { - counters.put(id, Integer - .valueOf(Math.max(counters.get(id).intValue() - 1, 0))); + counters.put(id, + Integer.valueOf(Math.max(counters.get(id).intValue() - 1, 0))); counterLock.notifyAll(); } } diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleInput.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleInput.java index 8e5e34e..e0daa7e 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleInput.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleInput.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -61,28 +61,28 @@ import net.bigeon.gclc.utils.ReadingRunnable; * @author Emmanuel Bigeon */ public final class PluggableConsoleInput implements ConsoleInput { /** The ten constant. */ - private static final int TENTH = 10; + private static final int TENTH = 10; /** Class logger. */ - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(PluggableConsoleInput.class.getName()); /** The default time out. */ - private static final long TIMEOUT = 100; + private static final long TIMEOUT = 100; /** The prompting. */ - private boolean prompting = false; + private boolean prompting = false; /** If the element is closed. */ - private boolean closed = false; + private boolean closed = false; /** The default prompt. */ - private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$ + private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$ /** If the input is plugged or buffering. */ - private boolean connected = false; + private boolean connected = false; /** The current connexion (if any). */ - private ReadingRunnable connexion; + private ReadingRunnable connexion; /** The interrupted status for prompts. */ - private boolean interrupted = false; + private boolean interrupted = false; /** The last hint hint. */ - private String hint; + private String hint; /** The output for hints. */ - private PrintStream output; + private PrintStream output; // Locks /** The lock for connexion and disconnexion of actual streams. */ @@ -100,18 +100,16 @@ public final class PluggableConsoleInput implements ConsoleInput { closed = true; } - /** Connect the given input stream to the input and output to the hints - * writing. + /** Connect the given input stream to the input and output to the hints writing. * * @param stream the input stream * @param out the output for hints. * @throws IOException if the input is already connected. */ - public void connect(final InputStream stream, - final PrintStream out) throws IOException { + public void connect(final InputStream stream, final PrintStream out) + throws IOException { synchronized (connexionLock) { if (connected) { - throw new IOException( - "Input already connected to an input stream"); //$NON-NLS-1$ + throw new IOException("Input already connected to an input stream"); //$NON-NLS-1$ } output = out; @@ -120,8 +118,8 @@ public final class PluggableConsoleInput implements ConsoleInput { out.flush(); } - final InputStreamReader streamReader = new InputStreamReader( - stream, StandardCharsets.UTF_8); + final InputStreamReader streamReader = new InputStreamReader(stream, + StandardCharsets.UTF_8); final BufferedReader reader = new BufferedReader(streamReader); connexion = new ReadingRunnable(reader); final Thread th = new Thread(connexion, "GCLC Socket - Read input"); //$NON-NLS-1$ @@ -218,11 +216,9 @@ public final class PluggableConsoleInput implements ConsoleInput { } /* (non-Javadoc) - * @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, - * long) */ + * @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */ @Override - public String prompt(final String message, - final long timeout) throws IOException { + public String prompt(final String message, final long timeout) throws IOException { if (closed) { throw new IOException(); } @@ -240,8 +236,7 @@ public final class PluggableConsoleInput implements ConsoleInput { long time = System.currentTimeMillis() - tic; while (res == null && !interrupted && time < timeout) { try { - res = waitMessageOrConnexion(timeout - time, - (timeout - time) / TENTH); + res = waitMessageOrConnexion(timeout - time, (timeout - time) / TENTH); } catch (final InterruptedException e) { LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$ Thread.currentThread().interrupt(); @@ -255,26 +250,25 @@ public final class PluggableConsoleInput implements ConsoleInput { return res; } + @Override + public void setPrompt(String prompt) { + setPrompt(new ConstantString(prompt)); + } + @Override public void setPrompt(final StringProvider prompt) { this.prompt = prompt; } - - @Override - public void setPrompt(String prompt) { - setPrompt(new ConstantString(prompt)); - } - /** Wait for a hint or connexion. + /** Wait for a hint or connection. * - * @param messageTimeout the timeout on the current connexion hint waiting - * @param connexionTimeout the timeout on the new connexion wait + * @param messageTimeout the timeout on the current connection hint waiting + * @param connexionTimeout the timeout on the new connection wait * @return the hint, or null if not connected or timed out. * @throws IOException if the reading failed. * @throws InterruptedException if the wait was interrupted */ private String waitMessageOrConnexion(final long messageTimeout, - final long connexionTimeout) throws IOException, - InterruptedException { + final long connexionTimeout) throws IOException, InterruptedException { synchronized (connexionLock) { if (connected) { return connexion.getNextMessage(messageTimeout); diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleOutput.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleOutput.java index f346fef..4dc307d 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleOutput.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/PluggableConsoleOutput.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -50,16 +50,17 @@ import net.bigeon.gclc.manager.ConsoleOutput; public final class PluggableConsoleOutput implements ConsoleOutput { /** The actual output. */ - private PrintStream out; + private PrintStream out; /** The buffered messages. */ private final Deque messages = new ArrayDeque<>(); /** If this output is closed. */ - private boolean closed = false; + private boolean closed = false; /** Default constructor. */ public PluggableConsoleOutput() { // } + /* (non-Javadoc) * @see java.lang.AutoCloseable#close() */ @Override diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/RemoteDisconnectCommand.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/RemoteDisconnectCommand.java index ea833d9..2bc1117 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/RemoteDisconnectCommand.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/RemoteDisconnectCommand.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -57,16 +57,16 @@ public final class RemoteDisconnectCommand extends Command { private final ConnexionManager manager; /** If all connexion should be disconnected when no argument have been * specified. */ - private final boolean all; + private final boolean all; /** Create the disconnection command. * * @param name the command name * @param manager the manager * @param all if all elements should be disconnected when no argument is - * provided */ - public RemoteDisconnectCommand(final String name, - final ConnexionManager manager, final boolean all) { + * provided */ + public RemoteDisconnectCommand(final String name, final ConnexionManager manager, + final boolean all) { super(name); this.manager = manager; this.all = all; @@ -74,11 +74,10 @@ public final class RemoteDisconnectCommand extends Command { /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { if (args.length == 0 && all) { final Collection coll = manager.getConnected(); for (final String string : coll) { @@ -89,8 +88,8 @@ public final class RemoteDisconnectCommand extends Command { if (manager.isConnected(string)) { manager.disconnect(string); } else { - print(out, MessageFormat - .format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$ + print(out, + MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$ } } } @@ -99,16 +98,14 @@ public final class RemoteDisconnectCommand extends Command { * * @param out the output * @param string the message - * @throws CommandRunException if the output exists but cannot be printed - * to */ - private void print(final ConsoleOutput out, - final String string) throws CommandRunException { + * @throws CommandRunException if the output exists but cannot be printed to */ + private static void print(final ConsoleOutput out, final String string) + throws CommandRunException { if (out != null) { try { out.println(string); } catch (final IOException e) { - throw new CommandRunException( - CommandRunExceptionType.INTERACTION, + throw new CommandRunException(CommandRunExceptionType.INTERACTION, "Unable to print to existing output", e); //$NON-NLS-1$ } } @@ -123,12 +120,11 @@ public final class RemoteDisconnectCommand extends Command { /* (non-Javadoc) * @see fr.bigeon.gclc.command.Command#usageDetail() */ - @SuppressWarnings("nls") @Override protected String usageDetail() { return MessageFormat.format( - " If arguments are provided the corresponding connexions are closed, " + - "otherwise{0}{1} are.", + " If arguments are provided the corresponding connexions are closed, " + + "otherwise{0}{1} are.", System.lineSeparator(), all ? "all connexions" : "none"); } } diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleApplicationShell.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleApplicationShell.java index e362a9e..bdb4e22 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleApplicationShell.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleApplicationShell.java @@ -7,17 +7,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -25,10 +25,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -64,31 +64,30 @@ import net.bigeon.gclc.ConsoleApplication; public final class SocketConsoleApplicationShell implements Runnable { /** The class logger. */ - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(SocketConsoleApplicationShell.class.getName()); /** The listening port. */ - private final int port; + private final int port; /** The running status. */ - private boolean running; + private boolean running; /** The socket console interface. */ - private SocketConsoleInterface sci; + private SocketConsoleInterface sci; /** The remote disconnection command. */ private ConnexionManager rdc; /** The application. */ - private ConsoleApplication app; + private ConsoleApplication app; /** The server socket. */ - private ServerSocket serverSocket; + private ServerSocket serverSocket; /** THe server address. */ private final InetAddress addr; - /** Create a socket application shell which will listen on the given port - * and network interface. + /** Create a socket application shell which will listen on the given port and + * network interface. * * @param port the part * @param addr the inet address */ - public SocketConsoleApplicationShell(final int port, - final InetAddress addr) { + public SocketConsoleApplicationShell(final int port, final InetAddress addr) { super(); this.port = port; this.addr = addr; @@ -110,9 +109,9 @@ public final class SocketConsoleApplicationShell implements Runnable { } /** If the port provided was 0, this allows to get the actual port. + * * @return the local port - * @see java.net.ServerSocket#getLocalPort() - */ + * @see java.net.ServerSocket#getLocalPort() */ public int getLocalPort() { return serverSocket.getLocalPort(); } @@ -122,16 +121,14 @@ public final class SocketConsoleApplicationShell implements Runnable { @Override public void run() { // Create the server - try (ServerSocket actualServerSocket = new ServerSocket(port, 1, - addr)) { + try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) { serverSocket = actualServerSocket; running = true; // Create the streams runSokectServer(); } catch (final IOException e) { LOGGER.severe("Communication error between client and server"); //$NON-NLS-1$ - LOGGER.log(Level.FINE, - "Communication error between client and server", e); //$NON-NLS-1$ + LOGGER.log(Level.FINE, "Communication error between client and server", e); //$NON-NLS-1$ } } @@ -141,7 +138,7 @@ public final class SocketConsoleApplicationShell implements Runnable { private void runSokectServer() throws IOException { while (running && app.isRunning()) { LOGGER.info("Waiting client"); //$NON-NLS-1$ - try (Socket clientSocket = serverSocket.accept();) { + try (Socket clientSocket = serverSocket.accept()) { sci.connect(clientSocket); diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleInterface.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleInterface.java index 1b33950..d4926d7 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleInterface.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/SocketConsoleInterface.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -48,7 +48,7 @@ import java.nio.charset.StandardCharsets; public final class SocketConsoleInterface { /** The application's input. */ - private final PluggableConsoleInput input; + private final PluggableConsoleInput input; /** The application's output. */ private final PluggableConsoleOutput output; @@ -57,7 +57,7 @@ public final class SocketConsoleInterface { * @param input the input * @param output the output */ public SocketConsoleInterface(final PluggableConsoleInput input, - final PluggableConsoleOutput output) { + final PluggableConsoleOutput output) { super(); this.input = input; this.output = output; @@ -68,12 +68,10 @@ public final class SocketConsoleInterface { * @param socket the socket * @throws IOException if the connection failed */ public void connect(final Socket socket) throws IOException { - final PrintStream printStream = new PrintStream( - socket.getOutputStream(), true, + final PrintStream printStream = new PrintStream(socket.getOutputStream(), true, StandardCharsets.UTF_8.name()); output.connect(printStream); - input.connect(socket.getInputStream(), - printStream); + input.connect(socket.getInputStream(), printStream); } /** Disconnect the input and output of the application from the socket's. */ diff --git a/gclc-socket/src/main/java/net/bigeon/gclc/socket/package-info.java b/gclc-socket/src/main/java/net/bigeon/gclc/socket/package-info.java index e972f3b..6f884eb 100644 --- a/gclc-socket/src/main/java/net/bigeon/gclc/socket/package-info.java +++ b/gclc-socket/src/main/java/net/bigeon/gclc/socket/package-info.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/ConsoleTestApplication.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/ConsoleTestApplication.java index ef3cd62..b9ed097 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/ConsoleTestApplication.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/ConsoleTestApplication.java @@ -7,17 +7,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -25,10 +25,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -55,20 +55,17 @@ public class ConsoleTestApplication { public static final String EXIT = "exit"; //$NON-NLS-1$ /** Create the test application. - * + * * @param output the output * @param input the input * @param manager the manager * @return create the application */ @SuppressWarnings("nls") public static ConsoleApplication create(final ConsoleOutput output, - final ConsoleInput input, - final ConnexionManager manager) { + final ConsoleInput input, final ConnexionManager manager) { try { - final ConsoleApplication application = new ConsoleApplication( - output, input, - "Welcome to the test application. Type help or test.", - "See you"); + final ConsoleApplication application = new ConsoleApplication(output, input, + "Welcome to the test application. Type help or test.", "See you"); application.add(new ExitCommand(EXIT, application) { /* (non-Javadoc) * @see fr.bigeon.gclc.command.ExitCommand#beforeExit() */ @@ -80,8 +77,7 @@ public class ConsoleTestApplication { } } }); - application - .add(new HelpExecutor("help", application.root)); + application.add(new HelpExecutor("help", application.root)); application.add(new Command("test") { /* (non-Javadoc) @@ -89,9 +85,8 @@ public class ConsoleTestApplication { * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * java.lang.String[]) */ @Override - public void execute(final ConsoleOutput out, - final ConsoleInput in, - final String... args) throws CommandRunException { + public void execute(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { try { output.println("Test command ran fine"); } catch (final IOException e) { @@ -105,8 +100,7 @@ public class ConsoleTestApplication { } /* (non-Javadoc) - * @see fr.bigeon.gclc.command.Command#usageDetail() - */ + * @see fr.bigeon.gclc.command.Command#usageDetail() */ @Override protected String usageDetail() { // TODO Auto-generated method stub @@ -121,9 +115,8 @@ public class ConsoleTestApplication { * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * java.lang.String[]) */ @Override - public void execute(final ConsoleOutput out, - final ConsoleInput in, - final String... args) throws CommandRunException { + public void execute(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { try { Thread.sleep(2000); output.println("Test command ran fine"); @@ -138,8 +131,7 @@ public class ConsoleTestApplication { } /* (non-Javadoc) - * @see fr.bigeon.gclc.command.Command#usageDetail() - */ + * @see fr.bigeon.gclc.command.Command#usageDetail() */ @Override protected String usageDetail() { // TODO Auto-generated method stub @@ -147,8 +139,7 @@ public class ConsoleTestApplication { throw new RuntimeException("Not implemented yet"); } }); - application.add( - new RemoteDisconnectCommand<>("out", manager, true)); + application.add(new RemoteDisconnectCommand<>("out", manager, true)); return application; } catch (final InvalidCommandName e) { e.printStackTrace(); diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/PluggableConsoleInputTest.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/PluggableConsoleInputTest.java index 8559164..6528411 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/PluggableConsoleInputTest.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/PluggableConsoleInputTest.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,16 +29,17 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% */ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -46,6 +47,7 @@ import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintStream; +import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; @@ -133,11 +135,11 @@ public class PluggableConsoleInputTest { input.disconnect(); try (final PipedInputStream pis = new PipedInputStream(); - final PipedOutputStream pos = new PipedOutputStream(); - final PipedInputStream inner = new PipedInputStream(pos); - final PipedOutputStream innerPos = new PipedOutputStream(pis); - final PrintStream testIn = new PrintStream(innerPos, true, "UTF8"); - final PrintStream out = new PrintStream(pos)) { + final PipedOutputStream pos = new PipedOutputStream(); + final PipedInputStream inner = new PipedInputStream(pos); + final PipedOutputStream innerPos = new PipedOutputStream(pis); + final PrintStream testIn = new PrintStream(innerPos, true, "UTF8"); + final PrintStream out = new PrintStream(pos)) { input.connect(pis, out); try { input.connect(pis, out); @@ -167,15 +169,17 @@ public class PluggableConsoleInputTest { input.connect(pis, out); testIn.println("tac"); + final AtomicReference ref = new AtomicReference<>(); final Thread th2 = new Thread(new Runnable() { @Override public void run() { try { input.prompt("Test", 5000); - fail("Prompt should io"); +// fail("Prompt should io"); } catch (final IOException e) { // ok + ref.set(e); } } }); @@ -185,7 +189,8 @@ public class PluggableConsoleInputTest { } input.close(); - + th2.join(); + assertNotNull("Prompt should io", ref.get()); } } diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/RemoteDisconnectCommandTest.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/RemoteDisconnectCommandTest.java index e540345..8a00668 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/RemoteDisconnectCommandTest.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/RemoteDisconnectCommandTest.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -63,10 +63,10 @@ public class RemoteDisconnectCommandTest { @Test public final void testExecute() throws CommandRunException, IOException { final DConnexionManager manager = new DConnexionManager<>(); - final RemoteDisconnectCommand cmd = new RemoteDisconnectCommand<>( - "quit", manager, true); - final RemoteDisconnectCommand cmd2 = new RemoteDisconnectCommand<>( - "quit", manager, false); + final RemoteDisconnectCommand cmd = new RemoteDisconnectCommand<>("quit", + manager, true); + final RemoteDisconnectCommand cmd2 = new RemoteDisconnectCommand<>("quit", + manager, false); manager.addConnexion("test"); cmd2.execute(null, null); diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/SocketConsoleApplicationTest.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/SocketConsoleApplicationTest.java index 6aaf9ef..ad8a09b 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/SocketConsoleApplicationTest.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/SocketConsoleApplicationTest.java @@ -11,17 +11,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -51,7 +51,7 @@ import org.junit.Test; /** Test class for {@link SocketConsoleApplicationShell} * * @author Emmanuel Bigeon */ -@SuppressWarnings({"static-method", "javadoc", "nls"}) +@SuppressWarnings({ "static-method", "javadoc", "nls" }) public class SocketConsoleApplicationTest { private static final Logger LOGGER = Logger @@ -60,12 +60,12 @@ public class SocketConsoleApplicationTest { /** @param in the input * @return the string * @throws IOException if the input reading failed */ - private String consumeToPrompt(final String server, - final BufferedReader in) throws IOException { + private String consumeToPrompt(final String server, final BufferedReader in) + throws IOException { String fromServer = server; LOGGER.fine("Server: \n" + fromServer); - while (fromServer != null && !fromServer.equals("Bye.") && - !fromServer.equals("> ")) { + while (fromServer != null && !fromServer.equals("Bye.") + && !fromServer.equals("> ")) { fromServer = in.readLine(); LOGGER.fine("Server: \n" + fromServer); } @@ -81,14 +81,13 @@ public class SocketConsoleApplicationTest { final int portNumber = 3300; try (Socket kkSocket = new Socket(hostName, portNumber); - PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), - true); - BufferedReader in = new BufferedReader( - new InputStreamReader(kkSocket.getInputStream()));) { + PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); + BufferedReader in = new BufferedReader( + new InputStreamReader(kkSocket.getInputStream()));) { String fromServer; int i = -1; - final String[] cmds = {"help", "toto", "test", "out"}; + final String[] cmds = { "help", "toto", "test", "out" }; while ((fromServer = in.readLine()) != null) { i++; fromServer = consumeToPrompt(fromServer, in); @@ -106,15 +105,13 @@ public class SocketConsoleApplicationTest { } try (Socket kkSocket = new Socket(hostName, portNumber); - PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), - true); - BufferedReader in = new BufferedReader( - new InputStreamReader(kkSocket.getInputStream()));) { + PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); + BufferedReader in = new BufferedReader( + new InputStreamReader(kkSocket.getInputStream()));) { String fromServer; int i = 0; - final String[] cmds = {"help", "toto", "test", - ConsoleTestApplication.EXIT}; + final String[] cmds = { "help", "toto", "test", ConsoleTestApplication.EXIT }; while ((fromServer = in.readLine()) != null) { fromServer = consumeToPrompt(fromServer, in); if (fromServer == null || fromServer.equals("Bye.")) { @@ -129,8 +126,7 @@ public class SocketConsoleApplicationTest { } i++; } - assertEquals("Application exit command should close connection", 4, - i); + assertEquals("Application exit command should close connection", 4, i); } Thread.sleep(100); TestServer.closeServer(); @@ -138,17 +134,14 @@ public class SocketConsoleApplicationTest { server = TestServer.getServer(); Thread.sleep(1000); - try (Socket kkSocket = new Socket(hostName, portNumber); - PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), - true); - BufferedReader in = new BufferedReader( - new InputStreamReader(kkSocket.getInputStream()));) { + PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); + BufferedReader in = new BufferedReader( + new InputStreamReader(kkSocket.getInputStream()));) { String fromServer; int i = 0; - final String[] cmds = {"help", "toto", "test", - ConsoleTestApplication.EXIT}; + final String[] cmds = { "help", "toto", "test", ConsoleTestApplication.EXIT }; while ((fromServer = in.readLine()) != null) { fromServer = consumeToPrompt(fromServer, in); if (fromServer == null || fromServer.equals("Bye.")) { @@ -162,8 +155,7 @@ public class SocketConsoleApplicationTest { } i++; } - assertEquals("Application exit command should close connection", 4, - i); + assertEquals("Application exit command should close connection", 4, i); } TestServer.closeServer(); server.join(); diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestConsoleClient.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestConsoleClient.java index 097a596..9f47a1c 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestConsoleClient.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestConsoleClient.java @@ -7,17 +7,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -25,10 +25,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -44,9 +44,8 @@ import java.util.Collection; import net.bigeon.smu.StringEncoder; /** TODO Describe TestConsoleClient.java - * @author Emmanuel Bigeon - * - */ + * + * @author Emmanuel Bigeon */ @SuppressWarnings("nls") public class TestConsoleClient { @SuppressWarnings("javadoc") @@ -56,8 +55,7 @@ public class TestConsoleClient { } @SuppressWarnings("javadoc") - private static final StringEncoder ENCODER = new StringEncoder("%", - TO_ENCODE); + private static final StringEncoder ENCODER = new StringEncoder("%", TO_ENCODE); @SuppressWarnings("javadoc") public static void main(String[] args) { @@ -65,10 +63,9 @@ public class TestConsoleClient { final int portNumber = 3300; try (Socket kkSocket = new Socket(hostName, portNumber); - PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), - true); - BufferedReader in = new BufferedReader(new InputStreamReader( - kkSocket.getInputStream()));) { + PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); + BufferedReader in = new BufferedReader( + new InputStreamReader(kkSocket.getInputStream()));) { String fromServer; while ((fromServer = in.readLine()) != null) { diff --git a/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestServer.java b/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestServer.java index 8fcfd8e..3f512d7 100644 --- a/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestServer.java +++ b/gclc-socket/src/test/java/net/bigeon/gclc/socket/TestServer.java @@ -7,17 +7,17 @@ package net.bigeon.gclc.socket; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -25,10 +25,10 @@ package net.bigeon.gclc.socket; * 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. - * + * 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. * #L% @@ -43,14 +43,14 @@ import net.bigeon.gclc.ConsoleApplication; /** A test server * * @author Emmanuel Bigeon */ -@SuppressWarnings({"javadoc", "nls"}) +@SuppressWarnings({ "javadoc", "nls" }) public class TestServer { private static SocketConsoleApplicationShell SHELL; - private static ConnexionManager manager; + private static ConnexionManager manager; - private static Thread server; - private static PluggableConsoleInput input; + private static Thread server; + private static PluggableConsoleInput input; private static PluggableConsoleOutput output; public static synchronized void closeServer() { @@ -77,8 +77,8 @@ public class TestServer { manager = new DConnexionManager<>(); SHELL = new SocketConsoleApplicationShell(3300, InetAddress.getByName("127.0.0.1")); - final ConsoleApplication app = ConsoleTestApplication - .create(output, input, manager); + final ConsoleApplication app = ConsoleTestApplication.create(output, input, + manager); SHELL.setInterface(new SocketConsoleInterface(input, output)); SHELL.setConnexionManager(manager); SHELL.setApplication(app); diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/ConsoleDelayIO.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/ConsoleDelayIO.java index 64de8e3..cc5eb04 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/ConsoleDelayIO.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/ConsoleDelayIO.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -77,11 +77,12 @@ package net.bigeon.gclc.swt; * @author Emmanuel Bigeon */ public interface ConsoleDelayIO { /** Get the input text. + * * @return the non validated input */ String getInput(); /** Set the input text. - * + * * @param input the input to set */ void setInput(String input); diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/HistoryTextKeyListener.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/HistoryTextKeyListener.java index 9d91bb2..2080d85 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/HistoryTextKeyListener.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/HistoryTextKeyListener.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -81,13 +81,13 @@ import net.bigeon.collections.Ribbon; public final class HistoryTextKeyListener extends KeyAdapter { /** The size of commands history. */ - private static final int DEFAULT_HISTORY_SIZE = 10; + private static final int DEFAULT_HISTORY_SIZE = 10; /** The empty string constant. */ - private static final String EMPTY = ""; //$NON-NLS-1$ + private static final String EMPTY = ""; //$NON-NLS-1$ /** The history ribbon. */ private final Ribbon commands; /** The current index in history search. */ - private int currentIndex = 0; + private int currentIndex = 0; /** The console to notify of command validation. */ private final ConsoleDelayIO console; @@ -123,8 +123,7 @@ public final class HistoryTextKeyListener extends KeyAdapter { } // Upper arrow retrieves previous commands - if (keyCode == SWT.ARROW_UP && - currentIndex < commands.size() - 1) { + if (keyCode == SWT.ARROW_UP && currentIndex < commands.size() - 1) { currentIndex++; final String cmd = commands.get(commands.size() - currentIndex - 1); console.setInput(cmd); @@ -136,8 +135,7 @@ public final class HistoryTextKeyListener extends KeyAdapter { currentIndex--; console.setInput(EMPTY); } else if (currentIndex > 0) { - final String cmd = commands - .get(commands.size() - (--currentIndex) - 1); + final String cmd = commands.get(commands.size() - (--currentIndex) - 1); console.setInput(cmd); } } diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsole.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsole.java index 3882ab9..5fc8c13 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsole.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsole.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -309,8 +309,8 @@ public final class SWTConsole extends Composite promptLock.notifyAll(); final long start = System.currentTimeMillis(); long cur = start; - while (prompting && start + timeout>cur) { - promptLock.wait((cur-start-timeout)/2); + while (prompting && start + timeout > cur) { + promptLock.wait((cur - start - timeout) / 2); cur = System.currentTimeMillis(); } } catch (final InterruptedException e) { @@ -397,6 +397,11 @@ public final class SWTConsole extends Composite consoleInput.setSelection(input.length()); } + @Override + public void setPrompt(String prompt) { + setPrompt(new ConstantString(prompt)); + } + /* (non-Javadoc) * @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */ @Override @@ -415,11 +420,6 @@ public final class SWTConsole extends Composite }); } - @Override - public void setPrompt(String prompt) { - setPrompt(new ConstantString(prompt)); - } - /** @param string the text */ public void setText(final String string) { consoleInput.setText(string); diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleShell.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleShell.java index 4c16bd4..2b5e1ed 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleShell.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleShell.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleView.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleView.java index 89b98e7..9d91267 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleView.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/SWTConsoleView.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -92,8 +92,7 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO { /** The local implementation of the forwarding runnable * * @author Emmanuel Bigeon */ - private final class ToSWTConsoleForwardRunnable - extends AOutputForwardRunnable { + private final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable { /** The running status */ private boolean running = true; @@ -119,14 +118,14 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO { } /** The class logger */ - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(SWTConsoleView.class.getName()); /** The console output text field */ - private final Text consoleOutput; + private final Text consoleOutput; /** The console input text field */ - private final Text consoleInput; + private final Text consoleInput; /** The input. */ - private PipedConsoleInput input; + private PipedConsoleInput input; /** The forwarding runnable */ private ToSWTConsoleForwardRunnable forward; @@ -139,15 +138,13 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO { setLayout(new GridLayout(1, false)); - consoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | - SWT.V_SCROLL | SWT.MULTI); - consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, - 1, 1)); + consoleOutput = new Text(this, + SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI); + consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); consoleOutput.setRedraw(true); consoleInput = new Text(this, SWT.BORDER); - consoleInput.setLayoutData( - new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); consoleInput.addKeyListener(new HistoryTextKeyListener(this)); } @@ -190,11 +187,11 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO { } /** Set the input and output. - * + * * @param manager the output to set * @param input the input */ public void setManager(final PipedConsoleOutput manager, - final PipedConsoleInput input) { + final PipedConsoleInput input) { this.input = input; if (forward != null) { forward.setRunning(false); diff --git a/gclc-swt/src/main/java/net/bigeon/gclc/swt/package-info.java b/gclc-swt/src/main/java/net/bigeon/gclc/swt/package-info.java index a1fc042..56e00bc 100644 --- a/gclc-swt/src/main/java/net/bigeon/gclc/swt/package-info.java +++ b/gclc-swt/src/main/java/net/bigeon/gclc/swt/package-info.java @@ -10,17 +10,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -28,10 +28,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% diff --git a/gclc-swt/src/test/java/net/bigeon/gclc/swt/HistoryTextKeyListenerTest.java b/gclc-swt/src/test/java/net/bigeon/gclc/swt/HistoryTextKeyListenerTest.java index 8b5150c..8b49c6c 100644 --- a/gclc-swt/src/test/java/net/bigeon/gclc/swt/HistoryTextKeyListenerTest.java +++ b/gclc-swt/src/test/java/net/bigeon/gclc/swt/HistoryTextKeyListenerTest.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -73,7 +73,8 @@ import static org.junit.Assert.assertEquals; import org.eclipse.swt.SWT; import org.junit.Test; -/**

+/** + *

* TODO * * @author Emmanuel Bigeon */ @@ -87,8 +88,8 @@ public class HistoryTextKeyListenerTest { private String input = ""; @Override - public void validateInput() { - input = ""; + public String getInput() { + return input; } @Override @@ -97,8 +98,8 @@ public class HistoryTextKeyListenerTest { } @Override - public String getInput() { - return input; + public void validateInput() { + input = ""; } }; HistoryTextKeyListener listener = new HistoryTextKeyListener(io); diff --git a/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleShellTest.java b/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleShellTest.java index d740163..f56a2d1 100644 --- a/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleShellTest.java +++ b/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleShellTest.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -91,19 +91,19 @@ import net.bigeon.gclc.manager.ConsoleOutput; * TODO * * @author Emmanuel Bigeon */ -@SuppressWarnings({"javadoc", "static-method", "nls", "deprecation"}) +@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" }) public class SWTConsoleShellTest { - protected static final long TWO_SECONDS = 2000; - private static final Display DISPLAY = Display.getDefault(); + protected static final long TWO_SECONDS = 2000; + private static final Display DISPLAY = Display.getDefault(); @Test public void test() { final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY); final SWTConsole swtConsole = shell.getManager(); try { - final ConsoleApplication appl = new ConsoleApplication(swtConsole, - swtConsole, "Hello", "See you"); + final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole, + "Hello", "See you"); appl.add(new ExitCommand("exit", appl)); appl.add(new Command("long") { @@ -112,9 +112,8 @@ public class SWTConsoleShellTest { * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * java.lang.String[]) */ @Override - public void execute(final ConsoleOutput out, - final ConsoleInput in, - final String... args) throws CommandRunException { + public void execute(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { try { Thread.sleep(TWO_SECONDS); } catch (final InterruptedException e) { @@ -137,7 +136,7 @@ public class SWTConsoleShellTest { throw new RuntimeException("Not implemented yet"); } }); -// shell.pack(); +// shell.pack(); shell.open(); final Thread applThread = new Thread(new Runnable() { @@ -184,7 +183,7 @@ public class SWTConsoleShellTest { DISPLAY.sleep(); } } -// DISPLAY.dispose(); +// DISPLAY.dispose(); assertTrue(swtConsole.isClosed()); Thread.sleep(TWO_SECONDS); assertFalse(appl.isRunning()); @@ -204,8 +203,8 @@ public class SWTConsoleShellTest { swtConsole.close(); swtConsole.setPrompt(":"); try { - final ConsoleApplication appl = new ConsoleApplication(swtConsole, - swtConsole, "Hello", "See you"); + final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole, + "Hello", "See you"); appl.add(new ExitCommand("exit", appl)); appl.add(new Command("long") { /* (non-Javadoc) @@ -213,9 +212,8 @@ public class SWTConsoleShellTest { * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * java.lang.String[]) */ @Override - public void execute(final ConsoleOutput out, - final ConsoleInput in, - final String... args) throws CommandRunException { + public void execute(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { try { Thread.sleep(TWO_SECONDS); } catch (final InterruptedException e) { @@ -244,9 +242,8 @@ public class SWTConsoleShellTest { * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * java.lang.String[]) */ @Override - public void execute(final ConsoleOutput out, - final ConsoleInput in, - final String... args) throws CommandRunException { + public void execute(final ConsoleOutput out, final ConsoleInput in, + final String... args) throws CommandRunException { try { swtConsole.prompt("Test"); } catch (final IOException e) { @@ -268,7 +265,7 @@ public class SWTConsoleShellTest { throw new RuntimeException("Not implemented yet"); } }); -// shell.pack(); +// shell.pack(); shell.open(); final Thread applThread = new Thread(new Runnable() { @@ -351,7 +348,7 @@ public class SWTConsoleShellTest { } catch (final IOException e) { assertNotNull(e); } -// DISPLAY.dispose(); +// DISPLAY.dispose(); assertTrue(swtConsole.isClosed()); Thread.sleep(TWO_SECONDS); assertFalse(appl.isRunning()); diff --git a/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleViewTest.java b/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleViewTest.java index b145b8f..3ba40e2 100644 --- a/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleViewTest.java +++ b/gclc-swt/src/test/java/net/bigeon/gclc/swt/SWTConsoleViewTest.java @@ -42,17 +42,17 @@ package net.bigeon.gclc.swt; * Copyright (C) 2015 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -60,10 +60,10 @@ package net.bigeon.gclc.swt; * 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. - * + * 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. * #L% @@ -87,41 +87,42 @@ import net.bigeon.gclc.manager.ConsoleOutput; import net.bigeon.gclc.utils.PipedConsoleInput; import net.bigeon.gclc.utils.PipedConsoleOutput; -/**

+/** + *

* TODO * * @author Emmanuel Bigeon */ -@SuppressWarnings({"javadoc", "static-method", "nls", "deprecation"}) +@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" }) public class SWTConsoleViewTest { - protected static final long TWO_SECONDS = 2000; - private static final Display DISPLAY = Display.getDefault(); + protected static final long TWO_SECONDS = 2000; + private static final Display DISPLAY = Display.getDefault(); @Test public void test() { final Shell shell = new Shell(DISPLAY); final SWTConsoleView swtConsole = new SWTConsoleView(shell, SWT.NONE); try (PipedConsoleOutput manager = new PipedConsoleOutput(); - PipedConsoleInput input = new PipedConsoleInput(System.out)) { + PipedConsoleInput input = new PipedConsoleInput(System.out)) { swtConsole.setManager(manager, input); } catch (final IOException e2) { assertNull(e2); } try (PipedConsoleOutput manager = new PipedConsoleOutput(); - PipedConsoleInput input = new PipedConsoleInput(System.out)) { + PipedConsoleInput input = new PipedConsoleInput(System.out)) { swtConsole.setManager(manager, input); - final ConsoleApplication appl = new ConsoleApplication(manager, - input, + final ConsoleApplication appl = new ConsoleApplication(manager, input, "Hello", "See you"); appl.add(new ExitCommand("exit", appl)); appl.add(new Command("long") { /* (non-Javadoc) - * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) - */ + * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, + * java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { try { Thread.sleep(TWO_SECONDS); } catch (final InterruptedException e) { @@ -144,7 +145,7 @@ public class SWTConsoleViewTest { throw new RuntimeException("Not implemented yet"); } }); -// shell.pack(); +// shell.pack(); shell.open(); final Thread applThread = new Thread(new Runnable() { 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 8f9ee56..79aa835 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 @@ -11,17 +11,17 @@ package net.bigeon.gclc.system; * Copyright (C) 2016 - 2018 Bigeon * %% * This software is governed by the CeCILL license under French law and - * abiding by the rules of distribution of free software. You can use, + * 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". - * + * "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. - * + * 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, @@ -29,10 +29,10 @@ package net.bigeon.gclc.system; * 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. - * + * 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. * #L% @@ -57,11 +57,11 @@ import net.bigeon.gclc.manager.ConsoleOutput; public class ExecSystemCommand extends Command { /** The command default name */ - private static final String COMMAND_DEFAULT_NAME = "exec"; //$NON-NLS-1$ + private static final String COMMAND_DEFAULT_NAME = "exec"; //$NON-NLS-1$ /** The end of line separator */ - private static final String EOL = System.lineSeparator(); + private static final String EOL = System.lineSeparator(); /** The class logger */ - private static final Logger LOGGER = Logger + private static final Logger LOGGER = Logger .getLogger(ExecSystemCommand.class.getName()); /***/ @@ -69,19 +69,18 @@ public class ExecSystemCommand extends Command { super(COMMAND_DEFAULT_NAME); } - /** @param name the name of the command (the input from the manager that - * should trigger this command) */ + /** @param name the name of the command (the input from the manager that should + * trigger this command) */ public ExecSystemCommand(final String name) { super(name); } /* (non-Javadoc) * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. - * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, - * java.lang.String[]) */ + * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */ @Override public void execute(final ConsoleOutput out, final ConsoleInput in, - final String... args) throws CommandRunException { + final String... args) throws CommandRunException { Process proc; try { proc = Runtime.getRuntime().exec(args); @@ -90,8 +89,7 @@ public class ExecSystemCommand extends Command { return; } - final InputStream is = proc - .getInputStream(); + final InputStream is = proc.getInputStream(); final Thread th = new Thread(new Runnable() { @SuppressWarnings("synthetic-access") @@ -101,8 +99,7 @@ public class ExecSystemCommand extends Command { readToEnd(out, is); is.close(); } catch (final CommandRunException e) { - LOGGER.log(Level.WARNING, - "Manager was closed in the meantime...", e); //$NON-NLS-1$ + LOGGER.log(Level.WARNING, "Manager was closed in the meantime...", e); //$NON-NLS-1$ } catch (final IOException e) { LOGGER.log(Level.WARNING, "Input stream was closed...", e); //$NON-NLS-1$ } @@ -111,15 +108,13 @@ public class ExecSystemCommand extends Command { th.start(); in.setPrompt(""); //$NON-NLS-1$ final OutputStream os = proc.getOutputStream(); - try (BufferedWriter writer = new BufferedWriter( - new OutputStreamWriter(os))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) { while (th.isAlive()) { String user; try { user = in.prompt(); } catch (final IOException e) { - throw new CommandRunException( - CommandRunExceptionType.INTERACTION, + throw new CommandRunException(CommandRunExceptionType.INTERACTION, "manager was closed", e); //$NON-NLS-1$ } writer.write(user + EOL); @@ -132,17 +127,16 @@ public class ExecSystemCommand extends Command { /** @param is the input stream * @throws CommandRunException if the manager was closed while writing the - * stream */ - protected void readToEnd(final ConsoleOutput out, - final InputStream is) throws CommandRunException { + * stream */ + protected void readToEnd(final ConsoleOutput out, final InputStream is) + throws CommandRunException { int c; try { while ((c = is.read()) != -1) { try { out.print(Character.valueOf((char) c).toString()); } catch (final IOException e) { - throw new CommandRunException( - CommandRunExceptionType.INTERACTION, + throw new CommandRunException(CommandRunExceptionType.INTERACTION, "manager was closed", e); //$NON-NLS-1$ } } @@ -163,12 +157,11 @@ public class ExecSystemCommand extends Command { @Override protected String usageDetail() { 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" + //$NON-NLS-1$ - System.lineSeparator() + - "system, you would get the computer name." + //$NON-NLS-1$ - System.lineSeparator(); + 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" //$NON-NLS-1$ + + System.lineSeparator() + "system, you would get the computer name." + //$NON-NLS-1$ + System.lineSeparator(); } /* (non-Javadoc)