Compare commits
21 Commits
socket-1.1
...
gclc-2.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| a0a1dfe91e | |||
| 04902c9868 | |||
| 9cf30ef7d2 | |||
| 3960b10e8e | |||
| d3bb6fa5a0 | |||
| b6b6ab9d36 | |||
| 92a664d193 | |||
| c230a23f81 | |||
| e5c3bb0152 | |||
| 24e57eca2f | |||
| da8765dd7b | |||
| ce4254941a | |||
| f459f78a75 | |||
| 8cd0b01490 | |||
| 698b3d0e5e | |||
| 9ad4a1e456 | |||
| e560fcb92d | |||
| 56f3d604a1 | |||
| 73317186df | |||
| 80bd7c0ac9 | |||
| dc71070dab |
@@ -7,7 +7,7 @@
|
||||
</parent>
|
||||
<groupId>net.bigeon.gclc</groupId>
|
||||
<artifactId>socket</artifactId>
|
||||
<version>1.1.16</version>
|
||||
<version>1.1.19-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>GCLC Socket</name>
|
||||
<description>Socket implementation of GCLC</description>
|
||||
@@ -36,7 +36,7 @@
|
||||
</developers>
|
||||
<scm>
|
||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||
<tag>socket-1.1.16</tag>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.socket;
|
||||
|
||||
/** Interface for listener of brutal disconnection from a pluggable
|
||||
* input/output.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@FunctionalInterface
|
||||
public interface DisconnexionListener {
|
||||
/** Indicate a brutal disconnection */
|
||||
void disconnected();
|
||||
}
|
||||
@@ -44,6 +44,8 @@ import java.io.InputStreamReader;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@@ -88,6 +90,8 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
||||
/** The output for hints. */
|
||||
private PrintStream output;
|
||||
|
||||
private final Set<DisconnexionListener> listeners = new HashSet<>();
|
||||
|
||||
// Locks
|
||||
/** The lock for connexion and disconnexion of actual streams. */
|
||||
private final Object connexionLock = new Object();
|
||||
@@ -287,11 +291,42 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
||||
throw e;
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.INFO, "Communication was abrubptly interrupted", e);
|
||||
disconnect();
|
||||
brutalDisconnection();
|
||||
}
|
||||
}
|
||||
connexionLock.wait(connexionTimeout);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void brutalDisconnection() {
|
||||
// clean up the disconnection
|
||||
disconnect();
|
||||
// notify listeners
|
||||
for (final DisconnexionListener listener : listeners) {
|
||||
listener.disconnected();
|
||||
}
|
||||
}
|
||||
|
||||
/** Add a listener to the list of listeners.
|
||||
*
|
||||
* @param e the listener
|
||||
* @return if the listener was added
|
||||
* @see java.util.Set#add(java.lang.Object) */
|
||||
public boolean add(final DisconnexionListener e) {
|
||||
return listeners.add(e);
|
||||
}
|
||||
|
||||
/** Remove a listener from the list of listeners.
|
||||
*
|
||||
* @param o the listener
|
||||
* @return if the listener was removed
|
||||
* @see java.util.Set#remove(java.lang.Object) */
|
||||
public boolean remove(final DisconnexionListener o) {
|
||||
return listeners.remove(o);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
* @param <T> the type of connected object */
|
||||
* @param <T> the type of connected object
|
||||
* @deprecated since 1.1.17, this has been moved to
|
||||
* {@link RemoteDisconnectCommand}. */
|
||||
@Deprecated
|
||||
public final class RemoteDisconnectCommand<T> extends Command {
|
||||
|
||||
/** The connexion manager. */
|
||||
|
||||
@@ -77,6 +77,8 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
||||
/** The application. */
|
||||
private ConsoleApplication app;
|
||||
|
||||
private final Object initLock = new Object();
|
||||
|
||||
/** The server socket. */
|
||||
private ServerSocket serverSocket;
|
||||
/** THe server address. */
|
||||
@@ -123,7 +125,10 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
||||
// Create the server
|
||||
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
|
||||
serverSocket = actualServerSocket;
|
||||
running = true;
|
||||
synchronized (initLock) {
|
||||
running = true;
|
||||
initLock.notifyAll();
|
||||
}
|
||||
// Create the streams
|
||||
runSokectServer();
|
||||
} catch (final IOException e) {
|
||||
@@ -194,4 +199,23 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
||||
LOGGER.log(Level.SEVERE, "Exception in closing socket server", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/** A method to wait for the socket server initialization.
|
||||
*
|
||||
* @param timeout the timeout */
|
||||
public void waitStartUp(final long timeout) {
|
||||
synchronized (initLock) {
|
||||
final long tic = System.currentTimeMillis() + timeout;
|
||||
long tac;
|
||||
while (!running && (tac = System.currentTimeMillis()) < tic) {
|
||||
final long idle = tic - tac;
|
||||
try {
|
||||
initLock.wait(idle);
|
||||
} catch (final InterruptedException e) {
|
||||
LOGGER.log(Level.INFO, "Thread interruption", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommand.java
|
||||
* Created on: Nov 18, 2017
|
||||
*/
|
||||
package net.bigeon.gclc.socket.cmd;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
* 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,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
* #L%
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.bigeon.gclc.command.Command;
|
||||
import net.bigeon.gclc.exception.CommandRunException;
|
||||
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
import net.bigeon.gclc.socket.ConnexionManager;
|
||||
|
||||
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
* @param <T> the type of connected object */
|
||||
public final class ConnexionListCommand<T> extends Command {
|
||||
|
||||
/** The connexion manager. */
|
||||
private final ConnexionManager<T> manager;
|
||||
|
||||
/** Create the connexion listing command.
|
||||
*
|
||||
* @param name the command name
|
||||
* @param manager the manager */
|
||||
public ConnexionListCommand(final String name, final ConnexionManager<T> manager) {
|
||||
super(name);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @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 Collection<String> coll = manager.getConnected();
|
||||
try {
|
||||
for (final String string : coll) {
|
||||
out.println(string);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
"User cannot be notified", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@Override
|
||||
public String tip() {
|
||||
return "List current connexions."; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommand.java
|
||||
* Created on: Nov 18, 2017
|
||||
*/
|
||||
package net.bigeon.gclc.socket.cmd;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
* 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,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
* #L%
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.bigeon.gclc.command.Command;
|
||||
import net.bigeon.gclc.exception.CommandRunException;
|
||||
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
import net.bigeon.gclc.socket.ConnexionManager;
|
||||
|
||||
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
* @param <T> the type of connected object */
|
||||
public final class RemoteDisconnectCommand<T> extends Command {
|
||||
|
||||
/** The connexion manager. */
|
||||
private final ConnexionManager<T> manager;
|
||||
/** If all connexion should be disconnected when no argument have been
|
||||
* specified. */
|
||||
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<T> manager,
|
||||
final boolean all) {
|
||||
super(name);
|
||||
this.manager = manager;
|
||||
this.all = all;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @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 {
|
||||
if (args.length == 0 && all) {
|
||||
final Collection<String> coll = manager.getConnected();
|
||||
for (final String string : coll) {
|
||||
manager.disconnect(string);
|
||||
}
|
||||
}
|
||||
for (final String string : args) {
|
||||
if (manager.isConnected(string)) {
|
||||
manager.disconnect(string);
|
||||
} else {
|
||||
print(out,
|
||||
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Print a message if the output is defined.
|
||||
*
|
||||
* @param out the output
|
||||
* @param string the message
|
||||
* @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,
|
||||
"Unable to print to existing output", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@Override
|
||||
public String tip() {
|
||||
return "Close a connexion."; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||
@Override
|
||||
protected String usageDetail() {
|
||||
final StringBuilder builder = new StringBuilder(
|
||||
" If arguments are provided the corresponding connexions are closed, otherwise\n");
|
||||
if (all) {
|
||||
builder.append("all connections");
|
||||
} else {
|
||||
builder.append("none");
|
||||
}
|
||||
builder.append(" are.");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.socket.cmd;
|
||||
@@ -66,6 +66,7 @@ public class TestServer {
|
||||
if (server == null) {
|
||||
server = new Thread(getShell(), "gclcServer");
|
||||
server.start();
|
||||
getShell().waitStartUp(500);
|
||||
}
|
||||
return server;
|
||||
}
|
||||
@@ -82,13 +83,7 @@ public class TestServer {
|
||||
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
||||
SHELL.setConnexionManager(manager);
|
||||
SHELL.setApplication(app);
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
app.start();
|
||||
}
|
||||
});
|
||||
final Thread th = new Thread(() -> app.start());
|
||||
th.start();
|
||||
try {
|
||||
final Object waiting = new Object();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommandTest.java
|
||||
* Created on: Nov 18, 2017
|
||||
*/
|
||||
package net.bigeon.gclc.socket;
|
||||
package net.bigeon.gclc.socket.cmd;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@@ -47,6 +47,7 @@ import org.junit.Test;
|
||||
|
||||
import net.bigeon.gclc.exception.CommandRunException;
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.socket.DConnexionManager;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -56,7 +57,7 @@ import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
public class RemoteDisconnectCommandTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.socket.RemoteDisconnectCommand#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
|
||||
* {@link net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
|
||||
*
|
||||
* @throws CommandRunException if the command unexpectedly failed.
|
||||
* @throws IOException if the output could not be written to */
|
||||
@@ -79,6 +79,9 @@ import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
||||
|
||||
/** A shell containing a {@link SWTConsoleView}
|
||||
* <p>
|
||||
|
||||
@@ -78,6 +78,9 @@ import org.eclipse.swt.widgets.Text;
|
||||
import net.bigeon.gclc.ConsoleApplication;
|
||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
||||
|
||||
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
||||
*
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
|
||||
* Created on: Nov 19, 2016
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.api;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.api;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt.api;
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.io;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@@ -42,6 +42,7 @@ import java.io.IOException;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||
|
||||
/** The object managing the console input.
|
||||
*
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.io;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@@ -40,6 +40,8 @@ package net.bigeon.gclc.swt;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
||||
import net.bigeon.gclc.swt.tools.TextAppendingRunnable;
|
||||
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
||||
|
||||
/** The manager for console output to insert in a text.
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.io;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt.io;
|
||||
@@ -33,7 +33,7 @@
|
||||
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
|
||||
* Created on: Jun 9, 2016
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
@@ -78,6 +78,7 @@ import org.eclipse.swt.events.KeyEvent;
|
||||
|
||||
import net.bigeon.collections.Ribbon;
|
||||
import net.bigeon.collections.ribbon.ArrayRibbon;
|
||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||
|
||||
/** A key listener to validate commands and manage the history of commands.
|
||||
*
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.bigeon.gclc.swt;
|
||||
package net.bigeon.gclc.swt.tools;
|
||||
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
@@ -33,4 +33,4 @@ public class TextAppendingRunnable implements Runnable {
|
||||
}
|
||||
text.append(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,12 @@ import org.eclipse.swt.widgets.Widget;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
||||
import net.bigeon.gclc.swt.ConsoleOutputDisplay;
|
||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
||||
|
||||
/** The local implementation of the forwarding runnable.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public final class ToSWTConsoleForwardRunnable
|
||||
extends AOutputForwardRunnable {
|
||||
public final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
||||
/** The running status. */
|
||||
private boolean running = true;
|
||||
/** The console output. */
|
||||
@@ -65,4 +64,4 @@ public final class ToSWTConsoleForwardRunnable
|
||||
public PipedConsoleOutput getOuput() {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.eclipse.swt.widgets.Text;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||
|
||||
/** @author Emmanuel Bigeon */
|
||||
public class ConsoleInputManagerTest {
|
||||
@@ -55,7 +56,7 @@ public class ConsoleInputManagerTest {
|
||||
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#setInput(java.lang.String)}. */
|
||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#setInput(java.lang.String)}. */
|
||||
@Test
|
||||
public void testSetText() {
|
||||
cim.setInput("Text");
|
||||
@@ -63,7 +64,7 @@ public class ConsoleInputManagerTest {
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#validateInput()}.
|
||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#validateInput()}.
|
||||
*
|
||||
* @throws IOException if an error occurred */
|
||||
@Test
|
||||
@@ -101,7 +102,7 @@ public class ConsoleInputManagerTest {
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#getText()}. */
|
||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#getText()}. */
|
||||
@Test
|
||||
public void testGetText() {
|
||||
assertEquals("Text component should be preserved", text, cim.getText());
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||
|
||||
/** @author Emmanuel Bigeon */
|
||||
public class ConsoleOutputManagerTest {
|
||||
@@ -71,7 +72,7 @@ public class ConsoleOutputManagerTest {
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||
* {@link net.bigeon.gclc.swt.io.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||
@Test
|
||||
public void testAppendConsoleOutput() {
|
||||
when(text.getText()).thenReturn("", "abc",
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.io.BufferedReader;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
@@ -56,7 +58,7 @@ public class ConsolePromptManagerTest {
|
||||
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
||||
|
||||
/**
|
||||
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setPrompt(java.lang.String)}.
|
||||
* Test method for {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setPrompt(java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetPrompt() {
|
||||
@@ -65,7 +67,7 @@ public class ConsolePromptManagerTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
||||
* Test method for {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetStream() {
|
||||
|
||||
@@ -75,6 +75,9 @@ import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.KeyEvent;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
@@ -83,7 +86,7 @@ import org.junit.Test;
|
||||
public class HistoryTextKeyListenerTest {
|
||||
|
||||
/** Test method for
|
||||
* {@link net.bigeon.gclc.swt.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
|
||||
* {@link net.bigeon.gclc.swt.tools.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
|
||||
@Test
|
||||
public final void testKeyPressedKeyEvent() {
|
||||
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</parent>
|
||||
<groupId>net.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>2.1.1-SNAPSHOT</version>
|
||||
<version>2.1.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Generic Command Ligne console</name>
|
||||
<description>A generic framework for console applications, with customized command input and output streams.</description>
|
||||
@@ -37,7 +37,7 @@
|
||||
</developers>
|
||||
<scm>
|
||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
<tag>gclc-2.1.2</tag>
|
||||
</scm>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -164,7 +164,7 @@ public final class GCLCConstants {
|
||||
}
|
||||
if (startIndex < cmd.length()) {
|
||||
final String arg = cmd.substring(startIndex, cmd.length());
|
||||
args.add(arg);
|
||||
args.add(removeEscaped(arg));
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,9 @@ public abstract class Command implements ICommand {
|
||||
* @param name the command name */
|
||||
public Command(final String name) {
|
||||
super();
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("The command name is mandatory");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public final class ScriptExecution extends Command {
|
||||
try (InputStreamReader fReader = new InputStreamReader(
|
||||
Files.newInputStream(Paths.get(scriptFile)), charset);
|
||||
BufferedReader reader = new BufferedReader(fReader)) {
|
||||
String[] emptyArray = new String[0];
|
||||
final String[] emptyArray = new String[0];
|
||||
while ((cmd = reader.readLine()) != null) {
|
||||
lineNo++;
|
||||
final String cmdLine = readCommandLine(cmd, params);
|
||||
@@ -237,10 +237,16 @@ public final class ScriptExecution extends Command {
|
||||
* @return the exception to actually throw */
|
||||
private static CommandRunException manageRunException(final CommandRunException e,
|
||||
final int lineNo) {
|
||||
final StringBuilder builder = new StringBuilder(e.getLocalizedMessage());
|
||||
int index = builder.indexOf("\n");
|
||||
while (index > 0) {
|
||||
builder.insert(index + 1, " ");
|
||||
index = builder.indexOf("\n", index + 1);
|
||||
}
|
||||
return new CommandRunException(CommandRunExceptionType.EXECUTION,
|
||||
MessageFormat.format(
|
||||
"The script could not complete due to command failure at line {0} ({1})", //$NON-NLS-1$
|
||||
Integer.valueOf(lineNo), e.getLocalizedMessage()),
|
||||
"The script could not complete due to command failure at line {0}\n {1})", //$NON-NLS-1$
|
||||
Integer.valueOf(lineNo + 1), builder),
|
||||
e);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,48 +40,12 @@ package net.bigeon.gclc.manager;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/*-
|
||||
* #%L
|
||||
* Generic Command Ligne console
|
||||
* %%
|
||||
* 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,
|
||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||
* "http://www.cecill.info".
|
||||
*
|
||||
* As a counterpart to the access to the source code and rights to copy,
|
||||
* modify and redistribute granted by the license, users are provided only
|
||||
* with a limited warranty and the software's author, the holder of the
|
||||
* economic rights, and the successive licensors have only limited
|
||||
* liability.
|
||||
*
|
||||
* In this respect, the user's attention is drawn to the risks associated
|
||||
* with loading, using, modifying and/or developing or reproducing the
|
||||
* software by the user in light of its specific status of free software,
|
||||
* that may mean that it is complicated to manipulate, and that also
|
||||
* therefore means that it is reserved for developers and experienced
|
||||
* professionals having in-depth computer knowledge. Users are therefore
|
||||
* encouraged to load and test the software's suitability as regards their
|
||||
* requirements in conditions enabling the security of their systems and/or
|
||||
* data to be ensured and, more generally, to use and operate it in the
|
||||
* same conditions as regards security.
|
||||
*
|
||||
* The fact that you are presently reading this means that you have had
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import net.bigeon.gclc.tools.ConstantString;
|
||||
|
||||
/** A console input that return empty to all prompting.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public final class EmptyInput implements ConsoleInput {
|
||||
|
||||
private static final ConstantString CONSTANT_STRING = new ConstantString("");
|
||||
private static final Supplier<String> CONSTANT_STRING = () -> "";
|
||||
/** The empty prompter. */
|
||||
public static final ConsoleInput INSTANCE = new EmptyInput();
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ import java.io.PrintStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.bigeon.gclc.tools.ConstantString;
|
||||
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||
|
||||
/** A console using the input stream and print stream.
|
||||
@@ -90,7 +89,7 @@ import net.bigeon.gclc.utils.ReadingRunnable;
|
||||
public final class StreamConsoleInput implements ConsoleInput {
|
||||
|
||||
/** The default prompt. */
|
||||
public static final Supplier<String> DEFAULT_PROMPT = new ConstantString("> "); //$NON-NLS-1$
|
||||
public static final Supplier<String> DEFAULT_PROMPT = () -> ("> "); //$NON-NLS-1$
|
||||
|
||||
/** The command prompt. It can be changed. */
|
||||
private Supplier<String> prompt = DEFAULT_PROMPT;
|
||||
@@ -213,7 +212,7 @@ public final class StreamConsoleInput implements ConsoleInput {
|
||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||
@Override
|
||||
public void setPrompt(final String prompt) {
|
||||
this.prompt = new ConstantString(prompt);
|
||||
this.prompt = () -> (prompt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,7 +73,9 @@ import java.util.function.Supplier;
|
||||
|
||||
/** A supplier of string that hold a constant string.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
* @author Emmanuel Bigeon
|
||||
* @deprecated since 2.1.2, use a lambda expression instead */
|
||||
@Deprecated
|
||||
public class ConstantString implements Supplier<String> {
|
||||
private final String string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user