Compare commits
No commits in common. "master" and "socket-1.1.17" have entirely different histories.
master
...
socket-1.1
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>ebigeon-config</artifactId>
|
<artifactId>ebigeon-config</artifactId>
|
||||||
<version>1.8.33</version>
|
<version>1.8.21</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
@ -38,7 +38,7 @@
|
|||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
@ -49,12 +49,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon.test</groupId>
|
<groupId>net.bigeon.test</groupId>
|
||||||
<artifactId>junitmt</artifactId>
|
<artifactId>junitmt</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -100,7 +100,7 @@ public abstract class ForkTask implements Task {
|
|||||||
/** Create the task.
|
/** Create the task.
|
||||||
*
|
*
|
||||||
* @param lines the number of print to store in the output */
|
* @param lines the number of print to store in the output */
|
||||||
protected ForkTask(final int lines) {
|
public ForkTask(final int lines) {
|
||||||
out = new ConnectingConsoleOutput(ConnectingConsoleOutput.PERSIST, lines);
|
out = new ConnectingConsoleOutput(ConnectingConsoleOutput.PERSIST, lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,18 +142,15 @@ public abstract class ForkTask implements Task {
|
|||||||
* @param timeout the maximal time to join for (0 for ever) */
|
* @param timeout the maximal time to join for (0 for ever) */
|
||||||
public final void join(final ConsoleOutput out, final ConsoleInput in,
|
public final void join(final ConsoleOutput out, final ConsoleInput in,
|
||||||
final long timeout) {
|
final long timeout) {
|
||||||
final long tic = System.currentTimeMillis();
|
|
||||||
synchronized (runLock) {
|
synchronized (runLock) {
|
||||||
this.out.connect(out);
|
this.out.connect(out);
|
||||||
this.in.connect(in);
|
this.in.connect(in);
|
||||||
long tac = System.currentTimeMillis() - tic;
|
try {
|
||||||
while (running && tac < timeout) {
|
if (running) {
|
||||||
try {
|
|
||||||
runLock.wait(timeout);
|
runLock.wait(timeout);
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
}
|
||||||
tac = System.currentTimeMillis() - tic;
|
} catch (final InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
this.out.disconnect();
|
this.out.disconnect();
|
||||||
this.in.disconnect();
|
this.in.disconnect();
|
||||||
|
@ -84,8 +84,8 @@ public abstract class TaskSpawner extends Command {
|
|||||||
private final ExecutorService threadPool;
|
private final ExecutorService threadPool;
|
||||||
|
|
||||||
/** @param name the command name
|
/** @param name the command name
|
||||||
* @param threadPool the pool */
|
* @param pool the pool */
|
||||||
protected TaskSpawner(final String name, final TaskPool pool,
|
public TaskSpawner(final String name, final TaskPool pool,
|
||||||
final ExecutorService threadPool) {
|
final ExecutorService threadPool) {
|
||||||
super(name);
|
super(name);
|
||||||
this.pool = pool;
|
this.pool = pool;
|
||||||
|
@ -72,16 +72,20 @@ import java.io.InterruptedIOException;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
|
||||||
/** A console input that can be connected to and diconnected from.
|
/** A console input that can be connected to and diconnected from.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class ConnectingConsoleInput implements ConsoleInput {
|
public final class ConnectingConsoleInput implements ConsoleInput {
|
||||||
|
|
||||||
|
/** The empty string provider. */
|
||||||
|
private static final ConstantString EMPTY_STRING = new ConstantString("");
|
||||||
|
|
||||||
/** 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 Supplier<String> prompt = () -> "";
|
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. */
|
||||||
@ -206,18 +210,10 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
return doPrompt(message, timeout, tic);
|
return doPrompt(message, timeout, tic);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Actually do the prompting
|
|
||||||
*
|
|
||||||
* @param message the prompt message
|
|
||||||
* @param timeout the time to wait for an answer
|
|
||||||
* @param tic the moment the wait started
|
|
||||||
* @return the message provided through the prompting
|
|
||||||
* @throws IOException if an IO error occurred while prompting. */
|
|
||||||
private String doPrompt(final String message, final long timeout, final long tic)
|
private String doPrompt(final String message, final long timeout, final long tic)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
do {
|
do {
|
||||||
if (!checkPrompt()) {
|
if (!checkPrompt()) {
|
||||||
// We are not prompting... lets stop here.
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
getConnection(getTimeoutLeft(tic, timeout));
|
getConnection(getTimeoutLeft(tic, timeout));
|
||||||
@ -228,13 +224,10 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
actualConnected = connected;
|
actualConnected = connected;
|
||||||
}
|
}
|
||||||
if (!connect) {
|
if (!connect) {
|
||||||
// There is no provide of input... So lets start again, until we actually
|
|
||||||
// DO get a provider of input.
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final String res = actualPrompt(message, timeout, tic, actualConnected);
|
final String res = actualPrompt(message, timeout, tic, actualConnected);
|
||||||
// We got something from the prompting
|
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
if (prompting) {
|
if (prompting) {
|
||||||
prompting = false;
|
prompting = false;
|
||||||
@ -293,10 +286,10 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getConnection(final long timeout) throws InterruptedIOException {
|
private void getConnection(final long timeout) throws InterruptedIOException {
|
||||||
final long tic = System.currentTimeMillis();
|
boolean connect;
|
||||||
synchronized (connectionLock) {
|
synchronized (connectionLock) {
|
||||||
while ((connected == null || !interrupting)
|
connect = connected != null;
|
||||||
&& (tic + timeout) > System.currentTimeMillis()) {
|
if (!connect) {
|
||||||
try {
|
try {
|
||||||
connectionLock.wait(timeout);
|
connectionLock.wait(timeout);
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
@ -314,7 +307,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final String prompt) {
|
public void setPrompt(final String prompt) {
|
||||||
this.prompt = () -> prompt;
|
this.prompt = new ConstantString(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package net.bigeon.gclc.process.io;
|
package net.bigeon.gclc.process.io;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
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.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
@ -8,16 +12,16 @@ import java.io.PipedInputStream;
|
|||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.StreamConsoleInput;
|
import net.bigeon.gclc.manager.StreamConsoleInput;
|
||||||
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
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.ThreadTest;
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
import net.bigeon.test.junitmt.api.ATestRunnable;
|
|
||||||
import net.bigeon.test.junitmt.api.TestFunction;
|
|
||||||
|
|
||||||
public class ConnectingConsoleInputTest {
|
public class ConnectingConsoleInputTest {
|
||||||
|
|
||||||
@ -63,8 +67,9 @@ public class ConnectingConsoleInputTest {
|
|||||||
public void testCoveragePrompt() {
|
public void testCoveragePrompt() {
|
||||||
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
||||||
in.setPrompt("test");
|
in.setPrompt("test");
|
||||||
assertEquals("Prompt should be set correctly", "test", in.getPrompt().get());
|
assertEquals("Prompt should be set correctly", "test",
|
||||||
final Supplier<String> prompt = () -> "other";
|
((ConstantString) in.getPrompt()).get());
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
@ -74,43 +79,51 @@ public class ConnectingConsoleInputTest {
|
|||||||
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
final ConnectingConsoleInput in = new ConnectingConsoleInput();
|
||||||
// Unconnected
|
// Unconnected
|
||||||
final AtomicBoolean ended = new AtomicBoolean(false);
|
final AtomicBoolean ended = new AtomicBoolean(false);
|
||||||
final TestFunction one = () -> {
|
final TestFunction one = new TestFunction() {
|
||||||
try {
|
|
||||||
final String res1 = in.prompt("m1", -1);
|
@Override
|
||||||
fail("interruption of infinite waiting prompt should cause error, but was "
|
public void apply() throws Exception {
|
||||||
+ res1);
|
|
||||||
} catch (final InterruptedIOException e1) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
final String res2 = in.prompt("m2", 25000);
|
|
||||||
fail("interruption of finite waiting prompt should cause error, but was "
|
|
||||||
+ res2);
|
|
||||||
} catch (final InterruptedIOException e2) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
synchronized (ended) {
|
|
||||||
ended.set(true);
|
|
||||||
try {
|
try {
|
||||||
assertNull("Overtime should return null", in.prompt("m3", 200));
|
final String res = in.prompt("m1", -1);
|
||||||
} catch (final InterruptedIOException e3) {
|
fail("interruption of infinite waiting prompt should cause error, but was "
|
||||||
fail("Unexpected interruption error in overtime");
|
+ 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);
|
final ATestRunnable runnable = new FunctionalTestRunnable(one);
|
||||||
final Thread th = new Thread(runnable, "TestPromptSequence");
|
final Thread th = new Thread(runnable);
|
||||||
final Thread inter = new Thread(() -> {
|
final Thread inter = new Thread(new Runnable() {
|
||||||
while (!ended.get()) {
|
|
||||||
try {
|
@Override
|
||||||
th.join(100);
|
public void run() {
|
||||||
} catch (final InterruptedException e) {
|
while (!ended.get()) {
|
||||||
// TODO Auto-generated catch block
|
try {
|
||||||
e.printStackTrace();
|
th.join(100);
|
||||||
}
|
} catch (final InterruptedException e) {
|
||||||
synchronized (ended) {
|
// TODO Auto-generated catch block
|
||||||
if (!ended.get()) {
|
e.printStackTrace();
|
||||||
in.interruptPrompt();
|
}
|
||||||
|
synchronized (ended) {
|
||||||
|
if (!ended.get()) {
|
||||||
|
in.interruptPrompt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,17 +139,21 @@ public class ConnectingConsoleInputTest {
|
|||||||
in.connect(new StreamConsoleInput(null, pis, StandardCharsets.UTF_8));
|
in.connect(new StreamConsoleInput(null, pis, StandardCharsets.UTF_8));
|
||||||
final ATestRunnable runnable2 = new FunctionalTestRunnable(one);
|
final ATestRunnable runnable2 = new FunctionalTestRunnable(one);
|
||||||
final Thread th2 = new Thread(runnable2);
|
final Thread th2 = new Thread(runnable2);
|
||||||
final Thread inter2 = new Thread(() -> {
|
final Thread inter2 = new Thread(new Runnable() {
|
||||||
while (!ended.get()) {
|
|
||||||
try {
|
@Override
|
||||||
th2.join(100);
|
public void run() {
|
||||||
} catch (final InterruptedException e) {
|
while (!ended.get()) {
|
||||||
// TODO Auto-generated catch block
|
try {
|
||||||
e.printStackTrace();
|
th2.join(100);
|
||||||
}
|
} catch (final InterruptedException e) {
|
||||||
synchronized (ended) {
|
// TODO Auto-generated catch block
|
||||||
if (!ended.get()) {
|
e.printStackTrace();
|
||||||
in.interruptPrompt();
|
}
|
||||||
|
synchronized (ended) {
|
||||||
|
if (!ended.get()) {
|
||||||
|
in.interruptPrompt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>ebigeon-public-conf</artifactId>
|
<artifactId>ebigeon-public-conf</artifactId>
|
||||||
<version>1.0.12</version>
|
<version>1.0.10</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
<artifactId>socket</artifactId>
|
<artifactId>socket</artifactId>
|
||||||
<version>1.1.19-SNAPSHOT</version>
|
<version>1.1.17</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>GCLC Socket</name>
|
<name>GCLC Socket</name>
|
||||||
<description>Socket implementation of GCLC</description>
|
<description>Socket implementation of GCLC</description>
|
||||||
@ -35,8 +35,8 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>socket-1.1.17</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
@ -46,17 +46,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>smu</artifactId>
|
<artifactId>smu</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.0.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon.test</groupId>
|
<groupId>net.bigeon.test</groupId>
|
||||||
<artifactId>junitmt</artifactId>
|
<artifactId>junitmt</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -51,6 +51,7 @@ 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.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.
|
||||||
@ -77,7 +78,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 Supplier<String> prompt = () -> "> "; //$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). */
|
||||||
@ -262,7 +263,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final String prompt) {
|
public void setPrompt(final String prompt) {
|
||||||
setPrompt(() -> prompt);
|
setPrompt(new ConstantString(prompt));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -293,9 +294,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
brutalDisconnection();
|
brutalDisconnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!connected) {
|
connexionLock.wait(connexionTimeout);
|
||||||
connexionLock.wait(connexionTimeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -311,23 +310,4 @@ public final class PluggableConsoleInput implements ConsoleInput {
|
|||||||
listener.disconnected();
|
listener.disconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a listener to the list of listeners.
|
|
||||||
*
|
|
||||||
* @param e the listener
|
|
||||||
* @return if the listener was added
|
|
||||||
* @see java.util.Set#add(java.lang.Object) */
|
|
||||||
public boolean add(final DisconnexionListener e) {
|
|
||||||
return listeners.add(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Remove a listener from the list of listeners.
|
|
||||||
*
|
|
||||||
* @param o the listener
|
|
||||||
* @return if the listener was removed
|
|
||||||
* @see java.util.Set#remove(java.lang.Object) */
|
|
||||||
public boolean remove(final DisconnexionListener o) {
|
|
||||||
return listeners.remove(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,46 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.socket;
|
package net.bigeon.gclc.socket;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* GCLC Socket
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2016 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
* "http://www.cecill.info".
|
||||||
|
*
|
||||||
|
* As a counterpart to the access to the source code and rights to copy,
|
||||||
|
* modify and redistribute granted by the license, users are provided only
|
||||||
|
* with a limited warranty and the software's author, the holder of the
|
||||||
|
* economic rights, and the successive licensors have only limited
|
||||||
|
* liability.
|
||||||
|
*
|
||||||
|
* In this respect, the user's attention is drawn to the risks associated
|
||||||
|
* with loading, using, modifying and/or developing or reproducing the
|
||||||
|
* software by the user in light of its specific status of free software,
|
||||||
|
* that may mean that it is complicated to manipulate, and that also
|
||||||
|
* therefore means that it is reserved for developers and experienced
|
||||||
|
* professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
* encouraged to load and test the software's suitability as regards their
|
||||||
|
* requirements in conditions enabling the security of their systems and/or
|
||||||
|
* data to be ensured and, more generally, to use and operate it in the
|
||||||
|
* same conditions as regards security.
|
||||||
|
*
|
||||||
|
* The fact that you are presently reading this means that you have had
|
||||||
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import net.bigeon.gclc.command.Command;
|
import net.bigeon.gclc.command.Command;
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
|
import net.bigeon.gclc.exception.CommandRunExceptionType;
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
|
|
||||||
@ -18,7 +56,11 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public final class RemoteDisconnectCommand<T> extends Command {
|
public final class RemoteDisconnectCommand<T> extends Command {
|
||||||
|
|
||||||
private final net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<T> real;
|
/** The connexion manager. */
|
||||||
|
private final ConnexionManager<T> manager;
|
||||||
|
/** If all connexion should be disconnected when no argument have been
|
||||||
|
* specified. */
|
||||||
|
private final boolean all;
|
||||||
|
|
||||||
/** Create the disconnection command.
|
/** Create the disconnection command.
|
||||||
*
|
*
|
||||||
@ -29,8 +71,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
|
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
|
||||||
final boolean all) {
|
final boolean all) {
|
||||||
super(name);
|
super(name);
|
||||||
real = new net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<>(name, manager,
|
this.manager = manager;
|
||||||
all);
|
this.all = all;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@ -39,20 +81,52 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
public void execute(final ConsoleOutput out, final ConsoleInput in,
|
||||||
final String... args) throws CommandRunException {
|
final String... args) throws CommandRunException {
|
||||||
real.execute(out, in, args);
|
if (args.length == 0 && all) {
|
||||||
|
final Collection<String> coll = manager.getConnected();
|
||||||
|
for (final String string : coll) {
|
||||||
|
manager.disconnect(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final String string : args) {
|
||||||
|
if (manager.isConnected(string)) {
|
||||||
|
manager.disconnect(string);
|
||||||
|
} else {
|
||||||
|
print(out,
|
||||||
|
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Print a message if the output is defined.
|
||||||
|
*
|
||||||
|
* @param out the output
|
||||||
|
* @param string the message
|
||||||
|
* @throws CommandRunException if the output exists but cannot be printed to */
|
||||||
|
private static void print(final ConsoleOutput out, final String string)
|
||||||
|
throws CommandRunException {
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.println(string);
|
||||||
|
} catch (final IOException e) {
|
||||||
|
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||||
|
"Unable to print to existing output", e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||||
@Override
|
@Override
|
||||||
public String tip() {
|
public String tip() {
|
||||||
return real.tip();
|
return "Close a connexion."; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||||
@Override
|
@Override
|
||||||
protected String usageDetail() {
|
protected String usageDetail() {
|
||||||
return "";
|
return MessageFormat.format(
|
||||||
|
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
|
||||||
|
all ? "all connexions" : "none");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,6 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
|||||||
/** The application. */
|
/** The application. */
|
||||||
private ConsoleApplication app;
|
private ConsoleApplication app;
|
||||||
|
|
||||||
private final Object initLock = new Object();
|
|
||||||
|
|
||||||
/** The server socket. */
|
/** The server socket. */
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
/** THe server address. */
|
/** THe server address. */
|
||||||
@ -125,10 +123,7 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
|||||||
// Create the server
|
// Create the server
|
||||||
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
|
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
|
||||||
serverSocket = actualServerSocket;
|
serverSocket = actualServerSocket;
|
||||||
synchronized (initLock) {
|
running = true;
|
||||||
running = true;
|
|
||||||
initLock.notifyAll();
|
|
||||||
}
|
|
||||||
// Create the streams
|
// Create the streams
|
||||||
runSokectServer();
|
runSokectServer();
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
@ -199,23 +194,4 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
|||||||
LOGGER.log(Level.SEVERE, "Exception in closing socket server", e); //$NON-NLS-1$
|
LOGGER.log(Level.SEVERE, "Exception in closing socket server", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A method to wait for the socket server initialization.
|
|
||||||
*
|
|
||||||
* @param timeout the timeout */
|
|
||||||
public void waitStartUp(final long timeout) {
|
|
||||||
synchronized (initLock) {
|
|
||||||
final long tic = System.currentTimeMillis() + timeout;
|
|
||||||
long tac;
|
|
||||||
while (!running && (tac = System.currentTimeMillis()) < tic) {
|
|
||||||
final long idle = tic - tac;
|
|
||||||
try {
|
|
||||||
initLock.wait(idle);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
LOGGER.log(Level.INFO, "Thread interruption", e);
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||||
@Override
|
@Override
|
||||||
protected String usageDetail() {
|
protected String usageDetail() {
|
||||||
final StringBuilder builder = new StringBuilder(
|
return MessageFormat.format(
|
||||||
" If arguments are provided the corresponding connexions are closed, otherwise\n");
|
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
|
||||||
if (all) {
|
all ? "all connexions" : "none");
|
||||||
builder.append("all connections");
|
|
||||||
} else {
|
|
||||||
builder.append("none");
|
|
||||||
}
|
|
||||||
builder.append(" are.");
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ public class TestServer {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
server = new Thread(getShell(), "gclcServer");
|
server = new Thread(getShell(), "gclcServer");
|
||||||
server.start();
|
server.start();
|
||||||
getShell().waitStartUp(500);
|
|
||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
@ -83,7 +82,13 @@ public class TestServer {
|
|||||||
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
||||||
SHELL.setConnexionManager(manager);
|
SHELL.setConnexionManager(manager);
|
||||||
SHELL.setApplication(app);
|
SHELL.setApplication(app);
|
||||||
final Thread th = new Thread(() -> app.start());
|
final Thread th = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
app.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
th.start();
|
th.start();
|
||||||
try {
|
try {
|
||||||
final Object waiting = new Object();
|
final Object waiting = new Object();
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>swt-public-conf</artifactId>
|
<artifactId>swt-public-conf</artifactId>
|
||||||
<version>1.0.2</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
<artifactId>swt</artifactId>
|
<artifactId>swt</artifactId>
|
||||||
<version>1.2.2-SNAPSHOT</version>
|
<version>1.2.1-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>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
@ -48,26 +48,27 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>collections</artifactId>
|
<artifactId>collections</artifactId>
|
||||||
<version>1.3.5</version>
|
<version>1.2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>5.15.2</version>
|
<version>2.27.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>2.10.3</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.github.sevntu-checkstyle</groupId>
|
<groupId>com.github.sevntu-checkstyle</groupId>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
|
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
|
||||||
* Created on: Nov 19, 2016
|
* Created on: Nov 19, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.api;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.io;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@ -42,7 +42,6 @@ import java.io.IOException;
|
|||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
|
||||||
|
|
||||||
/** The object managing the console input.
|
/** The object managing the console input.
|
||||||
*
|
*
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.api;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.io;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@ -40,8 +40,6 @@ package net.bigeon.gclc.swt.io;
|
|||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
|
||||||
import net.bigeon.gclc.swt.tools.TextAppendingRunnable;
|
|
||||||
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
||||||
|
|
||||||
/** The manager for console output to insert in a text.
|
/** The manager for console output to insert in a text.
|
||||||
@ -96,12 +94,4 @@ public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
|||||||
public Thread getForwardThread() {
|
public Thread getForwardThread() {
|
||||||
return forwardThread;
|
return forwardThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the output consumer */
|
|
||||||
public PipedConsoleOutput getManager() {
|
|
||||||
if (forward == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return forward.getOuput();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.io;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
@ -33,7 +33,7 @@
|
|||||||
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
|
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
|
||||||
* Created on: Jun 9, 2016
|
* Created on: Jun 9, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.tools;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -78,7 +78,6 @@ import org.eclipse.swt.events.KeyEvent;
|
|||||||
|
|
||||||
import net.bigeon.collections.Ribbon;
|
import net.bigeon.collections.Ribbon;
|
||||||
import net.bigeon.collections.ribbon.ArrayRibbon;
|
import net.bigeon.collections.ribbon.ArrayRibbon;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
|
||||||
|
|
||||||
/** A key listener to validate commands and manage the history of commands.
|
/** A key listener to validate commands and manage the history of commands.
|
||||||
*
|
*
|
@ -79,11 +79,6 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
|
||||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
|
||||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
|
||||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
|
||||||
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
|
||||||
|
|
||||||
/** A shell containing a {@link SWTConsoleView}
|
/** A shell containing a {@link SWTConsoleView}
|
||||||
* <p>
|
* <p>
|
||||||
@ -133,12 +128,12 @@ public final class SWTConsole extends Composite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return the inputManager */
|
/** @return the inputManager */
|
||||||
public ConsoleDelayIO getInputManager() {
|
public ConsoleInputManager getInputManager() {
|
||||||
return inputManager;
|
return inputManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the outputManager */
|
/** @return the outputManager */
|
||||||
public ConsoleOutputDisplay getOutputManager() {
|
public ConsoleOutputManager getOutputManager() {
|
||||||
return outputManager;
|
return outputManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,11 +78,6 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
import net.bigeon.gclc.ConsoleApplication;
|
import net.bigeon.gclc.ConsoleApplication;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
|
||||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
|
||||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
|
||||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
|
||||||
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
|
||||||
|
|
||||||
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
||||||
*
|
*
|
||||||
@ -134,14 +129,14 @@ public final class SWTConsoleView extends Composite {
|
|||||||
/** Get the manager of console input.
|
/** Get the manager of console input.
|
||||||
*
|
*
|
||||||
* @return the input manager */
|
* @return the input manager */
|
||||||
public ConsoleDelayIO getInputManager() {
|
public ConsoleInputManager getInputManager() {
|
||||||
return inManager;
|
return inManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the manager of console output.
|
/** Get the manager of console output.
|
||||||
*
|
*
|
||||||
* @return the output manager */
|
* @return the output manager */
|
||||||
public ConsoleOutputDisplay getOutputManager() {
|
public ConsoleOutputManager getOutputManager() {
|
||||||
return outManager;
|
return outManager;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt.tools;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @author Emmanuel Bigeon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package net.bigeon.gclc.swt.api;
|
|
@ -1,8 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @author Emmanuel Bigeon
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package net.bigeon.gclc.swt.io;
|
|
@ -6,13 +6,14 @@ package net.bigeon.gclc.swt.tools;
|
|||||||
import org.eclipse.swt.widgets.Widget;
|
import org.eclipse.swt.widgets.Widget;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
||||||
import net.bigeon.gclc.tools.AOutputForwardRunnable;
|
import net.bigeon.gclc.swt.ConsoleOutputDisplay;
|
||||||
|
|
||||||
/** The local implementation of the forwarding runnable.
|
/** The local implementation of the forwarding runnable.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
public final class ToSWTConsoleForwardRunnable
|
||||||
|
extends AOutputForwardRunnable {
|
||||||
/** The running status. */
|
/** The running status. */
|
||||||
private boolean running = true;
|
private boolean running = true;
|
||||||
/** The console output. */
|
/** The console output. */
|
||||||
|
@ -47,7 +47,6 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class ConsoleInputManagerTest {
|
public class ConsoleInputManagerTest {
|
||||||
@ -56,7 +55,7 @@ public class ConsoleInputManagerTest {
|
|||||||
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#setInput(java.lang.String)}. */
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#setInput(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testSetText() {
|
public void testSetText() {
|
||||||
cim.setInput("Text");
|
cim.setInput("Text");
|
||||||
@ -64,7 +63,7 @@ public class ConsoleInputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#validateInput()}.
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#validateInput()}.
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurred */
|
* @throws IOException if an error occurred */
|
||||||
@Test
|
@Test
|
||||||
@ -102,7 +101,7 @@ public class ConsoleInputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#getText()}. */
|
* {@link net.bigeon.gclc.swt.ConsoleInputManager#getText()}. */
|
||||||
@Test
|
@Test
|
||||||
public void testGetText() {
|
public void testGetText() {
|
||||||
assertEquals("Text component should be preserved", text, cim.getText());
|
assertEquals("Text component should be preserved", text, cim.getText());
|
||||||
|
@ -49,7 +49,6 @@ import org.mockito.invocation.InvocationOnMock;
|
|||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class ConsoleOutputManagerTest {
|
public class ConsoleOutputManagerTest {
|
||||||
@ -72,7 +71,7 @@ public class ConsoleOutputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testAppendConsoleOutput() {
|
public void testAppendConsoleOutput() {
|
||||||
when(text.getText()).thenReturn("", "abc",
|
when(text.getText()).thenReturn("", "abc",
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
* GCLC swt
|
* GCLC swt
|
||||||
@ -37,128 +36,46 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
* 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.mockito.Mockito.*;
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
|
||||||
import org.mockito.stubbing.Answer;
|
|
||||||
|
|
||||||
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
/**
|
||||||
|
* @author Emmanuel Bigeon
|
||||||
/** @author Emmanuel Bigeon */
|
*
|
||||||
|
*/
|
||||||
public class ConsolePromptManagerTest {
|
public class ConsolePromptManagerTest {
|
||||||
|
|
||||||
private final Label label = mock(Label.class);
|
private final Label label = mock(Label.class);
|
||||||
|
|
||||||
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
||||||
|
|
||||||
/** Test method for
|
/**
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setPrompt(java.lang.String)}. */
|
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setPrompt(java.lang.String)}.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetPrompt() {
|
public void testSetPrompt() {
|
||||||
manager.setPrompt("abc");
|
manager.setPrompt("abc");
|
||||||
verify(label).setText("abc");
|
verify(label).setText("abc");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/**
|
||||||
* {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
||||||
*
|
*/
|
||||||
* @throws IOException if error */
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetStream() throws IOException {
|
public void testSetStream() {
|
||||||
// Create the dispaly, in case...
|
|
||||||
final Display d = mock(Display.class);
|
|
||||||
when(label.getDisplay()).thenReturn(d);
|
|
||||||
Mockito.doAnswer(invocation -> {
|
|
||||||
((Runnable) invocation.getArgument(0)).run();
|
|
||||||
return null;
|
|
||||||
}).when(d).asyncExec(any(Runnable.class));
|
|
||||||
Mockito.doAnswer(invocation -> {
|
|
||||||
((Runnable) invocation.getArgument(0)).run();
|
|
||||||
return null;
|
|
||||||
}).when(d).syncExec(any(Runnable.class));
|
|
||||||
// Test.
|
|
||||||
BufferedReader output = mock(BufferedReader.class);
|
BufferedReader output = mock(BufferedReader.class);
|
||||||
final Object lock = new Object();
|
|
||||||
final AtomicInteger calls = new AtomicInteger(0);
|
|
||||||
Mockito.when(output.readLine()).then(new Answer<String>() {
|
|
||||||
String[] ans = { "A line" };
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String answer(final InvocationOnMock invocation) throws Throwable {
|
|
||||||
synchronized (lock) {
|
|
||||||
if (calls.get() >= ans.length) {
|
|
||||||
calls.incrementAndGet();
|
|
||||||
lock.notify();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
lock.notify();
|
|
||||||
return ans[calls.getAndIncrement()];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
manager.setStream(output);
|
manager.setStream(output);
|
||||||
manager.setStream(output);
|
manager.setStream(output);
|
||||||
synchronized (lock) {
|
|
||||||
while (calls.get() < 2) {
|
|
||||||
try {
|
|
||||||
lock.wait(10);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
verify(output, times(2)).readLine();
|
|
||||||
output = mock(BufferedReader.class);
|
output = mock(BufferedReader.class);
|
||||||
calls.set(0);
|
|
||||||
Mockito.when(output.readLine()).then(new Answer<String>() {
|
|
||||||
String[] ans = { "A line" };
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String answer(final InvocationOnMock invocation) throws Throwable {
|
|
||||||
synchronized (lock) {
|
|
||||||
if (calls.get() >= ans.length) {
|
|
||||||
calls.incrementAndGet();
|
|
||||||
lock.notify();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
lock.notify();
|
|
||||||
return ans[calls.getAndIncrement()];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
manager.setStream(output);
|
manager.setStream(output);
|
||||||
while (calls.get() < 2) {
|
|
||||||
synchronized (lock) {
|
|
||||||
try {
|
|
||||||
lock.wait(10);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
manager.setStream(null);
|
manager.setStream(null);
|
||||||
manager.setStream(output);
|
manager.setStream(output);
|
||||||
while (calls.get() < 3) {
|
|
||||||
synchronized (lock) {
|
|
||||||
try {
|
|
||||||
lock.wait(10);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
verify(output, times(3)).readLine();
|
|
||||||
verify(label, times(2)).setText("A line");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,17 +69,11 @@ package net.bigeon.gclc.swt;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.KeyEvent;
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
|
||||||
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -89,7 +83,7 @@ import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
|||||||
public class HistoryTextKeyListenerTest {
|
public class HistoryTextKeyListenerTest {
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.tools.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() {
|
||||||
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
||||||
@ -148,23 +142,11 @@ public class HistoryTextKeyListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeyPressedA() throws IOException {
|
public void testKeyPressed() {
|
||||||
final ConsoleDelayIO io = mock(ConsoleDelayIO.class);
|
final ConsoleDelayIO io = mock(ConsoleDelayIO.class);
|
||||||
final KeyEvent event = mock(KeyEvent.class);
|
final KeyEvent event = mock(KeyEvent.class);
|
||||||
event.keyCode = 'a';
|
event.keyCode = 'a';
|
||||||
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
||||||
listener.keyPressed(event);
|
listener.keyPressed(event);
|
||||||
verifyNoInteractions(io);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testKeyPressedReturn() throws IOException {
|
|
||||||
final ConsoleDelayIO io = mock(ConsoleDelayIO.class);
|
|
||||||
Mockito.when(io.getInput()).thenReturn("Alpha");
|
|
||||||
final KeyEvent event = mock(KeyEvent.class);
|
|
||||||
event.keyCode = '\r';
|
|
||||||
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
|
|
||||||
listener.keyPressed(event);
|
|
||||||
verify(io, times(1)).validateInput();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,8 @@ import java.util.logging.Logger;
|
|||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
|
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
|
||||||
|
|
||||||
@ -60,10 +61,16 @@ public class PromptReadingRunnableTest {
|
|||||||
private final Display display = mock(Display.class);
|
private final Display display = mock(Display.class);
|
||||||
{
|
{
|
||||||
when(view.getDisplay()).thenReturn(display);
|
when(view.getDisplay()).thenReturn(display);
|
||||||
doAnswer(invocation -> {
|
doAnswer(new Answer<Object>() {
|
||||||
final Runnable runnable = invocation.getArgument(0);
|
/* (non-Javadoc)
|
||||||
runnable.run();
|
* @see
|
||||||
return null;
|
* 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));
|
}).when(display).syncExec(any(Runnable.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +85,6 @@ public class PromptReadingRunnableTest {
|
|||||||
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
||||||
|
|
||||||
runnable.run();
|
runnable.run();
|
||||||
Mockito.verify(reader, Mockito.times(3)).readLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
|
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
|
||||||
@ -96,7 +102,6 @@ public class PromptReadingRunnableTest {
|
|||||||
|
|
||||||
runnable.run();
|
runnable.run();
|
||||||
logger.setLevel(back);
|
logger.setLevel(back);
|
||||||
Mockito.verify(reader, Mockito.times(1)).readLine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ package net.bigeon.gclc.swt;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
@ -47,7 +46,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class SWTConsoleShellTest {
|
public class SWTConsoleShellTest {
|
||||||
@ -72,8 +70,6 @@ public class SWTConsoleShellTest {
|
|||||||
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
||||||
// Disconnection should work.
|
// Disconnection should work.
|
||||||
console.connect(null, null, null);
|
console.connect(null, null, null);
|
||||||
assertNull("Console should disconnect",
|
|
||||||
((ConsoleOutputManager) console.getOutputManager()).getManager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ package net.bigeon.gclc.swt;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
@ -47,7 +46,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class SWTConsoleViewTest {
|
public class SWTConsoleViewTest {
|
||||||
@ -76,7 +74,5 @@ public class SWTConsoleViewTest {
|
|||||||
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
// Disconnection should work.
|
// Disconnection should work.
|
||||||
view.setManager(null, null);
|
view.setManager(null, null);
|
||||||
assertNull("Disconnection should replace the input.",
|
|
||||||
((ConsoleOutputManager) view.getOutputManager()).getManager());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>ebigeon-config</artifactId>
|
<artifactId>ebigeon-config</artifactId>
|
||||||
<version>1.8.33</version>
|
<version>1.8.21</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
<artifactId>test</artifactId>
|
<artifactId>test</artifactId>
|
||||||
@ -37,7 +37,7 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
@ -49,17 +49,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.0.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon.test</groupId>
|
<groupId>net.bigeon.test</groupId>
|
||||||
<artifactId>junitmt</artifactId>
|
<artifactId>junitmt</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<reporting>
|
<reporting>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>2.10.3</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.github.sevntu-checkstyle</groupId>
|
<groupId>com.github.sevntu-checkstyle</groupId>
|
||||||
|
@ -13,6 +13,7 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.ConsoleInput;
|
import net.bigeon.gclc.manager.ConsoleInput;
|
||||||
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
import net.bigeon.test.junitmt.FunctionalTestRunnable;
|
||||||
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
import net.bigeon.test.junitmt.ThreadTest;
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
@ -37,17 +38,24 @@ public final class InputContract {
|
|||||||
// Test interruption contract
|
// Test interruption contract
|
||||||
final ConsoleInput input2 = inputs.get();
|
final ConsoleInput input2 = inputs.get();
|
||||||
final FunctionalTestRunnable prompting = new FunctionalTestRunnable(
|
final FunctionalTestRunnable prompting = new FunctionalTestRunnable(
|
||||||
() -> {
|
new TestFunction() {
|
||||||
try {
|
|
||||||
input2.prompt();
|
@Override
|
||||||
fail("Interrupted prompt should throw INterruptedIOException");
|
public void apply() throws Exception {
|
||||||
} catch (final InterruptedIOException e) {
|
try {
|
||||||
// ok
|
input2.prompt();
|
||||||
|
fail("Interrupted prompt should throw INterruptedIOException");
|
||||||
|
} catch (final InterruptedIOException e) {
|
||||||
|
// ok
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final Thread th = new Thread(prompting);
|
final Thread th = new Thread(prompting);
|
||||||
th.start();
|
th.start();
|
||||||
|
// while (!input2.isPrompting()) {
|
||||||
th.join(200);
|
th.join(200);
|
||||||
|
//
|
||||||
|
// }
|
||||||
input2.interruptPrompt();
|
input2.interruptPrompt();
|
||||||
ThreadTest.assertRuns(th, prompting);
|
ThreadTest.assertRuns(th, prompting);
|
||||||
}
|
}
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
/** gclc-test: InputContractTest
|
|
||||||
* Created on Apr. 6, 2020
|
|
||||||
*/
|
|
||||||
package net.bigeon.gclc.test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PipedInputStream;
|
|
||||||
import java.io.PipedOutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.EmptyInput;
|
|
||||||
import net.bigeon.gclc.manager.StreamConsoleInput;
|
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
|
||||||
public class InputContractTest {
|
|
||||||
|
|
||||||
/** Test method for
|
|
||||||
* {@link net.bigeon.gclc.test.InputContract#testInputContract(java.util.function.Supplier)}. */
|
|
||||||
@Test
|
|
||||||
public void testTestInputContract() throws IOException, InterruptedException {
|
|
||||||
final InputContract contract = new InputContract();
|
|
||||||
try (InputStream in = new PipedInputStream(new PipedOutputStream());
|
|
||||||
PrintStream out = new PrintStream("temp.txt")) {
|
|
||||||
contract.testInputContract(
|
|
||||||
() -> new StreamConsoleInput(out, in, StandardCharsets.UTF_8));
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
contract.testInputContract(() -> EmptyInput.INSTANCE);
|
|
||||||
fail("Empty input does not fit the contract for inputs since it cannot be closed.");
|
|
||||||
} catch (final AssertionError e) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
final File f = new File("temp.txt");
|
|
||||||
if (f.exists()) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>ebigeon-config</artifactId>
|
<artifactId>ebigeon-config</artifactId>
|
||||||
<version>1.8.33</version>
|
<version>1.8.21</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon.gclc</groupId>
|
<groupId>net.bigeon.gclc</groupId>
|
||||||
<artifactId>system</artifactId>
|
<artifactId>system</artifactId>
|
||||||
@ -35,7 +35,7 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
@ -48,12 +48,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.5</version>
|
<version>2.0.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>5.15.2</version>
|
<version>2.23.0</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>2.10.3</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.github.sevntu-checkstyle</groupId>
|
<groupId>com.github.sevntu-checkstyle</groupId>
|
||||||
|
@ -101,7 +101,7 @@ public class ExecSystemCommand extends Command {
|
|||||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
|
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
|
||||||
while (th.isAlive()) {
|
while (th.isAlive()) {
|
||||||
final String user = in.prompt();
|
final String user = in.prompt();
|
||||||
// Forward to process if not empty.
|
// Avoid interruption being sent to process.
|
||||||
if (!user.isEmpty()) {
|
if (!user.isEmpty()) {
|
||||||
writer.write(user + EOL);
|
writer.write(user + EOL);
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,17 @@ package net.bigeon.gclc.system;
|
|||||||
* 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.jupiter.api.Assertions.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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.manager.EmptyInput;
|
import net.bigeon.gclc.utils.EmptyInput;
|
||||||
import net.bigeon.gclc.manager.SinkOutput;
|
import net.bigeon.gclc.utils.SinkOutput;
|
||||||
|
|
||||||
public class ExecSystemCommandTest {
|
public class ExecSystemCommandTest {
|
||||||
|
|
||||||
@ -51,10 +51,10 @@ public class ExecSystemCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testExecSystemCommand() {
|
public void testExecSystemCommand() {
|
||||||
final ExecSystemCommand cmd = new ExecSystemCommand("test");
|
final ExecSystemCommand cmd = new ExecSystemCommand("test");
|
||||||
assertEquals("test", cmd.getCommandName(), "Name should be preserved");
|
assertEquals("Name should be preserved", "test", cmd.getCommandName());
|
||||||
assertNotNull(cmd.tip(), "tip should be defined");
|
assertNotNull("tip should be defined", cmd.tip());
|
||||||
assertNotNull(cmd.usagePattern(), "usage should be defined");
|
assertNotNull("usage should be defined", cmd.usagePattern());
|
||||||
assertNotNull(cmd.usageDetail(), "usage should be detailed");
|
assertNotNull("usage should be defined", cmd.usageDetail());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test the execution of the command.
|
/** Test the execution of the command.
|
||||||
@ -79,26 +79,4 @@ public class ExecSystemCommandTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test the execution of the command.
|
|
||||||
*
|
|
||||||
* @throws CommandRunException if the command fails */
|
|
||||||
@Test
|
|
||||||
public void testLongExecute() throws CommandRunException {
|
|
||||||
final ConsoleOutput out = SinkOutput.INSTANCE;
|
|
||||||
final ConsoleInput in = EmptyInput.INSTANCE;
|
|
||||||
|
|
||||||
final ExecSystemCommand cmd = new ExecSystemCommand();
|
|
||||||
if (System.getProperty("os.name").contains("indows")) {
|
|
||||||
cmd.execute(out, in, "cmd", "/C", "dir", "/s");
|
|
||||||
} else if (System.getProperty("os.name").contains("inux")) {
|
|
||||||
cmd.execute(out, in, "ls", "-R");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
cmd.execute(out, in, "inexistent");
|
|
||||||
fail("Able to execute inexistent command in system");
|
|
||||||
} catch (final CommandRunException e) {
|
|
||||||
// ok
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,18 @@
|
|||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.system;
|
package net.bigeon.gclc.system;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import net.bigeon.gclc.exception.CommandRunException;
|
import net.bigeon.gclc.exception.CommandRunException;
|
||||||
import net.bigeon.gclc.manager.SinkOutput;
|
import net.bigeon.gclc.utils.SinkOutput;
|
||||||
import net.bigeon.gclc.manager.StreamConsoleOutput;
|
import net.bigeon.gclc.utils.StreamConsoleOutput;
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class ForwardingRunnableTest {
|
public class ForwardingRunnableTest {
|
||||||
@ -27,8 +27,8 @@ public class ForwardingRunnableTest {
|
|||||||
// Runnable should close immediatly.
|
// Runnable should close immediatly.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
|
||||||
assertInstanceOf(CommandRunException.class, runnable.getError(),
|
assertTrue("Error should be a CommandRunException",
|
||||||
"Error should be a CommandRunException");
|
runnable.getError() instanceof CommandRunException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -39,6 +39,6 @@ public class ForwardingRunnableTest {
|
|||||||
is);
|
is);
|
||||||
// Runnable should close immediatly.
|
// Runnable should close immediatly.
|
||||||
runnable.run();
|
runnable.run();
|
||||||
assertInstanceOf(IOException.class, runnable.getError(), "Error should be an IO");
|
assertTrue("Error should be an IO", runnable.getError() instanceof IOException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>net.bigeon.config</groupId>
|
<groupId>net.bigeon.config</groupId>
|
||||||
<artifactId>ebigeon-public-conf</artifactId>
|
<artifactId>ebigeon-public-conf</artifactId>
|
||||||
<version>1.0.12</version>
|
<version>1.0.10</version>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.6-SNAPSHOT</version>
|
<version>2.1.1-SNAPSHOT</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>
|
||||||
@ -36,7 +36,7 @@
|
|||||||
</developer>
|
</developer>
|
||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.bigeon.test</groupId>
|
<groupId>net.bigeon.test</groupId>
|
||||||
<artifactId>junitmt</artifactId>
|
<artifactId>junitmt</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -191,7 +191,7 @@ public final class ConsoleApplication implements ICommandProvider {
|
|||||||
args = GCLCConstants.splitCommand(cmd);
|
args = GCLCConstants.splitCommand(cmd);
|
||||||
} catch (final CommandParsingException e) {
|
} catch (final CommandParsingException e) {
|
||||||
out.println("Command line cannot be parsed"); //$NON-NLS-1$
|
out.println("Command line cannot be parsed"); //$NON-NLS-1$
|
||||||
LOGGER.log(Level.FINE, e, () -> "Invalid user command " + cmd); //$NON-NLS-1$
|
LOGGER.log(Level.FINE, "Invalid user command " + cmd, e); //$NON-NLS-1$
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!args.isEmpty()) {
|
if (!args.isEmpty()) {
|
||||||
@ -199,7 +199,7 @@ public final class ConsoleApplication implements ICommandProvider {
|
|||||||
executeSub(out, in, args.get(0),
|
executeSub(out, in, args.get(0),
|
||||||
Arrays.copyOfRange(args.toArray(new String[0]), 1, args.size()));
|
Arrays.copyOfRange(args.toArray(new String[0]), 1, args.size()));
|
||||||
} catch (final CommandRunException e) {
|
} catch (final CommandRunException e) {
|
||||||
LOGGER.log(Level.FINE, e, () -> "Command failed: " + cmd); //$NON-NLS-1$
|
LOGGER.log(Level.FINE, "Command failed: " + cmd, e); //$NON-NLS-1$
|
||||||
out.println(Messages.getString("ConsoleApplication.cmd.failed", cmd)); //$NON-NLS-1$
|
out.println(Messages.getString("ConsoleApplication.cmd.failed", cmd)); //$NON-NLS-1$
|
||||||
out.println(e.getLocalizedMessage());
|
out.println(e.getLocalizedMessage());
|
||||||
if (e.getType() == CommandRunExceptionType.USAGE) {
|
if (e.getType() == CommandRunExceptionType.USAGE) {
|
||||||
|
@ -146,7 +146,10 @@ public final class GCLCConstants {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == ' ' && !inString) {
|
if (c == ' ' && !inString) {
|
||||||
addArgument(args, cmd.substring(startIndex, index - 1));
|
final String arg = cmd.substring(startIndex, index - 1);
|
||||||
|
if (!arg.isEmpty()) {
|
||||||
|
args.add(removeEscaped(arg));
|
||||||
|
}
|
||||||
startIndex = index;
|
startIndex = index;
|
||||||
} else if (c == '"') {
|
} else if (c == '"') {
|
||||||
if (inString) {
|
if (inString) {
|
||||||
@ -161,18 +164,9 @@ public final class GCLCConstants {
|
|||||||
}
|
}
|
||||||
if (startIndex < cmd.length()) {
|
if (startIndex < cmd.length()) {
|
||||||
final String arg = cmd.substring(startIndex, cmd.length());
|
final String arg = cmd.substring(startIndex, cmd.length());
|
||||||
args.add(removeEscaped(arg));
|
args.add(arg);
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add an argument to the list of arguments if it is not an empty string.
|
|
||||||
*
|
|
||||||
* @param args the list of argument
|
|
||||||
* @param arg the candidate argument */
|
|
||||||
private static void addArgument(final List<String> args, final String arg) {
|
|
||||||
if (!arg.isEmpty()) {
|
|
||||||
args.add(removeEscaped(arg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,8 @@ public abstract class Command implements ICommand {
|
|||||||
/** Create the command.
|
/** Create the command.
|
||||||
*
|
*
|
||||||
* @param name the command name */
|
* @param name the command name */
|
||||||
protected Command(final String name) {
|
public Command(final String name) {
|
||||||
super();
|
super();
|
||||||
if (name == null) {
|
|
||||||
throw new IllegalArgumentException("The command name is mandatory");
|
|
||||||
}
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public final class CommandParameters {
|
|||||||
* @param key the key
|
* @param key the key
|
||||||
* @return if the key was specified */
|
* @return if the key was specified */
|
||||||
public boolean isActive(final String key) {
|
public boolean isActive(final String key) {
|
||||||
final Boolean val = booleanArguments.get(key);
|
Boolean val = booleanArguments.get(key);
|
||||||
return val != null && val.booleanValue();
|
return val != null && val.booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,8 +198,9 @@ public final class CommandParameters {
|
|||||||
* @param string the key
|
* @param string the key
|
||||||
* @param value the value */
|
* @param value the value */
|
||||||
public void set(final String string, final boolean value) {
|
public void set(final String string, final boolean value) {
|
||||||
booleanArguments.computeIfPresent(string,
|
if (booleanArguments.containsKey(string)) {
|
||||||
(final String k, final Boolean v) -> Boolean.valueOf(value));
|
booleanArguments.put(string, Boolean.valueOf(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set a string parameter value.
|
/** Set a string parameter value.
|
||||||
@ -207,9 +208,6 @@ public final class CommandParameters {
|
|||||||
* @param string the key
|
* @param string the key
|
||||||
* @param value the value */
|
* @param value the value */
|
||||||
public void set(final String string, final String value) {
|
public void set(final String string, final String value) {
|
||||||
// DO NOT USE computeIfPresent. This is a HashMap, not a ConcurrentHashMap and
|
|
||||||
// keys can be associated to null, but computeIfPresent will consider them as
|
|
||||||
// absent!
|
|
||||||
if (stringArguments.containsKey(string)) {
|
if (stringArguments.containsKey(string)) {
|
||||||
stringArguments.put(string, value);
|
stringArguments.put(string, value);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public abstract class ParametrizedCommand extends Command {
|
|||||||
* parameters.
|
* parameters.
|
||||||
*
|
*
|
||||||
* @param name the name */
|
* @param name the name */
|
||||||
protected ParametrizedCommand(final String name) {
|
public ParametrizedCommand(final String name) {
|
||||||
this(name, true);
|
this(name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ public abstract class ParametrizedCommand extends Command {
|
|||||||
*
|
*
|
||||||
* @param name the name
|
* @param name the name
|
||||||
* @param strict if the arguments are restricted to the declared ones */
|
* @param strict if the arguments are restricted to the declared ones */
|
||||||
protected ParametrizedCommand(final String name, final boolean strict) {
|
public ParametrizedCommand(final String name, final boolean strict) {
|
||||||
super(name);
|
super(name);
|
||||||
data = new ParametrizedCommandData(strict);
|
data = new ParametrizedCommandData(strict);
|
||||||
}
|
}
|
||||||
|
@ -149,16 +149,14 @@ public final class ParametrizedCommandData {
|
|||||||
* @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) {
|
||||||
final Boolean val = stringParams.computeIfPresent(param,
|
final Boolean val = stringParams.get(param);
|
||||||
(final String k, final Boolean v) -> {
|
if (val != null) {
|
||||||
final Boolean need = Boolean.valueOf(needed || v.booleanValue());
|
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
|
||||||
|
stringParams.put(param, need);
|
||||||
params.put(param, need);
|
params.put(param, need);
|
||||||
return need;
|
return;
|
||||||
});
|
|
||||||
if (val == null) {
|
|
||||||
throw new InvalidParameterException(
|
|
||||||
"Parameter is already defined as boolean"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
throw new InvalidParameterException("Parameter is already defined as boolean"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Retrieve the boolean parameters (aka flags).
|
/** Retrieve the boolean parameters (aka flags).
|
||||||
|
@ -139,7 +139,7 @@ public final class ScriptExecution extends Command {
|
|||||||
try (InputStreamReader fReader = new InputStreamReader(
|
try (InputStreamReader fReader = new InputStreamReader(
|
||||||
Files.newInputStream(Paths.get(scriptFile)), charset);
|
Files.newInputStream(Paths.get(scriptFile)), charset);
|
||||||
BufferedReader reader = new BufferedReader(fReader)) {
|
BufferedReader reader = new BufferedReader(fReader)) {
|
||||||
final String[] emptyArray = new String[0];
|
String[] emptyArray = new String[0];
|
||||||
while ((cmd = reader.readLine()) != null) {
|
while ((cmd = reader.readLine()) != null) {
|
||||||
lineNo++;
|
lineNo++;
|
||||||
final String cmdLine = readCommandLine(cmd, params);
|
final String cmdLine = readCommandLine(cmd, params);
|
||||||
@ -237,16 +237,10 @@ public final class ScriptExecution extends Command {
|
|||||||
* @return the exception to actually throw */
|
* @return the exception to actually throw */
|
||||||
private static CommandRunException manageRunException(final CommandRunException e,
|
private static CommandRunException manageRunException(final CommandRunException e,
|
||||||
final int lineNo) {
|
final int lineNo) {
|
||||||
final StringBuilder builder = new StringBuilder(e.getLocalizedMessage());
|
|
||||||
int index = builder.indexOf("\n");
|
|
||||||
while (index > 0) {
|
|
||||||
builder.insert(index + 1, " ");
|
|
||||||
index = builder.indexOf("\n", index + 1);
|
|
||||||
}
|
|
||||||
return new CommandRunException(CommandRunExceptionType.EXECUTION,
|
return new CommandRunException(CommandRunExceptionType.EXECUTION,
|
||||||
MessageFormat.format(
|
MessageFormat.format(
|
||||||
"The script could not complete due to command failure at line {0}\n {1})", //$NON-NLS-1$
|
"The script could not complete due to command failure at line {0} ({1})", //$NON-NLS-1$
|
||||||
Integer.valueOf(lineNo + 1), builder),
|
Integer.valueOf(lineNo), e.getLocalizedMessage()),
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ public final class Messages {
|
|||||||
try {
|
try {
|
||||||
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
|
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
|
||||||
} catch (final MissingResourceException e) {
|
} catch (final MissingResourceException e) {
|
||||||
LOGGER.log(Level.WARNING, e,
|
LOGGER.log(Level.WARNING,
|
||||||
() -> "Unrecognized internationalization message key: " + key); //$NON-NLS-1$
|
"Unrecognized internationalization message key: " + key, e); //$NON-NLS-1$
|
||||||
return '!' + key + '!';
|
return '!' + key + '!';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ package net.bigeon.gclc.manager;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InterruptedIOException;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/** A console application input.
|
/** A console application input.
|
||||||
@ -93,7 +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 immediately by throwing an java.io.InterruptedIOException. */
|
* return immediately by throwing an InterruptedIOException. */
|
||||||
void interruptPrompt();
|
void interruptPrompt();
|
||||||
|
|
||||||
/** Test if the input is closed.
|
/** Test if the input is closed.
|
||||||
@ -108,7 +109,7 @@ public interface ConsoleInput extends AutoCloseable {
|
|||||||
*
|
*
|
||||||
* @return the user inputed string
|
* @return the user inputed string
|
||||||
* @throws IOException if the manager is closed or could not read the prompt
|
* @throws IOException if the manager is closed or could not read the prompt
|
||||||
* @throws java.io.InterruptedIOException if the prompt was interrupted */
|
* @throws InterruptedIOException if the prompt was interrupted */
|
||||||
String prompt() throws IOException;
|
String prompt() throws IOException;
|
||||||
|
|
||||||
/** Prompt the user, with an allotated time to answer.
|
/** Prompt the user, with an allotated time to answer.
|
||||||
@ -116,7 +117,7 @@ public interface ConsoleInput extends AutoCloseable {
|
|||||||
* @param timeout the time to wait in milliseconds
|
* @param timeout the time to wait in milliseconds
|
||||||
* @return the user inputed string, null if the timeout was reached
|
* @return the user inputed string, null if the timeout was reached
|
||||||
* @throws IOException if the manager is closed or could not read the prompt
|
* @throws IOException if the manager is closed or could not read the prompt
|
||||||
* @throws java.io.InterruptedIOException if the prompt was interrupted */
|
* @throws InterruptedIOException if the prompt was interrupted */
|
||||||
String prompt(long timeout) throws IOException;
|
String prompt(long timeout) throws IOException;
|
||||||
|
|
||||||
/** Prompt the user, with a hint on what is prompted.
|
/** Prompt the user, with a hint on what is prompted.
|
||||||
@ -124,7 +125,7 @@ public interface ConsoleInput extends AutoCloseable {
|
|||||||
* @param message the message to prompt the user
|
* @param message the message to prompt the user
|
||||||
* @return the user inputed string
|
* @return the user inputed string
|
||||||
* @throws IOException if the manager is closed or could not read the prompt
|
* @throws IOException if the manager is closed or could not read the prompt
|
||||||
* @throws java.io.InterruptedIOException if the prompt was interrupted */
|
* @throws InterruptedIOException if the prompt was interrupted */
|
||||||
String prompt(String message) throws IOException;
|
String prompt(String message) throws IOException;
|
||||||
|
|
||||||
/** Prompt the user, with a hint on what is prompted and an allotated time to
|
/** Prompt the user, with a hint on what is prompted and an allotated time to
|
||||||
@ -134,7 +135,7 @@ public interface ConsoleInput extends AutoCloseable {
|
|||||||
* @param message the message to prompt the user
|
* @param message the message to prompt the user
|
||||||
* @return the user inputed string, null if the timeout was reached
|
* @return the user inputed string, null if the timeout was reached
|
||||||
* @throws IOException if the manager is closed or could not read the prompt
|
* @throws IOException if the manager is closed or could not read the prompt
|
||||||
* @throws java.io.InterruptedIOException if the prompt was interrupted */
|
* @throws InterruptedIOException if the prompt was interrupted */
|
||||||
String prompt(String message, long timeout) throws IOException;
|
String prompt(String message, long timeout) throws IOException;
|
||||||
|
|
||||||
/** Set a prompting prefix.
|
/** Set a prompting prefix.
|
||||||
|
@ -40,12 +40,48 @@ package net.bigeon.gclc.manager;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* #%L
|
||||||
|
* Generic Command Ligne console
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2014 - 2018 Bigeon
|
||||||
|
* %%
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
* "http://www.cecill.info".
|
||||||
|
*
|
||||||
|
* As a counterpart to the access to the source code and rights to copy,
|
||||||
|
* modify and redistribute granted by the license, users are provided only
|
||||||
|
* with a limited warranty and the software's author, the holder of the
|
||||||
|
* economic rights, and the successive licensors have only limited
|
||||||
|
* liability.
|
||||||
|
*
|
||||||
|
* In this respect, the user's attention is drawn to the risks associated
|
||||||
|
* with loading, using, modifying and/or developing or reproducing the
|
||||||
|
* software by the user in light of its specific status of free software,
|
||||||
|
* that may mean that it is complicated to manipulate, and that also
|
||||||
|
* therefore means that it is reserved for developers and experienced
|
||||||
|
* professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
* encouraged to load and test the software's suitability as regards their
|
||||||
|
* requirements in conditions enabling the security of their systems and/or
|
||||||
|
* data to be ensured and, more generally, to use and operate it in the
|
||||||
|
* same conditions as regards security.
|
||||||
|
*
|
||||||
|
* The fact that you are presently reading this means that you have had
|
||||||
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
|
||||||
|
import net.bigeon.gclc.tools.ConstantString;
|
||||||
|
|
||||||
/** A console input that return empty to all prompting.
|
/** A console input that return empty to all prompting.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class EmptyInput implements ConsoleInput {
|
public final class EmptyInput implements ConsoleInput {
|
||||||
|
|
||||||
private static final Supplier<String> CONSTANT_STRING = () -> "";
|
private static final ConstantString CONSTANT_STRING = new ConstantString("");
|
||||||
/** The empty prompter. */
|
/** The empty prompter. */
|
||||||
public static final ConsoleInput INSTANCE = new EmptyInput();
|
public static final ConsoleInput INSTANCE = new EmptyInput();
|
||||||
|
|
||||||
|
@ -101,14 +101,13 @@ public final class PipedConsoleOutput implements ConsoleOutput {
|
|||||||
private final PrintStream outPrint;
|
private final PrintStream outPrint;
|
||||||
/** The reading thread. */
|
/** The reading thread. */
|
||||||
private final ReadingRunnable reading;
|
private final ReadingRunnable reading;
|
||||||
private final PipedOutputStream out;
|
|
||||||
|
|
||||||
/** Create a manager that will write and read through piped stream.
|
/** Create a manager that will write and read through piped stream.
|
||||||
*
|
*
|
||||||
* @throws IOException if the piping failed for streams */
|
* @throws IOException if the piping failed for streams */
|
||||||
public PipedConsoleOutput() throws IOException {
|
public PipedConsoleOutput() throws IOException {
|
||||||
commandOutput = new PipedInputStream();
|
commandOutput = new PipedInputStream();
|
||||||
out = new PipedOutputStream(commandOutput);
|
final PipedOutputStream out = new PipedOutputStream(commandOutput);
|
||||||
commandBuffOutput = new BufferedReader(
|
commandBuffOutput = new BufferedReader(
|
||||||
new InputStreamReader(commandOutput, StandardCharsets.UTF_8));
|
new InputStreamReader(commandOutput, StandardCharsets.UTF_8));
|
||||||
outPrint = new PrintStream(out, true, UTF_8);
|
outPrint = new PrintStream(out, true, UTF_8);
|
||||||
@ -134,7 +133,6 @@ public final class PipedConsoleOutput implements ConsoleOutput {
|
|||||||
reading.setRunning(false);
|
reading.setRunning(false);
|
||||||
innerManager.close();
|
innerManager.close();
|
||||||
outPrint.close();
|
outPrint.close();
|
||||||
out.close();
|
|
||||||
commandBuffOutput.close();
|
commandBuffOutput.close();
|
||||||
commandOutput.close();
|
commandOutput.close();
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ 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.tools.ConstantString;
|
||||||
import net.bigeon.gclc.utils.ReadingRunnable;
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
|
||||||
/** A console using the input stream and print stream.
|
/** A console using the input stream and print stream.
|
||||||
@ -89,7 +90,7 @@ import net.bigeon.gclc.utils.ReadingRunnable;
|
|||||||
public final class StreamConsoleInput implements ConsoleInput {
|
public final class StreamConsoleInput implements ConsoleInput {
|
||||||
|
|
||||||
/** The default prompt. */
|
/** The default prompt. */
|
||||||
public static final Supplier<String> DEFAULT_PROMPT = () -> ("> "); //$NON-NLS-1$
|
public static final Supplier<String> DEFAULT_PROMPT = new ConstantString("> "); //$NON-NLS-1$
|
||||||
|
|
||||||
/** The command prompt. It can be changed. */
|
/** The command prompt. It can be changed. */
|
||||||
private Supplier<String> prompt = DEFAULT_PROMPT;
|
private Supplier<String> prompt = DEFAULT_PROMPT;
|
||||||
@ -212,7 +213,7 @@ public final class StreamConsoleInput implements ConsoleInput {
|
|||||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final String prompt) {
|
public void setPrompt(final String prompt) {
|
||||||
this.prompt = () -> (prompt);
|
this.prompt = new ConstantString(prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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.tools;
|
package net.bigeon.gclc.manager.forwarding;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@ -97,7 +97,7 @@ public abstract class AOutputForwardRunnable implements Runnable {
|
|||||||
/** Create a forwarding runnable.
|
/** Create a forwarding runnable.
|
||||||
*
|
*
|
||||||
* @param manager the manager */
|
* @param manager the manager */
|
||||||
protected AOutputForwardRunnable(final PipedConsoleOutput manager) {
|
public AOutputForwardRunnable(final PipedConsoleOutput manager) {
|
||||||
super();
|
super();
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
timeout = DEFAULT_TIMEOUT;
|
timeout = DEFAULT_TIMEOUT;
|
||||||
@ -116,8 +116,7 @@ public abstract class AOutputForwardRunnable implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param manager the manager
|
* @param manager the manager
|
||||||
* @param timeout the timeout between message requests. */
|
* @param timeout the timeout between message requests. */
|
||||||
protected AOutputForwardRunnable(final PipedConsoleOutput manager,
|
public AOutputForwardRunnable(final PipedConsoleOutput manager, final long timeout) {
|
||||||
final long timeout) {
|
|
||||||
super();
|
super();
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
@ -157,11 +156,8 @@ public abstract class AOutputForwardRunnable implements Runnable {
|
|||||||
/** a method to wait some time. */
|
/** a method to wait some time. */
|
||||||
protected final void waitASec() {
|
protected final void waitASec() {
|
||||||
try {
|
try {
|
||||||
final long tic = System.currentTimeMillis();
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
while (System.currentTimeMillis() - tic < timeout) {
|
wait(timeout);
|
||||||
wait(timeout + tic - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
|
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$
|
@ -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%
|
||||||
|
*/
|
||||||
|
|
@ -73,9 +73,7 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
/** A supplier of string that hold a constant string.
|
/** A supplier of string that hold a constant string.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon
|
* @author Emmanuel Bigeon */
|
||||||
* @deprecated since 2.1.2, use a lambda expression instead */
|
|
||||||
@Deprecated
|
|
||||||
public class ConstantString implements Supplier<String> {
|
public class ConstantString implements Supplier<String> {
|
||||||
private final String string;
|
private final String string;
|
||||||
|
|
||||||
|
@ -128,11 +128,8 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
* @throws IOException if the runnable was stopped and no essage was found. */
|
* @throws IOException if the runnable was stopped and no essage was found. */
|
||||||
private void doWaitMessage(final long timeout) throws IOException {
|
private void doWaitMessage(final long timeout) throws IOException {
|
||||||
try {
|
try {
|
||||||
final long tic = System.currentTimeMillis();
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
while (System.currentTimeMillis() - tic < timeout && messages.isEmpty()) {
|
lock.wait(timeout);
|
||||||
lock.wait(timeout);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
|
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
|
||||||
@ -202,13 +199,13 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
public void waitForDelivery(final String message) throws InterruptedException {
|
public void waitForDelivery(final String message) throws InterruptedException {
|
||||||
Object mLock;
|
Object mLock;
|
||||||
synchronized (messageBlockerLock) {
|
synchronized (messageBlockerLock) {
|
||||||
messageBlocker.computeIfAbsent(message, (final String k) -> new Object());
|
if (!messageBlocker.containsKey(message)) {
|
||||||
|
messageBlocker.put(message, new Object());
|
||||||
|
}
|
||||||
mLock = messageBlocker.get(message);
|
mLock = messageBlocker.get(message);
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
while (messageBlocker.containsKey(message)) {
|
mLock.wait();
|
||||||
mLock.wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,9 +251,9 @@ public final class ReadingRunnable implements Runnable {
|
|||||||
final Object mLock = messageBlocker.get(message);
|
final Object mLock = messageBlocker.get(message);
|
||||||
if (mLock!=null) {
|
if (mLock!=null) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
messageBlocker.remove(message);
|
|
||||||
mLock.notifyAll();
|
mLock.notifyAll();
|
||||||
}
|
}
|
||||||
|
messageBlocker.remove(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,11 @@ package net.bigeon.gclc;
|
|||||||
* 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.*;
|
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 static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -72,6 +72,7 @@ package net.bigeon.gclc;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -86,77 +87,52 @@ import net.bigeon.gclc.exception.CommandParsingException;
|
|||||||
@SuppressWarnings({ "nls", "static-method" })
|
@SuppressWarnings({ "nls", "static-method" })
|
||||||
public class GCLCConstantsTest {
|
public class GCLCConstantsTest {
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSplitCommandSingle() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
res = GCLCConstants.splitCommand("aCommand");
|
|
||||||
assertEquals("single word command should have one element", 1, res.size());
|
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSplitCommandSeveral() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
|
||||||
assertEquals("Command size", 4, res.size());
|
|
||||||
assertEquals("Elements should be preserved", "aCommand", res.get(0));
|
|
||||||
assertEquals("Command should be preserved", "with", res.get(1));
|
|
||||||
assertEquals("Command should be preserved", "some", res.get(2));
|
|
||||||
assertEquals("Command should be preserved", "arguments", res.get(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
|
||||||
*
|
*
|
||||||
* @throws CommandParsingException if an error occured */
|
* @throws CommandParsingException if an error occured */
|
||||||
@Test
|
@Test
|
||||||
public void testSplitCommandMultiSpaces() throws CommandParsingException {
|
public void testSplitCommand() throws CommandParsingException {
|
||||||
List<String> res;
|
List<String> res;
|
||||||
|
res = GCLCConstants.splitCommand("aCommand");
|
||||||
|
assertTrue("single word command should have one element", res.size() == 1);
|
||||||
|
assertTrue("Command should be preserved", res.get(0).equals("aCommand"));
|
||||||
|
|
||||||
|
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||||
|
assertEquals("Command size", 4, res.size());
|
||||||
|
assertEquals("Elements should be preserved", "aCommand", res.get(0));
|
||||||
|
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
||||||
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
res = GCLCConstants.splitCommand("aCommand with some arguments");
|
||||||
assertEquals("Command size", 4, res.size());
|
assertEquals("Command size", 4, res.size());
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
||||||
assertEquals("Command should be preserved", "with", res.get(1));
|
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||||
assertEquals("Command should be preserved", "some", res.get(2));
|
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||||
assertEquals("Command should be preserved", "arguments", res.get(3));
|
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
||||||
}
|
|
||||||
|
|
||||||
public void testSplitCommandWithString() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
res = GCLCConstants.splitCommand("aCommand \"with some\" arguments");
|
res = GCLCConstants.splitCommand("aCommand \"with some\" arguments");
|
||||||
assertEquals("Command size", 3, res.size());
|
assertEquals("Command size", 3, res.size());
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
||||||
assertEquals("Command should be preserved", "with some", res.get(1));
|
assertTrue("Elements should be preserved", res.get(1).equals("with some"));
|
||||||
assertEquals("Command should be preserved", "arguments", res.get(2));
|
assertTrue("Elements should be preserved", res.get(2).equals("arguments"));
|
||||||
|
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
||||||
|
assertEquals("Command size", 3, res.size());
|
||||||
|
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(1).equals("with some"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(2).equals("arguments"));
|
||||||
|
res = GCLCConstants.splitCommand("aCommand wi\\\"th some arguments");
|
||||||
|
assertEquals("Command size", 4, res.size());
|
||||||
|
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(1).equals("wi\"th"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(2).equals("some"));
|
||||||
|
assertTrue("Elements should be preserved", res.get(3).equals("arguments"));
|
||||||
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with \"some arguments\"");
|
res = GCLCConstants.splitCommand("aCommand with \"some arguments\"");
|
||||||
assertEquals("Command size", 3, res.size());
|
assertEquals("Command size", 3, res.size());
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
assertTrue("Elements should be preserved", res.get(0).equals("aCommand"));
|
||||||
assertEquals("Command should be preserved", "with", res.get(1));
|
assertTrue("Elements should be preserved", res.get(1).equals("with"));
|
||||||
assertEquals("Command should be preserved", "some arguments", res.get(2));
|
assertTrue("Elements should be preserved", res.get(2).equals("some arguments"));
|
||||||
}
|
|
||||||
|
|
||||||
public void testSplitCommandWithEscape() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
res = GCLCConstants.splitCommand("aCommand with\\ some arguments");
|
|
||||||
assertEquals("Command size", 3, res.size());
|
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
|
||||||
assertEquals("Command should be preserved", "with some", res.get(1));
|
|
||||||
assertEquals("Command should be preserved", "arguments", res.get(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSplitCommandWithQuoteInString() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
res = GCLCConstants.splitCommand("aCommand wi\\\"th some arguments");
|
|
||||||
assertEquals("Command size", 4, res.size());
|
|
||||||
assertEquals("Command should be preserved", "aCommand", res.get(0));
|
|
||||||
assertEquals("Command should be preserved", "wi\"th", res.get(1));
|
|
||||||
assertEquals("Command should be preserved", "some", res.get(2));
|
|
||||||
assertEquals("Command should be preserved", "arguments", res.get(3));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSplitCommandInvalidQuoting() throws CommandParsingException {
|
|
||||||
List<String> res;
|
|
||||||
try {
|
try {
|
||||||
// Wrong lines?
|
// Wrong lines?
|
||||||
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");
|
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");
|
||||||
|
@ -71,7 +71,11 @@ package net.bigeon.gclc.command;
|
|||||||
* 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.*;
|
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.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -33,7 +33,8 @@ package net.bigeon.gclc.command;
|
|||||||
* 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.fail;
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -71,7 +71,11 @@ package net.bigeon.gclc.command;
|
|||||||
* 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.*;
|
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.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -89,10 +93,10 @@ import net.bigeon.gclc.manager.ConsoleInput;
|
|||||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
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.ThreadTest;
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
import net.bigeon.test.junitmt.api.ATestRunnable;
|
|
||||||
import net.bigeon.test.junitmt.api.TestFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -509,18 +513,21 @@ public class ParametrizedCommandTest {
|
|||||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
|
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
|
||||||
cmd.execute(out, in, "-" + str1, str2, "-" + addParam, addParam);
|
cmd.execute(out, in, "-" + str1, str2, "-" + addParam, addParam);
|
||||||
|
|
||||||
final TestFunction function = () -> {
|
final TestFunction function = new TestFunction() {
|
||||||
assertEquals("value of " + str1 + "? ", buf.readLine());
|
|
||||||
in.type("");
|
@Override
|
||||||
assertEquals("value of " + str1 + "? (cannot be empty) ",
|
public void apply() throws Exception {
|
||||||
buf.readLine());
|
assertEquals("value of " + str1 + "? ", buf.readLine());
|
||||||
in.type("");
|
in.type("");
|
||||||
assertEquals("value of " + str1 + "? (cannot be empty) ",
|
assertEquals("value of " + str1 + "? (cannot be empty) ",
|
||||||
buf.readLine());
|
buf.readLine());
|
||||||
in.type(str2);
|
in.type("");
|
||||||
|
assertEquals("value of " + str1 + "? (cannot be empty) ",
|
||||||
|
buf.readLine());
|
||||||
|
in.type(str2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
final FunctionalTestRunnable testConsole = new FunctionalTestRunnable(
|
final ATestRunnable testConsole = new FunctionalTestRunnable(function);
|
||||||
function);
|
|
||||||
|
|
||||||
final Thread th = new Thread(testConsole);
|
final Thread th = new Thread(testConsole);
|
||||||
th.start();
|
th.start();
|
||||||
@ -536,9 +543,13 @@ public class ParametrizedCommandTest {
|
|||||||
new InputStreamReader(pis, StandardCharsets.UTF_8));
|
new InputStreamReader(pis, StandardCharsets.UTF_8));
|
||||||
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
|
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
|
||||||
|
|
||||||
final TestFunction function = () -> {
|
final TestFunction function = new TestFunction() {
|
||||||
assertEquals("value of " + str1 + "? ", buf.readLine());
|
|
||||||
in.type(str2);
|
@Override
|
||||||
|
public void apply() throws Exception {
|
||||||
|
assertEquals("value of " + str1 + "? ", buf.readLine());
|
||||||
|
in.type(str2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
final ATestRunnable testConsole = new FunctionalTestRunnable(function);
|
final ATestRunnable testConsole = new FunctionalTestRunnable(function);
|
||||||
|
|
||||||
@ -554,6 +565,7 @@ public class ParametrizedCommandTest {
|
|||||||
final PipedConsoleInput test = new PipedConsoleInput(null);
|
final PipedConsoleInput test = new PipedConsoleInput(null);
|
||||||
test.close();
|
test.close();
|
||||||
out.close();
|
out.close();
|
||||||
|
cmd.execute(out, test, "-" + str1, str2);
|
||||||
cmd.execute(out, test, "-" + addParam);
|
cmd.execute(out, test, "-" + addParam);
|
||||||
fail("Closed manager shall cause error");
|
fail("Closed manager shall cause error");
|
||||||
} catch (final CommandRunException e) {
|
} catch (final CommandRunException e) {
|
||||||
|
@ -71,7 +71,10 @@ package net.bigeon.gclc.command;
|
|||||||
* 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.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -92,8 +92,8 @@ 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.FunctionalTestRunnable;
|
||||||
|
import net.bigeon.test.junitmt.TestFunction;
|
||||||
import net.bigeon.test.junitmt.ThreadTest;
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
import net.bigeon.test.junitmt.api.TestFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -71,7 +71,10 @@ package net.bigeon.gclc.manager;
|
|||||||
* 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.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
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.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -71,7 +71,10 @@ package net.bigeon.gclc.prompt;
|
|||||||
* 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.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -91,10 +94,10 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
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.ThreadTest;
|
import net.bigeon.test.junitmt.ThreadTest;
|
||||||
import net.bigeon.test.junitmt.api.ATestRunnable;
|
|
||||||
import net.bigeon.test.junitmt.api.TestFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -78,6 +78,7 @@ import java.io.IOException;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -142,7 +143,7 @@ public class AOutputForwardRunnableTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.tools.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()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user