Compare commits
31 Commits
gclc-2.0.1
...
gclc-2.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 012ef6e668 | |||
| 583f3146fd | |||
| 8b52ba5d49 | |||
| a3051c6f03 | |||
| 18b98997d3 | |||
| 0e1c69dab7 | |||
| c206b5b22c | |||
| c4bbfd8434 | |||
| b671474f64 | |||
| 6443790532 | |||
| 2df99debf8 | |||
| d87aabd465 | |||
| 0562faad70 | |||
| bb06b2a799 | |||
| 626f557aa0 | |||
| 185d19bfcf | |||
| 7fd1bf90bd | |||
| 1fa1f168c8 | |||
| 09e9c69fe0 | |||
| 9f273f7595 | |||
| 143eb7036a | |||
| 9c64c708eb | |||
| 8449eddab8 | |||
| d0a286d45a | |||
| d6698a22fb | |||
| 5e1050a9d7 | |||
| 9374c5a681 | |||
| 4c1e28b04f | |||
| 80933bb636 | |||
| 48b4375565 | |||
| ba7b80689c |
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# maven files
|
||||||
|
target/
|
||||||
|
# Eclipse files
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.0.11</version>
|
<version>2.0.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon.test</groupId>
|
<groupId>net.bigeon.test</groupId>
|
||||||
|
|||||||
@@ -68,11 +68,10 @@ package net.bigeon.gclc.process.io;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Logger;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
import net.bigeon.gclc.tools.StringProvider;
|
|
||||||
|
|
||||||
/** A console input that can be connected to and diconnected from.
|
/** A console input that can be connected to and diconnected from.
|
||||||
*
|
*
|
||||||
@@ -81,14 +80,11 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
|
|
||||||
/** The empty string provider. */
|
/** The empty string provider. */
|
||||||
private static final ConstantString EMPTY_STRING = new ConstantString("");
|
private static final ConstantString EMPTY_STRING = new ConstantString("");
|
||||||
/** The logger. */
|
|
||||||
private static final Logger LOGGER = Logger
|
|
||||||
.getLogger(ConnectingConsoleInput.class.getName());
|
|
||||||
|
|
||||||
/** If the input is closed. */
|
/** If the input is closed. */
|
||||||
private boolean close = false;
|
private boolean close = false;
|
||||||
/** The prompt string. */
|
/** The prompt string. */
|
||||||
private StringProvider prompt = EMPTY_STRING;
|
private Supplier<String> prompt = EMPTY_STRING;
|
||||||
/** If the input is currently in prompting state.
|
/** If the input is currently in prompting state.
|
||||||
* <p>
|
* <p>
|
||||||
* To change it you should be in a promptLock. */
|
* To change it you should be in a promptLock. */
|
||||||
@@ -143,7 +139,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
||||||
@Override
|
@Override
|
||||||
public StringProvider getPrompt() {
|
public Supplier<String> getPrompt() {
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,14 +170,14 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
|
||||||
@Override
|
@Override
|
||||||
public String prompt() throws IOException {
|
public String prompt() throws IOException {
|
||||||
return prompt(prompt.apply());
|
return prompt(prompt.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
||||||
@Override
|
@Override
|
||||||
public String prompt(final long timeout) throws IOException {
|
public String prompt(final long timeout) throws IOException {
|
||||||
return prompt(prompt.apply(), timeout);
|
return prompt(prompt.get(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -286,7 +282,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools.
|
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools.
|
||||||
* StringProvider) */
|
* StringProvider) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final StringProvider string) {
|
public void setPrompt(final Supplier<String> string) {
|
||||||
prompt = string;
|
prompt = string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ public class ForkTaskTest {
|
|||||||
|
|
||||||
final Thread execThread = new Thread(task);
|
final Thread execThread = new Thread(task);
|
||||||
execThread.start();
|
execThread.start();
|
||||||
|
try {
|
||||||
|
execThread.join(100);
|
||||||
|
} catch (final InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try (PipedConsoleOutput pco = new PipedConsoleOutput();
|
try (PipedConsoleOutput pco = new PipedConsoleOutput();
|
||||||
PipedConsoleInput pci = new PipedConsoleInput(null)) {
|
PipedConsoleInput pci = new PipedConsoleInput(null)) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public class ConnectingConsoleInputTest {
|
|||||||
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
||||||
in.setPrompt("test");
|
in.setPrompt("test");
|
||||||
assertEquals("Prompt should be set correctly", "test",
|
assertEquals("Prompt should be set correctly", "test",
|
||||||
((ConstantString) in.getPrompt()).apply());
|
((ConstantString) in.getPrompt()).get());
|
||||||
final ConstantString prompt = new ConstantString("other");
|
final ConstantString prompt = new ConstantString("other");
|
||||||
in.setPrompt(prompt);
|
in.setPrompt(prompt);
|
||||||
assertEquals("Prompt should be set correctly", prompt, in.getPrompt());
|
assertEquals("Prompt should be set correctly", prompt, in.getPrompt());
|
||||||
|
|||||||
@@ -40,14 +40,13 @@
|
|||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.scm.id>git.code.bigeon.net</project.scm.id>
|
|
||||||
<license.licenseName>cecill_2.1</license.licenseName>
|
<license.licenseName>cecill_2.1</license.licenseName>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.0.11</version>
|
<version>2.0.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ import java.io.InputStream;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
import net.bigeon.gclc.tools.StringProvider;
|
|
||||||
import net.bigeon.gclc.utils.ReadingRunnable;
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
|
||||||
/** A console input where the stream can be plugged.
|
/** A console input where the stream can be plugged.
|
||||||
@@ -75,7 +75,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
/** 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 Supplier<String> 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). */
|
||||||
@@ -146,7 +146,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
|
||||||
@Override
|
@Override
|
||||||
public StringProvider getPrompt() {
|
public Supplier<String> getPrompt() {
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,14 +175,14 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
|
||||||
@Override
|
@Override
|
||||||
public String prompt() throws IOException {
|
public String prompt() throws IOException {
|
||||||
return prompt(prompt.apply());
|
return prompt(prompt.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
||||||
@Override
|
@Override
|
||||||
public String prompt(final long timeout) throws IOException {
|
public String prompt(final long timeout) throws IOException {
|
||||||
return prompt(prompt.apply(), timeout);
|
return prompt(prompt.get(), timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -264,7 +264,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(net.bigeon.gclc.tools.
|
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(net.bigeon.gclc.tools.
|
||||||
* StringProvider) */
|
* StringProvider) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final StringProvider prompt) {
|
public void setPrompt(final Supplier<String> prompt) {
|
||||||
this.prompt = prompt;
|
this.prompt = prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class PluggableConsoleInputTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object obj = new Object();
|
final Object obj = new Object();
|
||||||
synchronized (obj) {
|
synchronized (obj) {
|
||||||
obj.wait(100);
|
obj.wait(100);
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ public class PluggableConsoleInputTest {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Object obj = new Object();
|
final Object obj = new Object();
|
||||||
synchronized (obj) {
|
synchronized (obj) {
|
||||||
obj.wait(200);
|
obj.wait(200);
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ public class PluggableConsoleInputTest {
|
|||||||
});
|
});
|
||||||
th.start();
|
th.start();
|
||||||
|
|
||||||
Object obj = new Object();
|
final Object obj = new Object();
|
||||||
synchronized (obj) {
|
synchronized (obj) {
|
||||||
while (!input.isPrompting()) {
|
while (!input.isPrompting()) {
|
||||||
obj.wait(10);
|
obj.wait(10);
|
||||||
@@ -211,8 +211,8 @@ public class PluggableConsoleInputTest {
|
|||||||
@Test
|
@Test
|
||||||
public final void testGetPrompt() {
|
public final void testGetPrompt() {
|
||||||
final PluggableConsoleInput input = new PluggableConsoleInput();
|
final PluggableConsoleInput input = new PluggableConsoleInput();
|
||||||
assertEquals("Default prompt invalid", "> ", input.getPrompt().apply());
|
assertEquals("Default prompt invalid", "> ", input.getPrompt().get());
|
||||||
input.setPrompt("test");
|
input.setPrompt("test");
|
||||||
assertEquals("Prompt setting failed", "test", input.getPrompt().apply());
|
assertEquals("Prompt setting failed", "test", input.getPrompt().get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -76,8 +77,8 @@ public class SocketConsoleApplicationTest {
|
|||||||
public void testIntegration() throws IOException, InterruptedException {
|
public void testIntegration() throws IOException, InterruptedException {
|
||||||
Thread server;
|
Thread server;
|
||||||
server = TestServer.getServer();
|
server = TestServer.getServer();
|
||||||
final String hostName = "127.0.0.1";
|
final InetAddress hostName = InetAddress.getLocalHost();
|
||||||
final int portNumber = 12345;
|
final int portNumber = TestServer.PORT;
|
||||||
|
|
||||||
try (Socket kkSocket = new Socket(hostName, portNumber);
|
try (Socket kkSocket = new Socket(hostName, portNumber);
|
||||||
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
|
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import net.bigeon.gclc.ConsoleApplication;
|
|||||||
@SuppressWarnings({ "javadoc", "nls" })
|
@SuppressWarnings({ "javadoc", "nls" })
|
||||||
public class TestServer {
|
public class TestServer {
|
||||||
|
|
||||||
public static final int PORT = 3300;
|
public static final int PORT = 12343;
|
||||||
private static SocketConsoleApplicationShell SHELL;
|
private static SocketConsoleApplicationShell SHELL;
|
||||||
private static ConnexionManager<Socket> manager;
|
private static ConnexionManager<Socket> manager;
|
||||||
|
|
||||||
@@ -76,8 +76,7 @@ public class TestServer {
|
|||||||
input.setPrompt("> \n");
|
input.setPrompt("> \n");
|
||||||
output = new PluggableConsoleOutput();
|
output = new PluggableConsoleOutput();
|
||||||
manager = new DConnexionManager<>();
|
manager = new DConnexionManager<>();
|
||||||
SHELL = new SocketConsoleApplicationShell(PORT,
|
SHELL = new SocketConsoleApplicationShell(PORT, InetAddress.getLocalHost());
|
||||||
InetAddress.getByName("127.0.0.1"));
|
|
||||||
final ConsoleApplication app = ConsoleTestApplication.create(output, input,
|
final ConsoleApplication app = ConsoleTestApplication.create(output, input,
|
||||||
manager);
|
manager);
|
||||||
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
||||||
|
|||||||
4
gclc-swt/.gitignore
vendored
4
gclc-swt/.gitignore
vendored
@@ -1,4 +0,0 @@
|
|||||||
/target/
|
|
||||||
/.settings/
|
|
||||||
/.classpath
|
|
||||||
/.project
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
<artifactId>swt</artifactId>
|
<artifactId>swt</artifactId>
|
||||||
<version>1.1.7-SNAPSHOT</version>
|
<version>1.2.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>GCLC swt</name>
|
<name>GCLC swt</name>
|
||||||
<description>A swt window for console applications</description>
|
<description>A swt window for console applications</description>
|
||||||
@@ -48,13 +48,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.0.11</version>
|
<version>2.0.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>collections</artifactId>
|
<artifactId>collections</artifactId>
|
||||||
<version>1.1.6</version>
|
<version>1.1.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>2.23.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
* GCLC swt
|
* GCLC swt
|
||||||
@@ -86,6 +88,8 @@ public interface ConsoleDelayIO {
|
|||||||
* @param input the input to set */
|
* @param input the input to set */
|
||||||
void setInput(String input);
|
void setInput(String input);
|
||||||
|
|
||||||
/** Actually send the input as the prompt next input. */
|
/** Actually send the input as the prompt next input.
|
||||||
void validateInput();
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
void validateInput() throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
||||||
|
|
||||||
|
/** The object managing the console input.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public final class ConsoleInputManager implements ConsoleDelayIO {
|
||||||
|
|
||||||
|
private final Text text;
|
||||||
|
private PipedConsoleInput input;
|
||||||
|
|
||||||
|
/** Create a managing object.
|
||||||
|
*
|
||||||
|
* @param text the text */
|
||||||
|
public ConsoleInputManager(final Text text) {
|
||||||
|
super();
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
|
||||||
|
@Override
|
||||||
|
public void setInput(final String string) {
|
||||||
|
text.setText(string);
|
||||||
|
text.setSelection(string.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
|
||||||
|
@Override
|
||||||
|
public String getInput() {
|
||||||
|
return text.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
|
||||||
|
@Override
|
||||||
|
public void validateInput() throws IOException {
|
||||||
|
input.type(text.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the input to control.
|
||||||
|
*
|
||||||
|
* @param input the input */
|
||||||
|
public void setManager(final PipedConsoleInput input) {
|
||||||
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the text component containing the currently set input.
|
||||||
|
*
|
||||||
|
* @return the text */
|
||||||
|
public Text getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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%
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** The common interface for console display.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public interface ConsoleOutputDisplay {
|
||||||
|
|
||||||
|
/** Append a line to the display.
|
||||||
|
*
|
||||||
|
* @param m the line content */
|
||||||
|
void appendLine(String m);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 org.eclipse.swt.widgets.Text;
|
||||||
|
import org.eclipse.swt.widgets.Widget;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
||||||
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
|
|
||||||
|
/** The manager for console output to insert in a text.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
||||||
|
/** A runnable appending text to the content of a {@link Text} component.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
private static class TextAppendingRunnable implements Runnable {
|
||||||
|
/** The text to append on a line (possibly new). */
|
||||||
|
private final String next;
|
||||||
|
/** The {@link Text} component. */
|
||||||
|
private final Text text;
|
||||||
|
|
||||||
|
/** Create the appending runnable.
|
||||||
|
*
|
||||||
|
* @param text the component to update
|
||||||
|
* @param next the text to append */
|
||||||
|
public TextAppendingRunnable(final Text text, final String next) {
|
||||||
|
this.text = text;
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Runnable#run() */
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final String initialText = text.getText();
|
||||||
|
if (initialText != null && !initialText.isEmpty()) {
|
||||||
|
text.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
text.append(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The local implementation of the forwarding runnable.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
private static final class ToSWTConsoleForwardRunnable
|
||||||
|
extends AOutputForwardRunnable {
|
||||||
|
/** The running status. */
|
||||||
|
private boolean running = true;
|
||||||
|
/** The console output. */
|
||||||
|
private final PipedConsoleOutput out;
|
||||||
|
/** The console output display. */
|
||||||
|
private final ConsoleOutputDisplay display;
|
||||||
|
/** The actual SWT component. */
|
||||||
|
private final Widget element;
|
||||||
|
|
||||||
|
/** Create the forwarding runnable.
|
||||||
|
*
|
||||||
|
* @param manager the manager
|
||||||
|
* @param display the display
|
||||||
|
* @param element the composite */
|
||||||
|
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager,
|
||||||
|
final ConsoleOutputDisplay display,
|
||||||
|
final Widget element) {
|
||||||
|
super(manager);
|
||||||
|
out = manager;
|
||||||
|
this.display = display;
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see
|
||||||
|
* net.bigeon.gclc.utils.AOutputForwardRunnable#forwardLine(java.lang.String) */
|
||||||
|
@Override
|
||||||
|
protected void forwardLine(final String m) {
|
||||||
|
display.appendLine(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.utils.AOutputForwardRunnable#isRunning() */
|
||||||
|
@Override
|
||||||
|
protected boolean isRunning() {
|
||||||
|
return running && !element.isDisposed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the running status.
|
||||||
|
*
|
||||||
|
* @param running the running to set */
|
||||||
|
public void setRunning(final boolean running) {
|
||||||
|
this.running = running;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the output.
|
||||||
|
*
|
||||||
|
* @return the currently forwarded output */
|
||||||
|
public PipedConsoleOutput getOuput() {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The SWT component displaying the output content. */
|
||||||
|
private final Text text;
|
||||||
|
/** The forwarding runnable. */
|
||||||
|
private ToSWTConsoleForwardRunnable forward;
|
||||||
|
/** The forwarding thread. */
|
||||||
|
private Thread forwardThread;
|
||||||
|
|
||||||
|
/** Create the manager.
|
||||||
|
*
|
||||||
|
* @param text the text to display the output in. */
|
||||||
|
public ConsoleOutputManager(final Text text) {
|
||||||
|
super();
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see net.bigeon.gclc.swt.ConsoleOutputDisplay#appendLine(java.lang.String) */
|
||||||
|
@Override
|
||||||
|
public void appendLine(final String next) {
|
||||||
|
text.getDisplay().syncExec(new TextAppendingRunnable(text, next));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the output.
|
||||||
|
*
|
||||||
|
* @param output the output to set */
|
||||||
|
public void setManager(final PipedConsoleOutput output) {
|
||||||
|
if (forward != null) {
|
||||||
|
if (forward.getOuput() == output) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
forward.setRunning(false);
|
||||||
|
}
|
||||||
|
if (output == null) {
|
||||||
|
forward = null;
|
||||||
|
forwardThread = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
forward = new ToSWTConsoleForwardRunnable(output, this, text);
|
||||||
|
forwardThread = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
|
||||||
|
forwardThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the current thread forwarding the console output to the SWT components.
|
||||||
|
*
|
||||||
|
* @return the forwardThread */
|
||||||
|
public Thread getForwardThread() {
|
||||||
|
return forwardThread;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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.BufferedReader;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
|
/** The manager for the console prompt updates.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public final class ConsolePromptManager {
|
||||||
|
|
||||||
|
/** The label to set the prompts at. */
|
||||||
|
private final Label label;
|
||||||
|
|
||||||
|
/** The current prompt reading runnable. */
|
||||||
|
private PromptReadingRunnable promptRead;
|
||||||
|
|
||||||
|
/** Create the manager.
|
||||||
|
*
|
||||||
|
* @param label the label to update with prompts */
|
||||||
|
public ConsolePromptManager(final Label label) {
|
||||||
|
super();
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the prompt.
|
||||||
|
* <p>
|
||||||
|
* This method sets the prompt on the label as requested, without changing the
|
||||||
|
* actual prompt of the console input.
|
||||||
|
*
|
||||||
|
* @param string the text */
|
||||||
|
public void setPrompt(final String string) {
|
||||||
|
label.setText(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the input to control.
|
||||||
|
*
|
||||||
|
* @param promptStream the input */
|
||||||
|
public void setStream(final BufferedReader promptStream) {
|
||||||
|
if (promptRead != null) {
|
||||||
|
if (promptRead.getReader() == promptStream) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
promptRead.setRunning(false);
|
||||||
|
}
|
||||||
|
if (promptStream == null) {
|
||||||
|
promptRead = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
promptRead = new PromptReadingRunnable(promptStream, label);
|
||||||
|
final Thread th = new Thread(promptRead, "Prompt To Label");
|
||||||
|
th.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,10 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
* GCLC swt
|
* GCLC swt
|
||||||
@@ -84,6 +88,8 @@ public final class HistoryTextKeyListener extends KeyAdapter {
|
|||||||
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$
|
||||||
|
private static final Logger LOGGER = Logger
|
||||||
|
.getLogger(HistoryTextKeyListener.class.getName());
|
||||||
/** 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. */
|
||||||
@@ -118,7 +124,11 @@ public final class HistoryTextKeyListener extends KeyAdapter {
|
|||||||
if (!input.isEmpty()) {
|
if (!input.isEmpty()) {
|
||||||
commands.add(input);
|
commands.add(input);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
console.validateInput();
|
console.validateInput();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Unable to write to console", e);
|
||||||
|
}
|
||||||
currentIndex = -1;
|
currentIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,134 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
|
/** The runnable forwarding prompts from a buffered input to a label.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public class PromptReadingRunnable implements Runnable {
|
||||||
|
|
||||||
|
/** The logger for this class. */
|
||||||
|
private static final Logger LOGGER = Logger
|
||||||
|
.getLogger(PromptReadingRunnable.class.getName());
|
||||||
|
|
||||||
|
/** The reader providing the succession of prompts */
|
||||||
|
private final BufferedReader reader;
|
||||||
|
/** The label. */
|
||||||
|
private final Label view;
|
||||||
|
/** The running status. */
|
||||||
|
private boolean running = true;
|
||||||
|
|
||||||
|
/** The updating runnable implementation.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
private static class LabelUpdater implements Runnable {
|
||||||
|
/** The label to update. */
|
||||||
|
private final Label label;
|
||||||
|
/** The text to set. */
|
||||||
|
private final String content;
|
||||||
|
|
||||||
|
/** Create the updating runnable.
|
||||||
|
*
|
||||||
|
* @param label the label
|
||||||
|
* @param content the content */
|
||||||
|
public LabelUpdater(final Label label, final String content) {
|
||||||
|
super();
|
||||||
|
this.label = label;
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Runnable#run() */
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
label.setText(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create the prompt flow updating runnable.
|
||||||
|
*
|
||||||
|
* @param reader the reader
|
||||||
|
* @param view the view to update on lines. */
|
||||||
|
public PromptReadingRunnable(final BufferedReader reader, final Label view) {
|
||||||
|
super();
|
||||||
|
this.reader = reader;
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see java.lang.Runnable#run() */
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String prompt;
|
||||||
|
try {
|
||||||
|
while (isRunning() && (prompt = reader.readLine()) != null) {
|
||||||
|
view.getDisplay().syncExec(new LabelUpdater(view, prompt));
|
||||||
|
}
|
||||||
|
} catch (final IOException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Prompt cannot be read, or was prematuraly closed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the running state.
|
||||||
|
*
|
||||||
|
* @return the running */
|
||||||
|
public synchronized boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set the running state.
|
||||||
|
*
|
||||||
|
* @param running the running to set */
|
||||||
|
public synchronized void setRunning(final boolean running) {
|
||||||
|
this.running = running;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get the prompt flow.
|
||||||
|
*
|
||||||
|
* @return the reader */
|
||||||
|
public BufferedReader getReader() {
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,11 +30,13 @@
|
|||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* gclc-swt:net.bigeon.gclc.swt.SWTConsole.java
|
* gclc-swt:net.bigeon.gclc.swt.SWTConsoleShell.java
|
||||||
* Created on: Apr 18, 2015
|
* Created on: Apr 18, 2015
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
* GCLC swt
|
* GCLC swt
|
||||||
@@ -68,411 +70,75 @@ package net.bigeon.gclc.swt;
|
|||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.ConsoleApplication;
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
|
||||||
import net.bigeon.gclc.tools.StringProvider;
|
|
||||||
|
|
||||||
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
/** A shell containing a {@link SWTConsoleView}
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class SWTConsole extends Composite
|
public final class SWTConsole extends Composite {
|
||||||
implements ConsoleDelayIO, ConsoleInput, ConsoleOutput {
|
|
||||||
private static final int TWO = 2;
|
|
||||||
private static final String ERROR_SYNCHRO_PROMPT = "Error in synchronization of prompting";
|
|
||||||
/** The number of columns of the layout. */
|
|
||||||
private static final int LAYOUT_NB_COLUMNS = 2;
|
|
||||||
/** The cmd prefix in the output console. */
|
|
||||||
private static final String CMD_PREFIX = "[CMD] "; //$NON-NLS-1$
|
|
||||||
/** The class logger. */
|
|
||||||
private static final Logger LOGGER = Logger
|
|
||||||
.getLogger(SWTConsole.class.getName());
|
|
||||||
/** The empty string constant. */
|
|
||||||
private static final String EMPTY = ""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
/** The console output text field. */
|
private ConsoleInputManager inputManager;
|
||||||
private final Text consoleOutput;
|
private ConsoleOutputManager outputManager;
|
||||||
/** The console input text field. */
|
private ConsolePromptManager promptManager;
|
||||||
private final Text consoleInput;
|
|
||||||
/** The prompt label. */
|
|
||||||
private final Label lblPromptlabel;
|
|
||||||
/** The prompt text. */
|
|
||||||
private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$
|
|
||||||
/** The command entered by the user. */
|
|
||||||
private String command = null;
|
|
||||||
/** If the prompt should be active. */
|
|
||||||
private boolean prompting = false;
|
|
||||||
/** The object for thread synchronization with the prompt. */
|
|
||||||
private final Object promptLock = new Object();
|
|
||||||
|
|
||||||
/** Create the composite.
|
/** Create the shell.
|
||||||
*
|
*
|
||||||
* @param parent the prent composite
|
* @param parent the containing composite
|
||||||
* @param style the composite style */
|
* @param style the shell style */
|
||||||
public SWTConsole(final Composite parent, final int style) {
|
public SWTConsole(final Composite parent, final int style) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
|
setLayout(new GridLayout(2, false));
|
||||||
setLayout(new GridLayout(LAYOUT_NB_COLUMNS, false));
|
createContents();
|
||||||
|
|
||||||
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, LAYOUT_NB_COLUMNS, 1));
|
|
||||||
consoleOutput.setRedraw(true);
|
|
||||||
|
|
||||||
lblPromptlabel = new Label(this, SWT.NONE);
|
|
||||||
lblPromptlabel.setText(prompt.apply());
|
|
||||||
|
|
||||||
consoleInput = new Text(this, SWT.BORDER);
|
|
||||||
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
|
||||||
consoleInput.addKeyListener(new HistoryTextKeyListener(this));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** Create contents of the shell. */
|
||||||
* @see org.eclipse.swt.widgets.Composite#checkSubclass() */
|
private void createContents() {
|
||||||
@Override
|
final Text output = new Text(this,
|
||||||
protected void checkSubclass() {
|
SWT.WRAP | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
|
||||||
// Disable the check that prevents subclassing of SWT components
|
output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
||||||
|
final Label prompt = new Label(this, SWT.NONE);
|
||||||
|
prompt.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
|
||||||
|
final Text input = new Text(this, SWT.NONE);
|
||||||
|
input.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
||||||
|
|
||||||
|
inputManager = new ConsoleInputManager(input);
|
||||||
|
outputManager = new ConsoleOutputManager(output);
|
||||||
|
promptManager = new ConsolePromptManager(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** Connect the console parts to the shell.
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleManager#close() */
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
prompting = false;
|
|
||||||
promptLock.notifyAll();
|
|
||||||
}
|
|
||||||
if (consoleInput.isDisposed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
consoleInput.setEnabled(false);
|
|
||||||
consoleOutput.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
|
|
||||||
@Override
|
|
||||||
public String getInput() {
|
|
||||||
return consoleInput.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#getPrompt() */
|
|
||||||
@Override
|
|
||||||
public StringProvider getPrompt() {
|
|
||||||
return prompt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleManager#interruptPrompt() */
|
|
||||||
@Override
|
|
||||||
public void interruptPrompt() {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
promptLock.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleManager#isClosed() */
|
|
||||||
@Override
|
|
||||||
public boolean isClosed() {
|
|
||||||
return isDisposed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#print(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void print(final String text) throws IOException {
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
consoleOutput.append(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#println() */
|
|
||||||
@Override
|
|
||||||
public void println() throws IOException {
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
consoleOutput.append(System.lineSeparator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#println(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void println(final String message) throws IOException {
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
consoleOutput.append(message + System.lineSeparator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#prompt() */
|
|
||||||
@Override
|
|
||||||
public String prompt() throws IOException {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
initPrompt(prompt.apply());
|
|
||||||
promptLock.notifyAll();
|
|
||||||
try {
|
|
||||||
while (prompting) {
|
|
||||||
promptLock.wait();
|
|
||||||
}
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
|
||||||
command = null;
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException("Input closed"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Initialize the prompting.
|
|
||||||
*
|
*
|
||||||
* @param message the prompt message
|
* @param input the input
|
||||||
* @throws IOException if the console is disposed */
|
* @param output the output
|
||||||
private void initPrompt(final String message) throws IOException {
|
* @param promptStream the stream where the prompts are forwarded. */
|
||||||
if (isDisposed()) {
|
public void connect(final PipedConsoleInput input, final PipedConsoleOutput output,
|
||||||
throw new IOException();
|
final BufferedReader promptStream) {
|
||||||
}
|
inputManager.setManager(input);
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
outputManager.setManager(output);
|
||||||
@SuppressWarnings("synthetic-access")
|
promptManager.setStream(promptStream);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
lblPromptlabel.setText(message);
|
|
||||||
// relayout
|
|
||||||
SWTConsole.this.layout();
|
|
||||||
consoleInput.setEnabled(true);
|
|
||||||
consoleInput.setFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
prompting = true;
|
|
||||||
command = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** @return the inputManager */
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
public ConsoleInputManager getInputManager() {
|
||||||
@Override
|
return inputManager;
|
||||||
public String prompt(final long timeout) throws IOException {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
initPrompt(prompt.apply());
|
|
||||||
promptLock.notifyAll();
|
|
||||||
try {
|
|
||||||
waitPromptResolution(timeout);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
|
||||||
command = null;
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** @return the outputManager */
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#prompt(java.lang.String) */
|
public ConsoleOutputManager getOutputManager() {
|
||||||
@Override
|
return outputManager;
|
||||||
public String prompt(final String message) throws IOException {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
initPrompt(message);
|
|
||||||
promptLock.notifyAll();
|
|
||||||
try {
|
|
||||||
while (prompting) {
|
|
||||||
promptLock.wait();
|
|
||||||
}
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
|
||||||
command = null;
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
} finally {
|
|
||||||
resetPrompt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return command;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** @return the promptManager */
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
|
public ConsolePromptManager getPromptManager() {
|
||||||
@Override
|
return promptManager;
|
||||||
public String prompt(final String message, final long timeout) throws IOException {
|
|
||||||
synchronized (promptLock) {
|
|
||||||
initPrompt(message);
|
|
||||||
promptLock.notifyAll();
|
|
||||||
try {
|
|
||||||
waitPromptResolution(timeout);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
|
|
||||||
command = null;
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
} finally {
|
|
||||||
resetPrompt();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Wait the prompt resolution by user.
|
|
||||||
*
|
|
||||||
* @param timeout the timeout for the wait
|
|
||||||
* @throws InterruptedException if the thread is interrupted
|
|
||||||
* @throws IOException if the console is disposed. */
|
|
||||||
private void waitPromptResolution(final long timeout)
|
|
||||||
throws InterruptedException, IOException {
|
|
||||||
final long start = System.currentTimeMillis();
|
|
||||||
long cur = start;
|
|
||||||
while (prompting && start + timeout > cur) {
|
|
||||||
promptLock.wait((cur - start - timeout) / TWO);
|
|
||||||
cur = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
if (isDisposed()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Reset the prompt message. */
|
|
||||||
private void resetPrompt() {
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
lblPromptlabel.setText(prompt.apply());
|
|
||||||
// relayout
|
|
||||||
SWTConsole.this.layout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.swt.widgets.Composite#setFocus() */
|
|
||||||
@Override
|
|
||||||
public boolean setFocus() {
|
|
||||||
return consoleInput.setFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void setInput(final String input) {
|
|
||||||
consoleInput.setText(input);
|
|
||||||
consoleInput.setSelection(input.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void setPrompt(final String prompt) {
|
|
||||||
setPrompt(new ConstantString(prompt));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void setPrompt(final StringProvider prompt) {
|
|
||||||
this.prompt = prompt;
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!consoleOutput.isDisposed()) {
|
|
||||||
lblPromptlabel.setText(prompt.apply());
|
|
||||||
// relayout
|
|
||||||
SWTConsole.this.layout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Set the input text.
|
|
||||||
*
|
|
||||||
* @param string the text */
|
|
||||||
public void setText(final String string) {
|
|
||||||
consoleInput.setText(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
|
|
||||||
@Override
|
|
||||||
public void validateInput() {
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
consoleInput.setEnabled(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
synchronized (promptLock) {
|
|
||||||
while (!prompting) {
|
|
||||||
try {
|
|
||||||
promptLock.wait();
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Interruption while waiting prompt", e); //$NON-NLS-1$
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
command = consoleInput.getText();
|
|
||||||
prompting = false;
|
|
||||||
consoleInput.setText(EMPTY);
|
|
||||||
consoleOutput.append(CMD_PREFIX + command + System.lineSeparator());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
promptLock.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* GCLC swt, provide a swt window for console applications
|
|
||||||
* Copyright (C) 2015-2017 E. Bigeon
|
|
||||||
* mailto:emmanuel@bigeon.fr
|
|
||||||
*
|
|
||||||
* 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:net.bigeon.gclc.swt.SWTConsoleShell.java
|
|
||||||
* Created on: Apr 18, 2015
|
|
||||||
*/
|
|
||||||
package net.bigeon.gclc.swt;
|
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* GCLC swt
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2015 - 2018 Bigeon
|
|
||||||
* %%
|
|
||||||
* This software is governed by the CeCILL license under French law and
|
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
|
||||||
* 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 org.eclipse.swt.SWT;
|
|
||||||
import org.eclipse.swt.layout.FillLayout;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
|
||||||
|
|
||||||
/** A shell containing a {@link SWTConsole}
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
public final class SWTConsoleShell extends Shell {
|
|
||||||
|
|
||||||
/** The console component */
|
|
||||||
private SWTConsole console;
|
|
||||||
|
|
||||||
/** Create the shell.
|
|
||||||
*
|
|
||||||
* @param display the display */
|
|
||||||
public SWTConsoleShell(final Display display, final int style) {
|
|
||||||
super(display, style);
|
|
||||||
setLayout(new FillLayout(SWT.HORIZONTAL));
|
|
||||||
|
|
||||||
createContents();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkSubclass() {
|
|
||||||
// Disable the check that prevents subclassing of SWT components
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create contents of the shell. */
|
|
||||||
private void createContents() {
|
|
||||||
console = new SWTConsole(this, SWT.NONE);
|
|
||||||
setText("Console Application"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.swt.widgets.Shell#dispose() */
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
super.dispose();
|
|
||||||
console.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return the input and output. */
|
|
||||||
public SWTConsole getManager() {
|
|
||||||
return console;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -68,66 +68,25 @@ package net.bigeon.gclc.swt;
|
|||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.ConsoleApplication;
|
import net.bigeon.gclc.ConsoleApplication;
|
||||||
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
|
|
||||||
/** A SWT component to connect to gclc {@link ConsoleApplication}
|
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
||||||
* <p>
|
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
|
public final class SWTConsoleView extends Composite {
|
||||||
/** The local implementation of the forwarding runnable
|
/** The input manager. */
|
||||||
*
|
private final ConsoleInputManager inManager;
|
||||||
* @author Emmanuel Bigeon */
|
/** The output manager. */
|
||||||
private final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
private final ConsoleOutputManager outManager;
|
||||||
/** The running status */
|
|
||||||
private boolean running = true;
|
|
||||||
|
|
||||||
/** @param manager the manager */
|
|
||||||
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager) {
|
|
||||||
super(manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void forwardLine(final String m) {
|
|
||||||
appendConsoleOutput(System.lineSeparator() + m);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isRunning() {
|
|
||||||
return running && !isDisposed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param running the running to set */
|
|
||||||
public void setRunning(final 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 input. */
|
|
||||||
private PipedConsoleInput input;
|
|
||||||
/** The forwarding runnable */
|
|
||||||
private ToSWTConsoleForwardRunnable forward;
|
|
||||||
|
|
||||||
/** Create the composite.
|
/** Create the composite.
|
||||||
*
|
*
|
||||||
@@ -138,52 +97,23 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
|
|||||||
|
|
||||||
setLayout(new GridLayout(1, false));
|
setLayout(new GridLayout(1, false));
|
||||||
|
|
||||||
consoleOutput = new Text(this,
|
final Text consoleOutput = new Text(this,
|
||||||
SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | 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, 1, 1));
|
consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
||||||
consoleOutput.setRedraw(true);
|
consoleOutput.setRedraw(true);
|
||||||
|
outManager = new ConsoleOutputManager(consoleOutput);
|
||||||
|
|
||||||
consoleInput = new Text(this, SWT.BORDER);
|
final Text consoleInput = new Text(this, SWT.BORDER);
|
||||||
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
|
||||||
consoleInput.addKeyListener(new HistoryTextKeyListener(this));
|
inManager = new ConsoleInputManager(consoleInput);
|
||||||
}
|
consoleInput.addKeyListener(new HistoryTextKeyListener(inManager));
|
||||||
|
|
||||||
/** @param next the next message */
|
|
||||||
public void appendConsoleOutput(final String next) {
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
consoleOutput.append(next);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkSubclass() {
|
|
||||||
// Disable the check that prevents subclassing of SWT components
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
|
|
||||||
@Override
|
|
||||||
public String getInput() {
|
|
||||||
return consoleInput.getText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.swt.widgets.Composite#setFocus() */
|
* @see org.eclipse.swt.widgets.Composite#setFocus() */
|
||||||
@Override
|
@Override
|
||||||
public boolean setFocus() {
|
public boolean setFocus() {
|
||||||
return consoleInput.setFocus();
|
return inManager.getText().setFocus();
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
|
|
||||||
@Override
|
|
||||||
public void setInput(final String input) {
|
|
||||||
consoleInput.setText(input);
|
|
||||||
consoleInput.setSelection(input.length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set the input and output.
|
/** Set the input and output.
|
||||||
@@ -192,29 +122,21 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
|
|||||||
* @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;
|
outManager.setManager(manager);
|
||||||
if (forward != null) {
|
inManager.setManager(input);
|
||||||
forward.setRunning(false);
|
|
||||||
}
|
|
||||||
forward = new ToSWTConsoleForwardRunnable(manager);
|
|
||||||
final Thread th = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
|
|
||||||
th.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param string the text */
|
/** Get the manager of console input.
|
||||||
public void setText(final String string) {
|
|
||||||
consoleInput.setText(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
*
|
||||||
*/
|
* @return the input manager */
|
||||||
@Override
|
public ConsoleInputManager getInputManager() {
|
||||||
public void validateInput() {
|
return inManager;
|
||||||
try {
|
|
||||||
input.type(getInput());
|
|
||||||
} catch (final IOException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Unable to input value to console", e); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the manager of console output.
|
||||||
|
*
|
||||||
|
* @return the output manager */
|
||||||
|
public ConsoleOutputManager getOutputManager() {
|
||||||
|
return outManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Mockito.doThrow;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class ConsoleInputManagerTest {
|
||||||
|
|
||||||
|
private final Text text = mock(Text.class);
|
||||||
|
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#setInput(java.lang.String)}. */
|
||||||
|
@Test
|
||||||
|
public void testSetText() {
|
||||||
|
cim.setInput("Text");
|
||||||
|
verify(text).setText("Text");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#validateInput()}.
|
||||||
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
@Test
|
||||||
|
public void testValidateInput() throws IOException {
|
||||||
|
// Expected calls
|
||||||
|
when(text.getText()).thenReturn("abc");
|
||||||
|
|
||||||
|
try {
|
||||||
|
cim.validateInput();
|
||||||
|
fail("No input should cause exception for input validation");
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
final PipedConsoleInput input = mock(PipedConsoleInput.class);
|
||||||
|
cim.setManager(input);
|
||||||
|
|
||||||
|
cim.validateInput();
|
||||||
|
verify(input).type("abc");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateInputWithError() throws IOException {
|
||||||
|
final PipedConsoleInput input = mock(PipedConsoleInput.class);
|
||||||
|
cim.setManager(input);
|
||||||
|
// Expected calls
|
||||||
|
when(text.getText()).thenReturn("abc");
|
||||||
|
doThrow(new IOException()).when(input).type("abc");
|
||||||
|
|
||||||
|
try {
|
||||||
|
cim.validateInput();
|
||||||
|
fail("IO exception should be forwarded");
|
||||||
|
} catch (final IOException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#getText()}. */
|
||||||
|
@Test
|
||||||
|
public void testGetText() {
|
||||||
|
assertEquals("Text component should be preserved", text, cim.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetInput() {
|
||||||
|
when(text.getText()).thenReturn("abc");
|
||||||
|
assertEquals("Text component should be preserved", "abc", cim.getInput());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class ConsoleOutputManagerTest {
|
||||||
|
private final Text text = mock(Text.class);
|
||||||
|
private final ConsoleOutputManager com = new ConsoleOutputManager(text);
|
||||||
|
private final Display display = mock(Display.class);
|
||||||
|
{
|
||||||
|
when(text.getDisplay()).thenReturn(display);
|
||||||
|
doAnswer(new Answer<Object>() {
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see
|
||||||
|
* org.mockito.stubbing.Answer#answer(org.mockito.invocation.InvocationOnMock) */
|
||||||
|
@Override
|
||||||
|
public Object answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
|
final Runnable runnable = invocation.getArgument(0);
|
||||||
|
runnable.run();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(display).syncExec(any(Runnable.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||||
|
@Test
|
||||||
|
public void testAppendConsoleOutput() {
|
||||||
|
when(text.getText()).thenReturn("", "abc",
|
||||||
|
"abc" + System.lineSeparator() + "def");
|
||||||
|
com.appendLine("abc");
|
||||||
|
verify(text).append("abc");
|
||||||
|
com.appendLine("def");
|
||||||
|
verify(text).append(System.lineSeparator());
|
||||||
|
verify(text).append("def");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetManager() throws IOException, InterruptedException {
|
||||||
|
final PipedConsoleOutput output = mock(PipedConsoleOutput.class);
|
||||||
|
com.setManager(output);
|
||||||
|
com.setManager(output);
|
||||||
|
|
||||||
|
try (PipedConsoleOutput output2 = new PipedConsoleOutput()) {
|
||||||
|
com.setManager(output2);
|
||||||
|
output2.println("line");
|
||||||
|
final Thread forwardThread = com.getForwardThread();
|
||||||
|
forwardThread.join(500);
|
||||||
|
com.setManager(null);
|
||||||
|
forwardThread.join();
|
||||||
|
verify(text).append("line");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bigeon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ConsolePromptManagerTest {
|
||||||
|
|
||||||
|
private final Label label = mock(Label.class);
|
||||||
|
|
||||||
|
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setPrompt(java.lang.String)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSetPrompt() {
|
||||||
|
manager.setPrompt("abc");
|
||||||
|
verify(label).setText("abc");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testSetStream() {
|
||||||
|
BufferedReader output = mock(BufferedReader.class);
|
||||||
|
manager.setStream(output);
|
||||||
|
manager.setStream(output);
|
||||||
|
output = mock(BufferedReader.class);
|
||||||
|
manager.setStream(output);
|
||||||
|
manager.setStream(null);
|
||||||
|
manager.setStream(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -69,8 +69,10 @@ package net.bigeon.gclc.swt;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +86,7 @@ public class HistoryTextKeyListenerTest {
|
|||||||
* {@link net.bigeon.gclc.swt.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
|
* {@link net.bigeon.gclc.swt.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
|
||||||
@Test
|
@Test
|
||||||
public final void testKeyPressedKeyEvent() {
|
public final void testKeyPressedKeyEvent() {
|
||||||
ConsoleDelayIO io = new ConsoleDelayIO() {
|
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
||||||
private String input = "";
|
private String input = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,7 +95,7 @@ public class HistoryTextKeyListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInput(String input) {
|
public void setInput(final String input) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ public class HistoryTextKeyListenerTest {
|
|||||||
input = "";
|
input = "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
||||||
|
|
||||||
// no effects
|
// no effects
|
||||||
assertEquals("", io.getInput());
|
assertEquals("", io.getInput());
|
||||||
@@ -139,4 +141,12 @@ public class HistoryTextKeyListenerTest {
|
|||||||
assertEquals("cmd arg2", io.getInput());
|
assertEquals("cmd arg2", io.getInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testKeyPressed() {
|
||||||
|
final ConsoleDelayIO io = mock(ConsoleDelayIO.class);
|
||||||
|
final KeyEvent event = mock(KeyEvent.class);
|
||||||
|
event.keyCode = 'a';
|
||||||
|
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
||||||
|
listener.keyPressed(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC swt
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2015 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* 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 static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class PromptReadingRunnableTest {
|
||||||
|
private final Label view = mock(Label.class);
|
||||||
|
private final Display display = mock(Display.class);
|
||||||
|
{
|
||||||
|
when(view.getDisplay()).thenReturn(display);
|
||||||
|
doAnswer(new Answer<Object>() {
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see
|
||||||
|
* org.mockito.stubbing.Answer#answer(org.mockito.invocation.InvocationOnMock) */
|
||||||
|
@Override
|
||||||
|
public Object answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
|
final Runnable runnable = invocation.getArgument(0);
|
||||||
|
runnable.run();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(display).syncExec(any(Runnable.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
||||||
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
@Test
|
||||||
|
public void testRun() throws IOException {
|
||||||
|
final BufferedReader reader = mock(BufferedReader.class);
|
||||||
|
when(reader.readLine()).thenReturn("abc", "def", null);
|
||||||
|
|
||||||
|
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
||||||
|
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
||||||
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
@Test
|
||||||
|
public void testRunWithIO() throws IOException {
|
||||||
|
final BufferedReader reader = mock(BufferedReader.class);
|
||||||
|
when(reader.readLine()).thenThrow(new IOException());
|
||||||
|
|
||||||
|
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
||||||
|
final Logger logger = Logger.getLogger(PromptReadingRunnable.class.getName());
|
||||||
|
final Level back = logger.getLevel();
|
||||||
|
logger.setLevel(Level.OFF);
|
||||||
|
|
||||||
|
runnable.run();
|
||||||
|
logger.setLevel(back);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,37 +1,5 @@
|
|||||||
/*
|
|
||||||
* GCLC swt, provide a swt window for console applications
|
|
||||||
* Copyright (C) 2015-2017 E. Bigeon
|
|
||||||
* mailto:emmanuel@bigeon.fr
|
|
||||||
*
|
|
||||||
* 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:net.bigeon.gclc.swt.SWTConsoleShellTest.java
|
*
|
||||||
* Created on: Jun 8, 2016
|
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
@@ -68,299 +36,37 @@ package net.bigeon.gclc.swt;
|
|||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.ConsoleApplication;
|
/** @author Emmanuel Bigeon */
|
||||||
import net.bigeon.gclc.command.Command;
|
|
||||||
import net.bigeon.gclc.command.base.ExitCommand;
|
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
|
||||||
import net.bigeon.gclc.exception.InvalidCommandName;
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* TODO
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
|
|
||||||
public class SWTConsoleShellTest {
|
public class SWTConsoleShellTest {
|
||||||
|
|
||||||
protected static final long TWO_SECONDS = 2000;
|
/** Test method for
|
||||||
private static final Display DISPLAY = Display.getDefault();
|
* {@link net.bigeon.gclc.swt.SWTConsole#SWTConsole(Composite, int)}. */
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeneric() {
|
public void testSWTConsoleShell() {
|
||||||
final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY, SWT.SHELL_TRIM);
|
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
||||||
final SWTConsole swtConsole = shell.getManager();
|
assertNotNull("View should be initialized with managers",
|
||||||
try {
|
console.getInputManager());
|
||||||
final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
|
assertNotNull("View should be initialized with managers",
|
||||||
"Hello", "See you");
|
console.getOutputManager());
|
||||||
appl.add(new ExitCommand("exit", appl));
|
assertNotNull("View should be initialized with managers",
|
||||||
appl.add(new Command("long") {
|
console.getPromptManager());
|
||||||
|
|
||||||
/* (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 {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String tip() {
|
|
||||||
return "a long running command";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
|
||||||
@Override
|
|
||||||
protected String usageDetail() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// shell.pack();
|
|
||||||
shell.open();
|
|
||||||
shell.setVisible(false);
|
|
||||||
final Thread applThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
appl.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final Thread testThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("test"); //$NON-NLS-1$
|
|
||||||
swtConsole.validateInput();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
shell.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
applThread.start();
|
|
||||||
testThread.start();
|
|
||||||
while (!shell.isDisposed()) {
|
|
||||||
if (!DISPLAY.readAndDispatch()) {
|
|
||||||
DISPLAY.sleep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// DISPLAY.dispose();
|
|
||||||
assertTrue(swtConsole.isClosed());
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
assertFalse(appl.isRunning());
|
|
||||||
} catch (final InvalidCommandName e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.SWTConsole#connect(net.bigeon.gclc.utils.PipedConsoleInput, net.bigeon.gclc.utils.PipedConsoleOutput, java.io.BufferedReader)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testConsoleClose() {
|
public void testConnect() {
|
||||||
final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY, SWT.SHELL_TRIM);
|
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
||||||
final SWTConsole swtConsole = shell.getManager();
|
// Disconnection should work.
|
||||||
swtConsole.close();
|
console.connect(null, null, null);
|
||||||
swtConsole.setPrompt(":");
|
|
||||||
try {
|
|
||||||
final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
|
|
||||||
"Hello", "See you");
|
|
||||||
appl.add(new ExitCommand("exit", appl));
|
|
||||||
appl.add(new Command("long") {
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
|
|
||||||
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
|
||||||
* java.lang.String[]) */
|
|
||||||
@Override
|
|
||||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
|
||||||
final String... args) throws CommandRunException {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String tip() {
|
|
||||||
return "a long running command";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
|
||||||
@Override
|
|
||||||
protected String usageDetail() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
appl.add(new Command("test") {
|
|
||||||
/* (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 {
|
|
||||||
try {
|
|
||||||
swtConsole.prompt("Test");
|
|
||||||
} catch (final IOException e) {
|
|
||||||
throw new CommandRunException("No input", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String tip() {
|
|
||||||
return "a prompting running command";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
|
||||||
@Override
|
|
||||||
protected String usageDetail() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
// return null;
|
|
||||||
throw new RuntimeException("Not implemented yet");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// shell.pack();
|
|
||||||
shell.open();
|
|
||||||
shell.setVisible(false);
|
|
||||||
final Thread applThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
appl.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final Thread testThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("test"); //$NON-NLS-1$
|
|
||||||
swtConsole.validateInput();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("ok"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swtConsole.validateInput();
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("long"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swtConsole.validateInput();
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("test"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swtConsole.validateInput();
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("test"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swtConsole.validateInput();
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
shell.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
applThread.start();
|
|
||||||
testThread.start();
|
|
||||||
while (!shell.isDisposed()) {
|
|
||||||
if (!DISPLAY.readAndDispatch()) {
|
|
||||||
DISPLAY.sleep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
swtConsole.setPrompt(">");
|
|
||||||
try {
|
|
||||||
swtConsole.prompt();
|
|
||||||
fail("Prompting when closed should fail!");
|
|
||||||
} catch (final IOException e) {
|
|
||||||
assertNotNull(e);
|
|
||||||
}
|
|
||||||
// DISPLAY.dispose();
|
|
||||||
assertTrue(swtConsole.isClosed());
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
assertFalse(appl.isRunning());
|
|
||||||
} catch (final InvalidCommandName e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +1,5 @@
|
|||||||
/*
|
|
||||||
* GCLC swt, provide a swt window for console applications
|
|
||||||
* Copyright (C) 2015-2017 E. Bigeon
|
|
||||||
* mailto:emmanuel@bigeon.fr
|
|
||||||
*
|
|
||||||
* 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:net.bigeon.gclc.swt.SWTConsoleShellTest.java
|
*
|
||||||
* Created on: Jun 8, 2016
|
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
@@ -68,137 +36,40 @@ package net.bigeon.gclc.swt;
|
|||||||
* knowledge of the CeCILL license and that you accept its terms.
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.ConsoleApplication;
|
/** @author Emmanuel Bigeon */
|
||||||
import net.bigeon.gclc.command.Command;
|
|
||||||
import net.bigeon.gclc.command.base.ExitCommand;
|
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
|
||||||
import net.bigeon.gclc.exception.InvalidCommandName;
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* TODO
|
|
||||||
*
|
|
||||||
* @author Emmanuel Bigeon */
|
|
||||||
@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
|
|
||||||
public class SWTConsoleViewTest {
|
public class SWTConsoleViewTest {
|
||||||
|
|
||||||
protected static final long TWO_SECONDS = 2000;
|
/** Test method for {@link net.bigeon.gclc.swt.SWTConsoleView#setFocus()}. */
|
||||||
private static final Display DISPLAY = Display.getDefault();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGeneric() {
|
public void testSetFocus() {
|
||||||
final Shell shell = new Shell(DISPLAY);
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
final SWTConsoleView swtConsole = new SWTConsoleView(shell, SWT.NONE);
|
assertFalse("Non visible component set focus should fail", view.setFocus());
|
||||||
try (PipedConsoleOutput manager = new PipedConsoleOutput();
|
|
||||||
PipedConsoleInput input = new PipedConsoleInput(System.out)) {
|
|
||||||
swtConsole.setManager(manager, input);
|
|
||||||
} catch (final IOException e2) {
|
|
||||||
assertNull(e2);
|
|
||||||
}
|
|
||||||
try (PipedConsoleOutput manager = new PipedConsoleOutput();
|
|
||||||
PipedConsoleInput input = new PipedConsoleInput(System.out)) {
|
|
||||||
swtConsole.setManager(manager, input);
|
|
||||||
final ConsoleApplication appl = new ConsoleApplication(manager, input,
|
|
||||||
"Hello", "See you");
|
|
||||||
appl.add(new ExitCommand("exit", appl));
|
|
||||||
appl.add(new Command("long") {
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
|
|
||||||
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
|
|
||||||
* java.lang.String[]) */
|
|
||||||
@Override
|
|
||||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
|
||||||
final String... args) throws CommandRunException {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** Test method for
|
||||||
public String tip() {
|
* {@link net.bigeon.gclc.swt.SWTConsoleView#SWTConsoleView(org.eclipse.swt.widgets.Composite, int)}. */
|
||||||
return "a long running command";
|
@Test
|
||||||
|
public void testSWTConsoleView() {
|
||||||
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
|
assertNotNull("View should be initialized with managers", view.getInputManager());
|
||||||
|
assertNotNull("View should be initialized with managers",
|
||||||
|
view.getOutputManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/** Test method for
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
* {@link net.bigeon.gclc.swt.SWTConsoleView#setManager(net.bigeon.gclc.utils.PipedConsoleOutput, net.bigeon.gclc.utils.PipedConsoleInput)}. */
|
||||||
@Override
|
@Test
|
||||||
protected String usageDetail() {
|
public void testSetManager() {
|
||||||
// TODO Auto-generated method stub
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
// return null;
|
// Disconnection should work.
|
||||||
throw new RuntimeException("Not implemented yet");
|
view.setManager(null, null);
|
||||||
}
|
|
||||||
});
|
|
||||||
// shell.pack();
|
|
||||||
shell.open();
|
|
||||||
shell.setVisible(false);
|
|
||||||
final Thread applThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
appl.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final Thread testThread = new Thread(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
swtConsole.setText("test"); //$NON-NLS-1$
|
|
||||||
swtConsole.validateInput();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
Thread.sleep(TWO_SECONDS);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Display.getDefault().syncExec(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
shell.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
applThread.start();
|
|
||||||
testThread.start();
|
|
||||||
while (!shell.isDisposed()) {
|
|
||||||
if (!DISPLAY.readAndDispatch()) {
|
|
||||||
DISPLAY.sleep();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final InvalidCommandName e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (final IOException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
mock-maker-inline
|
||||||
79
gclc-test/pom.xml
Normal file
79
gclc-test/pom.xml
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
<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/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>net.bigeon.config</groupId>
|
||||||
|
<artifactId>ebigeon-config</artifactId>
|
||||||
|
<version>1.8.21</version>
|
||||||
|
</parent>
|
||||||
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
|
<artifactId>test</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>GCLC Tests</name>
|
||||||
|
<description>Test utilities for GCLC applications and extensions</description>
|
||||||
|
<inceptionYear>2018</inceptionYear>
|
||||||
|
<organization>
|
||||||
|
<name>Bigeon</name>
|
||||||
|
<url>https://bigeon.net</url>
|
||||||
|
</organization>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<distribution>manual</distribution>
|
||||||
|
<name>CeCILL 2.1</name>
|
||||||
|
<url>https://cecill.info/licences/Licence_CeCILL_V2.1-en.html</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<email>emmanuel@bigeon.fr</email>
|
||||||
|
<name>Emmanuel Bigeon</name>
|
||||||
|
<url>bigeon.net</url>
|
||||||
|
<roles>
|
||||||
|
<role>PM</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
|
<tag>HEAD</tag>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<license.licenseName>cecill_2.1</license.licenseName>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.bigeon</groupId>
|
||||||
|
<artifactId>gclc</artifactId>
|
||||||
|
<version>2.0.12</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.bigeon.test</groupId>
|
||||||
|
<artifactId>junitmt</artifactId>
|
||||||
|
<version>1.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<reporting>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.10.3</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.github.sevntu-checkstyle</groupId>
|
||||||
|
<artifactId>dsm-maven-plugin</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</reporting>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
||||||
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public final class InputContract {
|
||||||
|
|
||||||
|
public void testInputContract(final Supplier<ConsoleInput> inputs)
|
||||||
|
throws IOException, InterruptedException {
|
||||||
|
// Test close contract
|
||||||
|
final ConsoleInput input = inputs.get();
|
||||||
|
assertFalse("An input should not initially be closed", input.isClosed());
|
||||||
|
input.close();
|
||||||
|
assertTrue("An input should close", input.isClosed());
|
||||||
|
input.close();
|
||||||
|
assertTrue("A closed input should stay closed", input.isClosed());
|
||||||
|
try {
|
||||||
|
input.prompt();
|
||||||
|
fail("Closed input prompting should fail");
|
||||||
|
} catch (final IOException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test interruption contract
|
||||||
|
final ConsoleInput input2 = inputs.get();
|
||||||
|
final FunctionalTestRunnable prompting = new FunctionalTestRunnable(
|
||||||
|
new TestFunction() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() throws Exception {
|
||||||
|
try {
|
||||||
|
input2.prompt();
|
||||||
|
fail("Interrupted prompt should throw INterruptedIOException");
|
||||||
|
} catch (final InterruptedIOException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final Thread th = new Thread(prompting);
|
||||||
|
th.start();
|
||||||
|
// while (!input2.isPrompting()) {
|
||||||
|
th.join(200);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
input2.interruptPrompt();
|
||||||
|
ThreadTest.assertRuns(th, prompting);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.0.12</version>
|
<version>2.1.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Generic Command Ligne console</name>
|
<name>Generic Command Ligne console</name>
|
||||||
<description>A generic framework for console applications, with customized command input and output streams.</description>
|
<description>A generic framework for console applications, with customized command input and output streams.</description>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
</developers>
|
</developers>
|
||||||
<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-2.0.12</tag>
|
<tag>gclc-2.1.0</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
|||||||
* A typical use case is the following:
|
* A typical use case is the following:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* {@link ConsoleOutput} out = new {@link net.bigeon.gclc.utils.StreamConsoleOutput StreamConsoleOutput}();
|
* {@link ConsoleOutput} out = new {@link net.bigeon.gclc.manager.StreamConsoleOutput StreamConsoleOutput}();
|
||||||
* {@link ConsoleInput} in = new {@link net.bigeon.gclc.utils.StreamConsoleInput StreamConsoleInput}();
|
* {@link ConsoleInput} in = new {@link net.bigeon.gclc.manager.StreamConsoleInput StreamConsoleInput}();
|
||||||
* {@link ConsoleApplication} app = new {@link ConsoleApplication}(out, in, "welcome", "see you latter")};
|
* {@link ConsoleApplication} app = new {@link ConsoleApplication}(out, in, "welcome", "see you latter")};
|
||||||
* app.{@link ConsoleApplication#add(ICommand) add}("my_command", new {@link ICommand MyCommand()});
|
* app.{@link ConsoleApplication#add(ICommand) add}("my_command", new {@link ICommand MyCommand()});
|
||||||
* app.{@link ConsoleApplication#start() start()};
|
* app.{@link ConsoleApplication#start() start()};
|
||||||
|
|||||||
@@ -116,8 +116,7 @@ public abstract class ParametrizedCommand extends Command {
|
|||||||
* @param flag the boolean flag
|
* @param flag the boolean flag
|
||||||
* @throws InvalidParameterException if the parameter is already defined as a
|
* @throws InvalidParameterException if the parameter is already defined as a
|
||||||
* string parameter */
|
* string parameter */
|
||||||
protected final void addBooleanParameter(final String flag)
|
protected final void addBooleanParameter(final String flag) {
|
||||||
throws InvalidParameterException {
|
|
||||||
data.addBooleanParameter(flag);
|
data.addBooleanParameter(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,8 +126,7 @@ public abstract class ParametrizedCommand extends Command {
|
|||||||
* @param needed if the parameter's absence should cause an exception
|
* @param needed if the parameter's absence should cause an exception
|
||||||
* @throws InvalidParameterException if the parameter is already defined as a
|
* @throws InvalidParameterException if the parameter is already defined as a
|
||||||
* boolean parameter */
|
* boolean parameter */
|
||||||
protected final void addStringParameter(final String flag, final boolean needed)
|
protected final void addStringParameter(final String flag, final boolean needed) {
|
||||||
throws InvalidParameterException {
|
|
||||||
data.addStringParameter(flag, needed);
|
data.addStringParameter(flag, needed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import net.bigeon.gclc.exception.CommandParsingException;
|
import net.bigeon.gclc.exception.CommandParsingException;
|
||||||
import net.bigeon.gclc.exception.InvalidParameterException;
|
import net.bigeon.gclc.exception.InvalidParameterException;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.utils.EmptyInput;
|
import net.bigeon.gclc.manager.EmptyInput;
|
||||||
|
|
||||||
/** An object to handle standardized command parameters.
|
/** An object to handle standardized command parameters.
|
||||||
*
|
*
|
||||||
@@ -120,7 +120,7 @@ public final class ParametrizedCommandData {
|
|||||||
* @param flag the boolean flag
|
* @param flag the boolean flag
|
||||||
* @throws InvalidParameterException if the parameter is already defined as a
|
* @throws InvalidParameterException if the parameter is already defined as a
|
||||||
* string parameter */
|
* string parameter */
|
||||||
public void addBooleanParameter(final String flag) throws InvalidParameterException {
|
public void addBooleanParameter(final String flag) {
|
||||||
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
|
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
|
||||||
throw new InvalidParameterException("Parameter is already defined as string"); //$NON-NLS-1$
|
throw new InvalidParameterException("Parameter is already defined as string"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
@@ -134,8 +134,7 @@ public final class ParametrizedCommandData {
|
|||||||
* @param needed if the parameter's absence should cause an exception
|
* @param needed if the parameter's absence should cause an exception
|
||||||
* @throws InvalidParameterException if the parameter is already defined as a
|
* @throws InvalidParameterException if the parameter is already defined as a
|
||||||
* boolean parameter */
|
* boolean parameter */
|
||||||
public void addStringParameter(final String flag, final boolean needed)
|
public void addStringParameter(final String flag, final boolean needed) {
|
||||||
throws InvalidParameterException {
|
|
||||||
if (params.containsKey(flag)) {
|
if (params.containsKey(flag)) {
|
||||||
checkParam(flag, needed);
|
checkParam(flag, needed);
|
||||||
return;
|
return;
|
||||||
@@ -149,9 +148,8 @@ public final class ParametrizedCommandData {
|
|||||||
* @param param the string parameter
|
* @param param the string parameter
|
||||||
* @param needed if the parameter is needed
|
* @param needed if the parameter is needed
|
||||||
* @throws InvalidParameterException if the new definition is invalid */
|
* @throws InvalidParameterException if the new definition is invalid */
|
||||||
private void checkParam(final String param, final boolean needed)
|
private void checkParam(final String param, final boolean needed) {
|
||||||
throws InvalidParameterException {
|
final Boolean val = stringParams.get(param);
|
||||||
Boolean val = stringParams.get(param);
|
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
|
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
|
||||||
stringParams.put(param, need);
|
stringParams.put(param, need);
|
||||||
@@ -217,7 +215,7 @@ public final class ParametrizedCommandData {
|
|||||||
* @param param the parameter name
|
* @param param the parameter name
|
||||||
* @return if the parameter is needed */
|
* @return if the parameter is needed */
|
||||||
public boolean isNeeded(final String param) {
|
public boolean isNeeded(final String param) {
|
||||||
Boolean val = params.get(param);
|
final Boolean val = params.get(param);
|
||||||
return val != null && val.booleanValue();
|
return val != null && val.booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,39 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.command.base;
|
package net.bigeon.gclc.command.base;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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 java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ package net.bigeon.gclc.exception;
|
|||||||
/** An exception raised during command parsing.
|
/** An exception raised during command parsing.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public class CommandParsingException extends Exception {
|
public final class CommandParsingException extends Exception {
|
||||||
|
|
||||||
/** svuid. */
|
/** svuid. */
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ package net.bigeon.gclc.exception;
|
|||||||
* the command is already used.
|
* the command is already used.
|
||||||
*
|
*
|
||||||
* @author Emmanuel BIGEON */
|
* @author Emmanuel BIGEON */
|
||||||
public class InvalidCommandName extends Exception {
|
public final class InvalidCommandName extends Exception {
|
||||||
|
|
||||||
/** the SVUID. */
|
/** the SVUID. */
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ package net.bigeon.gclc.exception;
|
|||||||
* parameter definition.
|
* parameter definition.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public class InvalidParameterException extends Exception {
|
public final class InvalidParameterException extends RuntimeException {
|
||||||
|
|
||||||
/** the SVUID. */
|
/** the SVUID. */
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|||||||
@@ -94,8 +94,7 @@ public interface ConsoleInput extends AutoCloseable {
|
|||||||
/** Indicate to the input that is should interrompt the prompting, if possible.
|
/** Indicate to the input that is should interrompt the prompting, if possible.
|
||||||
* <p>
|
* <p>
|
||||||
* The pending {@link #prompt()} or {@link #prompt(String)} operations should
|
* The pending {@link #prompt()} or {@link #prompt(String)} operations should
|
||||||
* return immediatly. However the returned value can be anything (from the
|
* return immediately by throwing an InterruptedIOException. */
|
||||||
* partial prompt content to an empty string or even a null pointer). */
|
|
||||||
void interruptPrompt();
|
void interruptPrompt();
|
||||||
|
|
||||||
/** Test if the input is closed.
|
/** Test if the input is closed.
|
||||||
|
|||||||
@@ -36,12 +36,10 @@
|
|||||||
* gclc:net.bigeon.gclc.manager.EmptyInput.java
|
* gclc:net.bigeon.gclc.manager.EmptyInput.java
|
||||||
* Created on: Nov 13, 2017
|
* Created on: Nov 13, 2017
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
* Generic Command Ligne console
|
* Generic Command Ligne console
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
|
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
|
||||||
* Created on: Nov 18, 2016
|
* Created on: Nov 18, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -78,7 +78,7 @@ import java.io.PrintStream;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.utils.WritingRunnable;
|
||||||
|
|
||||||
/** This console input allows to enter commands and retrieve the output as an
|
/** This console input allows to enter commands and retrieve the output as an
|
||||||
* input.
|
* input.
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
|
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
|
||||||
* Created on: Nov 18, 2016
|
* Created on: Nov 18, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -79,7 +79,7 @@ import java.io.PipedOutputStream;
|
|||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
|
||||||
/** This console output allows to retrieve the output as an input.
|
/** This console output allows to retrieve the output as an input.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -36,9 +36,7 @@
|
|||||||
* gclc:net.bigeon.gclc.manager.SinkOutput.java
|
* gclc:net.bigeon.gclc.manager.SinkOutput.java
|
||||||
* Created on: Nov 13, 2017
|
* Created on: Nov 13, 2017
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
|
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
|
||||||
* Created on: Dec 19, 2014
|
* Created on: Dec 19, 2014
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -79,8 +79,8 @@ import java.io.PrintStream;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
|
||||||
/** A console using the input stream and print stream.
|
/** A console using the input stream and print stream.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
|
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
|
||||||
* Created on: Dec 19, 2014
|
* Created on: Dec 19, 2014
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -74,8 +74,6 @@ package net.bigeon.gclc.utils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
|
||||||
|
|
||||||
/** A console using the input stream and print stream.
|
/** A console using the input stream and print stream.
|
||||||
* <p>
|
* <p>
|
||||||
* The default constructor will use the system standart input and output.
|
* The default constructor will use the system standart input and output.
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
* gclc:net.bigeon.gclc.tools.AOutputForwardRunnable.java
|
* gclc:net.bigeon.gclc.tools.AOutputForwardRunnable.java
|
||||||
* Created on: Dec 1, 2016
|
* Created on: Dec 1, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.manager.forwarding;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -75,6 +75,8 @@ import java.io.IOException;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/** An incomplete implematation used to forward messages from a piped console.
|
/** An incomplete implematation used to forward messages from a piped console.
|
||||||
* <p>
|
* <p>
|
||||||
* This forwarding can be interrupted without closing the piped manager.
|
* This forwarding can be interrupted without closing the piped manager.
|
||||||
@@ -88,9 +90,9 @@ public abstract class AOutputForwardRunnable implements Runnable {
|
|||||||
/** The default timeout (one tenth of second). */
|
/** The default timeout (one tenth of second). */
|
||||||
private static final long DEFAULT_TIMEOUT = 100;
|
private static final long DEFAULT_TIMEOUT = 100;
|
||||||
/** The manager. */
|
/** The manager. */
|
||||||
private final PipedConsoleOutput manager;
|
protected final PipedConsoleOutput manager;
|
||||||
/** The timeout. */
|
/** The timeout. */
|
||||||
private final long timeout;
|
protected final long timeout;
|
||||||
|
|
||||||
/** Create a forwarding runnable.
|
/** Create a forwarding runnable.
|
||||||
*
|
*
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/** This package contains the {@link java.lang.Runnable} implementations used to
|
||||||
|
* forward messages to or from console output or input.
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
package net.bigeon.gclc.manager.forwarding;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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%
|
||||||
|
*/
|
||||||
|
|
||||||
@@ -111,6 +111,7 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
private final Map<String, Object> messageBlocker = new ConcurrentHashMap<>();
|
private final Map<String, Object> messageBlocker = new ConcurrentHashMap<>();
|
||||||
/** The lock. */
|
/** The lock. */
|
||||||
private final Object messageBlockerLock = new Object();
|
private final Object messageBlockerLock = new Object();
|
||||||
|
private boolean interrupting = false;
|
||||||
/** Create a reading runnable.
|
/** Create a reading runnable.
|
||||||
*
|
*
|
||||||
* @param reader the input to read from */
|
* @param reader the input to read from */
|
||||||
@@ -146,7 +147,7 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
public String getMessage() throws IOException {
|
public String getMessage() throws IOException {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (!messages.isEmpty()) {
|
if (!messages.isEmpty()) {
|
||||||
return messages.poll();
|
return pollMessage();
|
||||||
}
|
}
|
||||||
if (!running) {
|
if (!running) {
|
||||||
throw new IOException(CLOSED_PIPE);
|
throw new IOException(CLOSED_PIPE);
|
||||||
@@ -155,8 +156,7 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
waitMessage(TIMEOUT);
|
waitMessage(TIMEOUT);
|
||||||
LOGGER.log(Level.FINEST, "Polled: {0}", messages.peek()); //$NON-NLS-1$
|
LOGGER.log(Level.FINEST, "Polled: {0}", messages.peek()); //$NON-NLS-1$
|
||||||
waiting = false;
|
waiting = false;
|
||||||
notifyMessage(messages.peek());
|
return pollMessage();
|
||||||
return messages.poll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
public String getNextMessage(final long timeout) throws IOException {
|
public String getNextMessage(final long timeout) throws IOException {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (!messages.isEmpty()) {
|
if (!messages.isEmpty()) {
|
||||||
return messages.poll();
|
return pollMessage();
|
||||||
}
|
}
|
||||||
if (!running) {
|
if (!running) {
|
||||||
throw new IOException(CLOSED_PIPE);
|
throw new IOException(CLOSED_PIPE);
|
||||||
@@ -179,10 +179,23 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
if (messages.isEmpty()) {
|
if (messages.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return messages.poll();
|
return pollMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String pollMessage() throws InterruptedIOException {
|
||||||
|
final String msg = messages.poll();
|
||||||
|
if (msg.isEmpty() && interrupting) {
|
||||||
|
throw new InterruptedIOException();
|
||||||
|
}
|
||||||
|
notifyMessage(msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wait for a message to be delivered.
|
||||||
|
*
|
||||||
|
* @param message the message
|
||||||
|
* @throws InterruptedException if the wait was interrupted */
|
||||||
public void waitForDelivery(final String message) throws InterruptedException {
|
public void waitForDelivery(final String message) throws InterruptedException {
|
||||||
Object mLock;
|
Object mLock;
|
||||||
synchronized (messageBlockerLock) {
|
synchronized (messageBlockerLock) {
|
||||||
@@ -214,7 +227,8 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
public void interrupt() {
|
public void interrupt() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
messages.offer(""); //$NON-NLS-1$
|
messages.offer("");
|
||||||
|
interrupting = true;
|
||||||
lock.notifyAll();
|
lock.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.bigeon.gclc.command.ICommand;
|
import net.bigeon.gclc.command.ICommand;
|
||||||
import net.bigeon.gclc.exception.InvalidCommandName;
|
import net.bigeon.gclc.exception.InvalidCommandName;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ import net.bigeon.gclc.exception.InvalidCommandName;
|
|||||||
import net.bigeon.gclc.i18n.Messages;
|
import net.bigeon.gclc.i18n.Messages;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/** Test class for ConsoleApplication
|
/** Test class for ConsoleApplication
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ import org.junit.Test;
|
|||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ import net.bigeon.gclc.command.base.MockCommand;
|
|||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package net.bigeon.gclc.command;
|
package net.bigeon.gclc.command;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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 static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ import net.bigeon.gclc.exception.CommandRunException;
|
|||||||
import net.bigeon.gclc.exception.InvalidParameterException;
|
import net.bigeon.gclc.exception.InvalidParameterException;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.test.junitmt.ATestRunnable;
|
import net.bigeon.test.junitmt.ATestRunnable;
|
||||||
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
||||||
import net.bigeon.test.junitmt.TestFunction;
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
|
|||||||
@@ -85,8 +85,8 @@ import net.bigeon.gclc.ConsoleTestApplication;
|
|||||||
import net.bigeon.gclc.command.base.ScriptExecution;
|
import net.bigeon.gclc.command.base.ScriptExecution;
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ import net.bigeon.gclc.exception.CommandRunException;
|
|||||||
import net.bigeon.gclc.exception.InvalidCommandName;
|
import net.bigeon.gclc.exception.InvalidCommandName;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package net.bigeon.gclc.command.base;
|
package net.bigeon.gclc.command.base;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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 static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@@ -9,7 +43,7 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
|
||||||
public class EchoCommandTest {
|
public class EchoCommandTest {
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
@@ -90,6 +91,9 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.ReadingRunnable;
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
||||||
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -198,9 +202,11 @@ public class ReadingRunnableTest {
|
|||||||
public final void testGetPendingMessages() throws IOException, InterruptedException {
|
public final void testGetPendingMessages() throws IOException, InterruptedException {
|
||||||
|
|
||||||
final PipedOutputStream out = new PipedOutputStream();
|
final PipedOutputStream out = new PipedOutputStream();
|
||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(new PipedInputStream(out), StandardCharsets.UTF_8));
|
final BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(new PipedInputStream(out), StandardCharsets.UTF_8));
|
||||||
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
final BufferedWriter writer = new BufferedWriter(
|
||||||
|
new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||||
writer.write("one");
|
writer.write("one");
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
writer.write("two");
|
writer.write("two");
|
||||||
@@ -222,4 +228,30 @@ public class ReadingRunnableTest {
|
|||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterruption() throws IOException, InterruptedException {
|
||||||
|
final PipedOutputStream out = new PipedOutputStream();
|
||||||
|
final BufferedReader reader = new BufferedReader(
|
||||||
|
new InputStreamReader(new PipedInputStream(out), StandardCharsets.UTF_8));
|
||||||
|
final ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
|
|
||||||
|
final FunctionalTestRunnable test = new FunctionalTestRunnable(
|
||||||
|
new TestFunction() {
|
||||||
|
@Override
|
||||||
|
public void apply() throws IOException {
|
||||||
|
try {
|
||||||
|
runnable.getMessage();
|
||||||
|
fail("Message interruption should cause an exception");
|
||||||
|
} catch (final InterruptedIOException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
final Thread th = new Thread(test, "Prompt wait");
|
||||||
|
th.start();
|
||||||
|
th.join(200);
|
||||||
|
runnable.interrupt();
|
||||||
|
ThreadTest.assertRuns(th, test);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ import java.nio.charset.Charset;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.StreamConsoleInput;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* TODO
|
* TODO
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.test.junitmt.ATestRunnable;
|
import net.bigeon.test.junitmt.ATestRunnable;
|
||||||
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
||||||
import net.bigeon.test.junitmt.TestFunction;
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.AOutputForwardRunnable;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.utils.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -143,7 +143,7 @@ public class AOutputForwardRunnableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.utils.AOutputForwardRunnable#run()}. */
|
* {@link net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable#run()}. */
|
||||||
@Test
|
@Test
|
||||||
public final void testRun() {
|
public final void testRun() {
|
||||||
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.utils;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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 static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
@@ -8,6 +42,7 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
|
import net.bigeon.gclc.manager.EmptyInput;
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
|
||||||
public class EmptyInputTest {
|
public class EmptyInputTest {
|
||||||
|
|||||||
@@ -1,5 +1,39 @@
|
|||||||
package net.bigeon.gclc.utils;
|
package net.bigeon.gclc.utils;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%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 static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -7,6 +41,7 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
|
import net.bigeon.gclc.manager.SinkOutput;
|
||||||
|
|
||||||
public class SinkOutputTest {
|
public class SinkOutputTest {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user