Compare commits

..

22 Commits

Author SHA1 Message Date
e953c2e659 [maven-release-plugin] prepare release socket-1.1.15 2019-04-22 15:33:44 -04:00
0f4fd6109d Stop console closing on client dirty disconnection
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 15:29:11 -04:00
69a8fd2533 [maven-release-plugin] prepare for next development iteration 2019-04-14 17:20:28 -04:00
0b772ddeb3 [maven-release-plugin] prepare release swt-1.2.0 2019-04-14 17:20:24 -04:00
55f13ae004 Use public configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:19:44 -04:00
295075ca37 Update versions and configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:14:04 -04:00
75bbba9884 [maven-release-plugin] prepare for next development iteration 2019-04-14 17:10:09 -04:00
82daa84bdf [maven-release-plugin] prepare release socket-1.1.14 2019-04-14 17:10:05 -04:00
10a0858d81 Update configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:07:04 -04:00
dfd3645497 Update configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:03:57 -04:00
bd2da741f2 [maven-release-plugin] prepare for next development iteration 2019-04-02 09:41:05 -04:00
314db5b82f [maven-release-plugin] prepare release process-0.0.6 2019-04-02 09:40:56 -04:00
981668d3a7 Update dependency on collections
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-02-13 13:19:11 -05:00
9c8866827d Reduce prompting method complexity
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:25:01 -05:00
43c9faaee7 Added test for interruption and task failure
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:12:23 -05:00
8436e8926c Factor prompting methods code
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:12:13 -05:00
0cef23e17b Reduce branching depth
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 14:19:54 -05:00
6b2a25674d Fix interruption mechanic
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:57:48 -05:00
eec660e089 Improved message to test failure
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:57:21 -05:00
901469792d Added interruption flag
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:33:15 -05:00
79ee5394d4 Move inner classes into tool package
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:32:29 -05:00
acf4484eb3 [maven-release-plugin] prepare for next development iteration 2018-12-01 12:04:16 -05:00
26 changed files with 389 additions and 205 deletions

View File

@@ -8,7 +8,7 @@
<groupId>net.bigeon.gclc</groupId>
<artifactId>process</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<name>process</name>
@@ -49,7 +49,7 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.12</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>net.bigeon.test</groupId>

View File

@@ -68,6 +68,7 @@ package net.bigeon.gclc.process.io;
* #L%
*/
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
@@ -82,25 +83,27 @@ public final class ConnectingConsoleInput implements ConsoleInput {
private static final ConstantString EMPTY_STRING = new ConstantString("");
/** If the input is closed. */
private boolean close = false;
private boolean close = false;
/** The prompt string. */
private Supplier<String> prompt = EMPTY_STRING;
/** If the input is currently in prompting state.
* <p>
* To change it you should be in a promptLock. */
private boolean prompting = false;
private boolean prompting = false;
/** The synchronization lock for the prompting status. */
private final Object promptLock = new Object();
private final Object promptLock = new Object();
/** The synchronization lock for the connection status. */
private final Object connectionLock = new Object();
private final Object connectionLock = new Object();
/** The connected console input.
* <p>
* To use it, you should be in a promptLock and connectionLock. */
private ConsoleInput connected = null;
private ConsoleInput connected = null;
/** The connection state.
* <p>
* To read or modify it, you should be in a connectionLock synchronize block. */
private boolean disconnection = false;
private boolean disconnection = false;
private boolean interrupting = false;
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#close() */
@@ -149,6 +152,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
public void interruptPrompt() {
synchronized (connectionLock) {
synchronized (promptLock) {
if (prompting) {
interrupting = true;
}
connectionLock.notifyAll();
if (connected != null) {
connected.interruptPrompt();
@@ -187,32 +193,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
synchronized (promptLock) {
prompting = true;
}
while (true) {
synchronized (promptLock) {
if (!prompting) {
return null;
}
}
getConnection(0);
boolean connect;
ConsoleInput actualConnected;
synchronized (connectionLock) {
connect = connected != null;
actualConnected = connected;
}
if (connect) {
final String res = actualConnected.prompt(message);
synchronized (promptLock) {
if (disconnection) {
disconnection = false;
} else if (prompting) {
return res;
} else {
// prompt interrupted, lose the result.
}
}
}
}
return doPrompt(message, 0, 0);
}
/* (non-Javadoc)
@@ -222,42 +203,89 @@ public final class ConnectingConsoleInput implements ConsoleInput {
if (timeout <= 0) {
return prompt(message);
}
final long end = System.currentTimeMillis() + timeout;
synchronized (promptLock) {
prompting = true;
}
final long tic = System.currentTimeMillis();
return doPrompt(message, timeout, tic);
}
private String doPrompt(final String message, final long timeout, final long tic)
throws IOException {
do {
synchronized (promptLock) {
if (!prompting) {
break;
}
if (!checkPrompt()) {
break;
}
getConnection(timeout);
getConnection(getTimeoutLeft(tic, timeout));
boolean connect;
ConsoleInput actualConnected;
synchronized (connectionLock) {
connect = connected != null;
actualConnected = connected;
}
if (connect) {
if (!connect) {
continue;
}
try {
final String res = actualPrompt(message, timeout, tic, actualConnected);
synchronized (promptLock) {
final String res = actualConnected.prompt(message,
end - System.currentTimeMillis());
if (disconnection) {
disconnection = false;
} else if (prompting) {
if (prompting) {
prompting = false;
return res;
} else {
// prompt interrupted, lose the result.
}
}
} catch (final InterruptedIOException e) {
// The inner console was interrupted. This can mean we are
// disconnecting or actually interrupted.
if (disconnection) {
disconnection = false;
} else {
interrupting = false;
throw e;
}
}
} while (System.currentTimeMillis() < end);
} while (checkTimeout(tic, timeout));
return null;
}
private void getConnection(final long timeout) {
private static String actualPrompt(final String message, final long timeout,
final long tic, final ConsoleInput actualConnected) throws IOException {
final long timeoutLeft = getTimeoutLeft(tic, timeout);
if (timeoutLeft == 0) {
return actualConnected.prompt(message);
}
return actualConnected.prompt(message, timeoutLeft);
}
private static boolean checkTimeout(final long tic, final long timeout) {
return timeout <= 0 || tic + timeout > System.currentTimeMillis();
}
private static long getTimeoutLeft(final long tic, final long timeout) {
if (timeout > 0) {
return Math.max(timeout + tic - System.currentTimeMillis(), 1);
}
if (timeout < 0) {
return 1;
}
return 0;
}
/** Test if we are in prompting state.
*
* @return if the process is currently in prompting state.
* @throws InterruptedIOException if the prompting state has been interrupted */
private boolean checkPrompt() throws InterruptedIOException {
synchronized (promptLock) {
if (!prompting && interrupting) {
interrupting = false;
throw new InterruptedIOException("Prompt was interrupted");
}
return prompting;
}
}
private void getConnection(final long timeout) throws InterruptedIOException {
boolean connect;
synchronized (connectionLock) {
connect = connected != null;
@@ -268,6 +296,10 @@ public final class ConnectingConsoleInput implements ConsoleInput {
Thread.currentThread().interrupt();
}
}
if (interrupting) {
interrupting = false;
throw new InterruptedIOException("Prompt ws interrupted");
}
}
}

View File

@@ -5,15 +5,18 @@ package net.bigeon.gclc.process;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** @author Emmanuel Bigeon */
public class ForkTaskTest {
@@ -36,15 +39,11 @@ public class ForkTaskTest {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"Unable to prompt user");
}
if ("ok".equals(msg)) {
out.println("Message");
} else {
out.println("fail");
}
out.println(msg);
}
};
final Thread execThread = new Thread(task);
final Thread execThread = new Thread(task, "Task");
execThread.start();
try {
execThread.join(100);
@@ -55,14 +54,103 @@ public class ForkTaskTest {
try (PipedConsoleOutput pco = new PipedConsoleOutput();
PipedConsoleInput pci = new PipedConsoleInput(null)) {
pci.type("ok");
while (!pco.available()) {
pci.type("ok");
task.join(pco, pci, 1000);
}
assertEquals("Execution should work", "Message", pco.readNextLine());
assertEquals("Positive execution", "ok", pco.readNextLine());
}
assertFalse("Running state should be updated by task on its completion",
task.isRunning());
}
@Test
public void testTaskInterruption() throws IOException, InterruptedException {
final ForkTask task = new ForkTask(5) {
@Override
public String getName() {
return "name";
}
@Override
protected void doRun() throws CommandRunException {
while (isRunning()) {
String msg;
try {
msg = in.prompt(1000);
} catch (final IOException e) {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"Unable to prompt user");
}
if (msg != null) {
out.println(msg);
}
}
}
};
final Thread execThread = new Thread(task, "Task");
execThread.start();
execThread.join(100);
final AtomicBoolean interrupted = new AtomicBoolean(false);
final AtomicBoolean interrupted2 = new AtomicBoolean(false);
final InterruptionListener listener = new InterruptionListener() {
@Override
public void interrupted() {
interrupted.set(true);
}
};
final InterruptionListener listener2 = new InterruptionListener() {
@Override
public void interrupted() {
interrupted2.set(true);
}
};
task.addInterruptionListener(listener);
task.addInterruptionListener(listener2);
task.rmInterruptionListener(listener2);
assertFalse("Interruption should not be notified before actual interruption",
interrupted.get());
assertTrue("Task should be started", task.isStarted());
task.setRunning(false);
try (PipedConsoleOutput pco = new PipedConsoleOutput();
PipedConsoleInput pci = new PipedConsoleInput(null)) {
task.join(pco, pci, 2000);
}
execThread.join();
assertTrue("Interruption should be notified to listeners", interrupted.get());
assertFalse("Running state should be updated by task on its completion",
task.isRunning());
assertFalse("Interruption should not be notified to removed listeners",
interrupted2.get());
task.rmInterruptionListener(listener);
}
@Test
public void testFailingTask() throws InterruptedException {
final ForkTask task = new ForkTask(5) {
@Override
public String getName() {
return "name";
}
@Override
protected void doRun() throws CommandRunException {
throw new CommandRunException("Error");
}
};
final Thread execThread = new Thread(task, "Task");
execThread.start();
execThread.join();
assertNotNull("Exception should be forwarded", task.getException());
}
}

View File

@@ -14,8 +14,8 @@ import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.process.mocks.TaskMock;
import net.bigeon.gclc.utils.PipedConsoleOutput;
/** @author Emmanuel Bigeon */
public class ProcessListTest {

View File

@@ -4,8 +4,10 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;
@@ -13,9 +15,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.StreamConsoleInput;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.StreamConsoleInput;
import net.bigeon.test.junitmt.ATestRunnable;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.TestFunction;
@@ -81,10 +83,28 @@ public class ConnectingConsoleInputTest {
@Override
public void apply() throws Exception {
assertNull("Interrupted should return null", in.prompt("m1", -1));
assertNull("Interrupted should return null", in.prompt("m2", 5000));
ended.set(true);
assertNull("Overtime should return null", in.prompt("m3", 200));
try {
final String res = in.prompt("m1", -1);
fail("interruption of infinite waiting prompt should cause error, but was "
+ res);
} catch (final InterruptedIOException e) {
// ok
}
try {
final String res = in.prompt("m2", 25000);
fail("interruption of finite waiting prompt should cause error, but was "
+ res);
} catch (final InterruptedIOException e) {
// ok
}
synchronized (ended) {
ended.set(true);
try {
assertNull("Overtime should return null", in.prompt("m3", 200));
} catch (final InterruptedIOException e) {
fail("Unexpected interruption error in overtime");
}
}
}
};
final ATestRunnable runnable = new FunctionalTestRunnable(one);
@@ -95,12 +115,16 @@ public class ConnectingConsoleInputTest {
public void run() {
while (!ended.get()) {
try {
th.join(500);
th.join(100);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
in.interruptPrompt();
synchronized (ended) {
if (!ended.get()) {
in.interruptPrompt();
}
}
}
}
});
@@ -112,7 +136,7 @@ public class ConnectingConsoleInputTest {
final PipedOutputStream os = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(os);
in.connect(new StreamConsoleInput(System.out, pis, StandardCharsets.UTF_8));
in.connect(new StreamConsoleInput(null, pis, StandardCharsets.UTF_8));
final ATestRunnable runnable2 = new FunctionalTestRunnable(one);
final Thread th2 = new Thread(runnable2);
final Thread inter2 = new Thread(new Runnable() {
@@ -121,12 +145,16 @@ public class ConnectingConsoleInputTest {
public void run() {
while (!ended.get()) {
try {
th2.join(500);
th2.join(100);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
in.interruptPrompt();
synchronized (ended) {
if (!ended.get()) {
in.interruptPrompt();
}
}
}
}
});

View File

@@ -8,7 +8,7 @@ import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
public class ConnectingConsoleOutputTest {

View File

@@ -2,12 +2,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<artifactId>ebigeon-public-conf</artifactId>
<version>1.0.10</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>socket</artifactId>
<version>1.1.14-SNAPSHOT</version>
<version>1.1.15</version>
<packaging>jar</packaging>
<name>GCLC Socket</name>
<description>Socket implementation of GCLC</description>
@@ -36,7 +36,7 @@
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>HEAD</tag>
<tag>socket-1.1.15</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -46,17 +46,17 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.12</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>smu</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>net.bigeon.test</groupId>
<artifactId>junitmt</artifactId>
<version>1.0.0</version>
<version>1.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -41,6 +41,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;
@@ -119,6 +120,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
if (prompting) {
// print the hint, to indicate we are waiting for a user input.
out.print(hint);
out.println();
out.flush();
}
final InputStreamReader streamReader = new InputStreamReader(stream,
@@ -279,7 +281,13 @@ public final class PluggableConsoleInput implements ConsoleInput {
final long connexionTimeout) throws IOException, InterruptedException {
synchronized (connexionLock) {
if (connected) {
return connexion.getNextMessage(messageTimeout);
try {
return connexion.getNextMessage(messageTimeout);
} catch (final InterruptedIOException e) {
throw e;
} catch (final IOException e) {
LOGGER.log(Level.INFO, "Communication was abrubptly interrupted", e);
}
}
connexionLock.wait(connexionTimeout);
}

View File

@@ -46,7 +46,7 @@ import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -2,12 +2,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>swt-config</artifactId>
<version>1.8.11</version>
<artifactId>swt-public-conf</artifactId>
<version>1.0.1</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>swt</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>GCLC swt</name>
<description>A swt window for console applications</description>
@@ -48,17 +48,17 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.12</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>collections</artifactId>
<version>1.1.6</version>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -41,7 +41,7 @@ import java.io.IOException;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleInput;
/** The object managing the console input.
*

View File

@@ -38,103 +38,14 @@ package net.bigeon.gclc.swt;
*/
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import net.bigeon.gclc.utils.AOutputForwardRunnable;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
/** 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. */

View File

@@ -41,6 +41,8 @@ import java.io.BufferedReader;
import org.eclipse.swt.widgets.Label;
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
/** The manager for the console prompt updates.
*
* @author Emmanuel Bigeon */

View File

@@ -76,8 +76,8 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import net.bigeon.collections.ArrayRibbon;
import net.bigeon.collections.Ribbon;
import net.bigeon.collections.ribbon.ArrayRibbon;
/** A key listener to validate commands and manage the history of commands.
*

View File

@@ -77,8 +77,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** A shell containing a {@link SWTConsoleView}
* <p>

View File

@@ -76,8 +76,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.ConsoleApplication;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** A SWT component to connect to gclc {@link ConsoleApplication}.
*

View File

@@ -0,0 +1,36 @@
/**
*
*/
package net.bigeon.gclc.swt;
import org.eclipse.swt.widgets.Text;
/** A runnable appending text to the content of a {@link Text} component.
*
* @author Emmanuel Bigeon */
public 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);
}
}

View File

@@ -1,7 +1,7 @@
/**
*
*/
package net.bigeon.gclc.swt;
package net.bigeon.gclc.swt.tools;
/*-
* #%L

View File

@@ -0,0 +1,68 @@
/**
*
*/
package net.bigeon.gclc.swt.tools;
import org.eclipse.swt.widgets.Widget;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
import net.bigeon.gclc.swt.ConsoleOutputDisplay;
/** The local implementation of the forwarding runnable.
*
* @author Emmanuel Bigeon */
public 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;
}
}

View File

@@ -0,0 +1,9 @@
/**
*
*/
/** Tool classes for the library. External code should not rely on classes in
* there as they can be removed without notice.
*
* @author Emmanuel Bigeon */
package net.bigeon.gclc.swt.tools;

View File

@@ -39,17 +39,14 @@ package net.bigeon.gclc.swt;
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 static org.mockito.Mockito.*;
import java.io.IOException;
import org.eclipse.swt.widgets.Text;
import org.junit.Test;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleInput;
/** @author Emmanuel Bigeon */
public class ConsoleInputManagerTest {

View File

@@ -38,10 +38,7 @@ package net.bigeon.gclc.swt;
*/
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 static org.mockito.Mockito.*;
import java.io.IOException;
@@ -51,7 +48,7 @@ import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** @author Emmanuel Bigeon */
public class ConsoleOutputManagerTest {

View File

@@ -53,6 +53,8 @@ import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
/** @author Emmanuel Bigeon */
public class PromptReadingRunnableTest {
private final Label view = mock(Label.class);
@@ -72,7 +74,7 @@ public class PromptReadingRunnableTest {
}).when(display).syncExec(any(Runnable.class));
}
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
*
* @throws IOException if an error occurred */
@Test
@@ -85,7 +87,7 @@ public class PromptReadingRunnableTest {
runnable.run();
}
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
*
* @throws IOException if an error occurred */
@Test

View File

@@ -44,6 +44,9 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** @author Emmanuel Bigeon */
public class SWTConsoleShellTest {
@@ -61,7 +64,7 @@ public class SWTConsoleShellTest {
}
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsole#connect(net.bigeon.gclc.utils.PipedConsoleInput, net.bigeon.gclc.utils.PipedConsoleOutput, java.io.BufferedReader)}. */
* {@link net.bigeon.gclc.swt.SWTConsole#connect(PipedConsoleInput, PipedConsoleOutput, java.io.BufferedReader)}. */
@Test
public void testConnect() {
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);

View File

@@ -44,6 +44,9 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** @author Emmanuel Bigeon */
public class SWTConsoleViewTest {
@@ -65,7 +68,7 @@ public class SWTConsoleViewTest {
}
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsoleView#setManager(net.bigeon.gclc.utils.PipedConsoleOutput, net.bigeon.gclc.utils.PipedConsoleInput)}. */
* {@link net.bigeon.gclc.swt.SWTConsoleView#setManager(PipedConsoleOutput, PipedConsoleInput)}. */
@Test
public void testSetManager() {
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);

View File

@@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<artifactId>ebigeon-public-conf</artifactId>
<version>1.0.10</version>
</parent>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.1.0</version>
<version>2.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Generic Command Ligne console</name>
<description>A generic framework for console applications, with customized command input and output streams.</description>
@@ -37,7 +37,7 @@
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>gclc-2.1.0</tag>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>