Reformatting

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-10-14 23:07:41 -04:00
parent c23af20b17
commit 93589c750e
39 changed files with 689 additions and 742 deletions

View File

@ -72,13 +72,10 @@ import java.util.Arrays;
import net.bigeon.gclc.command.ICommand; import net.bigeon.gclc.command.ICommand;
import net.bigeon.gclc.exception.CommandRunException; import net.bigeon.gclc.exception.CommandRunException;
/** /** @author Emmanuel Bigeon */
* @author Emmanuel Bigeon
*
*/
public class ForkCommandTask extends ForkTask { public class ForkCommandTask extends ForkTask {
private final ICommand command; private final ICommand command;
private final String[] args; private final String[] args;
/** @param cmd the command /** @param cmd the command
* @param args the arguements * @param args the arguements
@ -89,13 +86,6 @@ public class ForkCommandTask extends ForkTask {
this.args = Arrays.copyOf(args, args.length); 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) /* (non-Javadoc)
* @see net.bigeon.gclc.process.ForkTask#doRun() */ * @see net.bigeon.gclc.process.ForkTask#doRun() */
@Override @Override
@ -103,4 +93,11 @@ public class ForkCommandTask extends ForkTask {
command.execute(out, in, args); command.execute(out, in, args);
} }
/* (non-Javadoc)
* @see net.bigeon.gclc.process.Task#getName() */
@Override
public String getName() {
return command.getCommandName();
}
} }

View File

@ -89,8 +89,8 @@ public abstract class ForkTask implements Task {
protected final ConnectingConsoleInput in = new ConnectingConsoleInput(); protected final ConnectingConsoleInput in = new ConnectingConsoleInput();
protected final ConnectingConsoleOutput out; protected final ConnectingConsoleOutput out;
private CommandRunException exception; private CommandRunException exception;
private final Object runLock = new Object(); private final Object runLock = new Object();
/** @param lines the number of print to store in the output */ /** @param lines the number of print to store in the output */
public ForkTask(int lines) { public ForkTask(int lines) {
@ -105,6 +105,20 @@ public abstract class ForkTask implements Task {
listeners.add(listener); 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) /* (non-Javadoc)
* @see net.bigeon.gclc.process.Task#isRunning() */ * @see net.bigeon.gclc.process.Task#isRunning() */
@Override @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) /* (non-Javadoc)
* @see net.bigeon.gclc.process.Task#setRunning(boolean) */ * @see net.bigeon.gclc.process.Task#setRunning(boolean) */
@Override @Override
@ -181,8 +185,4 @@ public abstract class ForkTask implements Task {
runLock.notifyAll(); runLock.notifyAll();
} }
} }
protected final Object getRunningLock() {
return runLock;
}
} }

View File

@ -71,10 +71,7 @@ import net.bigeon.gclc.ApplicationAttachement;
import net.bigeon.gclc.command.ICommandProvider; import net.bigeon.gclc.command.ICommandProvider;
import net.bigeon.gclc.exception.InvalidCommandName; import net.bigeon.gclc.exception.InvalidCommandName;
/** /** @author Emmanuel Bigeon */
* @author Emmanuel Bigeon
*
*/
public class ProcessAttachement implements ApplicationAttachement { public class ProcessAttachement implements ApplicationAttachement {
private final TaskPool pool; private final TaskPool pool;
@ -86,8 +83,8 @@ public class ProcessAttachement implements ApplicationAttachement {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.ApplicationAttachement#attach(fr.bigeon.gclc.ConsoleApplication) * @see fr.bigeon.gclc.ApplicationAttachement#attach(fr.bigeon.gclc.
*/ * ConsoleApplication) */
@Override @Override
public void attach(ICommandProvider application) throws InvalidCommandName { public void attach(ICommandProvider application) throws InvalidCommandName {
application.add(new ProcessKill("kill", pool)); application.add(new ProcessKill("kill", pool));

View File

@ -89,11 +89,10 @@ public final class ProcessClear extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, 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()) { for (final String id : pool.getPIDs()) {
if (!pool.get(id).isRunning()) { if (!pool.get(id).isRunning()) {
pool.remove(id); pool.remove(id);

View File

@ -89,11 +89,10 @@ public final class ProcessKill extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, 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); pool.get(args[0]).setRunning(false);
} }

View File

@ -95,11 +95,10 @@ public final class ProcessList extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException { final String... args) throws CommandRunException {
final ArrayList<String> pids = new ArrayList<>(pool.getPIDs()); final ArrayList<String> pids = new ArrayList<>(pool.getPIDs());
Collections.sort(pids); Collections.sort(pids);
for (final String string : 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$ out.println(MessageFormat.format("{0}\t{1}", string, //$NON-NLS-1$
pool.get(string).getName())); pool.get(string).getName()));
} catch (final IOException e) { } catch (final IOException e) {
throw new CommandRunException( throw new CommandRunException(CommandRunExceptionType.INTERACTION,
CommandRunExceptionType.INTERACTION,
"Unable to communicate with user", e); //$NON-NLS-1$ "Unable to communicate with user", e); //$NON-NLS-1$
} }
} }

View File

@ -103,8 +103,8 @@ public interface Task extends Runnable {
/** Set the running state. /** Set the running state.
* <p> * <p>
* This method should be only called by external objects with the false * This method should be only called by external objects with the false
* argument. Calling this method with true has unspecified behavior and * argument. Calling this method with true has unspecified behavior and could do
* could do nothing as well as restart the command for example. * nothing as well as restart the command for example.
* *
* @param running the running state */ * @param running the running state */
void setRunning(boolean running); void setRunning(boolean running);

View File

@ -95,16 +95,6 @@ public final class TaskPool {
this.autoClear = autoClear; 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. /** Add a process in the pool.
* *
* @param cmd the process * @param cmd the process
@ -168,6 +158,16 @@ public final class TaskPool {
return autoClear; 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. /** Request all task to stop running.
* <p> * <p>
* This call does not guaranty end of execution, it is up to the task * This call does not guaranty end of execution, it is up to the task

View File

@ -80,7 +80,7 @@ import net.bigeon.gclc.manager.ConsoleOutput;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public abstract class TaskSpawner extends Command { public abstract class TaskSpawner extends Command {
/** The process pool */ /** The process pool */
private final TaskPool pool; private final TaskPool pool;
private final ExecutorService threadPool; private final ExecutorService threadPool;
/** @param name the command name /** @param name the command name
@ -97,16 +97,15 @@ public abstract class TaskSpawner extends Command {
* @param args the arguments * @param args the arguments
* @return the process to start and add to the pool * @return the process to start and add to the pool
* @throws CommandRunException if the task creation failed */ * @throws CommandRunException if the task creation failed */
protected abstract Task createTask(ConsoleOutput out, ConsoleInput in, protected abstract Task createTask(ConsoleOutput out, ConsoleInput in, String... args)
String... args) throws CommandRunException; throws CommandRunException;
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public final void execute(final ConsoleOutput out, final ConsoleInput in, 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 Task task = createTask(out, in, args);
final Thread th = new Thread(task); final Thread th = new Thread(task);
pool.add(task); pool.add(task);

View File

@ -77,9 +77,9 @@ import net.bigeon.gclc.tools.StringProvider;
/** @author Emmanuel Bigeon */ /** @author Emmanuel Bigeon */
public final class ConnectingConsoleInput implements ConsoleInput { public final class ConnectingConsoleInput implements ConsoleInput {
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(ConnectingConsoleInput.class.getName()); .getLogger(ConnectingConsoleInput.class.getName());
private boolean close = false; private boolean close = false;
private StringProvider prompt; private StringProvider prompt;
private boolean prompting; private boolean prompting;
private final Object promptLock = new Object(); private final Object promptLock = new Object();
@ -94,6 +94,26 @@ public final class ConnectingConsoleInput implements ConsoleInput {
close = true; 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) /* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */ * @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@Override @Override
@ -128,14 +148,6 @@ public final class ConnectingConsoleInput implements ConsoleInput {
return prompt(prompt.apply()); 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) /* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */ * @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
@Override @Override
@ -222,23 +234,11 @@ public final class ConnectingConsoleInput implements ConsoleInput {
}; };
} }
public void connect(ConsoleInput input) { /* (non-Javadoc)
disconnect(); * @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools.
synchronized (promptLock) { * StringProvider) */
connected = input; @Override
promptLock.notifyAll(); public void setPrompt(StringProvider string) {
} prompt = string;
}
public void disconnect() {
synchronized (connectionLock) {
if (connected != null) {
disconnection = true;
synchronized (promptLock) {
connected.interruptPrompt();
}
connected = null;
}
}
} }
} }

View File

@ -130,6 +130,25 @@ public class ConnectingConsoleOutput implements ConsoleOutput {
close = true; 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) /* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleOutput#isClosed() */ * @see fr.bigeon.gclc.manager.ConsoleOutput#isClosed() */
@Override @Override
@ -157,23 +176,4 @@ public class ConnectingConsoleOutput implements ConsoleOutput {
public void println(String message) { public void println(String message) {
addMessage(message + System.lineSeparator()); 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;
}
} }

View File

@ -50,23 +50,24 @@ import java.util.logging.Logger;
public final class DConnexionManager<T> implements ConnexionManager<T> { public final class DConnexionManager<T> implements ConnexionManager<T> {
/** Class logger. */ /** Class logger. */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(DConnexionManager.class.getName()); .getLogger(DConnexionManager.class.getName());
/** The connected objects. */ /** The connected objects. */
private final Map<String, T> connecteds = new HashMap<>(); private final Map<String, T> connecteds = new HashMap<>();
/** The locks for the connexions. */ /** The locks for the connexions. */
private final Map<String, Object> locks = new HashMap<>(); private final Map<String, Object> locks = new HashMap<>();
/** The counter for the disconnexion locks. */ /** The counter for the disconnexion locks. */
private final Map<String, Integer> counters = new HashMap<>(); private final Map<String, Integer> counters = new HashMap<>();
/** The lock for modification of {@link #counters}. */ /** The lock for modification of {@link #counters}. */
private final Object counterLock = new Object(); private final Object counterLock = new Object();
/** The count of connexions. */ /** The count of connexions. */
private int count = 0; private int count;
/** Default.constructor. */ /** Default.constructor. */
public DConnexionManager() { public DConnexionManager() {
// //
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see * @see
* net.bigeon.gclc.socket.ConnexionManager#addConnexion(java.lang.Object) */ * net.bigeon.gclc.socket.ConnexionManager#addConnexion(java.lang.Object) */
@ -80,29 +81,28 @@ public final class DConnexionManager<T> implements ConnexionManager<T> {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see * @see net.bigeon.gclc.socket.ConnexionManager#disconnect(java.lang.String) */
* net.bigeon.gclc.socket.ConnexionManager#disconnect(java.lang.String) */
@Override @Override
public T disconnect(final String id) { public T disconnect(final String id) {
if (connecteds.containsKey(id)) { if (!connecteds.containsKey(id)) {
final T disc = connecteds.remove(id); return null;
final Object lock = locks.get(id); }
synchronized (lock) { final T disc = connecteds.remove(id);
lock.notifyAll(); final Object lock = locks.get(id);
} synchronized (lock) {
synchronized (counterLock) { lock.notifyAll();
while (counters.get(id).intValue() > 0) { }
try { synchronized (counterLock) {
counterLock.wait(); while (counters.get(id).intValue() > 0) {
} catch (final InterruptedException e) { try {
LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$ counterLock.wait();
Thread.currentThread().interrupt(); } 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) /* (non-Javadoc)
@ -120,8 +120,7 @@ public final class DConnexionManager<T> implements ConnexionManager<T> {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see * @see net.bigeon.gclc.socket.ConnexionManager#isConnected(java.lang.String) */
* net.bigeon.gclc.socket.ConnexionManager#isConnected(java.lang.String) */
@Override @Override
public boolean isConnected(final String id) { public boolean isConnected(final String id) {
return connecteds.containsKey(id); return connecteds.containsKey(id);
@ -154,8 +153,8 @@ public final class DConnexionManager<T> implements ConnexionManager<T> {
@Override @Override
public void releaseDisconnexionLock(final String id) { public void releaseDisconnexionLock(final String id) {
synchronized (counterLock) { synchronized (counterLock) {
counters.put(id, Integer counters.put(id,
.valueOf(Math.max(counters.get(id).intValue() - 1, 0))); Integer.valueOf(Math.max(counters.get(id).intValue() - 1, 0)));
counterLock.notifyAll(); counterLock.notifyAll();
} }
} }

View File

@ -61,28 +61,28 @@ import net.bigeon.gclc.utils.ReadingRunnable;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public final class PluggableConsoleInput implements ConsoleInput { public final class PluggableConsoleInput implements ConsoleInput {
/** The ten constant. */ /** The ten constant. */
private static final int TENTH = 10; private static final int TENTH = 10;
/** Class logger. */ /** Class logger. */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(PluggableConsoleInput.class.getName()); .getLogger(PluggableConsoleInput.class.getName());
/** The default time out. */ /** The default time out. */
private static final long TIMEOUT = 100; private static final long TIMEOUT = 100;
/** The prompting. */ /** The prompting. */
private boolean prompting = false; private boolean prompting = false;
/** If the element is closed. */ /** If the element is closed. */
private boolean closed = false; private boolean closed = false;
/** The default prompt. */ /** 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. */ /** If the input is plugged or buffering. */
private boolean connected = false; private boolean connected = false;
/** The current connexion (if any). */ /** The current connexion (if any). */
private ReadingRunnable connexion; private ReadingRunnable connexion;
/** The interrupted status for prompts. */ /** The interrupted status for prompts. */
private boolean interrupted = false; private boolean interrupted = false;
/** The last hint hint. */ /** The last hint hint. */
private String hint; private String hint;
/** The output for hints. */ /** The output for hints. */
private PrintStream output; private PrintStream output;
// Locks // Locks
/** The lock for connexion and disconnexion of actual streams. */ /** The lock for connexion and disconnexion of actual streams. */
@ -100,18 +100,16 @@ public final class PluggableConsoleInput implements ConsoleInput {
closed = true; closed = true;
} }
/** Connect the given input stream to the input and output to the hints /** Connect the given input stream to the input and output to the hints writing.
* writing.
* *
* @param stream the input stream * @param stream the input stream
* @param out the output for hints. * @param out the output for hints.
* @throws IOException if the input is already connected. */ * @throws IOException if the input is already connected. */
public void connect(final InputStream stream, public void connect(final InputStream stream, final PrintStream out)
final PrintStream out) throws IOException { throws IOException {
synchronized (connexionLock) { synchronized (connexionLock) {
if (connected) { if (connected) {
throw new IOException( throw new IOException("Input already connected to an input stream"); //$NON-NLS-1$
"Input already connected to an input stream"); //$NON-NLS-1$
} }
output = out; output = out;
@ -120,8 +118,8 @@ public final class PluggableConsoleInput implements ConsoleInput {
out.flush(); out.flush();
} }
final InputStreamReader streamReader = new InputStreamReader( final InputStreamReader streamReader = new InputStreamReader(stream,
stream, StandardCharsets.UTF_8); StandardCharsets.UTF_8);
final BufferedReader reader = new BufferedReader(streamReader); final BufferedReader reader = new BufferedReader(streamReader);
connexion = new ReadingRunnable(reader); connexion = new ReadingRunnable(reader);
final Thread th = new Thread(connexion, "GCLC Socket - Read input"); //$NON-NLS-1$ 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) /* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, * @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
* long) */
@Override @Override
public String prompt(final String message, public String prompt(final String message, final long timeout) throws IOException {
final long timeout) throws IOException {
if (closed) { if (closed) {
throw new IOException(); throw new IOException();
} }
@ -240,8 +236,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
long time = System.currentTimeMillis() - tic; long time = System.currentTimeMillis() - tic;
while (res == null && !interrupted && time < timeout) { while (res == null && !interrupted && time < timeout) {
try { try {
res = waitMessageOrConnexion(timeout - time, res = waitMessageOrConnexion(timeout - time, (timeout - time) / TENTH);
(timeout - time) / TENTH);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$ LOGGER.log(Level.FINE, "Interruption of thread", e); //$NON-NLS-1$
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
@ -255,26 +250,25 @@ public final class PluggableConsoleInput implements ConsoleInput {
return res; return res;
} }
@Override
public void setPrompt(String prompt) {
setPrompt(new ConstantString(prompt));
}
@Override @Override
public void setPrompt(final StringProvider prompt) { public void setPrompt(final StringProvider prompt) {
this.prompt = prompt; this.prompt = prompt;
} }
@Override /** Wait for a hint or connection.
public void setPrompt(String prompt) {
setPrompt(new ConstantString(prompt));
}
/** Wait for a hint or connexion.
* *
* @param messageTimeout the timeout on the current connexion hint waiting * @param messageTimeout the timeout on the current connection hint waiting
* @param connexionTimeout the timeout on the new connexion wait * @param connexionTimeout the timeout on the new connection wait
* @return the hint, or null if not connected or timed out. * @return the hint, or null if not connected or timed out.
* @throws IOException if the reading failed. * @throws IOException if the reading failed.
* @throws InterruptedException if the wait was interrupted */ * @throws InterruptedException if the wait was interrupted */
private String waitMessageOrConnexion(final long messageTimeout, private String waitMessageOrConnexion(final long messageTimeout,
final long connexionTimeout) throws IOException, final long connexionTimeout) throws IOException, InterruptedException {
InterruptedException {
synchronized (connexionLock) { synchronized (connexionLock) {
if (connected) { if (connected) {
return connexion.getNextMessage(messageTimeout); return connexion.getNextMessage(messageTimeout);

View File

@ -50,16 +50,17 @@ import net.bigeon.gclc.manager.ConsoleOutput;
public final class PluggableConsoleOutput implements ConsoleOutput { public final class PluggableConsoleOutput implements ConsoleOutput {
/** The actual output. */ /** The actual output. */
private PrintStream out; private PrintStream out;
/** The buffered messages. */ /** The buffered messages. */
private final Deque<String> messages = new ArrayDeque<>(); private final Deque<String> messages = new ArrayDeque<>();
/** If this output is closed. */ /** If this output is closed. */
private boolean closed = false; private boolean closed = false;
/** Default constructor. */ /** Default constructor. */
public PluggableConsoleOutput() { public PluggableConsoleOutput() {
// //
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.AutoCloseable#close() */ * @see java.lang.AutoCloseable#close() */
@Override @Override

View File

@ -57,16 +57,16 @@ public final class RemoteDisconnectCommand<T> extends Command {
private final ConnexionManager<T> manager; private final ConnexionManager<T> manager;
/** If all connexion should be disconnected when no argument have been /** If all connexion should be disconnected when no argument have been
* specified. */ * specified. */
private final boolean all; private final boolean all;
/** Create the disconnection command. /** Create the disconnection command.
* *
* @param name the command name * @param name the command name
* @param manager the manager * @param manager the manager
* @param all if all elements should be disconnected when no argument is * @param all if all elements should be disconnected when no argument is
* provided */ * provided */
public RemoteDisconnectCommand(final String name, public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
final ConnexionManager<T> manager, final boolean all) { final boolean all) {
super(name); super(name);
this.manager = manager; this.manager = manager;
this.all = all; this.all = all;
@ -74,11 +74,10 @@ public final class RemoteDisconnectCommand<T> extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException { final String... args) throws CommandRunException {
if (args.length == 0 && all) { if (args.length == 0 && all) {
final Collection<String> coll = manager.getConnected(); final Collection<String> coll = manager.getConnected();
for (final String string : coll) { for (final String string : coll) {
@ -89,8 +88,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
if (manager.isConnected(string)) { if (manager.isConnected(string)) {
manager.disconnect(string); manager.disconnect(string);
} else { } else {
print(out, MessageFormat print(out,
.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$ MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
} }
} }
} }
@ -99,16 +98,14 @@ public final class RemoteDisconnectCommand<T> extends Command {
* *
* @param out the output * @param out the output
* @param string the message * @param string the message
* @throws CommandRunException if the output exists but cannot be printed * @throws CommandRunException if the output exists but cannot be printed to */
* to */ private static void print(final ConsoleOutput out, final String string)
private void print(final ConsoleOutput out, throws CommandRunException {
final String string) throws CommandRunException {
if (out != null) { if (out != null) {
try { try {
out.println(string); out.println(string);
} catch (final IOException e) { } catch (final IOException e) {
throw new CommandRunException( throw new CommandRunException(CommandRunExceptionType.INTERACTION,
CommandRunExceptionType.INTERACTION,
"Unable to print to existing output", e); //$NON-NLS-1$ "Unable to print to existing output", e); //$NON-NLS-1$
} }
} }
@ -123,12 +120,11 @@ public final class RemoteDisconnectCommand<T> extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */ * @see fr.bigeon.gclc.command.Command#usageDetail() */
@SuppressWarnings("nls")
@Override @Override
protected String usageDetail() { protected String usageDetail() {
return MessageFormat.format( return MessageFormat.format(
" If arguments are provided the corresponding connexions are closed, " + " If arguments are provided the corresponding connexions are closed, "
"otherwise{0}{1} are.", + "otherwise{0}{1} are.",
System.lineSeparator(), all ? "all connexions" : "none"); System.lineSeparator(), all ? "all connexions" : "none");
} }
} }

View File

@ -64,31 +64,30 @@ import net.bigeon.gclc.ConsoleApplication;
public final class SocketConsoleApplicationShell implements Runnable { public final class SocketConsoleApplicationShell implements Runnable {
/** The class logger. */ /** The class logger. */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(SocketConsoleApplicationShell.class.getName()); .getLogger(SocketConsoleApplicationShell.class.getName());
/** The listening port. */ /** The listening port. */
private final int port; private final int port;
/** The running status. */ /** The running status. */
private boolean running; private boolean running;
/** The socket console interface. */ /** The socket console interface. */
private SocketConsoleInterface sci; private SocketConsoleInterface sci;
/** The remote disconnection command. */ /** The remote disconnection command. */
private ConnexionManager<Socket> rdc; private ConnexionManager<Socket> rdc;
/** The application. */ /** The application. */
private ConsoleApplication app; private ConsoleApplication app;
/** The server socket. */ /** The server socket. */
private ServerSocket serverSocket; private ServerSocket serverSocket;
/** THe server address. */ /** THe server address. */
private final InetAddress addr; private final InetAddress addr;
/** Create a socket application shell which will listen on the given port /** Create a socket application shell which will listen on the given port and
* and network interface. * network interface.
* *
* @param port the part * @param port the part
* @param addr the inet address */ * @param addr the inet address */
public SocketConsoleApplicationShell(final int port, public SocketConsoleApplicationShell(final int port, final InetAddress addr) {
final InetAddress addr) {
super(); super();
this.port = port; this.port = port;
this.addr = addr; 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. /** If the port provided was 0, this allows to get the actual port.
*
* @return the local port * @return the local port
* @see java.net.ServerSocket#getLocalPort() * @see java.net.ServerSocket#getLocalPort() */
*/
public int getLocalPort() { public int getLocalPort() {
return serverSocket.getLocalPort(); return serverSocket.getLocalPort();
} }
@ -122,16 +121,14 @@ public final class SocketConsoleApplicationShell implements Runnable {
@Override @Override
public void run() { public void run() {
// Create the server // Create the server
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
addr)) {
serverSocket = actualServerSocket; serverSocket = actualServerSocket;
running = true; running = true;
// Create the streams // Create the streams
runSokectServer(); runSokectServer();
} catch (final IOException e) { } catch (final IOException e) {
LOGGER.severe("Communication error between client and server"); //$NON-NLS-1$ LOGGER.severe("Communication error between client and server"); //$NON-NLS-1$
LOGGER.log(Level.FINE, LOGGER.log(Level.FINE, "Communication error between client and server", e); //$NON-NLS-1$
"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 { private void runSokectServer() throws IOException {
while (running && app.isRunning()) { while (running && app.isRunning()) {
LOGGER.info("Waiting client"); //$NON-NLS-1$ LOGGER.info("Waiting client"); //$NON-NLS-1$
try (Socket clientSocket = serverSocket.accept();) { try (Socket clientSocket = serverSocket.accept()) {
sci.connect(clientSocket); sci.connect(clientSocket);

View File

@ -48,7 +48,7 @@ import java.nio.charset.StandardCharsets;
public final class SocketConsoleInterface { public final class SocketConsoleInterface {
/** The application's input. */ /** The application's input. */
private final PluggableConsoleInput input; private final PluggableConsoleInput input;
/** The application's output. */ /** The application's output. */
private final PluggableConsoleOutput output; private final PluggableConsoleOutput output;
@ -57,7 +57,7 @@ public final class SocketConsoleInterface {
* @param input the input * @param input the input
* @param output the output */ * @param output the output */
public SocketConsoleInterface(final PluggableConsoleInput input, public SocketConsoleInterface(final PluggableConsoleInput input,
final PluggableConsoleOutput output) { final PluggableConsoleOutput output) {
super(); super();
this.input = input; this.input = input;
this.output = output; this.output = output;
@ -68,12 +68,10 @@ public final class SocketConsoleInterface {
* @param socket the socket * @param socket the socket
* @throws IOException if the connection failed */ * @throws IOException if the connection failed */
public void connect(final Socket socket) throws IOException { public void connect(final Socket socket) throws IOException {
final PrintStream printStream = new PrintStream( final PrintStream printStream = new PrintStream(socket.getOutputStream(), true,
socket.getOutputStream(), true,
StandardCharsets.UTF_8.name()); StandardCharsets.UTF_8.name());
output.connect(printStream); output.connect(printStream);
input.connect(socket.getInputStream(), input.connect(socket.getInputStream(), printStream);
printStream);
} }
/** Disconnect the input and output of the application from the socket's. */ /** Disconnect the input and output of the application from the socket's. */

View File

@ -62,13 +62,10 @@ public class ConsoleTestApplication {
* @return create the application */ * @return create the application */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static ConsoleApplication create(final ConsoleOutput output, public static ConsoleApplication create(final ConsoleOutput output,
final ConsoleInput input, final ConsoleInput input, final ConnexionManager<Socket> manager) {
final ConnexionManager<Socket> manager) {
try { try {
final ConsoleApplication application = new ConsoleApplication( final ConsoleApplication application = new ConsoleApplication(output, input,
output, input, "Welcome to the test application. Type help or test.", "See you");
"Welcome to the test application. Type help or test.",
"See you");
application.add(new ExitCommand(EXIT, application) { application.add(new ExitCommand(EXIT, application) {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ExitCommand#beforeExit() */ * @see fr.bigeon.gclc.command.ExitCommand#beforeExit() */
@ -80,8 +77,7 @@ public class ConsoleTestApplication {
} }
} }
}); });
application application.add(new HelpExecutor("help", application.root));
.add(new HelpExecutor("help", application.root));
application.add(new Command("test") { application.add(new Command("test") {
/* (non-Javadoc) /* (non-Javadoc)
@ -89,9 +85,8 @@ public class ConsoleTestApplication {
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */ * java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, public void execute(final ConsoleOutput out, final ConsoleInput in,
final ConsoleInput in, final String... args) throws CommandRunException {
final String... args) throws CommandRunException {
try { try {
output.println("Test command ran fine"); output.println("Test command ran fine");
} catch (final IOException e) { } catch (final IOException e) {
@ -105,8 +100,7 @@ public class ConsoleTestApplication {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() * @see fr.bigeon.gclc.command.Command#usageDetail() */
*/
@Override @Override
protected String usageDetail() { protected String usageDetail() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -121,9 +115,8 @@ public class ConsoleTestApplication {
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */ * java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, public void execute(final ConsoleOutput out, final ConsoleInput in,
final ConsoleInput in, final String... args) throws CommandRunException {
final String... args) throws CommandRunException {
try { try {
Thread.sleep(2000); Thread.sleep(2000);
output.println("Test command ran fine"); output.println("Test command ran fine");
@ -138,8 +131,7 @@ public class ConsoleTestApplication {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() * @see fr.bigeon.gclc.command.Command#usageDetail() */
*/
@Override @Override
protected String usageDetail() { protected String usageDetail() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -147,8 +139,7 @@ public class ConsoleTestApplication {
throw new RuntimeException("Not implemented yet"); throw new RuntimeException("Not implemented yet");
} }
}); });
application.add( application.add(new RemoteDisconnectCommand<>("out", manager, true));
new RemoteDisconnectCommand<>("out", manager, true));
return application; return application;
} catch (final InvalidCommandName e) { } catch (final InvalidCommandName e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -39,6 +39,7 @@ package net.bigeon.gclc.socket;
*/ */
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -46,6 +47,7 @@ import java.io.IOException;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test; import org.junit.Test;
@ -133,11 +135,11 @@ public class PluggableConsoleInputTest {
input.disconnect(); input.disconnect();
try (final PipedInputStream pis = new PipedInputStream(); try (final PipedInputStream pis = new PipedInputStream();
final PipedOutputStream pos = new PipedOutputStream(); final PipedOutputStream pos = new PipedOutputStream();
final PipedInputStream inner = new PipedInputStream(pos); final PipedInputStream inner = new PipedInputStream(pos);
final PipedOutputStream innerPos = new PipedOutputStream(pis); final PipedOutputStream innerPos = new PipedOutputStream(pis);
final PrintStream testIn = new PrintStream(innerPos, true, "UTF8"); final PrintStream testIn = new PrintStream(innerPos, true, "UTF8");
final PrintStream out = new PrintStream(pos)) { final PrintStream out = new PrintStream(pos)) {
input.connect(pis, out); input.connect(pis, out);
try { try {
input.connect(pis, out); input.connect(pis, out);
@ -167,15 +169,17 @@ public class PluggableConsoleInputTest {
input.connect(pis, out); input.connect(pis, out);
testIn.println("tac"); testIn.println("tac");
final AtomicReference<IOException> ref = new AtomicReference<>();
final Thread th2 = new Thread(new Runnable() { final Thread th2 = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
input.prompt("Test", 5000); input.prompt("Test", 5000);
fail("Prompt should io"); // fail("Prompt should io");
} catch (final IOException e) { } catch (final IOException e) {
// ok // ok
ref.set(e);
} }
} }
}); });
@ -185,7 +189,8 @@ public class PluggableConsoleInputTest {
} }
input.close(); input.close();
th2.join();
assertNotNull("Prompt should io", ref.get());
} }
} }

View File

@ -63,10 +63,10 @@ public class RemoteDisconnectCommandTest {
@Test @Test
public final void testExecute() throws CommandRunException, IOException { public final void testExecute() throws CommandRunException, IOException {
final DConnexionManager<String> manager = new DConnexionManager<>(); final DConnexionManager<String> manager = new DConnexionManager<>();
final RemoteDisconnectCommand<String> cmd = new RemoteDisconnectCommand<>( final RemoteDisconnectCommand<String> cmd = new RemoteDisconnectCommand<>("quit",
"quit", manager, true); manager, true);
final RemoteDisconnectCommand<String> cmd2 = new RemoteDisconnectCommand<>( final RemoteDisconnectCommand<String> cmd2 = new RemoteDisconnectCommand<>("quit",
"quit", manager, false); manager, false);
manager.addConnexion("test"); manager.addConnexion("test");
cmd2.execute(null, null); cmd2.execute(null, null);

View File

@ -51,7 +51,7 @@ import org.junit.Test;
/** Test class for {@link SocketConsoleApplicationShell} /** Test class for {@link SocketConsoleApplicationShell}
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@SuppressWarnings({"static-method", "javadoc", "nls"}) @SuppressWarnings({ "static-method", "javadoc", "nls" })
public class SocketConsoleApplicationTest { public class SocketConsoleApplicationTest {
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
@ -60,12 +60,12 @@ public class SocketConsoleApplicationTest {
/** @param in the input /** @param in the input
* @return the string * @return the string
* @throws IOException if the input reading failed */ * @throws IOException if the input reading failed */
private String consumeToPrompt(final String server, private String consumeToPrompt(final String server, final BufferedReader in)
final BufferedReader in) throws IOException { throws IOException {
String fromServer = server; String fromServer = server;
LOGGER.fine("Server: \n" + fromServer); LOGGER.fine("Server: \n" + fromServer);
while (fromServer != null && !fromServer.equals("Bye.") && while (fromServer != null && !fromServer.equals("Bye.")
!fromServer.equals("> ")) { && !fromServer.equals("> ")) {
fromServer = in.readLine(); fromServer = in.readLine();
LOGGER.fine("Server: \n" + fromServer); LOGGER.fine("Server: \n" + fromServer);
} }
@ -81,14 +81,13 @@ public class SocketConsoleApplicationTest {
final int portNumber = 3300; final int portNumber = 3300;
try (Socket kkSocket = new Socket(hostName, portNumber); try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
true); BufferedReader in = new BufferedReader(
BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream()));) {
new InputStreamReader(kkSocket.getInputStream()));) {
String fromServer; String fromServer;
int i = -1; int i = -1;
final String[] cmds = {"help", "toto", "test", "out"}; final String[] cmds = { "help", "toto", "test", "out" };
while ((fromServer = in.readLine()) != null) { while ((fromServer = in.readLine()) != null) {
i++; i++;
fromServer = consumeToPrompt(fromServer, in); fromServer = consumeToPrompt(fromServer, in);
@ -106,15 +105,13 @@ public class SocketConsoleApplicationTest {
} }
try (Socket kkSocket = new Socket(hostName, portNumber); try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
true); BufferedReader in = new BufferedReader(
BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream()));) {
new InputStreamReader(kkSocket.getInputStream()));) {
String fromServer; String fromServer;
int i = 0; int i = 0;
final String[] cmds = {"help", "toto", "test", final String[] cmds = { "help", "toto", "test", ConsoleTestApplication.EXIT };
ConsoleTestApplication.EXIT};
while ((fromServer = in.readLine()) != null) { while ((fromServer = in.readLine()) != null) {
fromServer = consumeToPrompt(fromServer, in); fromServer = consumeToPrompt(fromServer, in);
if (fromServer == null || fromServer.equals("Bye.")) { if (fromServer == null || fromServer.equals("Bye.")) {
@ -129,8 +126,7 @@ public class SocketConsoleApplicationTest {
} }
i++; i++;
} }
assertEquals("Application exit command should close connection", 4, assertEquals("Application exit command should close connection", 4, i);
i);
} }
Thread.sleep(100); Thread.sleep(100);
TestServer.closeServer(); TestServer.closeServer();
@ -138,17 +134,14 @@ public class SocketConsoleApplicationTest {
server = TestServer.getServer(); server = TestServer.getServer();
Thread.sleep(1000); Thread.sleep(1000);
try (Socket kkSocket = new Socket(hostName, portNumber); try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
true); BufferedReader in = new BufferedReader(
BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream()));) {
new InputStreamReader(kkSocket.getInputStream()));) {
String fromServer; String fromServer;
int i = 0; int i = 0;
final String[] cmds = {"help", "toto", "test", final String[] cmds = { "help", "toto", "test", ConsoleTestApplication.EXIT };
ConsoleTestApplication.EXIT};
while ((fromServer = in.readLine()) != null) { while ((fromServer = in.readLine()) != null) {
fromServer = consumeToPrompt(fromServer, in); fromServer = consumeToPrompt(fromServer, in);
if (fromServer == null || fromServer.equals("Bye.")) { if (fromServer == null || fromServer.equals("Bye.")) {
@ -162,8 +155,7 @@ public class SocketConsoleApplicationTest {
} }
i++; i++;
} }
assertEquals("Application exit command should close connection", 4, assertEquals("Application exit command should close connection", 4, i);
i);
} }
TestServer.closeServer(); TestServer.closeServer();
server.join(); server.join();

View File

@ -44,9 +44,8 @@ import java.util.Collection;
import net.bigeon.smu.StringEncoder; import net.bigeon.smu.StringEncoder;
/** TODO Describe TestConsoleClient.java /** TODO Describe TestConsoleClient.java
* @author Emmanuel Bigeon
* *
*/ * @author Emmanuel Bigeon */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class TestConsoleClient { public class TestConsoleClient {
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
@ -56,8 +55,7 @@ public class TestConsoleClient {
} }
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
private static final StringEncoder ENCODER = new StringEncoder("%", private static final StringEncoder ENCODER = new StringEncoder("%", TO_ENCODE);
TO_ENCODE);
@SuppressWarnings("javadoc") @SuppressWarnings("javadoc")
public static void main(String[] args) { public static void main(String[] args) {
@ -65,10 +63,9 @@ public class TestConsoleClient {
final int portNumber = 3300; final int portNumber = 3300;
try (Socket kkSocket = new Socket(hostName, portNumber); try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
true); BufferedReader in = new BufferedReader(
BufferedReader in = new BufferedReader(new InputStreamReader( new InputStreamReader(kkSocket.getInputStream()));) {
kkSocket.getInputStream()));) {
String fromServer; String fromServer;
while ((fromServer = in.readLine()) != null) { while ((fromServer = in.readLine()) != null) {

View File

@ -43,14 +43,14 @@ import net.bigeon.gclc.ConsoleApplication;
/** A test server /** A test server
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@SuppressWarnings({"javadoc", "nls"}) @SuppressWarnings({ "javadoc", "nls" })
public class TestServer { public class TestServer {
private static SocketConsoleApplicationShell SHELL; private static SocketConsoleApplicationShell SHELL;
private static ConnexionManager<Socket> manager; private static ConnexionManager<Socket> manager;
private static Thread server; private static Thread server;
private static PluggableConsoleInput input; private static PluggableConsoleInput input;
private static PluggableConsoleOutput output; private static PluggableConsoleOutput output;
public static synchronized void closeServer() { public static synchronized void closeServer() {
@ -77,8 +77,8 @@ public class TestServer {
manager = new DConnexionManager<>(); manager = new DConnexionManager<>();
SHELL = new SocketConsoleApplicationShell(3300, SHELL = new SocketConsoleApplicationShell(3300,
InetAddress.getByName("127.0.0.1")); InetAddress.getByName("127.0.0.1"));
final ConsoleApplication app = ConsoleTestApplication final ConsoleApplication app = ConsoleTestApplication.create(output, input,
.create(output, input, manager); manager);
SHELL.setInterface(new SocketConsoleInterface(input, output)); SHELL.setInterface(new SocketConsoleInterface(input, output));
SHELL.setConnexionManager(manager); SHELL.setConnexionManager(manager);
SHELL.setApplication(app); SHELL.setApplication(app);

View File

@ -77,6 +77,7 @@ package net.bigeon.gclc.swt;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public interface ConsoleDelayIO { public interface ConsoleDelayIO {
/** Get the input text. /** Get the input text.
*
* @return the non validated input */ * @return the non validated input */
String getInput(); String getInput();

View File

@ -81,13 +81,13 @@ import net.bigeon.collections.Ribbon;
public final class HistoryTextKeyListener extends KeyAdapter { public final class HistoryTextKeyListener extends KeyAdapter {
/** The size of commands history. */ /** 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. */ /** The empty string constant. */
private static final String EMPTY = ""; //$NON-NLS-1$ private static final String EMPTY = ""; //$NON-NLS-1$
/** The history ribbon. */ /** The history ribbon. */
private final Ribbon<String> commands; private final Ribbon<String> commands;
/** The current index in history search. */ /** The current index in history search. */
private int currentIndex = 0; private int currentIndex = 0;
/** The console to notify of command validation. */ /** The console to notify of command validation. */
private final ConsoleDelayIO console; private final ConsoleDelayIO console;
@ -123,8 +123,7 @@ public final class HistoryTextKeyListener extends KeyAdapter {
} }
// Upper arrow retrieves previous commands // Upper arrow retrieves previous commands
if (keyCode == SWT.ARROW_UP && if (keyCode == SWT.ARROW_UP && currentIndex < commands.size() - 1) {
currentIndex < commands.size() - 1) {
currentIndex++; currentIndex++;
final String cmd = commands.get(commands.size() - currentIndex - 1); final String cmd = commands.get(commands.size() - currentIndex - 1);
console.setInput(cmd); console.setInput(cmd);
@ -136,8 +135,7 @@ public final class HistoryTextKeyListener extends KeyAdapter {
currentIndex--; currentIndex--;
console.setInput(EMPTY); console.setInput(EMPTY);
} else if (currentIndex > 0) { } else if (currentIndex > 0) {
final String cmd = commands final String cmd = commands.get(commands.size() - (--currentIndex) - 1);
.get(commands.size() - (--currentIndex) - 1);
console.setInput(cmd); console.setInput(cmd);
} }
} }

View File

@ -309,8 +309,8 @@ public final class SWTConsole extends Composite
promptLock.notifyAll(); promptLock.notifyAll();
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
long cur = start; long cur = start;
while (prompting && start + timeout>cur) { while (prompting && start + timeout > cur) {
promptLock.wait((cur-start-timeout)/2); promptLock.wait((cur - start - timeout) / 2);
cur = System.currentTimeMillis(); cur = System.currentTimeMillis();
} }
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -397,6 +397,11 @@ public final class SWTConsole extends Composite
consoleInput.setSelection(input.length()); consoleInput.setSelection(input.length());
} }
@Override
public void setPrompt(String prompt) {
setPrompt(new ConstantString(prompt));
}
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */ * @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */
@Override @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 */ /** @param string the text */
public void setText(final String string) { public void setText(final String string) {
consoleInput.setText(string); consoleInput.setText(string);

View File

@ -92,8 +92,7 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
/** The local implementation of the forwarding runnable /** The local implementation of the forwarding runnable
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
private final class ToSWTConsoleForwardRunnable private final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
extends AOutputForwardRunnable {
/** The running status */ /** The running status */
private boolean running = true; private boolean running = true;
@ -119,14 +118,14 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
} }
/** The class logger */ /** The class logger */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(SWTConsoleView.class.getName()); .getLogger(SWTConsoleView.class.getName());
/** The console output text field */ /** The console output text field */
private final Text consoleOutput; private final Text consoleOutput;
/** The console input text field */ /** The console input text field */
private final Text consoleInput; private final Text consoleInput;
/** The input. */ /** The input. */
private PipedConsoleInput input; private PipedConsoleInput input;
/** The forwarding runnable */ /** The forwarding runnable */
private ToSWTConsoleForwardRunnable forward; private ToSWTConsoleForwardRunnable forward;
@ -139,15 +138,13 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
setLayout(new GridLayout(1, false)); setLayout(new GridLayout(1, false));
consoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | consoleOutput = new Text(this,
SWT.V_SCROLL | SWT.MULTI); SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
1, 1));
consoleOutput.setRedraw(true); consoleOutput.setRedraw(true);
consoleInput = new Text(this, SWT.BORDER); consoleInput = new Text(this, SWT.BORDER);
consoleInput.setLayoutData( consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
consoleInput.addKeyListener(new HistoryTextKeyListener(this)); consoleInput.addKeyListener(new HistoryTextKeyListener(this));
} }
@ -194,7 +191,7 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
* @param manager the output to set * @param manager the output to set
* @param input the input */ * @param input the input */
public void setManager(final PipedConsoleOutput manager, public void setManager(final PipedConsoleOutput manager,
final PipedConsoleInput input) { final PipedConsoleInput input) {
this.input = input; this.input = input;
if (forward != null) { if (forward != null) {
forward.setRunning(false); forward.setRunning(false);

View File

@ -73,7 +73,8 @@ import static org.junit.Assert.assertEquals;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.junit.Test; import org.junit.Test;
/** <p> /**
* <p>
* TODO * TODO
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@ -87,8 +88,8 @@ public class HistoryTextKeyListenerTest {
private String input = ""; private String input = "";
@Override @Override
public void validateInput() { public String getInput() {
input = ""; return input;
} }
@Override @Override
@ -97,8 +98,8 @@ public class HistoryTextKeyListenerTest {
} }
@Override @Override
public String getInput() { public void validateInput() {
return input; input = "";
} }
}; };
HistoryTextKeyListener listener = new HistoryTextKeyListener(io); HistoryTextKeyListener listener = new HistoryTextKeyListener(io);

View File

@ -91,19 +91,19 @@ import net.bigeon.gclc.manager.ConsoleOutput;
* TODO * TODO
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@SuppressWarnings({"javadoc", "static-method", "nls", "deprecation"}) @SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
public class SWTConsoleShellTest { public class SWTConsoleShellTest {
protected static final long TWO_SECONDS = 2000; protected static final long TWO_SECONDS = 2000;
private static final Display DISPLAY = Display.getDefault(); private static final Display DISPLAY = Display.getDefault();
@Test @Test
public void test() { public void test() {
final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY); final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY);
final SWTConsole swtConsole = shell.getManager(); final SWTConsole swtConsole = shell.getManager();
try { try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
swtConsole, "Hello", "See you"); "Hello", "See you");
appl.add(new ExitCommand("exit", appl)); appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") { appl.add(new Command("long") {
@ -112,9 +112,8 @@ public class SWTConsoleShellTest {
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */ * java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, public void execute(final ConsoleOutput out, final ConsoleInput in,
final ConsoleInput in, final String... args) throws CommandRunException {
final String... args) throws CommandRunException {
try { try {
Thread.sleep(TWO_SECONDS); Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -137,7 +136,7 @@ public class SWTConsoleShellTest {
throw new RuntimeException("Not implemented yet"); throw new RuntimeException("Not implemented yet");
} }
}); });
// shell.pack(); // shell.pack();
shell.open(); shell.open();
final Thread applThread = new Thread(new Runnable() { final Thread applThread = new Thread(new Runnable() {
@ -184,7 +183,7 @@ public class SWTConsoleShellTest {
DISPLAY.sleep(); DISPLAY.sleep();
} }
} }
// DISPLAY.dispose(); // DISPLAY.dispose();
assertTrue(swtConsole.isClosed()); assertTrue(swtConsole.isClosed());
Thread.sleep(TWO_SECONDS); Thread.sleep(TWO_SECONDS);
assertFalse(appl.isRunning()); assertFalse(appl.isRunning());
@ -204,8 +203,8 @@ public class SWTConsoleShellTest {
swtConsole.close(); swtConsole.close();
swtConsole.setPrompt(":"); swtConsole.setPrompt(":");
try { try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
swtConsole, "Hello", "See you"); "Hello", "See you");
appl.add(new ExitCommand("exit", appl)); appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") { appl.add(new Command("long") {
/* (non-Javadoc) /* (non-Javadoc)
@ -213,9 +212,8 @@ public class SWTConsoleShellTest {
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */ * java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, public void execute(final ConsoleOutput out, final ConsoleInput in,
final ConsoleInput in, final String... args) throws CommandRunException {
final String... args) throws CommandRunException {
try { try {
Thread.sleep(TWO_SECONDS); Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -244,9 +242,8 @@ public class SWTConsoleShellTest {
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */ * java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, public void execute(final ConsoleOutput out, final ConsoleInput in,
final ConsoleInput in, final String... args) throws CommandRunException {
final String... args) throws CommandRunException {
try { try {
swtConsole.prompt("Test"); swtConsole.prompt("Test");
} catch (final IOException e) { } catch (final IOException e) {
@ -268,7 +265,7 @@ public class SWTConsoleShellTest {
throw new RuntimeException("Not implemented yet"); throw new RuntimeException("Not implemented yet");
} }
}); });
// shell.pack(); // shell.pack();
shell.open(); shell.open();
final Thread applThread = new Thread(new Runnable() { final Thread applThread = new Thread(new Runnable() {
@ -351,7 +348,7 @@ public class SWTConsoleShellTest {
} catch (final IOException e) { } catch (final IOException e) {
assertNotNull(e); assertNotNull(e);
} }
// DISPLAY.dispose(); // DISPLAY.dispose();
assertTrue(swtConsole.isClosed()); assertTrue(swtConsole.isClosed());
Thread.sleep(TWO_SECONDS); Thread.sleep(TWO_SECONDS);
assertFalse(appl.isRunning()); assertFalse(appl.isRunning());

View File

@ -87,41 +87,42 @@ import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleInput; import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput; import net.bigeon.gclc.utils.PipedConsoleOutput;
/** <p> /**
* <p>
* TODO * TODO
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@SuppressWarnings({"javadoc", "static-method", "nls", "deprecation"}) @SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
public class SWTConsoleViewTest { public class SWTConsoleViewTest {
protected static final long TWO_SECONDS = 2000; protected static final long TWO_SECONDS = 2000;
private static final Display DISPLAY = Display.getDefault(); private static final Display DISPLAY = Display.getDefault();
@Test @Test
public void test() { public void test() {
final Shell shell = new Shell(DISPLAY); final Shell shell = new Shell(DISPLAY);
final SWTConsoleView swtConsole = new SWTConsoleView(shell, SWT.NONE); final SWTConsoleView swtConsole = new SWTConsoleView(shell, SWT.NONE);
try (PipedConsoleOutput manager = new PipedConsoleOutput(); try (PipedConsoleOutput manager = new PipedConsoleOutput();
PipedConsoleInput input = new PipedConsoleInput(System.out)) { PipedConsoleInput input = new PipedConsoleInput(System.out)) {
swtConsole.setManager(manager, input); swtConsole.setManager(manager, input);
} catch (final IOException e2) { } catch (final IOException e2) {
assertNull(e2); assertNull(e2);
} }
try (PipedConsoleOutput manager = new PipedConsoleOutput(); try (PipedConsoleOutput manager = new PipedConsoleOutput();
PipedConsoleInput input = new PipedConsoleInput(System.out)) { PipedConsoleInput input = new PipedConsoleInput(System.out)) {
swtConsole.setManager(manager, input); swtConsole.setManager(manager, input);
final ConsoleApplication appl = new ConsoleApplication(manager, final ConsoleApplication appl = new ConsoleApplication(manager, input,
input,
"Hello", "See you"); "Hello", "See you");
appl.add(new ExitCommand("exit", appl)); appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") { appl.add(new Command("long") {
/* (non-Javadoc) /* (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 @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException { final String... args) throws CommandRunException {
try { try {
Thread.sleep(TWO_SECONDS); Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
@ -144,7 +145,7 @@ public class SWTConsoleViewTest {
throw new RuntimeException("Not implemented yet"); throw new RuntimeException("Not implemented yet");
} }
}); });
// shell.pack(); // shell.pack();
shell.open(); shell.open();
final Thread applThread = new Thread(new Runnable() { final Thread applThread = new Thread(new Runnable() {

View File

@ -57,11 +57,11 @@ import net.bigeon.gclc.manager.ConsoleOutput;
public class ExecSystemCommand extends Command { public class ExecSystemCommand extends Command {
/** The command default name */ /** 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 */ /** The end of line separator */
private static final String EOL = System.lineSeparator(); private static final String EOL = System.lineSeparator();
/** The class logger */ /** The class logger */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(ExecSystemCommand.class.getName()); .getLogger(ExecSystemCommand.class.getName());
/***/ /***/
@ -69,19 +69,18 @@ public class ExecSystemCommand extends Command {
super(COMMAND_DEFAULT_NAME); super(COMMAND_DEFAULT_NAME);
} }
/** @param name the name of the command (the input from the manager that /** @param name the name of the command (the input from the manager that should
* should trigger this command) */ * trigger this command) */
public ExecSystemCommand(final String name) { public ExecSystemCommand(final String name) {
super(name); super(name);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager. * @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, * ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
* java.lang.String[]) */
@Override @Override
public void execute(final ConsoleOutput out, final ConsoleInput in, public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException { final String... args) throws CommandRunException {
Process proc; Process proc;
try { try {
proc = Runtime.getRuntime().exec(args); proc = Runtime.getRuntime().exec(args);
@ -90,8 +89,7 @@ public class ExecSystemCommand extends Command {
return; return;
} }
final InputStream is = proc final InputStream is = proc.getInputStream();
.getInputStream();
final Thread th = new Thread(new Runnable() { final Thread th = new Thread(new Runnable() {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@ -101,8 +99,7 @@ public class ExecSystemCommand extends Command {
readToEnd(out, is); readToEnd(out, is);
is.close(); is.close();
} catch (final CommandRunException e) { } catch (final CommandRunException e) {
LOGGER.log(Level.WARNING, LOGGER.log(Level.WARNING, "Manager was closed in the meantime...", e); //$NON-NLS-1$
"Manager was closed in the meantime...", e); //$NON-NLS-1$
} catch (final IOException e) { } catch (final IOException e) {
LOGGER.log(Level.WARNING, "Input stream was closed...", e); //$NON-NLS-1$ LOGGER.log(Level.WARNING, "Input stream was closed...", e); //$NON-NLS-1$
} }
@ -111,15 +108,13 @@ public class ExecSystemCommand extends Command {
th.start(); th.start();
in.setPrompt(""); //$NON-NLS-1$ in.setPrompt(""); //$NON-NLS-1$
final OutputStream os = proc.getOutputStream(); final OutputStream os = proc.getOutputStream();
try (BufferedWriter writer = new BufferedWriter( try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
new OutputStreamWriter(os))) {
while (th.isAlive()) { while (th.isAlive()) {
String user; String user;
try { try {
user = in.prompt(); user = in.prompt();
} catch (final IOException e) { } catch (final IOException e) {
throw new CommandRunException( throw new CommandRunException(CommandRunExceptionType.INTERACTION,
CommandRunExceptionType.INTERACTION,
"manager was closed", e); //$NON-NLS-1$ "manager was closed", e); //$NON-NLS-1$
} }
writer.write(user + EOL); writer.write(user + EOL);
@ -132,17 +127,16 @@ public class ExecSystemCommand extends Command {
/** @param is the input stream /** @param is the input stream
* @throws CommandRunException if the manager was closed while writing the * @throws CommandRunException if the manager was closed while writing the
* stream */ * stream */
protected void readToEnd(final ConsoleOutput out, protected void readToEnd(final ConsoleOutput out, final InputStream is)
final InputStream is) throws CommandRunException { throws CommandRunException {
int c; int c;
try { try {
while ((c = is.read()) != -1) { while ((c = is.read()) != -1) {
try { try {
out.print(Character.valueOf((char) c).toString()); out.print(Character.valueOf((char) c).toString());
} catch (final IOException e) { } catch (final IOException e) {
throw new CommandRunException( throw new CommandRunException(CommandRunExceptionType.INTERACTION,
CommandRunExceptionType.INTERACTION,
"manager was closed", e); //$NON-NLS-1$ "manager was closed", e); //$NON-NLS-1$
} }
} }
@ -163,12 +157,11 @@ public class ExecSystemCommand extends Command {
@Override @Override
protected String usageDetail() { protected String usageDetail() {
return " The system command is a system dependend command like sh on linux or" + //$NON-NLS-1$ 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() + "powershell on windows." + //$NON-NLS-1$
System.lineSeparator() + System.lineSeparator() + System.lineSeparator() + System.lineSeparator()
" As an example if you give \"cat /etc/hostname\" as argument, on a linux" + //$NON-NLS-1$ + " As an example if you give \"cat /etc/hostname\" as argument, on a linux" //$NON-NLS-1$
System.lineSeparator() + + System.lineSeparator() + "system, you would get the computer name." + //$NON-NLS-1$
"system, you would get the computer name." + //$NON-NLS-1$ System.lineSeparator();
System.lineSeparator();
} }
/* (non-Javadoc) /* (non-Javadoc)