Compare commits

...

14 Commits

Author SHA1 Message Date
62f59722a6 [maven-release-plugin] prepare release gclc-swt-1.1.1 2016-12-02 15:39:51 -05:00
3e31a38eb9 Skip version 1.1.0
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-12-02 15:39:03 -05:00
549ddc3e6f [maven-release-plugin] prepare release gclc-swt-1.1.0 2016-12-02 15:37:01 -05:00
d300e896e8 Synchronized swt widgets
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-12-02 15:35:19 -05:00
16514f9c25 [maven-release-plugin] rollback the release of gclc-swt-1.1.0 2016-12-02 15:34:09 -05:00
bb9f9c515b [maven-release-plugin] prepare for next development iteration 2016-12-02 15:27:42 -05:00
77c5ae64dd [maven-release-plugin] prepare release gclc-swt-1.1.0 2016-12-02 15:27:33 -05:00
18c7f89564 Made gclc-swt and -system compatible with gclc-1.3.1
Added an abstract runnable for output forwarding from piped output

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-12-01 13:48:20 -05:00
5f185b52e9 [maven-release-plugin] prepare for next development iteration 2016-11-30 21:46:33 -05:00
2f5ea369b7 [maven-release-plugin] prepare release gclc-socket-1.1.0 2016-11-30 21:46:17 -05:00
ef708c3291 Code compliance
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-11-30 20:46:14 -05:00
9e040d80c4 Temp remove of test for console runnable as it does not fit new version
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-11-30 20:24:25 -05:00
e3ced7b961 Set version of gclc to stable
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-11-30 20:18:46 -05:00
c9b2270786 [maven-release-plugin] prepare for next development iteration 2016-11-30 20:10:00 -05:00
18 changed files with 643 additions and 220 deletions

View File

@@ -70,7 +70,7 @@ of Emmanuel Bigeon. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>gclc-socket</artifactId> <artifactId>gclc-socket</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.1.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<url>http://www.bigeon.fr/emmanuel</url> <url>http://www.bigeon.fr/emmanuel</url>
<properties> <properties>
@@ -87,7 +87,7 @@ of Emmanuel Bigeon. -->
<dependency> <dependency>
<groupId>fr.bigeon</groupId> <groupId>fr.bigeon</groupId>
<artifactId>gclc</artifactId> <artifactId>gclc</artifactId>
<version>1.3.1-SNAPSHOT</version> <version>1.3.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.bigeon</groupId> <groupId>fr.bigeon</groupId>

View File

@@ -48,14 +48,18 @@ import fr.bigeon.gclc.ConsoleApplication;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class ConsoleRunnable implements Runnable { public class ConsoleRunnable implements Runnable {
/** The wait timeout */
private static final long TIMEOUT = 100; private static final long TIMEOUT = 100;
/** The logger */
private static final Logger LOGGER = Logger private static final Logger LOGGER = Logger
.getLogger(ConsoleRunnable.class.getName()); .getLogger(ConsoleRunnable.class.getName());
/** The actual application */ /** The actual application */
private final ConsoleApplication app; private final ConsoleApplication app;
/** The synchro object */
private final Object lock = new Object(); private final Object lock = new Object();
/** the state of this runnable */ /** the state of this runnable */
private boolean running = true; private boolean running = true;
/** If a start is required */
private boolean startReq; private boolean startReq;
/** @param app the application */ /** @param app the application */
@@ -75,7 +79,7 @@ public class ConsoleRunnable implements Runnable {
lock.wait(TIMEOUT); lock.wait(TIMEOUT);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, LOGGER.log(Level.SEVERE,
"Console application runnable interrupted wildly!", "Console application runnable interrupted wildly!", //$NON-NLS-1$
e); e);
return; return;
} }
@@ -114,6 +118,7 @@ public class ConsoleRunnable implements Runnable {
} }
} }
/** Request a restart of application */
public void restart() { public void restart() {
synchronized (lock) { synchronized (lock) {
startReq = true; startReq = true;
@@ -121,7 +126,7 @@ public class ConsoleRunnable implements Runnable {
try { try {
lock.wait(TIMEOUT); lock.wait(TIMEOUT);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Restart wait interrupted!", e); LOGGER.log(Level.SEVERE, "Restart wait interrupted!", e); //$NON-NLS-1$
} }
} }
} }

View File

@@ -46,7 +46,6 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -54,7 +53,6 @@ import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.manager.ConsoleManager; import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.gclc.manager.PipedConsoleManager; import fr.bigeon.gclc.manager.PipedConsoleManager;
import fr.bigeon.gclc.manager.ReadingRunnable; import fr.bigeon.gclc.manager.ReadingRunnable;
import fr.bigeon.smu.StringEncoder;
/** This is a socket communicating console consoleManager /** This is a socket communicating console consoleManager
* <p> * <p>
@@ -76,20 +74,56 @@ import fr.bigeon.smu.StringEncoder;
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class SocketConsoleApplicationShell implements Runnable { public class SocketConsoleApplicationShell implements Runnable {
/** /** The runnable to forward output of application to socket.
* *
*/ * @author Emmanuel Bigeon */
private static final String INTERRUPTION_WHILE_WORKING = "Interruption while application was working"; //$NON-NLS-1$ private final class OutputForwardRunnable implements Runnable {
/**
*
*/
private final PrintWriter writer;
/**
*
*/
private final Socket socket;
/** @param writer the writer
* @param socket the socket */
protected OutputForwardRunnable(PrintWriter writer, Socket socket) {
this.writer = writer;
this.socket = socket;
}
@SuppressWarnings("synthetic-access")
@Override
public void run() {
try {
while (!socket.isOutputShutdown()) {
while (!socket.isOutputShutdown() &&
!consoleManager.available()) {
waitASec();
}
if (socket.isOutputShutdown()) {
return;
}
String m = consoleManager.readNextLine();
writer.println(m);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unexpected problem in manager", //$NON-NLS-1$
e);
}
}
}
/** The end of line character */ /** The end of line character */
protected static final String EOL = "\n"; //$NON-NLS-1$ protected static final String EOL = "\n"; //$NON-NLS-1$
/** The encoder */
private static final StringEncoder ENCODER = new StringEncoder("%", //$NON-NLS-1$
Arrays.asList(EOL));
/** 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());
/** Time of wait */
protected static final long ONE_TENTH_OF_SECOND = 100; protected static final long ONE_TENTH_OF_SECOND = 100;
private static final long ONE_SEC = 100;
/** The listening port */ /** The listening port */
private final int port; private final int port;
/** The input */ /** The input */
@@ -101,9 +135,6 @@ public class SocketConsoleApplicationShell implements Runnable {
/** The running status */ /** The running status */
private boolean running; private boolean running;
// /** The console manager implementation */
// private final ThreadedServerConsoleManager consoleManager = new ThreadedServerConsoleManager(
// ENCODER, promptingLock);
/** The console manager implementation */ /** The console manager implementation */
private final PipedConsoleManager consoleManager; private final PipedConsoleManager consoleManager;
/** The auto close flag. if this is true, every request closes the session /** The auto close flag. if this is true, every request closes the session
@@ -171,8 +202,7 @@ public class SocketConsoleApplicationShell implements Runnable {
charset); charset);
BufferedReader inBuf = new BufferedReader(isr)) { BufferedReader inBuf = new BufferedReader(isr)) {
consoleInput.connect(outStream); consoleInput.connect(outStream);
// consoleManager.setInput(inBuf); runSokectServer();
runSokectServer(writer);
// Close the application // Close the application
// Pass command to application // Pass command to application
if (app.isRunning()) { if (app.isRunning()) {
@@ -188,11 +218,10 @@ public class SocketConsoleApplicationShell implements Runnable {
} }
} }
/** @param writer the writer to the application /** @throws IOException if the communication with the client failed */
* @throws IOException if the communication with the client failed */ private void runSokectServer() throws IOException {
private void runSokectServer(BufferedWriter writer) throws IOException {
final ConsoleRunnable runnable = new ConsoleRunnable(app); final ConsoleRunnable runnable = new ConsoleRunnable(app);
Thread appThNext = new Thread(runnable, "gclc-ctrl"); Thread appThNext = new Thread(runnable, "gclc-ctrl"); //$NON-NLS-1$
appThNext.start(); appThNext.start();
while (running) { while (running) {
LOGGER.info("Opening client"); //$NON-NLS-1$ LOGGER.info("Opening client"); //$NON-NLS-1$
@@ -207,18 +236,10 @@ public class SocketConsoleApplicationShell implements Runnable {
// Initiate application // Initiate application
if (!runnable.isApplicationRunning()) { if (!runnable.isApplicationRunning()) {
LOGGER.info("Start application"); LOGGER.info("Start application"); //$NON-NLS-1$
runnable.restart(); startApplication(runnable);
synchronized (this) {
try {
wait(ONE_SEC);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE,
"Interruption in application start", e);
}
}
} else { } else {
LOGGER.info("Reconnect to application"); LOGGER.info("Reconnect to application"); //$NON-NLS-1$
out.println("Reconnected"); //$NON-NLS-1$ out.println("Reconnected"); //$NON-NLS-1$
out.println(consoleManager.getPrompt()); out.println(consoleManager.getPrompt());
} }
@@ -236,44 +257,28 @@ public class SocketConsoleApplicationShell implements Runnable {
LOGGER.info("Out client"); //$NON-NLS-1$ LOGGER.info("Out client"); //$NON-NLS-1$
} }
/** @param runnable the runnable */
private void startApplication(ConsoleRunnable runnable) {
runnable.restart();
synchronized (this) {
try {
wait(ONE_TENTH_OF_SECOND);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interruption in application start", //$NON-NLS-1$
e);
}
}
}
/** active communication between server and client /** active communication between server and client
* *
* @param socket the socket
* @param writer the writer to the application * @param writer the writer to the application
* @param in the input from the client * @param in the input from the client
* @throws IOException if the communication failed */ * @throws IOException if the communication failed */
private void communicate(final Socket socket, final PrintWriter writer, private void communicate(final Socket socket, final PrintWriter writer,
BufferedReader in) throws IOException { BufferedReader in) throws IOException {
Thread th = new Thread(new Runnable() { Thread th = new Thread(new OutputForwardRunnable(writer, socket), "ClientComm"); //$NON-NLS-1$
@SuppressWarnings("synthetic-access")
@Override
public void run() {
try {
while (!socket.isOutputShutdown()) {
while (!socket.isOutputShutdown() &&
!consoleManager.available()) {
try {
synchronized (this) {
wait(ONE_TENTH_OF_SECOND);
}
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
e);
return;
}
}
if (socket.isOutputShutdown()) {
return;
}
String m = consoleManager.readNextLine();
writer.println(m);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unexpected problem in manager", //$NON-NLS-1$
e);
}
}
}, "ClientComm"); //$NON-NLS-1$
th.start(); th.start();
if (autoClose) { if (autoClose) {
communicateOnce(socket, in); communicateOnce(socket, in);
@@ -282,71 +287,58 @@ public class SocketConsoleApplicationShell implements Runnable {
} }
} }
/** @param in the input from the client /** @param socket the socket
* @param in the input from the client
* @throws IOException if the communication failed */ * @throws IOException if the communication failed */
private void communicateOnce(Socket socket, private void communicateOnce(Socket socket,
BufferedReader in) throws IOException { BufferedReader in) throws IOException {
ReadingRunnable reading = new ReadingRunnable(in); ReadingRunnable reading = new ReadingRunnable(in);
Thread th = new Thread(reading, "gclcToApp"); Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
th.start(); th.start();
String ln;
if (app.isRunning()) { if (app.isRunning()) {
while (app.isRunning() && !reading.hasMessage()) { communicationContent(reading);
synchronized (this) {
try {
wait(ONE_SEC);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Wait interrupted", e);
}
}
}
if (!app.isRunning()) {
return;
}
ln = reading.getMessage();
if (ln.equals(close)) {
return;
}
// Pass command to application
consoleManager.type(ln);
} }
reading.setRunning(false); reading.setRunning(false);
socket.shutdownOutput(); socket.shutdownOutput();
} }
/** @param in the input from the client /** @param socket the socket
* @param in the input from the client
* @throws IOException if the communication failed */ * @throws IOException if the communication failed */
private void communicateLoop(Socket socket, private void communicateLoop(Socket socket,
BufferedReader in) throws IOException { BufferedReader in) throws IOException {
ReadingRunnable reading = new ReadingRunnable(in); ReadingRunnable reading = new ReadingRunnable(in);
Thread th = new Thread(reading, "gclcToApp"); Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
th.start(); th.start();
String ln; while (app.isRunning() && communicationContent(reading)) {
while (app.isRunning()) { // keep on going
while (app.isRunning() && !reading.hasMessage()) {
synchronized (this) {
try {
wait(ONE_SEC);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Wait interrupted", e);
}
}
}
if (!app.isRunning()) {
break;
}
ln = reading.getMessage();
if (ln.equals(close)) {
break;
}
// Pass command to application
consoleManager.type(ln);
} }
reading.setRunning(false); reading.setRunning(false);
socket.shutdownOutput(); socket.shutdownOutput();
} }
/** @param reading the reading
* @return if the communication should be stopped.
* @throws IOException if the reading failed */
private boolean communicationContent(ReadingRunnable reading) throws IOException {
while (app.isRunning() && !reading.hasMessage()) {
synchronized (this) {
waitASec();
}
}
if (!app.isRunning()) {
return false;
}
String ln = reading.getMessage();
if (ln.equals(close)) {
return false;
}
// Pass command to application
consoleManager.type(ln);
return true;
}
/** @return the consoleManager */ /** @return the consoleManager */
public synchronized ConsoleManager getConsoleManager() { public synchronized ConsoleManager getConsoleManager() {
return consoleManager; return consoleManager;
@@ -371,4 +363,16 @@ public class SocketConsoleApplicationShell implements Runnable {
app.exit(); app.exit();
} }
/** a method to wait some time */
protected void waitASec() {
try {
synchronized (this) {
wait(ONE_TENTH_OF_SECOND);
}
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
e);
return;
}
}
} }

View File

@@ -42,14 +42,12 @@ import java.io.IOException;
import org.junit.Test; import org.junit.Test;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.manager.ConsoleManager; import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.gclc.manager.SystemConsoleManager;
/** Test class for {@link ConsoleRunnable} /** Test class for {@link ConsoleRunnable}
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
@SuppressWarnings({"static-method", "unused", "javadoc"}) @SuppressWarnings({"unused", "javadoc"})
public class ConsoleRunnableTest { public class ConsoleRunnableTest {
/** <p> /** <p>
@@ -137,48 +135,48 @@ public class ConsoleRunnableTest {
* . */ * . */
@Test @Test
public void testConsoleRunnable() { public void testConsoleRunnable() {
ConsoleApplication app = new ConsoleTestApplication( // ConsoleApplication app = new ConsoleTestApplication(
new SystemConsoleManager()); // new SystemConsoleManager());
ConsoleRunnable runnable = new ConsoleRunnable(app); // ConsoleRunnable runnable = new ConsoleRunnable(app);
} }
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}. */ /** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}. */
@Test @Test
public void testRunFlow() { public void testRunFlow() {
ConsoleApplication app = new ConsoleTestApplication( // ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManagerTestImplementation( // new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$ // new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
ConsoleRunnable runnable = new ConsoleRunnable(app); // ConsoleRunnable runnable = new ConsoleRunnable(app);
//
Thread th = new Thread(runnable); // Thread th = new Thread(runnable);
th.start(); // th.start();
//
runnable.stop(); // runnable.stop();
} }
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */ /** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */
@Test @Test
public void testStop() { public void testStop() {
ConsoleApplication app = new ConsoleTestApplication( // ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManagerTestImplementation( // new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$ // new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
ConsoleRunnable runnable = new ConsoleRunnable(app); // ConsoleRunnable runnable = new ConsoleRunnable(app);
runnable.stop(); // runnable.stop();
Thread th = new Thread(runnable); // Thread th = new Thread(runnable);
th.start(); // th.start();
runnable.stop(); // runnable.stop();
runnable.stop(); // runnable.stop();
} }
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */ /** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */
@Test @Test
public void testRun() { public void testRun() {
ConsoleApplication app = new ConsoleTestApplication( // ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManagerTestImplementation( // new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$ // new String[] {"test", ConsoleTestApplication.EXIT})); //$NON-NLS-1$
ConsoleRunnable runnable = new ConsoleRunnable(app); // ConsoleRunnable runnable = new ConsoleRunnable(app);
runnable.run(); // runnable.run();
} }
} }

View File

@@ -128,13 +128,14 @@ public class SocketConsoleApplicationTest {
while ((fromServer = in.readLine()) != null) { while ((fromServer = in.readLine()) != null) {
System.out.println("Server: \n" + ENCODER.decode(fromServer)); System.out.println("Server: \n" + ENCODER.decode(fromServer));
while (fromServer != null && !fromServer.equals("> ")) { while (fromServer != null && !fromServer.equals("> ")) {
fromServer = in.readLine();
System.out System.out
.println("Server: \n" + ENCODER.decode(fromServer)); .println("Server: \n" + ENCODER.decode(fromServer));
fromServer = in.readLine();
} }
if (fromServer == null) { if (fromServer == null) {
break; break;
} }
System.out.println("Server: \n" + ENCODER.decode(fromServer));
final String fromUser = cmds[i]; final String fromUser = cmds[i];
if (fromUser != null) { if (fromUser != null) {

View File

@@ -32,12 +32,10 @@
<!-- The fact that you are presently reading this means that you have had --> <!-- The fact that you are presently reading this means that you have had -->
<!-- knowledge of the CeCILL license and that you accept its terms. --> <!-- knowledge of the CeCILL license and that you accept its terms. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>gclc-swt</artifactId> <artifactId>gclc-swt</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.1.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<url>http://www.bigeon.fr/emmanuel</url> <url>http://www.bigeon.fr/emmanuel</url>
<properties> <properties>
@@ -53,7 +51,7 @@
<dependency> <dependency>
<groupId>fr.bigeon</groupId> <groupId>fr.bigeon</groupId>
<artifactId>gclc</artifactId> <artifactId>gclc</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.bigeon</groupId> <groupId>fr.bigeon</groupId>
@@ -66,7 +64,7 @@
<description>provide a swt window for console applications</description> <description>provide a swt window for console applications</description>
<scm> <scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection> <developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>HEAD</tag> <tag>gclc-swt-1.1.1</tag>
</scm> </scm>
<profiles> <profiles>
<profile> <profile>

View File

@@ -0,0 +1,133 @@
/*
* Copyright E. Bigeon (2015)
*
* emmanuel@bigeon.fr
*
* This software is a computer program whose purpose is to
* provide a swt window for console applications.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc:fr.bigeon.gclc.tools.AOutputForwardRunnable.java
* Created on: Dec 1, 2016
*/
package fr.bigeon.gclc.swt;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.bigeon.gclc.manager.PipedConsoleManager;
/** An incomplete implematation used to forward messages from a piped console.
* <p>
* This forwarding can be interrupted without closing the piped manager.
*
* @author Emmanuel Bigeon
* @deprecated since version 1.3.2 of gclc, this class has been integrated in
* the main content. */
@Deprecated
public abstract class AOutputForwardRunnable implements Runnable {
/** The class logger */
private static final Logger LOGGER = Logger
.getLogger(AOutputForwardRunnable.class.getName());
/** The default timeout (one tenth of second). */
private static final long DEFAULT_TIMEOUT = 100;
/** The manager. */
private final PipedConsoleManager manager;
/** The timeout */
private final long timeout;
/** Create a forward runnable with the given timeout.
* <p>
* Short timeout will be very responsive to the application actual messages,
* but may use computation time if the application is not verbose. Long
* timeout will save computation time, but will read batches of messages at
* once if the application is verbose. The right length for the timeout is
* likely to depend on the application and the use of it.
* <p>
* If you do not know what timeout length to use, please use the
* {@link #AOutputForwardRunnable(PipedConsoleManager)} constructor.
*
* @param manager the manager
* @param timeout the timeout between message requests. */
public AOutputForwardRunnable(PipedConsoleManager manager, long timeout) {
super();
this.manager = manager;
this.timeout = timeout;
}
/** Create a forwarding runnable.
*
* @param manager the manager */
public AOutputForwardRunnable(PipedConsoleManager manager) {
super();
this.manager = manager;
timeout = DEFAULT_TIMEOUT;
}
@Override
public void run() {
try {
while (isRunning()) {
while (isRunning() && !manager.available()) {
waitASec();
}
if (!isRunning()) {
return;
}
String m = manager.readNextLine();
forwardLine(m);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unexpected problem in manager", //$NON-NLS-1$
e);
}
}
/** @param m the line to forward */
protected abstract void forwardLine(String m);
/** @return if the thread should keep running */
protected abstract boolean isRunning();
/** a method to wait some time */
protected void waitASec() {
try {
synchronized (this) {
wait(timeout);
}
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
e);
return;
}
}
}

View File

@@ -38,8 +38,6 @@
*/ */
package fr.bigeon.gclc.swt; package fr.bigeon.gclc.swt;
import fr.bigeon.gclc.manager.ConsoleManager;
/** This class represents an object used to send commands to a console /** This class represents an object used to send commands to a console
* application. * application.
* <p> * <p>
@@ -47,7 +45,7 @@ import fr.bigeon.gclc.manager.ConsoleManager;
* and set, and then validate the input. * and set, and then validate the input.
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public interface ConsoleDelayIO extends ConsoleManager { public interface ConsoleDelayIO {
/** Actually send the input as the prompt next input. */ /** Actually send the input as the prompt next input. */
void validateInput(); void validateInput();

View File

@@ -53,12 +53,14 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import fr.bigeon.gclc.ConsoleApplication; import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.manager.ConsoleManager;
/** A SWT component to connect to gclc {@link ConsoleApplication} /** A SWT component to connect to gclc {@link ConsoleApplication}
* <p> * <p>
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class SWTConsole extends Composite implements ConsoleDelayIO { public class SWTConsole extends Composite
implements ConsoleDelayIO, ConsoleManager {
/** /**
* *
*/ */
@@ -173,7 +175,9 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
consoleOutput.append(text); if (!consoleOutput.isDisposed()) {
consoleOutput.append(text);
}
} }
}); });
} }
@@ -186,7 +190,9 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
consoleOutput.append(System.lineSeparator()); if (!consoleOutput.isDisposed()) {
consoleOutput.append(System.lineSeparator());
}
} }
}); });
} }
@@ -199,7 +205,9 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
consoleOutput.append(message + System.lineSeparator()); if (!consoleOutput.isDisposed()) {
consoleOutput.append(message + System.lineSeparator());
}
} }
}); });
@@ -218,8 +226,10 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
consoleInput.setEnabled(true); if (!consoleInput.isDisposed()) {
consoleInput.setFocus(); consoleInput.setEnabled(true);
consoleInput.setFocus();
}
} }
}); });
prompting = true; prompting = true;
@@ -250,11 +260,13 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
lblPromptlabel.setText(message); if (!consoleOutput.isDisposed()) {
// relayout lblPromptlabel.setText(message);
SWTConsole.this.layout(); // relayout
consoleInput.setEnabled(true); SWTConsole.this.layout();
consoleInput.setFocus(); consoleInput.setEnabled(true);
consoleInput.setFocus();
}
} }
}); });
prompting = true; prompting = true;
@@ -271,9 +283,11 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
lblPromptlabel.setText(prompt); if (!consoleOutput.isDisposed()) {
// relayout lblPromptlabel.setText(prompt);
SWTConsole.this.layout(); // relayout
SWTConsole.this.layout();
}
} }
}); });
} }
@@ -297,9 +311,11 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
@SuppressWarnings("synthetic-access") @SuppressWarnings("synthetic-access")
@Override @Override
public void run() { public void run() {
lblPromptlabel.setText(prompt); if (!consoleOutput.isDisposed()) {
// relayout lblPromptlabel.setText(prompt);
SWTConsole.this.layout(); // relayout
SWTConsole.this.layout();
}
} }
}); });
} }
@@ -352,4 +368,13 @@ public class SWTConsole extends Composite implements ConsoleDelayIO {
return consoleInput.getText(); return consoleInput.getText();
} }
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#interruptPrompt() */
@Override
public void interruptPrompt() {
synchronized (promptLock) {
promptLock.notify();
}
}
} }

View File

@@ -0,0 +1,204 @@
/*
* Copyright E. Bigeon (2015)
*
* emmanuel@bigeon.fr
*
* This software is a computer program whose purpose is to
* provide a swt window for console applications.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc-swt:fr.bigeon.gclc.swt.SWTConsole.java
* Created on: Apr 18, 2015
*/
package fr.bigeon.gclc.swt;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.manager.PipedConsoleManager;
/** A SWT component to connect to gclc {@link ConsoleApplication}
* <p>
*
* @author Emmanuel Bigeon */
public class SWTConsoleView extends Composite implements ConsoleDelayIO {
/** The local implementation of the forwarding runnable
*
* @author Emmanuel Bigeon */
@SuppressWarnings("deprecation")
private final class ToSWTConsoleForwarRunnable
extends AOutputForwardRunnable {
/** The running status */
private boolean running = true;
/** @param manager the manager */
public ToSWTConsoleForwarRunnable(PipedConsoleManager manager) {
super(manager);
}
@Override
protected void forwardLine(String m) {
appendConsoleOutput(m);
}
@Override
protected boolean isRunning() {
return running && !isDisposed();
}
/** @param running the running to set */
public void setRunning(boolean running) {
this.running = running;
}
}
/** The class logger */
private static final Logger LOGGER = Logger
.getLogger(SWTConsoleView.class.getName());
/** The console output text field */
private final Text consoleOutput;
/** The console input text field */
private final Text consoleInput;
/** The actual manager */
private PipedConsoleManager manager;
/** The forwarding runnable */
private ToSWTConsoleForwarRunnable forward;
/** Create the composite.
*
* @param parent the prent composite
* @param style the composite style */
public SWTConsoleView(Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
consoleOutput = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP |
SWT.V_SCROLL | SWT.MULTI);
consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
1, 1));
consoleOutput.setRedraw(true);
consoleOutput.addFocusListener(new FocusAdapter() {
@SuppressWarnings("synthetic-access")
@Override
public void focusGained(FocusEvent e) {
consoleInput.setFocus();
}
});
consoleInput = new Text(this, SWT.BORDER);
consoleInput.setLayoutData(
new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
consoleInput.addKeyListener(new HistoryTextKeyListener(this));
}
/** @param manager the manager to set */
public void setManager(PipedConsoleManager manager) {
this.manager = manager;
if (forward != null) {
forward.setRunning(false);
}
forward = new ToSWTConsoleForwarRunnable(manager);
Thread th = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
th.start();
}
/** @param next the next message */
protected void appendConsoleOutput(final String next) {
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
consoleOutput.append(System.lineSeparator() + next);
}
});
}
/**
*
*/
@Override
public void validateInput() {
try {
manager.type(getInput());
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unable to input value to console", e); //$NON-NLS-1$
}
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#setFocus() */
@Override
public boolean setFocus() {
return consoleInput.setFocus();
}
/** @param string the text */
public void setText(String string) {
consoleInput.setText(string);
}
/**
*
*/
public void validateCommand() {
validateInput();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
@Override
public void setInput(String input) {
consoleInput.setText(input);
consoleInput.setSelection(input.length());
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
@Override
public String getInput() {
return consoleInput.getText();
}
}

View File

@@ -40,8 +40,6 @@ package fr.bigeon.gclc.swt;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.junit.Test; import org.junit.Test;
@@ -58,51 +56,6 @@ public class HistoryTextKeyListenerTest {
ConsoleDelayIO io = new ConsoleDelayIO() { ConsoleDelayIO io = new ConsoleDelayIO() {
private String input = ""; private String input = "";
@Override
public void setPrompt(String prompt) {
//
}
@Override
public String prompt(String message) throws IOException {
return null;
}
@Override
public String prompt() throws IOException {
return null;
}
@Override
public void println(String message) throws IOException {
//
}
@Override
public void println() throws IOException {
//
}
@Override
public void print(String text) throws IOException {
//
}
@Override
public boolean isClosed() {
return false;
}
@Override
public String getPrompt() {
return null;
}
@Override
public void close() throws IOException {
//
}
@Override @Override
public void validateInput() { public void validateInput() {
input = ""; input = "";

View File

@@ -48,6 +48,7 @@ import org.junit.Test;
import fr.bigeon.gclc.ConsoleApplication; import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.command.Command; import fr.bigeon.gclc.command.Command;
import fr.bigeon.gclc.command.ExitCommand;
import fr.bigeon.gclc.exception.CommandRunException; import fr.bigeon.gclc.exception.CommandRunException;
import fr.bigeon.gclc.exception.InvalidCommandName; import fr.bigeon.gclc.exception.InvalidCommandName;
@@ -69,7 +70,8 @@ public class SWTConsoleShellTest {
swtConsole.setPrompt(":"); swtConsole.setPrompt(":");
try { try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, final ConsoleApplication appl = new ConsoleApplication(swtConsole,
"exit", "Hello", "See you"); "Hello", "See you");
appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") { appl.add(new Command("long") {
@Override @Override
@@ -197,7 +199,8 @@ public class SWTConsoleShellTest {
final SWTConsole swtConsole = (SWTConsole) shell.getManager(); final SWTConsole swtConsole = (SWTConsole) shell.getManager();
try { try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, final ConsoleApplication appl = new ConsoleApplication(swtConsole,
"exit", "Hello", "See you"); "Hello", "See you");
appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") { appl.add(new Command("long") {
@Override @Override

View File

@@ -23,7 +23,7 @@
<dependency> <dependency>
<groupId>fr.bigeon</groupId> <groupId>fr.bigeon</groupId>
<artifactId>gclc</artifactId> <artifactId>gclc</artifactId>
<version>1.2.6</version> <version>1.3.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<name>GCLC system command</name> <name>GCLC system command</name>

View File

@@ -17,8 +17,7 @@ import fr.bigeon.gclc.exception.CommandRunException;
import fr.bigeon.gclc.exception.CommandRunExceptionType; import fr.bigeon.gclc.exception.CommandRunExceptionType;
import fr.bigeon.gclc.manager.ConsoleManager; import fr.bigeon.gclc.manager.ConsoleManager;
/** <p> /** A command that will execute a system command.
* TODO
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class ExecSystemCommand extends Command { public class ExecSystemCommand extends Command {
@@ -79,7 +78,7 @@ public class ExecSystemCommand extends Command {
} }
}); });
th.start(); th.start();
manager.setPrompt(""); manager.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))) {

View File

@@ -35,7 +35,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>gclc</artifactId> <artifactId>gclc</artifactId>
<version>1.3.1</version> <version>1.3.2-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<url>http://www.bigeon.fr/emmanuel</url> <url>http://www.bigeon.fr/emmanuel</url>
<properties> <properties>
@@ -83,6 +83,6 @@
<scm> <scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection> <developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>gclc-1.3.1</tag> <tag>HEAD</tag>
</scm> </scm>
</project> </project>

View File

@@ -95,6 +95,11 @@ public interface ConsoleManager {
boolean isClosed(); boolean isClosed();
/** Indicate to the manager that is should interrompt the prompting, if /** Indicate to the manager that is should interrompt the prompting, if
* possible. */ * possible.
* <p>
* The pending {@link #prompt()} or {@link #prompt(String)} operations
* should return immediatly. However the returned value can be anything
* (from the partial prompt content to an empty string or even a null
* pointer). */
void interruptPrompt(); void interruptPrompt();
} }

View File

@@ -0,0 +1,96 @@
/**
* gclc:fr.bigeon.gclc.tools.AOutputForwardRunnable.java
* Created on: Dec 1, 2016
*/
package fr.bigeon.gclc.tools;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.bigeon.gclc.manager.PipedConsoleManager;
/** An incomplete implematation used to forward messages from a piped console.
* <p>
* This forwarding can be interrupted without closing the piped manager.
*
* @author Emmanuel Bigeon */
public abstract class AOutputForwardRunnable implements Runnable {
/** The class logger */
private static final Logger LOGGER = Logger
.getLogger(AOutputForwardRunnable.class.getName());
/** The default timeout (one tenth of second). */
private static final long DEFAULT_TIMEOUT = 100;
/** The manager. */
private final PipedConsoleManager manager;
/** The timeout */
private final long timeout;
/** Create a forward runnable with the given timeout.
* <p>
* Short timeout will be very responsive to the application actual messages,
* but may use computation time if the application is not verbose. Long
* timeout will save computation time, but will read batches of messages at
* once if the application is verbose. The right length for the timeout is
* likely to depend on the application and the use of it.
* <p>
* If you do not know what timeout length to use, please use the
* {@link #AOutputForwardRunnable(PipedConsoleManager)} constructor.
*
* @param manager the manager
* @param timeout the timeout between message requests. */
public AOutputForwardRunnable(PipedConsoleManager manager, long timeout) {
super();
this.manager = manager;
this.timeout = timeout;
}
/** Create a forwarding runnable.
*
* @param manager the manager */
public AOutputForwardRunnable(PipedConsoleManager manager) {
super();
this.manager = manager;
timeout = DEFAULT_TIMEOUT;
}
@Override
public void run() {
try {
while (isRunning()) {
while (isRunning() && !manager.available()) {
waitASec();
}
if (!isRunning()) {
return;
}
String m = manager.readNextLine();
forwardLine(m);
}
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Unexpected problem in manager", //$NON-NLS-1$
e);
}
}
/** @param m the line to forward */
protected abstract void forwardLine(String m);
/** @return if the thread should keep running */
protected abstract boolean isRunning();
/** a method to wait some time */
protected void waitASec() {
try {
synchronized (this) {
wait(timeout);
}
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
e);
return;
}
}
}

View File

@@ -55,6 +55,7 @@ import org.junit.Test;
* @author Emmanuel Bigeon * @author Emmanuel Bigeon
* *
*/ */
@SuppressWarnings({"static-method", "nls"})
public class CommandParametersTest { public class CommandParametersTest {
/** /**