Compare commits

...

161 Commits

Author SHA1 Message Date
48d4db4086 [maven-release-plugin] prepare release swt-1.2.1 2022-09-10 12:58:31 +02:00
6a7d1f4636 [fix] Fix runnable superclass location
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2022-09-10 12:56:50 +02:00
9748b14872 [Jenkins] Dependency Updates 2022-08-18 12:19:03 +02:00
3219729b92 [Jenkins] Dependency Updates 2022-08-18 04:38:06 +02:00
e8eb56287e [Jenkins] Dependency Updates 2022-06-09 12:19:03 +02:00
6bc567d3b9 [Jenkins] Dependency Updates 2022-06-09 04:38:08 +02:00
cf2a90d2b7 [Jenkins] Dependency Updates 2022-06-02 12:19:03 +02:00
0dee4837ed [Jenkins] Dependency Updates 2022-04-28 12:19:02 +02:00
d605ed7aa1 [Jenkins] Dependency Updates 2022-04-28 04:38:08 +02:00
e570680ef8 [Jenkins] Dependency Updates 2022-04-21 12:19:02 +02:00
8da0a10616 [Jenkins] Dependency Updates 2022-04-21 04:38:06 +02:00
0839487620 [Jenkins] Dependency Updates 2022-03-19 08:47:06 +01:00
e37e84019a [Jenkins] Dependency Updates 2022-03-10 12:19:02 +01:00
bf593d4989 [Jenkins] Dependency Updates 2022-03-10 04:38:08 +01:00
0f120f7330 [Jenkins] Dependency Updates 2022-02-27 13:51:27 +01:00
52c76b4633 [Jenkins] Dependency Updates 2022-02-10 12:19:02 +01:00
3393294ddc [Jenkins] Dependency Updates 2022-02-10 04:38:07 +01:00
990b89848d [Jenkins] Dependency Updates 2022-02-09 05:36:03 +01:00
a74a909011 [maven-release-plugin] prepare for next development iteration 2022-02-05 10:53:58 +01:00
999c97dbf8 [maven-release-plugin] prepare release gclc-2.1.5 2022-02-05 10:53:55 +01:00
a9916eacab [chore] Update pom scm. Skip gclc-2.1.4
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2022-02-05 10:51:39 +01:00
fe942533cd [maven-release-plugin] prepare release gclc-2.1.4 2022-02-05 10:47:50 +01:00
a31c13ef1b [chore] Pom update scm. skip gclc 2.1.3 release.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2022-02-05 10:45:42 +01:00
c7c53d15c5 [maven-release-plugin] prepare release gclc-2.1.3 2022-02-05 10:42:37 +01:00
d86a254604 Merge branch 'master' into dev 2022-02-05 10:39:23 +01:00
3d9b0d039a [Jenkins] Dependency Updates 2022-01-27 12:20:02 +01:00
39ae13e01a [Jenkins] Dependency Updates 2022-01-27 04:39:08 +01:00
eeea0148f6 Merge branch 'master' into dev 2022-01-05 17:14:28 +01:00
a25360f50f [Jenkins] Dependency Updates 2021-12-23 12:19:02 +01:00
4212776bb9 [Jenkins] Dependency Updates 2021-12-23 04:38:08 +01:00
4d42dff80a [Jenkins] Dependency Updates 2021-11-25 12:19:02 +01:00
d680694d0a [Jenkins] Dependency Updates 2021-11-25 04:38:07 +01:00
c174e90562 [test] Remove use of deprecated code in test
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-22 08:20:51 +01:00
6bb3ad2354 [test] Fix invalid cast
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-22 08:19:53 +01:00
0f731270d5 [test] Fix the test of history text listener
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-13 19:13:00 +01:00
45fa90c75e Merge branch 'master' into dev 2021-11-13 19:00:38 +01:00
da107f0a40 [doc] Added comments on a brain overloading method.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 10:06:48 +01:00
14007f4d9a [fix] Remove use of deprecated code
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 10:00:06 +01:00
c500c3c046 [fix] Specify command type
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 09:53:35 +01:00
0c1cfe3946 [style] Set abstract class constructor as protected
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 09:52:11 +01:00
66d25697a8 [fix] Set waits inside loops
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 09:50:51 +01:00
a9c97a7ebc [chore] Remove commented out code
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-12 09:31:49 +01:00
0acc900a7c [Jenkins] Dependency Updates 2021-11-11 12:19:03 +01:00
8025122906 [test] Complete tests.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-10 11:14:08 +01:00
c8804fcd74 [Jenkins] Dependency Updates 2021-11-10 05:36:03 +01:00
80b8993e1f [Jenkins] Dependency Updates 2021-11-08 10:09:38 +01:00
625cacb198 [fix] Fix use of computeIfPresent with HashMap with possible null values
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 12:22:11 +01:00
ea01d346d3 [test] Use assert equals
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 12:13:13 +01:00
b38980eeb5 [chore] Move InterruptedIOException full name into documentation.
This avoids unnecessarily importing it.

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:59:32 +01:00
7b7d0e6747 [style] protected context for constructor of abstract classes
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:57:13 +01:00
8643b69054 [refactor] Use mapping computeIfPresent/Absent for conditional branch
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:55:21 +01:00
d726312341 [fix] Use string concatenation in delegated function for logging
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:45:29 +01:00
2ece273148 [fix] Put wait in while loops to consider spurious interruptions.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:44:20 +01:00
63de5448de [refactor] Reduced complexity of argument reading by one by refactoring
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:32:33 +01:00
51d8caa51e [fix] Unclosed stream wrapped in delegating stream.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:22:40 +01:00
72f768e6de [fix] Bug in Test for interactive
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2021-11-07 11:20:38 +01:00
8f386b4abd [tests] Add test on input contract
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2020-04-10 15:58:30 -04:00
1454938db8 [fix] Fix imports in new version of tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2020-04-10 15:53:39 -04:00
2f24c30d44 [jenkins] Update configuration and dependency 2020-04-06 06:25:29 -04:00
c97e5de32e [chore] update dependencies
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2020-04-04 12:45:33 -04:00
3df6482a64 [tests] Fix failing test because of incoherent assertion
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2020-04-04 11:48:53 -04:00
5c7635f550 Fix cycle
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-09 12:13:41 -04:00
54a267092d Moved util class to the right package
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 20:13:39 -04:00
c1ce1277d3 Extract interface as method return
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 20:09:03 -04:00
ba61efaa4a Add test with long execution command
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 19:59:26 -04:00
7a2991acc1 Reduce line duplication due to moved class
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 12:05:50 -04:00
fe8f0212ea [maven-release-plugin] prepare for next development iteration 2019-06-08 11:34:22 -04:00
a0a1dfe91e [maven-release-plugin] prepare release gclc-2.1.2 2019-06-08 11:34:17 -04:00
04902c9868 Remove unecessary method call
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 11:27:20 -04:00
9cf30ef7d2 #4 #5 Update exception of script command
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 10:55:35 -04:00
3960b10e8e #3 Add null chack for command name
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-06-08 10:50:51 -04:00
d3bb6fa5a0 Add eof new line
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-07 09:08:23 -04:00
b6b6ab9d36 Cut cycle
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 21:19:42 -04:00
92a664d193 Fix javadoc
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 21:14:26 -04:00
c230a23f81 Fix toString ternary operator presence
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 21:14:18 -04:00
e5c3bb0152 Replace ConstantString by lambda expression
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 20:51:12 -04:00
24e57eca2f Adding shell start up wait method.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 20:31:37 -04:00
da8765dd7b [maven-release-plugin] prepare for next development iteration 2019-05-06 20:00:30 -04:00
ce4254941a [maven-release-plugin] prepare release gclc-2.1.1 2019-05-06 20:00:25 -04:00
f459f78a75 #2 add removal of escaped character from last argument in line.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-05-06 19:53:55 -04:00
8cd0b01490 [maven-release-plugin] prepare for next development iteration 2019-04-22 17:52:41 -04:00
698b3d0e5e [maven-release-plugin] prepare release socket-1.1.18 2019-04-22 17:52:38 -04:00
9ad4a1e456 Add accesses to the listener list
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 17:52:18 -04:00
e560fcb92d [maven-release-plugin] prepare for next development iteration 2019-04-22 17:46:19 -04:00
56f3d604a1 [maven-release-plugin] prepare release socket-1.1.17 2019-04-22 17:46:16 -04:00
73317186df Update tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 17:45:40 -04:00
80bd7c0ac9 Add listener for brutal disconnection
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 17:44:23 -04:00
dc71070dab [maven-release-plugin] prepare for next development iteration 2019-04-22 16:07:42 -04:00
78b5926af1 [maven-release-plugin] prepare release socket-1.1.16 2019-04-22 16:07:39 -04:00
a3d2c2c07e Update disconnection
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 16:04:40 -04:00
9df812273c [maven-release-plugin] prepare for next development iteration 2019-04-22 15:33:47 -04:00
e953c2e659 [maven-release-plugin] prepare release socket-1.1.15 2019-04-22 15:33:44 -04:00
0f4fd6109d Stop console closing on client dirty disconnection
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-22 15:29:11 -04:00
69a8fd2533 [maven-release-plugin] prepare for next development iteration 2019-04-14 17:20:28 -04:00
0b772ddeb3 [maven-release-plugin] prepare release swt-1.2.0 2019-04-14 17:20:24 -04:00
55f13ae004 Use public configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:19:44 -04:00
295075ca37 Update versions and configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:14:04 -04:00
75bbba9884 [maven-release-plugin] prepare for next development iteration 2019-04-14 17:10:09 -04:00
82daa84bdf [maven-release-plugin] prepare release socket-1.1.14 2019-04-14 17:10:05 -04:00
10a0858d81 Update configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:07:04 -04:00
dfd3645497 Update configuration
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-04-14 17:03:57 -04:00
bd2da741f2 [maven-release-plugin] prepare for next development iteration 2019-04-02 09:41:05 -04:00
314db5b82f [maven-release-plugin] prepare release process-0.0.6 2019-04-02 09:40:56 -04:00
981668d3a7 Update dependency on collections
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2019-02-13 13:19:11 -05:00
9c8866827d Reduce prompting method complexity
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:25:01 -05:00
43c9faaee7 Added test for interruption and task failure
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:12:23 -05:00
8436e8926c Factor prompting methods code
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-03 11:12:13 -05:00
0cef23e17b Reduce branching depth
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 14:19:54 -05:00
6b2a25674d Fix interruption mechanic
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:57:48 -05:00
eec660e089 Improved message to test failure
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:57:21 -05:00
901469792d Added interruption flag
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:33:15 -05:00
79ee5394d4 Move inner classes into tool package
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-02 13:32:29 -05:00
acf4484eb3 [maven-release-plugin] prepare for next development iteration 2018-12-01 12:04:16 -05:00
012ef6e668 [maven-release-plugin] prepare release gclc-2.1.0 2018-12-01 12:04:13 -05:00
583f3146fd Removed declaration of runtime exception
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 12:01:44 -05:00
8b52ba5d49 Licensing
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 11:48:34 -05:00
a3051c6f03 Update next release version.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 11:48:07 -05:00
18b98997d3 Move console IO implemetations. #1 fixed
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 11:45:16 -05:00
0e1c69dab7 Moved output forward runnable
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 11:38:53 -05:00
c206b5b22c Changed prompt interruption contract
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 10:54:51 -05:00
c4bbfd8434 Moved console input/output implementations
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-12-01 10:54:30 -05:00
b671474f64 Added a delai for the task initialization
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 22:56:51 -05:00
6443790532 Change port for test server
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 22:35:38 -05:00
2df99debf8 Added test. removed implementation of shell
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 22:31:45 -05:00
d87aabd465 Change internal classes as private definitions
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 22:03:43 -05:00
0562faad70 Javadoc
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 22:02:44 -05:00
bb06b2a799 Removed suppress warning
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 21:56:08 -05:00
626f557aa0 Warning removal
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 21:47:10 -05:00
185d19bfcf Added documentation
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 21:35:17 -05:00
7fd1bf90bd Remove unused attributes
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 21:32:20 -05:00
1fa1f168c8 Added documentation
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 21:30:13 -05:00
09e9c69fe0 Use inet address rather than host name
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 16:02:22 -05:00
9f273f7595 Fix host name in test
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 14:18:50 -05:00
143eb7036a Added junit dependency, added input contract
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 12:18:16 -05:00
9c64c708eb Removed uneeded line
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 12:17:53 -05:00
8449eddab8 Extract model of view from graphics of view
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 12:17:38 -05:00
d0a286d45a Allow access to output forward to subclasses
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 10:44:05 -05:00
d6698a22fb Initial sharing of test. Moved gitignore to global ignore
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 09:21:46 -05:00
5e1050a9d7 Update test server to use getLocalHost rather than loopback.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-30 09:05:40 -05:00
9374c5a681 Added message notifications.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-26 10:40:40 -05:00
4c1e28b04f Update gclc version
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 12:07:04 -05:00
80933bb636 Update test
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 12:03:06 -05:00
48b4375565 removed logger
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 12:03:00 -05:00
ba7b80689c [maven-release-plugin] prepare for next development iteration 2018-11-25 12:00:44 -05:00
bd311d185e [maven-release-plugin] prepare release gclc-2.0.12 2018-11-25 12:00:41 -05:00
aa26173f26 Update port
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 11:37:07 -05:00
df688b1a85 Code factoring
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 11:31:52 -05:00
bcd0faceef Fixed runnable to allow acces to pending messages
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 11:22:37 -05:00
5e5cc2a1cd Added tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 11:05:06 -05:00
b24b72f3e2 Fixed console input
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 11:05:00 -05:00
ad79e3ccb6 Change to Supplier. Fix tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 09:16:38 -05:00
ddd818d93b Fix test
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 00:40:54 -05:00
6993513f38 Improve exception mechanics. remove closure of stream.
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-25 00:27:30 -05:00
b9a7142c5c Added comments
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-24 23:37:27 -05:00
85ef68f6ae Added error storing in the forwarding runnable. Added tests
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-11-24 21:07:28 -05:00
dfca63b179 [maven-release-plugin] prepare for next development iteration 2018-10-27 17:17:47 -04:00
787f951ff7 [maven-release-plugin] prepare release process-0.0.5 2018-10-27 17:17:44 -04:00
a364b6442b Added javadoc
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2018-10-27 17:16:15 -04:00
211b965e9e [maven-release-plugin] prepare for next development iteration 2018-10-27 16:39:13 -04:00
e1d030c6c5 [maven-release-plugin] prepare release swt-1.1.6 2018-10-27 16:39:10 -04:00
8bc2b13a92 [maven-release-plugin] prepare for next development iteration 2018-10-27 15:58:12 -04:00
102 changed files with 3316 additions and 2122 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# maven files
target/
# Eclipse files
.settings/
.classpath
.project

View File

@@ -3,12 +3,12 @@
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<version>1.8.29</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>process</artifactId>
<version>0.0.5-SNAPSHOT</version>
<version>0.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<name>process</name>
@@ -38,7 +38,7 @@
</developers>
<scm>
<tag>HEAD</tag>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -49,7 +49,13 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.11</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>net.bigeon.test</groupId>
<artifactId>junitmt</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>

View File

@@ -100,7 +100,7 @@ public abstract class ForkTask implements Task {
/** Create the task.
*
* @param lines the number of print to store in the output */
public ForkTask(final int lines) {
protected ForkTask(final int lines) {
out = new ConnectingConsoleOutput(ConnectingConsoleOutput.PERSIST, lines);
}
@@ -142,16 +142,19 @@ public abstract class ForkTask implements Task {
* @param timeout the maximal time to join for (0 for ever) */
public final void join(final ConsoleOutput out, final ConsoleInput in,
final long timeout) {
final long tic = System.currentTimeMillis();
synchronized (runLock) {
this.out.connect(out);
this.in.connect(in);
long tac = System.currentTimeMillis() - tic;
while (running && tac < timeout) {
try {
if (running) {
runLock.wait(timeout);
}
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
tac = System.currentTimeMillis() - tic;
}
this.out.disconnect();
this.in.disconnect();
}

View File

@@ -84,8 +84,8 @@ public abstract class TaskSpawner extends Command {
private final ExecutorService threadPool;
/** @param name the command name
* @param pool the pool */
public TaskSpawner(final String name, final TaskPool pool,
* @param threadPool the pool */
protected TaskSpawner(final String name, final TaskPool pool,
final ExecutorService threadPool) {
super(name);
this.pool = pool;

View File

@@ -68,28 +68,20 @@ package net.bigeon.gclc.process.io;
* #L%
*/
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.InterruptedIOException;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.tools.StringProvider;
/** A console input that can be connected to and diconnected from.
*
* @author Emmanuel Bigeon */
public final class ConnectingConsoleInput implements ConsoleInput {
/** The empty string provider. */
private static final ConstantString EMPTY_STRING = new ConstantString("");
/** The logger. */
private static final Logger LOGGER = Logger
.getLogger(ConnectingConsoleInput.class.getName());
/** If the input is closed. */
private boolean close = false;
/** The prompt string. */
private StringProvider prompt = EMPTY_STRING;
private Supplier<String> prompt = () -> "";
/** If the input is currently in prompting state.
* <p>
* To change it you should be in a promptLock. */
@@ -107,6 +99,8 @@ public final class ConnectingConsoleInput implements ConsoleInput {
* To read or modify it, you should be in a connectionLock synchronize block. */
private boolean disconnection = false;
private boolean interrupting = false;
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#close() */
@Override
@@ -120,15 +114,18 @@ public final class ConnectingConsoleInput implements ConsoleInput {
public void connect(final ConsoleInput input) {
disconnect();
synchronized (promptLock) {
connected = input;
promptLock.notifyAll();
synchronized (connectionLock) {
connected = input;
connectionLock.notifyAll();
}
}
}
/** Disconnect the current input. */
public void disconnect() {
synchronized (promptLock) {
synchronized (connectionLock) {
synchronized (promptLock) {
if (connected != null) {
disconnection = true;
connected.interruptPrompt();
@@ -141,7 +138,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@Override
public StringProvider getPrompt() {
public Supplier<String> getPrompt() {
return prompt;
}
@@ -149,14 +146,20 @@ public final class ConnectingConsoleInput implements ConsoleInput {
* @see fr.bigeon.gclc.manager.ConsoleInput#interruptPrompt() */
@Override
public void interruptPrompt() {
synchronized (connectionLock) {
synchronized (promptLock) {
prompting = false;
if (prompting) {
interrupting = true;
}
connectionLock.notifyAll();
if (connected != null) {
connected.interruptPrompt();
}
prompting = false;
promptLock.notifyAll();
}
}
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#isClosed() */
@@ -169,14 +172,14 @@ public final class ConnectingConsoleInput implements ConsoleInput {
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
@Override
public String prompt() throws IOException {
return prompt(prompt.apply());
return prompt(prompt.get());
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
@Override
public String prompt(final long timeout) throws IOException {
return prompt(prompt.apply(), timeout);
return prompt(prompt.get(), timeout);
}
/* (non-Javadoc)
@@ -186,36 +189,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
synchronized (promptLock) {
prompting = true;
}
while (true) {
synchronized (promptLock) {
if (!prompting) {
return null;
}
boolean connect;
synchronized (connectionLock) {
connect = connected != null;
}
if (!connect) {
try {
promptLock.wait();
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, "Inerruption of console thread", e);
Thread.currentThread().interrupt();
}
} else {
synchronized (connectionLock) {
final String res = connected.prompt(message);
if (disconnection) {
disconnection = false;
} else if (prompting) {
return res;
} else {
// prompt interrupted, lose the result.
}
}
}
}
}
return doPrompt(message, 0, 0);
}
/* (non-Javadoc)
@@ -225,56 +199,129 @@ public final class ConnectingConsoleInput implements ConsoleInput {
if (timeout <= 0) {
return prompt(message);
}
final long end = System.currentTimeMillis() + timeout;
synchronized (promptLock) {
prompting = true;
}
do {
synchronized (promptLock) {
if (!prompting) {
return null;
final long tic = System.currentTimeMillis();
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)
throws IOException {
do {
if (!checkPrompt()) {
// We are not prompting... lets stop here.
break;
}
getConnection(getTimeoutLeft(tic, timeout));
boolean connect;
ConsoleInput actualConnected;
synchronized (connectionLock) {
connect = connected != null;
actualConnected = connected;
}
if (!connect) {
try {
promptLock.wait(timeout);
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, "Inerruption of console thread", e);
Thread.currentThread().interrupt();
// There is no provide of input... So lets start again, until we actually
// DO get a provider of input.
continue;
}
} else {
synchronized (connectionLock) {
final String res = connected.prompt(message,
end - System.currentTimeMillis());
try {
final String res = actualPrompt(message, timeout, tic, actualConnected);
// We got something from the prompting
synchronized (promptLock) {
if (prompting) {
prompting = false;
return res;
}
}
} catch (final InterruptedIOException e) {
// The inner console was interrupted. This can mean we are
// disconnecting or actually interrupted.
if (disconnection) {
disconnection = false;
} else if (prompting) {
return res;
} else {
// prompt interrupted, lose the result.
interrupting = false;
throw e;
}
}
}
}
} while (System.currentTimeMillis() < end);
} while (checkTimeout(tic, timeout));
return null;
}
private static String actualPrompt(final String message, final long timeout,
final long tic, final ConsoleInput actualConnected) throws IOException {
final long timeoutLeft = getTimeoutLeft(tic, timeout);
if (timeoutLeft == 0) {
return actualConnected.prompt(message);
}
return actualConnected.prompt(message, timeoutLeft);
}
private static boolean checkTimeout(final long tic, final long timeout) {
return timeout <= 0 || tic + timeout > System.currentTimeMillis();
}
private static long getTimeoutLeft(final long tic, final long timeout) {
if (timeout > 0) {
return Math.max(timeout + tic - System.currentTimeMillis(), 1);
}
if (timeout < 0) {
return 1;
}
return 0;
}
/** Test if we are in prompting state.
*
* @return if the process is currently in prompting state.
* @throws InterruptedIOException if the prompting state has been interrupted */
private boolean checkPrompt() throws InterruptedIOException {
synchronized (promptLock) {
if (!prompting && interrupting) {
interrupting = false;
throw new InterruptedIOException("Prompt was interrupted");
}
return prompting;
}
}
private void getConnection(final long timeout) throws InterruptedIOException {
final long tic = System.currentTimeMillis();
synchronized (connectionLock) {
while ((connected == null || !interrupting)
&& (tic + timeout) > System.currentTimeMillis()) {
try {
connectionLock.wait(timeout);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
if (interrupting) {
interrupting = false;
throw new InterruptedIOException("Prompt ws interrupted");
}
}
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
@Override
public void setPrompt(final String prompt) {
this.prompt = new ConstantString(prompt);
this.prompt = () -> prompt;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools.
* StringProvider) */
@Override
public void setPrompt(final StringProvider string) {
public void setPrompt(final Supplier<String> string) {
prompt = string;
}
}

View File

@@ -37,7 +37,7 @@ public class CommandForkTest {
* {@link net.bigeon.gclc.process.CommandFork#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
*
* @throws InvalidCommandName if the test init failed
* @throws CommandRunException */
* @throws CommandRunException if the command execution failed in the test */
@Test
public void testExecute() throws InvalidCommandName, CommandRunException {
final TaskPool pool = new TaskPool(false);

View File

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

View File

@@ -0,0 +1,34 @@
/**
*
*/
package net.bigeon.gclc.process;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import net.bigeon.gclc.command.SubedCommand;
import net.bigeon.gclc.exception.InvalidCommandName;
/**
* @author Emmanuel Bigeon
*
*/
public class ProcessAttachementTest {
/** Test method for
* {@link net.bigeon.gclc.process.ProcessAttachement#attach(net.bigeon.gclc.command.ICommandProvider)}.
*
* @throws InvalidCommandName if the command has already some subcommand that is
* incompatible */
@Test
public void testAttach() throws InvalidCommandName {
final TaskPool pool = new TaskPool();
final ProcessAttachement attachement = new ProcessAttachement(pool);
final SubedCommand testPoint = new SubedCommand("test");
attachement.attach(testPoint);
assertNotNull("Commands should be added", testPoint.get("kill"));
assertNotNull("Commands should be added", testPoint.get("list"));
}
}

View File

@@ -7,8 +7,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
@@ -30,8 +28,7 @@ public class ProcessKillTest {
/** Test method for
* {@link net.bigeon.gclc.process.ProcessKill#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
*
* @throws CommandRunException if an error occured in test
* @throws IOException if an error occured with the console output */
* @throws CommandRunException if an error occured in test */
@Test
public void testExecute() throws CommandRunException {
final TaskPool pool = new TaskPool();

View File

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

View File

@@ -0,0 +1,33 @@
/**
*
*/
package net.bigeon.gclc.process;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import net.bigeon.gclc.command.SubedCommand;
import net.bigeon.gclc.exception.InvalidCommandName;
/** @author Emmanuel Bigeon */
public class ScreenAttachementTest {
/** Test method for
* {@link net.bigeon.gclc.process.ScreenAttachement#attach(net.bigeon.gclc.command.ICommandProvider)}.
*
* @throws InvalidCommandName if an error occured in attachement */
@Test
public void testAttach() throws InvalidCommandName {
final TaskPool pool = new TaskPool();
final ScreenAttachement attachement = new ScreenAttachement(pool, 15);
final SubedCommand testPoint = new SubedCommand("test");
attachement.attach(testPoint);
assertNotNull("Commands should be added", testPoint.get("terminate"));
assertNotNull("Commands should be added", testPoint.get("list"));
assertNotNull("Commands should be added", testPoint.get("clear"));
assertNotNull("Commands should be added", testPoint.get("fg"));
assertNotNull("Commands should be added", testPoint.get("fork"));
}
}

View File

@@ -0,0 +1,80 @@
/**
*
*/
package net.bigeon.gclc.process;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
/** @author Emmanuel Bigeon */
public class TaskSpawnerTest {
/** Test method for
* {@link net.bigeon.gclc.process.TaskSpawner#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
*
* @throws CommandRunException if an error occurred */
@Test
public void testExecute() throws CommandRunException {
final Task task = new Task() {
@Override
public void run() {
//
}
@Override
public void setRunning(final boolean running) {
//
}
@Override
public void rmInterruptionListener(final InterruptionListener listener) {
//
}
@Override
public boolean isRunning() {
return false;
}
@Override
public String getName() {
return "abc";
}
@Override
public void addInterruptionListener(final InterruptionListener listener) {
//
}
};
final TaskPool pool = new TaskPool();
assertTrue("Pool not empty", pool.getPIDs().isEmpty());
final ExecutorService service = Executors.newSingleThreadExecutor();
final TaskSpawner spawner = new TaskSpawner("name", pool, service) {
@Override
public String tip() {
return "tip";
}
@Override
protected String usageDetail() {
return "no details";
}
@Override
protected Task createTask(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
return task;
}
};
spawner.execute(null, null);
assertEquals("Added the task", 1, pool.getPIDs().size());
final Integer id = pool.getPIDs().iterator().next();
assertEquals("Added task is not the one", task, pool.get(id));
}
}

View File

@@ -1,16 +1,23 @@
package net.bigeon.gclc.process.io;
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.*;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import org.junit.Test;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.StreamConsoleInput;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.ThreadTest;
import net.bigeon.test.junitmt.api.ATestRunnable;
import net.bigeon.test.junitmt.api.TestFunction;
public class ConnectingConsoleInputTest {
@@ -56,10 +63,86 @@ public class ConnectingConsoleInputTest {
public void testCoveragePrompt() {
final ConnectingConsoleInput in = new ConnectingConsoleInput();
in.setPrompt("test");
assertEquals("Prompt should be set correctly", "test",
((ConstantString) in.getPrompt()).apply());
final ConstantString prompt = new ConstantString("other");
assertEquals("Prompt should be set correctly", "test", in.getPrompt().get());
final Supplier<String> prompt = () -> "other";
in.setPrompt(prompt);
assertEquals("Prompt should be set correctly", prompt, in.getPrompt());
}
@Test
public void testPromptSequence() throws IOException, InterruptedException {
final ConnectingConsoleInput in = new ConnectingConsoleInput();
// Unconnected
final AtomicBoolean ended = new AtomicBoolean(false);
final TestFunction one = () -> {
try {
final String res1 = in.prompt("m1", -1);
fail("interruption of infinite waiting prompt should cause error, but was "
+ 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 {
assertNull("Overtime should return null", in.prompt("m3", 200));
} catch (final InterruptedIOException e3) {
fail("Unexpected interruption error in overtime");
}
}
};
final ATestRunnable runnable = new FunctionalTestRunnable(one);
final Thread th = new Thread(runnable, "TestPromptSequence");
final Thread inter = new Thread(() -> {
while (!ended.get()) {
try {
th.join(100);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (ended) {
if (!ended.get()) {
in.interruptPrompt();
}
}
}
});
th.start();
inter.start();
ThreadTest.assertRuns(th, runnable);
inter.join();
ended.set(false);
final PipedOutputStream os = new PipedOutputStream();
final PipedInputStream pis = new PipedInputStream(os);
in.connect(new StreamConsoleInput(null, pis, StandardCharsets.UTF_8));
final ATestRunnable runnable2 = new FunctionalTestRunnable(one);
final Thread th2 = new Thread(runnable2);
final Thread inter2 = new Thread(() -> {
while (!ended.get()) {
try {
th2.join(100);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (ended) {
if (!ended.get()) {
in.interruptPrompt();
}
}
}
});
th2.start();
inter2.start();
ThreadTest.assertRuns(th2, runnable2);
}
}

View File

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

View File

@@ -15,7 +15,7 @@ public class ForkTaskMock extends ForkTask implements Task {
private int runCall = 0;
/** @param lines */
/** Default constructor. */
public ForkTaskMock() {
super(10);
}

View File

@@ -49,8 +49,8 @@ public class TaskMock implements Task {
setRunningCall = 0;
}
/** @return */
public Object getNumberSetRunning() {
/** @return the number of calls to set running method */
public int getNumberSetRunning() {
return setRunningCall;
}

View File

@@ -2,12 +2,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<artifactId>ebigeon-public-conf</artifactId>
<version>1.0.12</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>socket</artifactId>
<version>1.1.13</version>
<version>1.1.19-SNAPSHOT</version>
<packaging>jar</packaging>
<name>GCLC Socket</name>
<description>Socket implementation of GCLC</description>
@@ -35,29 +35,28 @@
</developer>
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>socket-1.1.13</tag>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.scm.id>git.code.bigeon.net</project.scm.id>
<license.licenseName>cecill_2.1</license.licenseName>
</properties>
<dependencies>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.11</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>smu</artifactId>
<version>1.0.6</version>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>net.bigeon.test</groupId>
<artifactId>junitmt</artifactId>
<version>1.0.0</version>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -0,0 +1,14 @@
/**
*
*/
package net.bigeon.gclc.socket;
/** Interface for listener of brutal disconnection from a pluggable
* input/output.
*
* @author Emmanuel Bigeon */
@FunctionalInterface
public interface DisconnexionListener {
/** Indicate a brutal disconnection */
void disconnected();
}

View File

@@ -41,14 +41,16 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.tools.StringProvider;
import net.bigeon.gclc.utils.ReadingRunnable;
/** A console input where the stream can be plugged.
@@ -75,7 +77,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
/** If the element is closed. */
private boolean closed = false;
/** The default prompt. */
private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$
private Supplier<String> prompt = () -> "> "; //$NON-NLS-1$
/** If the input is plugged or buffering. */
private boolean connected = false;
/** The current connexion (if any). */
@@ -87,6 +89,8 @@ public final class PluggableConsoleInput implements ConsoleInput {
/** The output for hints. */
private PrintStream output;
private final Set<DisconnexionListener> listeners = new HashSet<>();
// Locks
/** The lock for connexion and disconnexion of actual streams. */
private final Object connexionLock = new Object();
@@ -119,6 +123,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
if (prompting) {
// print the hint, to indicate we are waiting for a user input.
out.print(hint);
out.println();
out.flush();
}
final InputStreamReader streamReader = new InputStreamReader(stream,
@@ -146,7 +151,7 @@ public final class PluggableConsoleInput implements ConsoleInput {
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@Override
public StringProvider getPrompt() {
public Supplier<String> getPrompt() {
return prompt;
}
@@ -175,14 +180,14 @@ public final class PluggableConsoleInput implements ConsoleInput {
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt() */
@Override
public String prompt() throws IOException {
return prompt(prompt.apply());
return prompt(prompt.get());
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
@Override
public String prompt(final long timeout) throws IOException {
return prompt(prompt.apply(), timeout);
return prompt(prompt.get(), timeout);
}
/* (non-Javadoc)
@@ -257,14 +262,14 @@ public final class PluggableConsoleInput implements ConsoleInput {
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
@Override
public void setPrompt(final String prompt) {
setPrompt(new ConstantString(prompt));
setPrompt(() -> prompt);
}
/* (non-Javadoc)
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(net.bigeon.gclc.tools.
* StringProvider) */
@Override
public void setPrompt(final StringProvider prompt) {
public void setPrompt(final Supplier<String> prompt) {
this.prompt = prompt;
}
@@ -279,10 +284,50 @@ public final class PluggableConsoleInput implements ConsoleInput {
final long connexionTimeout) throws IOException, InterruptedException {
synchronized (connexionLock) {
if (connected) {
try {
return connexion.getNextMessage(messageTimeout);
} catch (final InterruptedIOException e) {
throw e;
} catch (final IOException e) {
LOGGER.log(Level.INFO, "Communication was abrubptly interrupted", e);
brutalDisconnection();
}
}
while (!connected) {
connexionLock.wait(connexionTimeout);
}
}
return null;
}
/**
*
*/
private void brutalDisconnection() {
// clean up the disconnection
disconnect();
// notify listeners
for (final DisconnexionListener listener : listeners) {
listener.disconnected();
}
}
/** Add a listener to the list of listeners.
*
* @param e the listener
* @return if the listener was added
* @see java.util.Set#add(java.lang.Object) */
public boolean add(final DisconnexionListener e) {
return listeners.add(e);
}
/** Remove a listener from the list of listeners.
*
* @param o the listener
* @return if the listener was removed
* @see java.util.Set#remove(java.lang.Object) */
public boolean remove(final DisconnexionListener o) {
return listeners.remove(o);
}
}

View File

@@ -4,60 +4,21 @@
*/
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.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
*
* @author Emmanuel Bigeon
* @param <T> the type of connected object */
* @param <T> the type of connected object
* @deprecated since 1.1.17, this has been moved to
* {@link RemoteDisconnectCommand}. */
@Deprecated
public final class RemoteDisconnectCommand<T> extends Command {
/** The connexion manager. */
private final ConnexionManager<T> manager;
/** If all connexion should be disconnected when no argument have been
* specified. */
private final boolean all;
private final net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<T> real;
/** Create the disconnection command.
*
@@ -68,8 +29,8 @@ public final class RemoteDisconnectCommand<T> extends Command {
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
final boolean all) {
super(name);
this.manager = manager;
this.all = all;
real = new net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand<>(name, manager,
all);
}
/* (non-Javadoc)
@@ -78,52 +39,20 @@ public final class RemoteDisconnectCommand<T> extends Command {
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
if (args.length == 0 && all) {
final Collection<String> coll = manager.getConnected();
for (final String string : coll) {
manager.disconnect(string);
}
}
for (final String string : args) {
if (manager.isConnected(string)) {
manager.disconnect(string);
} else {
print(out,
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
}
}
}
/** Print a message if the output is defined.
*
* @param out the output
* @param string the message
* @throws CommandRunException if the output exists but cannot be printed to */
private static void print(final ConsoleOutput out, final String string)
throws CommandRunException {
if (out != null) {
try {
out.println(string);
} catch (final IOException e) {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"Unable to print to existing output", e); //$NON-NLS-1$
}
}
real.execute(out, in, args);
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() */
@Override
public String tip() {
return "Close a connexion."; //$NON-NLS-1$
return real.tip();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
return MessageFormat.format(
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
all ? "all connexions" : "none");
return "";
}
}

View File

@@ -77,6 +77,8 @@ public final class SocketConsoleApplicationShell implements Runnable {
/** The application. */
private ConsoleApplication app;
private final Object initLock = new Object();
/** The server socket. */
private ServerSocket serverSocket;
/** THe server address. */
@@ -123,7 +125,10 @@ public final class SocketConsoleApplicationShell implements Runnable {
// Create the server
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
serverSocket = actualServerSocket;
synchronized (initLock) {
running = true;
initLock.notifyAll();
}
// Create the streams
runSokectServer();
} catch (final IOException e) {
@@ -194,4 +199,23 @@ public final class SocketConsoleApplicationShell implements Runnable {
LOGGER.log(Level.SEVERE, "Exception in closing socket server", e); //$NON-NLS-1$
}
}
/** A method to wait for the socket server initialization.
*
* @param timeout the timeout */
public void waitStartUp(final long timeout) {
synchronized (initLock) {
final long tic = System.currentTimeMillis() + timeout;
long tac;
while (!running && (tac = System.currentTimeMillis()) < tic) {
final long idle = tic - tac;
try {
initLock.wait(idle);
} catch (final InterruptedException e) {
LOGGER.log(Level.INFO, "Thread interruption", e);
Thread.currentThread().interrupt();
}
}
}
}
}

View File

@@ -0,0 +1,98 @@
/**
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommand.java
* Created on: Nov 18, 2017
*/
package net.bigeon.gclc.socket.cmd;
/*-
* #%L
* GCLC Socket
* %%
* Copyright (C) 2016 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.util.Collection;
import net.bigeon.gclc.command.Command;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.socket.ConnexionManager;
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
*
* @author Emmanuel Bigeon
* @param <T> the type of connected object */
public final class ConnexionListCommand<T> extends Command {
/** The connexion manager. */
private final ConnexionManager<T> manager;
/** Create the connexion listing command.
*
* @param name the command name
* @param manager the manager */
public ConnexionListCommand(final String name, final ConnexionManager<T> manager) {
super(name);
this.manager = manager;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
final Collection<String> coll = manager.getConnected();
try {
for (final String string : coll) {
out.println(string);
}
} catch (final IOException e) {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"User cannot be notified", e);
}
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() */
@Override
public String tip() {
return "List current connexions."; //$NON-NLS-1$
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
return "";
}
}

View File

@@ -0,0 +1,136 @@
/**
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommand.java
* Created on: Nov 18, 2017
*/
package net.bigeon.gclc.socket.cmd;
/*-
* #%L
* GCLC Socket
* %%
* Copyright (C) 2016 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collection;
import net.bigeon.gclc.command.Command;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.socket.ConnexionManager;
/** A {@link Command} to disconnect elements from a {@link ConnexionManager}.
*
* @author Emmanuel Bigeon
* @param <T> the type of connected object */
public final class RemoteDisconnectCommand<T> extends Command {
/** The connexion manager. */
private final ConnexionManager<T> manager;
/** If all connexion should be disconnected when no argument have been
* specified. */
private final boolean all;
/** Create the disconnection command.
*
* @param name the command name
* @param manager the manager
* @param all if all elements should be disconnected when no argument is
* provided */
public RemoteDisconnectCommand(final String name, final ConnexionManager<T> manager,
final boolean all) {
super(name);
this.manager = manager;
this.all = all;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput, java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
if (args.length == 0 && all) {
final Collection<String> coll = manager.getConnected();
for (final String string : coll) {
manager.disconnect(string);
}
}
for (final String string : args) {
if (manager.isConnected(string)) {
manager.disconnect(string);
} else {
print(out,
MessageFormat.format("[WARNING] {0} is not connected", string)); //$NON-NLS-1$
}
}
}
/** Print a message if the output is defined.
*
* @param out the output
* @param string the message
* @throws CommandRunException if the output exists but cannot be printed to */
private static void print(final ConsoleOutput out, final String string)
throws CommandRunException {
if (out != null) {
try {
out.println(string);
} catch (final IOException e) {
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
"Unable to print to existing output", e); //$NON-NLS-1$
}
}
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() */
@Override
public String tip() {
return "Close a connexion."; //$NON-NLS-1$
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
final StringBuilder builder = new StringBuilder(
" If arguments are provided the corresponding connexions are closed, otherwise\n");
if (all) {
builder.append("all connections");
} else {
builder.append("none");
}
builder.append(" are.");
return builder.toString();
}
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Emmanuel Bigeon
*
*/
package net.bigeon.gclc.socket.cmd;

View File

@@ -90,7 +90,7 @@ public class PluggableConsoleInputTest {
}
try {
Object obj = new Object();
final Object obj = new Object();
synchronized (obj) {
obj.wait(100);
}
@@ -115,7 +115,7 @@ public class PluggableConsoleInputTest {
@Override
public void run() {
try {
Object obj = new Object();
final Object obj = new Object();
synchronized (obj) {
obj.wait(200);
}
@@ -168,7 +168,7 @@ public class PluggableConsoleInputTest {
});
th.start();
Object obj = new Object();
final Object obj = new Object();
synchronized (obj) {
while (!input.isPrompting()) {
obj.wait(10);
@@ -211,8 +211,8 @@ public class PluggableConsoleInputTest {
@Test
public final void testGetPrompt() {
final PluggableConsoleInput input = new PluggableConsoleInput();
assertEquals("Default prompt invalid", "> ", input.getPrompt().apply());
assertEquals("Default prompt invalid", "> ", input.getPrompt().get());
input.setPrompt("test");
assertEquals("Prompt setting failed", "test", input.getPrompt().apply());
assertEquals("Prompt setting failed", "test", input.getPrompt().get());
}
}

View File

@@ -43,6 +43,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.util.logging.Logger;
@@ -76,8 +77,8 @@ public class SocketConsoleApplicationTest {
public void testIntegration() throws IOException, InterruptedException {
Thread server;
server = TestServer.getServer();
final String hostName = "127.0.0.1";
final int portNumber = 3300;
final InetAddress hostName = InetAddress.getLocalHost();
final int portNumber = TestServer.PORT;
try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);

View File

@@ -46,7 +46,7 @@ import net.bigeon.gclc.ConsoleApplication;
@SuppressWarnings({ "javadoc", "nls" })
public class TestServer {
public static final int PORT = 3300;
public static final int PORT = 12343;
private static SocketConsoleApplicationShell SHELL;
private static ConnexionManager<Socket> manager;
@@ -66,6 +66,7 @@ public class TestServer {
if (server == null) {
server = new Thread(getShell(), "gclcServer");
server.start();
getShell().waitStartUp(500);
}
return server;
}
@@ -76,20 +77,13 @@ public class TestServer {
input.setPrompt("> \n");
output = new PluggableConsoleOutput();
manager = new DConnexionManager<>();
SHELL = new SocketConsoleApplicationShell(PORT,
InetAddress.getByName("127.0.0.1"));
SHELL = new SocketConsoleApplicationShell(PORT, InetAddress.getLocalHost());
final ConsoleApplication app = ConsoleTestApplication.create(output, input,
manager);
SHELL.setInterface(new SocketConsoleInterface(input, output));
SHELL.setConnexionManager(manager);
SHELL.setApplication(app);
final Thread th = new Thread(new Runnable() {
@Override
public void run() {
app.start();
}
});
final Thread th = new Thread(() -> app.start());
th.start();
try {
final Object waiting = new Object();

View File

@@ -2,7 +2,7 @@
* gclc-socket:net.bigeon.gclc.socket.RemoteDisconnectCommandTest.java
* Created on: Nov 18, 2017
*/
package net.bigeon.gclc.socket;
package net.bigeon.gclc.socket.cmd;
/*-
* #%L
@@ -46,7 +46,8 @@ import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.socket.DConnexionManager;
/**
* <p>
@@ -56,7 +57,7 @@ import net.bigeon.gclc.utils.PipedConsoleOutput;
public class RemoteDisconnectCommandTest {
/** Test method for
* {@link net.bigeon.gclc.socket.RemoteDisconnectCommand#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
* {@link net.bigeon.gclc.socket.cmd.RemoteDisconnectCommand#execute(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, java.lang.String[])}.
*
* @throws CommandRunException if the command unexpectedly failed.
* @throws IOException if the output could not be written to */

4
gclc-swt/.gitignore vendored
View File

@@ -1,4 +0,0 @@
/target/
/.settings/
/.classpath
/.project

View File

@@ -1,15 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>swt-config</artifactId>
<version>1.8.11</version>
<artifactId>swt-public-conf</artifactId>
<version>1.0.2</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>swt</artifactId>
<version>1.1.6-SNAPSHOT</version>
<version>1.2.1</version>
<packaging>jar</packaging>
<name>GCLC swt</name>
<description>A swt window for console applications</description>
@@ -37,8 +35,8 @@
</developer>
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<tag>HEAD</tag>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
<tag>swt-1.2.1</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -50,21 +48,26 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.11</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>collections</artifactId>
<version>1.1.6</version>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>com.github.sevntu-checkstyle</groupId>

View File

@@ -30,11 +30,13 @@
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc-swt:net.bigeon.gclc.swt.SWTConsole.java
* gclc-swt:net.bigeon.gclc.swt.SWTConsoleShell.java
* Created on: Apr 18, 2015
*/
package net.bigeon.gclc.swt;
import java.io.BufferedReader;
/*-
* #%L
* GCLC swt
@@ -68,411 +70,80 @@ package net.bigeon.gclc.swt;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.ConsoleApplication;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.tools.StringProvider;
import net.bigeon.gclc.manager.PipedConsoleInput;
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 SWT component to connect to gclc {@link ConsoleApplication}.
/** A shell containing a {@link SWTConsoleView}
* <p>
*
* @author Emmanuel Bigeon */
public final class SWTConsole extends Composite
implements ConsoleDelayIO, ConsoleInput, ConsoleOutput {
private static final int TWO = 2;
private static final String ERROR_SYNCHRO_PROMPT = "Error in synchronization of prompting";
/** The number of columns of the layout. */
private static final int LAYOUT_NB_COLUMNS = 2;
/** The cmd prefix in the output console. */
private static final String CMD_PREFIX = "[CMD] "; //$NON-NLS-1$
/** The class logger. */
private static final Logger LOGGER = Logger
.getLogger(SWTConsole.class.getName());
/** The empty string constant. */
private static final String EMPTY = ""; //$NON-NLS-1$
public final class SWTConsole extends Composite {
/** The console output text field. */
private final Text consoleOutput;
/** The console input text field. */
private final Text consoleInput;
/** The prompt label. */
private final Label lblPromptlabel;
/** The prompt text. */
private StringProvider prompt = new ConstantString("> "); //$NON-NLS-1$
/** The command entered by the user. */
private String command = null;
/** If the prompt should be active. */
private boolean prompting = false;
/** The object for thread synchronization with the prompt. */
private final Object promptLock = new Object();
private ConsoleInputManager inputManager;
private ConsoleOutputManager outputManager;
private ConsolePromptManager promptManager;
/** Create the composite.
/** Create the shell.
*
* @param parent the prent composite
* @param style the composite style */
* @param parent the containing composite
* @param style the shell style */
public SWTConsole(final Composite parent, final int style) {
super(parent, style);
setLayout(new GridLayout(LAYOUT_NB_COLUMNS, false));
consoleOutput = new Text(this,
SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
consoleOutput.setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true, LAYOUT_NB_COLUMNS, 1));
consoleOutput.setRedraw(true);
lblPromptlabel = new Label(this, SWT.NONE);
lblPromptlabel.setText(prompt.apply());
consoleInput = new Text(this, SWT.BORDER);
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
consoleInput.addKeyListener(new HistoryTextKeyListener(this));
setLayout(new GridLayout(2, false));
createContents();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#checkSubclass() */
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
/** Create contents of the shell. */
private void createContents() {
final Text output = new Text(this,
SWT.WRAP | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
output.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
final Label prompt = new Label(this, SWT.NONE);
prompt.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
final Text input = new Text(this, SWT.NONE);
input.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
inputManager = new ConsoleInputManager(input);
outputManager = new ConsoleOutputManager(output);
promptManager = new ConsolePromptManager(prompt);
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#close() */
@Override
public void close() {
synchronized (promptLock) {
prompting = false;
promptLock.notifyAll();
}
if (consoleInput.isDisposed()) {
return;
}
consoleInput.setEnabled(false);
consoleOutput.setEnabled(false);
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
@Override
public String getInput() {
return consoleInput.getText();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#getPrompt() */
@Override
public StringProvider getPrompt() {
return prompt;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#interruptPrompt() */
@Override
public void interruptPrompt() {
synchronized (promptLock) {
promptLock.notifyAll();
}
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#isClosed() */
@Override
public boolean isClosed() {
return isDisposed();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#print(java.lang.String) */
@Override
public void print(final String text) throws IOException {
if (isDisposed()) {
throw new IOException();
}
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
consoleOutput.append(text);
}
}
});
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#println() */
@Override
public void println() throws IOException {
if (isDisposed()) {
throw new IOException();
}
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
consoleOutput.append(System.lineSeparator());
}
}
});
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#println(java.lang.String) */
@Override
public void println(final String message) throws IOException {
if (isDisposed()) {
throw new IOException();
}
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
consoleOutput.append(message + System.lineSeparator());
}
}
});
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#prompt() */
@Override
public String prompt() throws IOException {
synchronized (promptLock) {
initPrompt(prompt.apply());
promptLock.notifyAll();
try {
while (prompting) {
promptLock.wait();
}
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
command = null;
Thread.currentThread().interrupt();
}
}
if (isDisposed()) {
throw new IOException("Input closed"); //$NON-NLS-1$
}
return command;
}
/** Initialize the prompting.
/** Connect the console parts to the shell.
*
* @param message the prompt message
* @throws IOException if the console is disposed */
private void initPrompt(final String message) throws IOException {
if (isDisposed()) {
throw new IOException();
}
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
lblPromptlabel.setText(message);
// relayout
SWTConsole.this.layout();
consoleInput.setEnabled(true);
consoleInput.setFocus();
}
}
});
prompting = true;
command = null;
* @param input the input
* @param output the output
* @param promptStream the stream where the prompts are forwarded. */
public void connect(final PipedConsoleInput input, final PipedConsoleOutput output,
final BufferedReader promptStream) {
inputManager.setManager(input);
outputManager.setManager(output);
promptManager.setStream(promptStream);
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
@Override
public String prompt(final long timeout) throws IOException {
synchronized (promptLock) {
initPrompt(prompt.apply());
promptLock.notifyAll();
try {
waitPromptResolution(timeout);
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
command = null;
Thread.currentThread().interrupt();
}
}
return command;
/** @return the inputManager */
public ConsoleDelayIO getInputManager() {
return inputManager;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#prompt(java.lang.String) */
@Override
public String prompt(final String message) throws IOException {
synchronized (promptLock) {
initPrompt(message);
promptLock.notifyAll();
try {
while (prompting) {
promptLock.wait();
}
if (isDisposed()) {
throw new IOException();
}
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
command = null;
Thread.currentThread().interrupt();
} finally {
resetPrompt();
}
}
return command;
/** @return the outputManager */
public ConsoleOutputDisplay getOutputManager() {
return outputManager;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
@Override
public String prompt(final String message, final long timeout) throws IOException {
synchronized (promptLock) {
initPrompt(message);
promptLock.notifyAll();
try {
waitPromptResolution(timeout);
} catch (final InterruptedException e) {
LOGGER.log(Level.WARNING, ERROR_SYNCHRO_PROMPT, e);
command = null;
Thread.currentThread().interrupt();
} finally {
resetPrompt();
/** @return the promptManager */
public ConsolePromptManager getPromptManager() {
return promptManager;
}
}
return command;
}
/** Wait the prompt resolution by user.
*
* @param timeout the timeout for the wait
* @throws InterruptedException if the thread is interrupted
* @throws IOException if the console is disposed. */
private void waitPromptResolution(final long timeout)
throws InterruptedException, IOException {
final long start = System.currentTimeMillis();
long cur = start;
while (prompting && start + timeout > cur) {
promptLock.wait((cur - start - timeout) / TWO);
cur = System.currentTimeMillis();
}
if (isDisposed()) {
throw new IOException();
}
}
/** Reset the prompt message. */
private void resetPrompt() {
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
lblPromptlabel.setText(prompt.apply());
// relayout
SWTConsole.this.layout();
}
}
});
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#setFocus() */
@Override
public boolean setFocus() {
return consoleInput.setFocus();
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
@Override
public void setInput(final String input) {
consoleInput.setText(input);
consoleInput.setSelection(input.length());
}
/* (non-Javadoc)
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
@Override
public void setPrompt(final String prompt) {
setPrompt(new ConstantString(prompt));
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.ConsoleManager#setPrompt(java.lang.String) */
@Override
public void setPrompt(final StringProvider prompt) {
this.prompt = prompt;
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
if (!consoleOutput.isDisposed()) {
lblPromptlabel.setText(prompt.apply());
// relayout
SWTConsole.this.layout();
}
}
});
}
/** Set the input text.
*
* @param string the text */
public void setText(final String string) {
consoleInput.setText(string);
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
@Override
public void validateInput() {
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
consoleInput.setEnabled(false);
}
});
synchronized (promptLock) {
while (!prompting) {
try {
promptLock.wait();
} catch (final InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interruption while waiting prompt", e); //$NON-NLS-1$
Thread.currentThread().interrupt();
}
}
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
command = consoleInput.getText();
prompting = false;
consoleInput.setText(EMPTY);
consoleOutput.append(CMD_PREFIX + command + System.lineSeparator());
}
});
promptLock.notifyAll();
}
}
}

View File

@@ -1,118 +0,0 @@
/*
* GCLC swt, provide a swt window for console applications
* Copyright (C) 2015-2017 E. Bigeon
* mailto:emmanuel@bigeon.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc-swt:net.bigeon.gclc.swt.SWTConsoleShell.java
* Created on: Apr 18, 2015
*/
package net.bigeon.gclc.swt;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/** A shell containing a {@link SWTConsole}
* <p>
*
* @author Emmanuel Bigeon */
public final class SWTConsoleShell extends Shell {
/** The console component */
private SWTConsole console;
/** Create the shell.
*
* @param display the display */
public SWTConsoleShell(final Display display, final int style) {
super(display, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
createContents();
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
/** Create contents of the shell. */
private void createContents() {
console = new SWTConsole(this, SWT.NONE);
setText("Console Application"); //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Shell#dispose() */
@Override
public void dispose() {
super.dispose();
console.close();
}
/** @return the input and output. */
public SWTConsole getManager() {
return console;
}
}

View File

@@ -68,66 +68,30 @@ package net.bigeon.gclc.swt;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.ConsoleApplication;
import net.bigeon.gclc.utils.AOutputForwardRunnable;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
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}
* <p>
/** A SWT component to connect to gclc {@link ConsoleApplication}.
*
* @author Emmanuel Bigeon */
public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
/** The local implementation of the forwarding runnable
*
* @author Emmanuel Bigeon */
private final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
/** The running status */
private boolean running = true;
/** @param manager the manager */
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager) {
super(manager);
}
@Override
protected void forwardLine(final String m) {
appendConsoleOutput(System.lineSeparator() + m);
}
@Override
protected boolean isRunning() {
return running && !isDisposed();
}
/** @param running the running to set */
public void setRunning(final boolean running) {
this.running = running;
}
}
/** The class logger */
private static final Logger LOGGER = Logger
.getLogger(SWTConsoleView.class.getName());
/** The console output text field */
private final Text consoleOutput;
/** The console input text field */
private final Text consoleInput;
/** The input. */
private PipedConsoleInput input;
/** The forwarding runnable */
private ToSWTConsoleForwardRunnable forward;
public final class SWTConsoleView extends Composite {
/** The input manager. */
private final ConsoleInputManager inManager;
/** The output manager. */
private final ConsoleOutputManager outManager;
/** Create the composite.
*
@@ -138,52 +102,23 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
setLayout(new GridLayout(1, false));
consoleOutput = new Text(this,
final Text consoleOutput = new Text(this,
SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
consoleOutput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
consoleOutput.setRedraw(true);
outManager = new ConsoleOutputManager(consoleOutput);
consoleInput = new Text(this, SWT.BORDER);
final Text consoleInput = new Text(this, SWT.BORDER);
consoleInput.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
consoleInput.addKeyListener(new HistoryTextKeyListener(this));
}
/** @param next the next message */
public void appendConsoleOutput(final String next) {
Display.getDefault().syncExec(new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
public void run() {
consoleOutput.append(next);
}
});
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
@Override
public String getInput() {
return consoleInput.getText();
inManager = new ConsoleInputManager(consoleInput);
consoleInput.addKeyListener(new HistoryTextKeyListener(inManager));
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#setFocus() */
@Override
public boolean setFocus() {
return consoleInput.setFocus();
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
@Override
public void setInput(final String input) {
consoleInput.setText(input);
consoleInput.setSelection(input.length());
return inManager.getText().setFocus();
}
/** Set the input and output.
@@ -192,29 +127,21 @@ public final class SWTConsoleView extends Composite implements ConsoleDelayIO {
* @param input the input */
public void setManager(final PipedConsoleOutput manager,
final PipedConsoleInput input) {
this.input = input;
if (forward != null) {
forward.setRunning(false);
}
forward = new ToSWTConsoleForwardRunnable(manager);
final Thread th = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
th.start();
outManager.setManager(manager);
inManager.setManager(input);
}
/** @param string the text */
public void setText(final String string) {
consoleInput.setText(string);
}
/**
/** Get the manager of console input.
*
*/
@Override
public void validateInput() {
try {
input.type(getInput());
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, "Unable to input value to console", e); //$NON-NLS-1$
* @return the input manager */
public ConsoleDelayIO getInputManager() {
return inManager;
}
/** Get the manager of console output.
*
* @return the output manager */
public ConsoleOutputDisplay getOutputManager() {
return outManager;
}
}

View File

@@ -33,7 +33,9 @@
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
* Created on: Nov 19, 2016
*/
package net.bigeon.gclc.swt;
package net.bigeon.gclc.swt.api;
import java.io.IOException;
/*-
* #%L
@@ -86,6 +88,8 @@ public interface ConsoleDelayIO {
* @param input the input to set */
void setInput(String input);
/** Actually send the input as the prompt next input. */
void validateInput();
/** Actually send the input as the prompt next input.
*
* @throws IOException if an error occurred */
void validateInput() throws IOException;
}

View File

@@ -0,0 +1,50 @@
/**
*
*/
package net.bigeon.gclc.swt.api;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
/** The common interface for console display.
*
* @author Emmanuel Bigeon */
public interface ConsoleOutputDisplay {
/** Append a line to the display.
*
* @param m the line content */
void appendLine(String m);
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Emmanuel Bigeon
*
*/
package net.bigeon.gclc.swt.api;

View File

@@ -0,0 +1,98 @@
/**
*
*/
package net.bigeon.gclc.swt.io;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
/** The object managing the console input.
*
* @author Emmanuel Bigeon */
public final class ConsoleInputManager implements ConsoleDelayIO {
private final Text text;
private PipedConsoleInput input;
/** Create a managing object.
*
* @param text the text */
public ConsoleInputManager(final Text text) {
super();
this.text = text;
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#setInput(java.lang.String) */
@Override
public void setInput(final String string) {
text.setText(string);
text.setSelection(string.length());
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#getInput() */
@Override
public String getInput() {
return text.getText();
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleDelayIO#validateInput() */
@Override
public void validateInput() throws IOException {
input.type(text.getText());
}
/** Set the input to control.
*
* @param input the input */
public void setManager(final PipedConsoleInput input) {
this.input = input;
}
/** Get the text component containing the currently set input.
*
* @return the text */
public Text getText() {
return text;
}
}

View File

@@ -0,0 +1,107 @@
/**
*
*/
package net.bigeon.gclc.swt.io;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import org.eclipse.swt.widgets.Text;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
import net.bigeon.gclc.swt.tools.TextAppendingRunnable;
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
/** The manager for console output to insert in a text.
*
* @author Emmanuel Bigeon */
public final class ConsoleOutputManager implements ConsoleOutputDisplay {
/** The SWT component displaying the output content. */
private final Text text;
/** The forwarding runnable. */
private ToSWTConsoleForwardRunnable forward;
/** The forwarding thread. */
private Thread forwardThread;
/** Create the manager.
*
* @param text the text to display the output in. */
public ConsoleOutputManager(final Text text) {
super();
this.text = text;
}
/* (non-Javadoc)
* @see net.bigeon.gclc.swt.ConsoleOutputDisplay#appendLine(java.lang.String) */
@Override
public void appendLine(final String next) {
text.getDisplay().syncExec(new TextAppendingRunnable(text, next));
}
/** Set the output.
*
* @param output the output to set */
public void setManager(final PipedConsoleOutput output) {
if (forward != null) {
if (forward.getOuput() == output) {
return;
}
forward.setRunning(false);
}
if (output == null) {
forward = null;
forwardThread = null;
return;
}
forward = new ToSWTConsoleForwardRunnable(output, this, text);
forwardThread = new Thread(forward, "gclcToSWT"); //$NON-NLS-1$
forwardThread.start();
}
/** Get the current thread forwarding the console output to the SWT components.
*
* @return the forwardThread */
public Thread getForwardThread() {
return forwardThread;
}
/** @return the output consumer */
public PipedConsoleOutput getManager() {
if (forward == null) {
return null;
}
return forward.getOuput();
}
}

View File

@@ -0,0 +1,93 @@
/**
*
*/
package net.bigeon.gclc.swt.io;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.BufferedReader;
import org.eclipse.swt.widgets.Label;
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
/** The manager for the console prompt updates.
*
* @author Emmanuel Bigeon */
public final class ConsolePromptManager {
/** The label to set the prompts at. */
private final Label label;
/** The current prompt reading runnable. */
private PromptReadingRunnable promptRead;
/** Create the manager.
*
* @param label the label to update with prompts */
public ConsolePromptManager(final Label label) {
super();
this.label = label;
}
/** Set the prompt.
* <p>
* This method sets the prompt on the label as requested, without changing the
* actual prompt of the console input.
*
* @param string the text */
public void setPrompt(final String string) {
label.setText(string);
}
/** Set the input to control.
*
* @param promptStream the input */
public void setStream(final BufferedReader promptStream) {
if (promptRead != null) {
if (promptRead.getReader() == promptStream) {
return;
}
promptRead.setRunning(false);
}
if (promptStream == null) {
promptRead = null;
return;
}
promptRead = new PromptReadingRunnable(promptStream, label);
final Thread th = new Thread(promptRead, "Prompt To Label");
th.start();
}
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Emmanuel Bigeon
*
*/
package net.bigeon.gclc.swt.io;

View File

@@ -33,7 +33,11 @@
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
* Created on: Jun 9, 2016
*/
package net.bigeon.gclc.swt;
package net.bigeon.gclc.swt.tools;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*-
* #%L
@@ -72,8 +76,9 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import net.bigeon.collections.ArrayRibbon;
import net.bigeon.collections.Ribbon;
import net.bigeon.collections.ribbon.ArrayRibbon;
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
/** A key listener to validate commands and manage the history of commands.
*
@@ -84,6 +89,8 @@ public final class HistoryTextKeyListener extends KeyAdapter {
private static final int DEFAULT_HISTORY_SIZE = 10;
/** The empty string constant. */
private static final String EMPTY = ""; //$NON-NLS-1$
private static final Logger LOGGER = Logger
.getLogger(HistoryTextKeyListener.class.getName());
/** The history ribbon. */
private final Ribbon<String> commands;
/** The current index in history search. */
@@ -118,7 +125,11 @@ public final class HistoryTextKeyListener extends KeyAdapter {
if (!input.isEmpty()) {
commands.add(input);
}
try {
console.validateInput();
} catch (final IOException e) {
LOGGER.log(Level.SEVERE, "Unable to write to console", e);
}
currentIndex = -1;
}

View File

@@ -0,0 +1,134 @@
/**
*
*/
package net.bigeon.gclc.swt.tools;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.widgets.Label;
/** The runnable forwarding prompts from a buffered input to a label.
*
* @author Emmanuel Bigeon */
public class PromptReadingRunnable implements Runnable {
/** The logger for this class. */
private static final Logger LOGGER = Logger
.getLogger(PromptReadingRunnable.class.getName());
/** The reader providing the succession of prompts */
private final BufferedReader reader;
/** The label. */
private final Label view;
/** The running status. */
private boolean running = true;
/** The updating runnable implementation.
*
* @author Emmanuel Bigeon */
private static class LabelUpdater implements Runnable {
/** The label to update. */
private final Label label;
/** The text to set. */
private final String content;
/** Create the updating runnable.
*
* @param label the label
* @param content the content */
public LabelUpdater(final Label label, final String content) {
super();
this.label = label;
this.content = content;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run() */
@Override
public void run() {
label.setText(content);
}
}
/** Create the prompt flow updating runnable.
*
* @param reader the reader
* @param view the view to update on lines. */
public PromptReadingRunnable(final BufferedReader reader, final Label view) {
super();
this.reader = reader;
this.view = view;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run() */
@Override
public void run() {
String prompt;
try {
while (isRunning() && (prompt = reader.readLine()) != null) {
view.getDisplay().syncExec(new LabelUpdater(view, prompt));
}
} catch (final IOException e) {
LOGGER.log(Level.INFO, "Prompt cannot be read, or was prematuraly closed", e);
}
}
/** Get the running state.
*
* @return the running */
public synchronized boolean isRunning() {
return running;
}
/** Set the running state.
*
* @param running the running to set */
public synchronized void setRunning(final boolean running) {
this.running = running;
}
/** Get the prompt flow.
*
* @return the reader */
public BufferedReader getReader() {
return reader;
}
}

View File

@@ -0,0 +1,36 @@
/**
*
*/
package net.bigeon.gclc.swt.tools;
import org.eclipse.swt.widgets.Text;
/** A runnable appending text to the content of a {@link Text} component.
*
* @author Emmanuel Bigeon */
public class TextAppendingRunnable implements Runnable {
/** The text to append on a line (possibly new). */
private final String next;
/** The {@link Text} component. */
private final Text text;
/** Create the appending runnable.
*
* @param text the component to update
* @param next the text to append */
public TextAppendingRunnable(final Text text, final String next) {
this.text = text;
this.next = next;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run() */
@Override
public void run() {
final String initialText = text.getText();
if (initialText != null && !initialText.isEmpty()) {
text.append(System.lineSeparator());
}
text.append(next);
}
}

View File

@@ -0,0 +1,67 @@
/**
*
*/
package net.bigeon.gclc.swt.tools;
import org.eclipse.swt.widgets.Widget;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
import net.bigeon.gclc.tools.AOutputForwardRunnable;
/** The local implementation of the forwarding runnable.
*
* @author Emmanuel Bigeon */
public final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
/** The running status. */
private boolean running = true;
/** The console output. */
private final PipedConsoleOutput out;
/** The console output display. */
private final ConsoleOutputDisplay display;
/** The actual SWT component. */
private final Widget element;
/** Create the forwarding runnable.
*
* @param manager the manager
* @param display the display
* @param element the composite */
public ToSWTConsoleForwardRunnable(final PipedConsoleOutput manager,
final ConsoleOutputDisplay display,
final Widget element) {
super(manager);
out = manager;
this.display = display;
this.element = element;
}
/* (non-Javadoc)
* @see
* net.bigeon.gclc.utils.AOutputForwardRunnable#forwardLine(java.lang.String) */
@Override
protected void forwardLine(final String m) {
display.appendLine(m);
}
/* (non-Javadoc)
* @see net.bigeon.gclc.utils.AOutputForwardRunnable#isRunning() */
@Override
protected boolean isRunning() {
return running && !element.isDisposed();
}
/** Set the running status.
*
* @param running the running to set */
public void setRunning(final boolean running) {
this.running = running;
}
/** Get the output.
*
* @return the currently forwarded output */
public PipedConsoleOutput getOuput() {
return out;
}
}

View File

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

View File

@@ -0,0 +1,117 @@
/**
*
*/
package net.bigeon.gclc.swt;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;
import java.io.IOException;
import org.eclipse.swt.widgets.Text;
import org.junit.Test;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.swt.io.ConsoleInputManager;
/** @author Emmanuel Bigeon */
public class ConsoleInputManagerTest {
private final Text text = mock(Text.class);
private final ConsoleInputManager cim = new ConsoleInputManager(text);
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#setInput(java.lang.String)}. */
@Test
public void testSetText() {
cim.setInput("Text");
verify(text).setText("Text");
}
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#validateInput()}.
*
* @throws IOException if an error occurred */
@Test
public void testValidateInput() throws IOException {
// Expected calls
when(text.getText()).thenReturn("abc");
try {
cim.validateInput();
fail("No input should cause exception for input validation");
} catch (final Exception e) {
// ok
}
final PipedConsoleInput input = mock(PipedConsoleInput.class);
cim.setManager(input);
cim.validateInput();
verify(input).type("abc");
}
@Test
public void testValidateInputWithError() throws IOException {
final PipedConsoleInput input = mock(PipedConsoleInput.class);
cim.setManager(input);
// Expected calls
when(text.getText()).thenReturn("abc");
doThrow(new IOException()).when(input).type("abc");
try {
cim.validateInput();
fail("IO exception should be forwarded");
} catch (final IOException e) {
// ok
}
}
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#getText()}. */
@Test
public void testGetText() {
assertEquals("Text component should be preserved", text, cim.getText());
}
@Test
public void testGetInput() {
when(text.getText()).thenReturn("abc");
assertEquals("Text component should be preserved", "abc", cim.getInput());
}
}

View File

@@ -0,0 +1,103 @@
/**
*
*/
package net.bigeon.gclc.swt;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import java.io.IOException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
/** @author Emmanuel Bigeon */
public class ConsoleOutputManagerTest {
private final Text text = mock(Text.class);
private final ConsoleOutputManager com = new ConsoleOutputManager(text);
private final Display display = mock(Display.class);
{
when(text.getDisplay()).thenReturn(display);
doAnswer(new Answer<Object>() {
/* (non-Javadoc)
* @see
* org.mockito.stubbing.Answer#answer(org.mockito.invocation.InvocationOnMock) */
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
final Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}
}).when(display).syncExec(any(Runnable.class));
}
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsoleOutputManager#appendLine(java.lang.String)}. */
@Test
public void testAppendConsoleOutput() {
when(text.getText()).thenReturn("", "abc",
"abc" + System.lineSeparator() + "def");
com.appendLine("abc");
verify(text).append("abc");
com.appendLine("def");
verify(text).append(System.lineSeparator());
verify(text).append("def");
}
@Test
public void testSetManager() throws IOException, InterruptedException {
final PipedConsoleOutput output = mock(PipedConsoleOutput.class);
com.setManager(output);
com.setManager(output);
try (PipedConsoleOutput output2 = new PipedConsoleOutput()) {
com.setManager(output2);
output2.println("line");
final Thread forwardThread = com.getForwardThread();
forwardThread.join(500);
com.setManager(null);
forwardThread.join();
verify(text).append("line");
}
}
}

View File

@@ -0,0 +1,164 @@
/**
*
*/
package net.bigeon.gclc.swt;
import static org.mockito.ArgumentMatchers.any;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.mockito.Mockito.*;
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.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 */
public class ConsolePromptManagerTest {
private final Label label = mock(Label.class);
private final ConsolePromptManager manager = new ConsolePromptManager(label);
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setPrompt(java.lang.String)}. */
@Test
public void testSetPrompt() {
manager.setPrompt("abc");
verify(label).setText("abc");
}
/** Test method for
* {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setStream(java.io.BufferedReader)}.
*
* @throws IOException if error */
@Test
public void testSetStream() throws IOException {
// 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);
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);
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);
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);
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(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");
}
}

View File

@@ -69,9 +69,17 @@ package net.bigeon.gclc.swt;
* #L%
*/
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.junit.Test;
import org.mockito.Mockito;
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
/**
* <p>
@@ -81,10 +89,10 @@ import org.junit.Test;
public class HistoryTextKeyListenerTest {
/** Test method for
* {@link net.bigeon.gclc.swt.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
* {@link net.bigeon.gclc.swt.tools.HistoryTextKeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)}. */
@Test
public final void testKeyPressedKeyEvent() {
ConsoleDelayIO io = new ConsoleDelayIO() {
final ConsoleDelayIO io = new ConsoleDelayIO() {
private String input = "";
@Override
@@ -93,7 +101,7 @@ public class HistoryTextKeyListenerTest {
}
@Override
public void setInput(String input) {
public void setInput(final String input) {
this.input = input;
}
@@ -102,7 +110,7 @@ public class HistoryTextKeyListenerTest {
input = "";
}
};
HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
// no effects
assertEquals("", io.getInput());
@@ -139,4 +147,24 @@ public class HistoryTextKeyListenerTest {
assertEquals("cmd arg2", io.getInput());
}
@Test
public void testKeyPressedA() throws IOException {
final ConsoleDelayIO io = mock(ConsoleDelayIO.class);
final KeyEvent event = mock(KeyEvent.class);
event.keyCode = 'a';
final HistoryTextKeyListener listener = new HistoryTextKeyListener(io);
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();
}
}

View File

@@ -0,0 +1,102 @@
/**
*
*/
package net.bigeon.gclc.swt;
/*-
* #%L
* GCLC swt
* %%
* Copyright (C) 2015 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.junit.Test;
import org.mockito.Mockito;
import net.bigeon.gclc.swt.tools.PromptReadingRunnable;
/** @author Emmanuel Bigeon */
public class PromptReadingRunnableTest {
private final Label view = mock(Label.class);
private final Display display = mock(Display.class);
{
when(view.getDisplay()).thenReturn(display);
doAnswer(invocation -> {
final Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}).when(display).syncExec(any(Runnable.class));
}
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
*
* @throws IOException if an error occurred */
@Test
public void testRun() throws IOException {
final BufferedReader reader = mock(BufferedReader.class);
when(reader.readLine()).thenReturn("abc", "def", null);
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
runnable.run();
Mockito.verify(reader, Mockito.times(3)).readLine();
}
/** Test method for {@link net.bigeon.gclc.swt.tools.PromptReadingRunnable#run()}.
*
* @throws IOException if an error occurred */
@Test
public void testRunWithIO() throws IOException {
final BufferedReader reader = mock(BufferedReader.class);
when(reader.readLine()).thenThrow(new IOException());
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
final Logger logger = Logger.getLogger(PromptReadingRunnable.class.getName());
final Level back = logger.getLevel();
logger.setLevel(Level.OFF);
runnable.run();
logger.setLevel(back);
Mockito.verify(reader, Mockito.times(1)).readLine();
}
}

View File

@@ -1,37 +1,5 @@
/*
* GCLC swt, provide a swt window for console applications
* Copyright (C) 2015-2017 E. Bigeon
* mailto:emmanuel@bigeon.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc-swt:net.bigeon.gclc.swt.SWTConsoleShellTest.java
* Created on: Jun 8, 2016
*
*/
package net.bigeon.gclc.swt;
@@ -68,299 +36,44 @@ package net.bigeon.gclc.swt;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import net.bigeon.gclc.ConsoleApplication;
import net.bigeon.gclc.command.Command;
import net.bigeon.gclc.command.base.ExitCommand;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.InvalidCommandName;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
/**
* <p>
* TODO
*
* @author Emmanuel Bigeon */
@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
/** @author Emmanuel Bigeon */
public class SWTConsoleShellTest {
protected static final long TWO_SECONDS = 2000;
private static final Display DISPLAY = Display.getDefault();
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsole#SWTConsole(Composite, int)}. */
@Test
public void testGeneric() {
final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY, SWT.SHELL_TRIM);
final SWTConsole swtConsole = shell.getManager();
try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
"Hello", "See you");
appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") {
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public String tip() {
return "a long running command";
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
// TODO Auto-generated method stub
// return null;
throw new RuntimeException("Not implemented yet");
}
});
// shell.pack();
shell.open();
shell.setVisible(false);
final Thread applThread = new Thread(new Runnable() {
@Override
public void run() {
appl.start();
}
});
final Thread testThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("test"); //$NON-NLS-1$
swtConsole.validateInput();
}
});
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
shell.dispose();
}
});
}
});
applThread.start();
testThread.start();
while (!shell.isDisposed()) {
if (!DISPLAY.readAndDispatch()) {
DISPLAY.sleep();
}
}
// DISPLAY.dispose();
assertTrue(swtConsole.isClosed());
Thread.sleep(TWO_SECONDS);
assertFalse(appl.isRunning());
} catch (final InvalidCommandName e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void testSWTConsoleShell() {
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
assertNotNull("View should be initialized with managers",
console.getInputManager());
assertNotNull("View should be initialized with managers",
console.getOutputManager());
assertNotNull("View should be initialized with managers",
console.getPromptManager());
}
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsole#connect(PipedConsoleInput, PipedConsoleOutput, java.io.BufferedReader)}. */
@Test
public void testConsoleClose() {
final SWTConsoleShell shell = new SWTConsoleShell(DISPLAY, SWT.SHELL_TRIM);
final SWTConsole swtConsole = shell.getManager();
swtConsole.close();
swtConsole.setPrompt(":");
try {
final ConsoleApplication appl = new ConsoleApplication(swtConsole, swtConsole,
"Hello", "See you");
appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") {
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void testConnect() {
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
// Disconnection should work.
console.connect(null, null, null);
assertNull("Console should disconnect",
((ConsoleOutputManager) console.getOutputManager()).getManager());
}
@Override
public String tip() {
return "a long running command";
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
// TODO Auto-generated method stub
// return null;
throw new RuntimeException("Not implemented yet");
}
});
appl.add(new Command("test") {
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.
* manager.ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
try {
swtConsole.prompt("Test");
} catch (final IOException e) {
throw new CommandRunException("No input", e);
}
}
@Override
public String tip() {
return "a prompting running command";
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
// TODO Auto-generated method stub
// return null;
throw new RuntimeException("Not implemented yet");
}
});
// shell.pack();
shell.open();
shell.setVisible(false);
final Thread applThread = new Thread(new Runnable() {
@Override
public void run() {
appl.start();
}
});
final Thread testThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("test"); //$NON-NLS-1$
swtConsole.validateInput();
}
});
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("ok"); //$NON-NLS-1$
}
});
swtConsole.validateInput();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("long"); //$NON-NLS-1$
}
});
swtConsole.validateInput();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("test"); //$NON-NLS-1$
}
});
swtConsole.validateInput();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("test"); //$NON-NLS-1$
}
});
swtConsole.validateInput();
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
shell.dispose();
}
});
}
});
applThread.start();
testThread.start();
while (!shell.isDisposed()) {
if (!DISPLAY.readAndDispatch()) {
DISPLAY.sleep();
}
}
swtConsole.setPrompt(">");
try {
swtConsole.prompt();
fail("Prompting when closed should fail!");
} catch (final IOException e) {
assertNotNull(e);
}
// DISPLAY.dispose();
assertTrue(swtConsole.isClosed());
Thread.sleep(TWO_SECONDS);
assertFalse(appl.isRunning());
} catch (final InvalidCommandName e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -1,37 +1,5 @@
/*
* GCLC swt, provide a swt window for console applications
* Copyright (C) 2015-2017 E. Bigeon
* mailto:emmanuel@bigeon.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
/**
* gclc-swt:net.bigeon.gclc.swt.SWTConsoleShellTest.java
* Created on: Jun 8, 2016
*
*/
package net.bigeon.gclc.swt;
@@ -68,137 +36,47 @@ package net.bigeon.gclc.swt;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import net.bigeon.gclc.ConsoleApplication;
import net.bigeon.gclc.command.Command;
import net.bigeon.gclc.command.base.ExitCommand;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.InvalidCommandName;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
/**
* <p>
* TODO
*
* @author Emmanuel Bigeon */
@SuppressWarnings({ "javadoc", "static-method", "nls", "deprecation" })
/** @author Emmanuel Bigeon */
public class SWTConsoleViewTest {
protected static final long TWO_SECONDS = 2000;
private static final Display DISPLAY = Display.getDefault();
/** Test method for {@link net.bigeon.gclc.swt.SWTConsoleView#setFocus()}. */
@Test
public void testGeneric() {
final Shell shell = new Shell(DISPLAY);
final SWTConsoleView swtConsole = new SWTConsoleView(shell, SWT.NONE);
try (PipedConsoleOutput manager = new PipedConsoleOutput();
PipedConsoleInput input = new PipedConsoleInput(System.out)) {
swtConsole.setManager(manager, input);
} catch (final IOException e2) {
assertNull(e2);
}
try (PipedConsoleOutput manager = new PipedConsoleOutput();
PipedConsoleInput input = new PipedConsoleInput(System.out)) {
swtConsole.setManager(manager, input);
final ConsoleApplication appl = new ConsoleApplication(manager, input,
"Hello", "See you");
appl.add(new ExitCommand("exit", appl));
appl.add(new Command("long") {
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#execute(fr.bigeon.gclc.manager.
* ConsoleOutput, fr.bigeon.gclc.manager.ConsoleInput,
* java.lang.String[]) */
@Override
public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
public void testSetFocus() {
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
assertFalse("Non visible component set focus should fail", view.setFocus());
}
@Override
public String tip() {
return "a long running command";
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsoleView#SWTConsoleView(org.eclipse.swt.widgets.Composite, int)}. */
@Test
public void testSWTConsoleView() {
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
assertNotNull("View should be initialized with managers", view.getInputManager());
assertNotNull("View should be initialized with managers",
view.getOutputManager());
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.Command#usageDetail() */
@Override
protected String usageDetail() {
// TODO Auto-generated method stub
// return null;
throw new RuntimeException("Not implemented yet");
}
});
// shell.pack();
shell.open();
shell.setVisible(false);
final Thread applThread = new Thread(new Runnable() {
@Override
public void run() {
appl.start();
}
});
final Thread testThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
swtConsole.setText("test"); //$NON-NLS-1$
swtConsole.validateInput();
}
});
try {
Thread.sleep(TWO_SECONDS);
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
shell.dispose();
}
});
}
});
applThread.start();
testThread.start();
while (!shell.isDisposed()) {
if (!DISPLAY.readAndDispatch()) {
DISPLAY.sleep();
}
}
} catch (final InvalidCommandName e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/** Test method for
* {@link net.bigeon.gclc.swt.SWTConsoleView#setManager(PipedConsoleOutput, PipedConsoleInput)}. */
@Test
public void testSetManager() {
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
// Disconnection should work.
view.setManager(null, null);
assertNull("Disconnection should replace the input.",
((ConsoleOutputManager) view.getOutputManager()).getManager());
}
}

View File

@@ -0,0 +1 @@
mock-maker-inline

79
gclc-test/pom.xml Normal file
View File

@@ -0,0 +1,79 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.29</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>GCLC Tests</name>
<description>Test utilities for GCLC applications and extensions</description>
<inceptionYear>2018</inceptionYear>
<organization>
<name>Bigeon</name>
<url>https://bigeon.net</url>
</organization>
<licenses>
<license>
<distribution>manual</distribution>
<name>CeCILL 2.1</name>
<url>https://cecill.info/licences/Licence_CeCILL_V2.1-en.html</url>
</license>
</licenses>
<developers>
<developer>
<email>emmanuel@bigeon.fr</email>
<name>Emmanuel Bigeon</name>
<url>bigeon.net</url>
<roles>
<role>PM</role>
</roles>
</developer>
</developers>
<scm>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<license.licenseName>cecill_2.1</license.licenseName>
</properties>
<dependencies>
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>net.bigeon.test</groupId>
<artifactId>junitmt</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>com.github.sevntu-checkstyle</groupId>
<artifactId>dsm-maven-plugin</artifactId>
<version>2.2.0</version>
</plugin>
</plugins>
</reporting>
</project>

View File

@@ -0,0 +1,54 @@
/**
*
*/
package net.bigeon.gclc.test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.ThreadTest;
/** @author Emmanuel Bigeon */
public final class InputContract {
public void testInputContract(final Supplier<ConsoleInput> inputs)
throws IOException, InterruptedException {
// Test close contract
final ConsoleInput input = inputs.get();
assertFalse("An input should not initially be closed", input.isClosed());
input.close();
assertTrue("An input should close", input.isClosed());
input.close();
assertTrue("A closed input should stay closed", input.isClosed());
try {
input.prompt();
fail("Closed input prompting should fail");
} catch (final IOException e) {
// ok
}
// Test interruption contract
final ConsoleInput input2 = inputs.get();
final FunctionalTestRunnable prompting = new FunctionalTestRunnable(
() -> {
try {
input2.prompt();
fail("Interrupted prompt should throw INterruptedIOException");
} catch (final InterruptedIOException e) {
// ok
}
});
final Thread th = new Thread(prompting);
th.start();
th.join(200);
input2.interruptPrompt();
ThreadTest.assertRuns(th, prompting);
}
}

View File

@@ -0,0 +1,52 @@
/** 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();
}
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<version>1.8.29</version>
</parent>
<groupId>net.bigeon.gclc</groupId>
<artifactId>system</artifactId>
@@ -35,7 +35,7 @@
</developer>
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
@@ -48,7 +48,13 @@
<dependency>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.11</version>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -61,7 +67,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.0.1</version>
</plugin>
<plugin>
<groupId>com.github.sevntu-checkstyle</groupId>

View File

@@ -101,7 +101,7 @@ public class ExecSystemCommand extends Command {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
while (th.isAlive()) {
final String user = in.prompt();
// Avoid interruption being sent to process.
// Forward to process if not empty.
if (!user.isEmpty()) {
writer.write(user + EOL);
}

View File

@@ -63,6 +63,7 @@ public final class ForwardingRunnable implements Runnable {
private final ConsoleOutput out;
/** The input stream. */
private final InputStream is;
private Exception error;
/** Create the runnable.
*
@@ -78,22 +79,23 @@ public final class ForwardingRunnable implements Runnable {
@Override
public void run() {
try {
readToEnd(out, is);
is.close();
readToEnd();
} catch (final CommandRunException e) {
LOGGER.log(Level.WARNING, "Manager was closed in the meantime...", e); //$NON-NLS-1$
} catch (final IOException e) {
LOGGER.log(Level.WARNING, "Input stream was closed...", e); //$NON-NLS-1$
setError(e);
}
}
/** Read the input until its end.
* <p>
* This method actually perform a loop on the input stream to read the next
* character and then print int on the screen.
* <p>
* When the stream returns a negative value, it will exit its loop and return.
*
* @param is the input stream
* @throws CommandRunException if the manager was closed while writing the
* stream */
private static void readToEnd(final ConsoleOutput out, final InputStream is)
throws CommandRunException {
private void readToEnd() throws CommandRunException {
int c;
try {
while ((c = is.read()) >= 0) {
@@ -102,6 +104,7 @@ public final class ForwardingRunnable implements Runnable {
}
} catch (final IOException e) {
LOGGER.log(Level.INFO, "input stream reading failed", e); //$NON-NLS-1$
setError(e);
}
}
@@ -141,4 +144,22 @@ public final class ForwardingRunnable implements Runnable {
public static Thread connect(final InputStream stream, final ConsoleOutput output) {
return connect(stream, output, "Forwarding");
}
/** Get the error in this runnable execution if any.
* <p>
* In the current implementation, this error can be an {@link IOException} if
* the input stream failed or a {@link CommandRunException} if the output was
* closed.
*
* @return the error */
public synchronized Exception getError() {
return error;
}
/** Set the error that caused this runnable to stop executing.
*
* @param error the error to set */
private synchronized void setError(final Exception error) {
this.error = error;
}
}

View File

@@ -42,8 +42,8 @@ import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.EmptyInput;
import net.bigeon.gclc.utils.SinkOutput;
import net.bigeon.gclc.manager.EmptyInput;
import net.bigeon.gclc.manager.SinkOutput;
public class ExecSystemCommandTest {
@@ -59,7 +59,7 @@ public class ExecSystemCommandTest {
/** Test the execution of the command.
*
* @throws CommandRunException */
* @throws CommandRunException if the command fails */
@Test
public void testExecute() throws CommandRunException {
final ConsoleOutput out = SinkOutput.INSTANCE;
@@ -79,4 +79,26 @@ 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
}
}
}

View File

@@ -0,0 +1,44 @@
/**
*
*/
package net.bigeon.gclc.system;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Test;
import org.mockito.Mockito;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.manager.SinkOutput;
import net.bigeon.gclc.manager.StreamConsoleOutput;
/** @author Emmanuel Bigeon */
public class ForwardingRunnableTest {
public void testClosedOutput() {
final StreamConsoleOutput out = new StreamConsoleOutput();
out.close();
final InputStream is = new ByteArrayInputStream(new byte[] { 1, 2, 3 });
final ForwardingRunnable runnable = new ForwardingRunnable(out, is);
// Runnable should close immediatly.
runnable.run();
assertTrue("Error should be a CommandRunException",
runnable.getError() instanceof CommandRunException);
}
@Test
public void testIOInInput() throws IOException {
final InputStream is = Mockito.mock(InputStream.class);
Mockito.when(is.read()).thenThrow(new IOException());
final ForwardingRunnable runnable = new ForwardingRunnable(SinkOutput.INSTANCE,
is);
// Runnable should close immediatly.
runnable.run();
assertTrue("Error should be an IO", runnable.getError() instanceof IOException);
}
}

View File

@@ -3,12 +3,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.bigeon.config</groupId>
<artifactId>ebigeon-config</artifactId>
<version>1.8.21</version>
<artifactId>ebigeon-public-conf</artifactId>
<version>1.0.12</version>
</parent>
<groupId>net.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>2.0.12-SNAPSHOT</version>
<version>2.1.6-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Generic Command Ligne console</name>
<description>A generic framework for console applications, with customized command input and output streams.</description>
@@ -36,7 +36,7 @@
</developer>
</developers>
<scm>
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
<developerConnection>scm:git:gitea@git.code.bigeon.net:emmanuel/gclc-core.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
@@ -49,7 +49,7 @@
<dependency>
<groupId>net.bigeon.test</groupId>
<artifactId>junitmt</artifactId>
<version>1.0.0</version>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -95,8 +95,8 @@ import net.bigeon.gclc.manager.ConsoleOutput;
* A typical use case is the following:
*
* <pre>
* {@link ConsoleOutput} out = new {@link net.bigeon.gclc.utils.StreamConsoleOutput StreamConsoleOutput}();
* {@link ConsoleInput} in = new {@link net.bigeon.gclc.utils.StreamConsoleInput StreamConsoleInput}();
* {@link ConsoleOutput} out = new {@link net.bigeon.gclc.manager.StreamConsoleOutput StreamConsoleOutput}();
* {@link ConsoleInput} in = new {@link net.bigeon.gclc.manager.StreamConsoleInput StreamConsoleInput}();
* {@link ConsoleApplication} app = new {@link ConsoleApplication}(out, in, "welcome", "see you latter")};
* app.{@link ConsoleApplication#add(ICommand) add}("my_command", new {@link ICommand MyCommand()});
* app.{@link ConsoleApplication#start() start()};
@@ -191,7 +191,7 @@ public final class ConsoleApplication implements ICommandProvider {
args = GCLCConstants.splitCommand(cmd);
} catch (final CommandParsingException e) {
out.println("Command line cannot be parsed"); //$NON-NLS-1$
LOGGER.log(Level.FINE, "Invalid user command " + cmd, e); //$NON-NLS-1$
LOGGER.log(Level.FINE, e, () -> "Invalid user command " + cmd); //$NON-NLS-1$
return;
}
if (!args.isEmpty()) {
@@ -199,7 +199,7 @@ public final class ConsoleApplication implements ICommandProvider {
executeSub(out, in, args.get(0),
Arrays.copyOfRange(args.toArray(new String[0]), 1, args.size()));
} catch (final CommandRunException e) {
LOGGER.log(Level.FINE, "Command failed: " + cmd, e); //$NON-NLS-1$
LOGGER.log(Level.FINE, e, () -> "Command failed: " + cmd); //$NON-NLS-1$
out.println(Messages.getString("ConsoleApplication.cmd.failed", cmd)); //$NON-NLS-1$
out.println(e.getLocalizedMessage());
if (e.getType() == CommandRunExceptionType.USAGE) {

View File

@@ -146,10 +146,7 @@ public final class GCLCConstants {
continue;
}
if (c == ' ' && !inString) {
final String arg = cmd.substring(startIndex, index - 1);
if (!arg.isEmpty()) {
args.add(removeEscaped(arg));
}
addArgument(args, cmd.substring(startIndex, index - 1));
startIndex = index;
} else if (c == '"') {
if (inString) {
@@ -164,9 +161,18 @@ public final class GCLCConstants {
}
if (startIndex < cmd.length()) {
final String arg = cmd.substring(startIndex, cmd.length());
args.add(arg);
args.add(removeEscaped(arg));
}
return args;
}
/** 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));
}
}
}

View File

@@ -73,8 +73,11 @@ public abstract class Command implements ICommand {
/** Create the command.
*
* @param name the command name */
public Command(final String name) {
protected Command(final String name) {
super();
if (name == null) {
throw new IllegalArgumentException("The command name is mandatory");
}
this.name = name;
}

View File

@@ -103,7 +103,7 @@ public final class CommandParameters {
* @param key the key
* @return if the key was specified */
public boolean isActive(final String key) {
Boolean val = booleanArguments.get(key);
final Boolean val = booleanArguments.get(key);
return val != null && val.booleanValue();
}
@@ -198,9 +198,8 @@ public final class CommandParameters {
* @param string the key
* @param value the value */
public void set(final String string, final boolean value) {
if (booleanArguments.containsKey(string)) {
booleanArguments.put(string, Boolean.valueOf(value));
}
booleanArguments.computeIfPresent(string,
(final String k, final Boolean v) -> Boolean.valueOf(value));
}
/** Set a string parameter value.
@@ -208,6 +207,9 @@ public final class CommandParameters {
* @param string the key
* @param value the 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)) {
stringArguments.put(string, value);
}

View File

@@ -94,7 +94,7 @@ public abstract class ParametrizedCommand extends Command {
* parameters.
*
* @param name the name */
public ParametrizedCommand(final String name) {
protected ParametrizedCommand(final String name) {
this(name, true);
}
@@ -106,7 +106,7 @@ public abstract class ParametrizedCommand extends Command {
*
* @param name the name
* @param strict if the arguments are restricted to the declared ones */
public ParametrizedCommand(final String name, final boolean strict) {
protected ParametrizedCommand(final String name, final boolean strict) {
super(name);
data = new ParametrizedCommandData(strict);
}
@@ -116,8 +116,7 @@ public abstract class ParametrizedCommand extends Command {
* @param flag the boolean flag
* @throws InvalidParameterException if the parameter is already defined as a
* string parameter */
protected final void addBooleanParameter(final String flag)
throws InvalidParameterException {
protected final void addBooleanParameter(final String flag) {
data.addBooleanParameter(flag);
}
@@ -127,8 +126,7 @@ public abstract class ParametrizedCommand extends Command {
* @param needed if the parameter's absence should cause an exception
* @throws InvalidParameterException if the parameter is already defined as a
* boolean parameter */
protected final void addStringParameter(final String flag, final boolean needed)
throws InvalidParameterException {
protected final void addStringParameter(final String flag, final boolean needed) {
data.addStringParameter(flag, needed);
}

View File

@@ -85,7 +85,7 @@ import java.util.concurrent.ConcurrentHashMap;
import net.bigeon.gclc.exception.CommandParsingException;
import net.bigeon.gclc.exception.InvalidParameterException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.utils.EmptyInput;
import net.bigeon.gclc.manager.EmptyInput;
/** An object to handle standardized command parameters.
*
@@ -120,7 +120,7 @@ public final class ParametrizedCommandData {
* @param flag the boolean flag
* @throws InvalidParameterException if the parameter is already defined as a
* string parameter */
public void addBooleanParameter(final String flag) throws InvalidParameterException {
public void addBooleanParameter(final String flag) {
if (params.containsKey(flag) && stringParams.containsKey(flag)) {
throw new InvalidParameterException("Parameter is already defined as string"); //$NON-NLS-1$
}
@@ -134,8 +134,7 @@ public final class ParametrizedCommandData {
* @param needed if the parameter's absence should cause an exception
* @throws InvalidParameterException if the parameter is already defined as a
* boolean parameter */
public void addStringParameter(final String flag, final boolean needed)
throws InvalidParameterException {
public void addStringParameter(final String flag, final boolean needed) {
if (params.containsKey(flag)) {
checkParam(flag, needed);
return;
@@ -149,16 +148,17 @@ public final class ParametrizedCommandData {
* @param param the string parameter
* @param needed if the parameter is needed
* @throws InvalidParameterException if the new definition is invalid */
private void checkParam(final String param, final boolean needed)
throws InvalidParameterException {
Boolean val = stringParams.get(param);
if (val != null) {
final Boolean need = Boolean.valueOf(needed || val.booleanValue());
stringParams.put(param, need);
private void checkParam(final String param, final boolean needed) {
final Boolean val = stringParams.computeIfPresent(param,
(final String k, final Boolean v) -> {
final Boolean need = Boolean.valueOf(needed || v.booleanValue());
params.put(param, need);
return;
return need;
});
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).
@@ -217,7 +217,7 @@ public final class ParametrizedCommandData {
* @param param the parameter name
* @return if the parameter is needed */
public boolean isNeeded(final String param) {
Boolean val = params.get(param);
final Boolean val = params.get(param);
return val != null && val.booleanValue();
}

View File

@@ -34,6 +34,39 @@
*/
package net.bigeon.gclc.command.base;
/*-
* #%L
* Generic Command Ligne console
* %%
* Copyright (C) 2014 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;

View File

@@ -139,7 +139,7 @@ public final class ScriptExecution extends Command {
try (InputStreamReader fReader = new InputStreamReader(
Files.newInputStream(Paths.get(scriptFile)), charset);
BufferedReader reader = new BufferedReader(fReader)) {
String[] emptyArray = new String[0];
final String[] emptyArray = new String[0];
while ((cmd = reader.readLine()) != null) {
lineNo++;
final String cmdLine = readCommandLine(cmd, params);
@@ -237,10 +237,16 @@ public final class ScriptExecution extends Command {
* @return the exception to actually throw */
private static CommandRunException manageRunException(final CommandRunException e,
final int lineNo) {
final StringBuilder builder = new StringBuilder(e.getLocalizedMessage());
int index = builder.indexOf("\n");
while (index > 0) {
builder.insert(index + 1, " ");
index = builder.indexOf("\n", index + 1);
}
return new CommandRunException(CommandRunExceptionType.EXECUTION,
MessageFormat.format(
"The script could not complete due to command failure at line {0} ({1})", //$NON-NLS-1$
Integer.valueOf(lineNo), e.getLocalizedMessage()),
"The script could not complete due to command failure at line {0}\n {1})", //$NON-NLS-1$
Integer.valueOf(lineNo + 1), builder),
e);
}

View File

@@ -74,7 +74,7 @@ package net.bigeon.gclc.exception;
/** An exception raised during command parsing.
*
* @author Emmanuel Bigeon */
public class CommandParsingException extends Exception {
public final class CommandParsingException extends Exception {
/** svuid. */
private static final long serialVersionUID = 1L;

View File

@@ -75,7 +75,7 @@ package net.bigeon.gclc.exception;
* the command is already used.
*
* @author Emmanuel BIGEON */
public class InvalidCommandName extends Exception {
public final class InvalidCommandName extends Exception {
/** the SVUID. */
private static final long serialVersionUID = 1L;

View File

@@ -75,7 +75,7 @@ package net.bigeon.gclc.exception;
* parameter definition.
*
* @author Emmanuel Bigeon */
public class InvalidParameterException extends Exception {
public final class InvalidParameterException extends RuntimeException {
/** the SVUID. */
private static final long serialVersionUID = 1L;

View File

@@ -105,8 +105,8 @@ public final class Messages {
try {
return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
} catch (final MissingResourceException e) {
LOGGER.log(Level.WARNING,
"Unrecognized internationalization message key: " + key, e); //$NON-NLS-1$
LOGGER.log(Level.WARNING, e,
() -> "Unrecognized internationalization message key: " + key); //$NON-NLS-1$
return '!' + key + '!';
}
}

View File

@@ -72,9 +72,7 @@ package net.bigeon.gclc.manager;
* #L%
*/
import java.io.IOException;
import java.io.InterruptedIOException;
import net.bigeon.gclc.tools.StringProvider;
import java.util.function.Supplier;
/** A console application input.
*
@@ -90,13 +88,12 @@ public interface ConsoleInput extends AutoCloseable {
/** Get the prompt string.
*
* @return the prompt prefix */
StringProvider getPrompt();
Supplier<String> getPrompt();
/** Indicate to the input that is should interrompt the prompting, if possible.
* <p>
* The pending {@link #prompt()} or {@link #prompt(String)} operations should
* return immediatly. However the returned value can be anything (from the
* partial prompt content to an empty string or even a null pointer). */
* return immediately by throwing an java.io.InterruptedIOException. */
void interruptPrompt();
/** Test if the input is closed.
@@ -111,7 +108,7 @@ public interface ConsoleInput extends AutoCloseable {
*
* @return the user inputed string
* @throws IOException if the manager is closed or could not read the prompt
* @throws InterruptedIOException if the prompt was interrupted */
* @throws java.io.InterruptedIOException if the prompt was interrupted */
String prompt() throws IOException;
/** Prompt the user, with an allotated time to answer.
@@ -119,7 +116,7 @@ public interface ConsoleInput extends AutoCloseable {
* @param timeout the time to wait in milliseconds
* @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 InterruptedIOException if the prompt was interrupted */
* @throws java.io.InterruptedIOException if the prompt was interrupted */
String prompt(long timeout) throws IOException;
/** Prompt the user, with a hint on what is prompted.
@@ -127,7 +124,7 @@ public interface ConsoleInput extends AutoCloseable {
* @param message the message to prompt the user
* @return the user inputed string
* @throws IOException if the manager is closed or could not read the prompt
* @throws InterruptedIOException if the prompt was interrupted */
* @throws java.io.InterruptedIOException if the prompt was interrupted */
String prompt(String message) throws IOException;
/** Prompt the user, with a hint on what is prompted and an allotated time to
@@ -137,7 +134,7 @@ public interface ConsoleInput extends AutoCloseable {
* @param message the message to prompt the user
* @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 InterruptedIOException if the prompt was interrupted */
* @throws java.io.InterruptedIOException if the prompt was interrupted */
String prompt(String message, long timeout) throws IOException;
/** Set a prompting prefix.
@@ -148,5 +145,5 @@ public interface ConsoleInput extends AutoCloseable {
/** Set the prompting string.
*
* @param string the prompt string */
void setPrompt(StringProvider string);
void setPrompt(Supplier<String> string);
}

View File

@@ -36,53 +36,16 @@
* gclc:net.bigeon.gclc.manager.EmptyInput.java
* Created on: Nov 13, 2017
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.manager;
import net.bigeon.gclc.manager.ConsoleInput;
/*-
* #%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;
import net.bigeon.gclc.tools.StringProvider;
import java.util.function.Supplier;
/** A console input that return empty to all prompting.
*
* @author Emmanuel Bigeon */
public final class EmptyInput implements ConsoleInput {
private static final ConstantString CONSTANT_STRING = new ConstantString("");
private static final Supplier<String> CONSTANT_STRING = () -> "";
/** The empty prompter. */
public static final ConsoleInput INSTANCE = new EmptyInput();
@@ -101,8 +64,8 @@ public final class EmptyInput implements ConsoleInput {
/* (non-Javadoc)
* @see net.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@Override
public StringProvider getPrompt() {
return CONSTANT_STRING; //$NON-NLS-1$
public Supplier<String> getPrompt() {
return CONSTANT_STRING;
}
/* (non-Javadoc)
@@ -155,7 +118,7 @@ public final class EmptyInput implements ConsoleInput {
}
@Override
public void setPrompt(StringProvider string) {
public void setPrompt(final Supplier<String> string) {
//
}
}

View File

@@ -36,7 +36,7 @@
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
* Created on: Nov 18, 2016
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.manager;
/*-
* #%L
@@ -76,9 +76,9 @@ import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.tools.StringProvider;
import net.bigeon.gclc.utils.WritingRunnable;
/** This console input allows to enter commands and retrieve the output as an
* input.
@@ -120,7 +120,7 @@ public final class PipedConsoleInput implements ConsoleInput {
}
@Override
public StringProvider getPrompt() {
public Supplier<String> getPrompt() {
return innerManager.getPrompt();
}
@@ -174,7 +174,7 @@ public final class PipedConsoleInput implements ConsoleInput {
}
@Override
public void setPrompt(StringProvider string) {
public void setPrompt(final Supplier<String> string) {
innerManager.setPrompt(string);
}

View File

@@ -36,7 +36,7 @@
* gclc-test:net.bigeon.gclc.test.TestConsoleManager.java
* Created on: Nov 18, 2016
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.manager;
/*-
* #%L
@@ -79,7 +79,7 @@ import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.ReadingRunnable;
/** This console output allows to retrieve the output as an input.
* <p>
@@ -101,13 +101,14 @@ public final class PipedConsoleOutput implements ConsoleOutput {
private final PrintStream outPrint;
/** The reading thread. */
private final ReadingRunnable reading;
private final PipedOutputStream out;
/** Create a manager that will write and read through piped stream.
*
* @throws IOException if the piping failed for streams */
public PipedConsoleOutput() throws IOException {
commandOutput = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(commandOutput);
out = new PipedOutputStream(commandOutput);
commandBuffOutput = new BufferedReader(
new InputStreamReader(commandOutput, StandardCharsets.UTF_8));
outPrint = new PrintStream(out, true, UTF_8);
@@ -133,6 +134,7 @@ public final class PipedConsoleOutput implements ConsoleOutput {
reading.setRunning(false);
innerManager.close();
outPrint.close();
out.close();
commandBuffOutput.close();
commandOutput.close();
}

View File

@@ -36,9 +36,7 @@
* gclc:net.bigeon.gclc.manager.SinkOutput.java
* Created on: Nov 13, 2017
*/
package net.bigeon.gclc.utils;
import net.bigeon.gclc.manager.ConsoleOutput;
package net.bigeon.gclc.manager;
/*-
* #%L

View File

@@ -36,7 +36,7 @@
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
* Created on: Dec 19, 2014
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.manager;
/*-
* #%L
@@ -77,10 +77,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.util.function.Supplier;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.tools.ConstantString;
import net.bigeon.gclc.tools.StringProvider;
import net.bigeon.gclc.utils.ReadingRunnable;
/** A console using the input stream and print stream.
* <p>
@@ -90,10 +89,10 @@ import net.bigeon.gclc.tools.StringProvider;
public final class StreamConsoleInput implements ConsoleInput {
/** The default prompt. */
public static final StringProvider DEFAULT_PROMPT = new ConstantString("> "); //$NON-NLS-1$
public static final Supplier<String> DEFAULT_PROMPT = () -> ("> "); //$NON-NLS-1$
/** The command prompt. It can be changed. */
private StringProvider prompt = DEFAULT_PROMPT;
private Supplier<String> prompt = DEFAULT_PROMPT;
/** The print stream. */
private final PrintStream out;
@@ -152,7 +151,7 @@ public final class StreamConsoleInput implements ConsoleInput {
/* (non-Javadoc)
* @see net.bigeon.gclc.manager.ConsoleInput#getPrompt() */
@Override
public StringProvider getPrompt() {
public Supplier<String> getPrompt() {
return prompt;
}
@@ -175,14 +174,14 @@ public final class StreamConsoleInput implements ConsoleInput {
* @see net.bigeon.gclc.ConsoleManager#prompt() */
@Override
public String prompt() throws IOException {
return prompt(prompt.apply());
return prompt(prompt.get());
}
/* (non-Javadoc)
* @see net.bigeon.gclc.manager.ConsoleManager#prompt(long) */
@Override
public String prompt(final long timeout) throws IOException {
return prompt(prompt.apply(), timeout);
return prompt(prompt.get(), timeout);
}
/* (non-Javadoc)
@@ -213,11 +212,11 @@ public final class StreamConsoleInput implements ConsoleInput {
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
@Override
public void setPrompt(final String prompt) {
this.prompt = new ConstantString(prompt);
this.prompt = () -> (prompt);
}
@Override
public void setPrompt(StringProvider string) {
public void setPrompt(final Supplier<String> string) {
prompt = string;
}
}

View File

@@ -36,7 +36,7 @@
* gclc:net.bigeon.gclc.system.SystemConsoleManager.java
* Created on: Dec 19, 2014
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.manager;
/*-
* #%L
@@ -74,8 +74,6 @@ package net.bigeon.gclc.utils;
import java.io.IOException;
import java.io.PrintStream;
import net.bigeon.gclc.manager.ConsoleOutput;
/** A console using the input stream and print stream.
* <p>
* The default constructor will use the system standart input and output.

View File

@@ -36,7 +36,7 @@
* gclc:net.bigeon.gclc.tools.AOutputForwardRunnable.java
* Created on: Dec 1, 2016
*/
package net.bigeon.gclc.utils;
package net.bigeon.gclc.tools;
/*-
* #%L
@@ -75,6 +75,8 @@ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** An incomplete implematation used to forward messages from a piped console.
* <p>
* This forwarding can be interrupted without closing the piped manager.
@@ -88,14 +90,14 @@ public abstract class AOutputForwardRunnable implements Runnable {
/** The default timeout (one tenth of second). */
private static final long DEFAULT_TIMEOUT = 100;
/** The manager. */
private final PipedConsoleOutput manager;
protected final PipedConsoleOutput manager;
/** The timeout. */
private final long timeout;
protected final long timeout;
/** Create a forwarding runnable.
*
* @param manager the manager */
public AOutputForwardRunnable(final PipedConsoleOutput manager) {
protected AOutputForwardRunnable(final PipedConsoleOutput manager) {
super();
this.manager = manager;
timeout = DEFAULT_TIMEOUT;
@@ -114,7 +116,8 @@ public abstract class AOutputForwardRunnable implements Runnable {
*
* @param manager the manager
* @param timeout the timeout between message requests. */
public AOutputForwardRunnable(final PipedConsoleOutput manager, final long timeout) {
protected AOutputForwardRunnable(final PipedConsoleOutput manager,
final long timeout) {
super();
this.manager = manager;
this.timeout = timeout;
@@ -154,8 +157,11 @@ public abstract class AOutputForwardRunnable implements Runnable {
/** a method to wait some time. */
protected final void waitASec() {
try {
final long tic = System.currentTimeMillis();
synchronized (this) {
wait(timeout);
while (System.currentTimeMillis() - tic < timeout) {
wait(timeout + tic - System.currentTimeMillis());
}
}
} catch (final InterruptedException e) {
LOGGER.log(Level.SEVERE, "Interrupted wait", //$NON-NLS-1$

View File

@@ -34,6 +34,9 @@
*/
package net.bigeon.gclc.tools;
import java.util.Objects;
import java.util.function.Supplier;
/*-
* #%L
* Generic Command Ligne console
@@ -68,10 +71,12 @@ package net.bigeon.gclc.tools;
* #L%
*/
/** A {@link StringProvider} that hold a constant string.
/** A supplier of string that hold a constant string.
*
* @author Emmanuel Bigeon */
public class ConstantString implements StringProvider {
* @author Emmanuel Bigeon
* @deprecated since 2.1.2, use a lambda expression instead */
@Deprecated
public class ConstantString implements Supplier<String> {
private final String string;
/** Create a provider for a string.
@@ -81,10 +86,8 @@ public class ConstantString implements StringProvider {
this.string = string;
}
/* (non-Javadoc)
* @see net.bigeon.gclc.tools.StringProvider#apply() */
@Override
public String apply() {
public String get() {
return string;
}
@@ -92,10 +95,7 @@ public class ConstantString implements StringProvider {
* @see java.lang.Object#hashCode() */
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((string == null) ? 0 : string.hashCode());
return result;
return Objects.hash(string);
}
/* (non-Javadoc)
@@ -112,13 +112,6 @@ public class ConstantString implements StringProvider {
return false;
}
final ConstantString other = (ConstantString) obj;
if (string == null) {
if (other.string != null) {
return false;
}
} else if (!string.equals(other.string)) {
return false;
}
return true;
return Objects.equals(string, other.string);
}
}

View File

@@ -1,83 +0,0 @@
/*
* Copyright Bigeon Emmanuel (2014)
*
* emmanuel@bigeon.fr
*
* This software is a computer program whose purpose is to
* provide a generic framework for console applications.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package net.bigeon.gclc.tools;
/*-
* #%L
* Generic Command Ligne console
* %%
* Copyright (C) 2014 - 2018 bigeon.fr
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
/** A string providing object.
* <p>
* Implementations of this interface will provide a string, this internal state
* of the object may be so that successive calls to the apply method return
* different results.
*
* @author Emmanuel */
public interface StringProvider {
/** Provide a string.
*
* @return the string */
String apply();
}

View File

@@ -111,6 +111,7 @@ public final class ReadingRunnable implements Runnable {
private final Map<String, Object> messageBlocker = new ConcurrentHashMap<>();
/** The lock. */
private final Object messageBlockerLock = new Object();
private boolean interrupting = false;
/** Create a reading runnable.
*
* @param reader the input to read from */
@@ -127,9 +128,12 @@ public final class ReadingRunnable implements Runnable {
* @throws IOException if the runnable was stopped and no essage was found. */
private void doWaitMessage(final long timeout) throws IOException {
try {
final long tic = System.currentTimeMillis();
synchronized (lock) {
while (System.currentTimeMillis() - tic < timeout && messages.isEmpty()) {
lock.wait(timeout);
}
}
} catch (final InterruptedException e) {
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION, e);
Thread.currentThread().interrupt();
@@ -145,6 +149,9 @@ public final class ReadingRunnable implements Runnable {
* @throws IOException if the pipe is closed */
public String getMessage() throws IOException {
synchronized (lock) {
if (!messages.isEmpty()) {
return pollMessage();
}
if (!running) {
throw new IOException(CLOSED_PIPE);
}
@@ -152,8 +159,7 @@ public final class ReadingRunnable implements Runnable {
waitMessage(TIMEOUT);
LOGGER.log(Level.FINEST, "Polled: {0}", messages.peek()); //$NON-NLS-1$
waiting = false;
notifyMessage(messages.peek());
return messages.poll();
return pollMessage();
}
}
@@ -164,6 +170,9 @@ public final class ReadingRunnable implements Runnable {
* @throws IOException if the input was closed */
public String getNextMessage(final long timeout) throws IOException {
synchronized (lock) {
if (!messages.isEmpty()) {
return pollMessage();
}
if (!running) {
throw new IOException(CLOSED_PIPE);
}
@@ -173,22 +182,35 @@ public final class ReadingRunnable implements Runnable {
if (messages.isEmpty()) {
return null;
}
return messages.poll();
return pollMessage();
}
}
private String pollMessage() throws InterruptedIOException {
final String msg = messages.poll();
if (msg.isEmpty() && interrupting) {
throw new InterruptedIOException();
}
notifyMessage(msg);
return msg;
}
/** Wait for a message to be delivered.
*
* @param message the message
* @throws InterruptedException if the wait was interrupted */
public void waitForDelivery(final String message) throws InterruptedException {
Object mLock;
synchronized (messageBlockerLock) {
if (!messageBlocker.containsKey(message)) {
messageBlocker.put(message, new Object());
}
messageBlocker.computeIfAbsent(message, (final String k) -> new Object());
mLock = messageBlocker.get(message);
}
synchronized (mLock) {
while (messageBlocker.containsKey(message)) {
mLock.wait();
}
}
}
/** Test if some data is available.
*
@@ -208,7 +230,8 @@ public final class ReadingRunnable implements Runnable {
public void interrupt() {
synchronized (lock) {
if (waiting) {
messages.offer(""); //$NON-NLS-1$
messages.offer("");
interrupting = true;
lock.notifyAll();
}
}
@@ -231,9 +254,9 @@ public final class ReadingRunnable implements Runnable {
final Object mLock = messageBlocker.get(message);
if (mLock!=null) {
synchronized (mLock) {
messageBlocker.remove(message);
mLock.notifyAll();
}
messageBlocker.remove(message);
}
}
}

View File

@@ -75,8 +75,8 @@ import java.io.IOException;
import net.bigeon.gclc.command.ICommand;
import net.bigeon.gclc.exception.InvalidCommandName;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -71,11 +71,7 @@ package net.bigeon.gclc;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
@@ -95,8 +91,8 @@ import net.bigeon.gclc.exception.InvalidCommandName;
import net.bigeon.gclc.i18n.Messages;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/** Test class for ConsoleApplication
*

View File

@@ -72,7 +72,6 @@ package net.bigeon.gclc;
* #L%
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.List;
@@ -87,52 +86,77 @@ import net.bigeon.gclc.exception.CommandParsingException;
@SuppressWarnings({ "nls", "static-method" })
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
* {@link net.bigeon.gclc.GCLCConstants#splitCommand(java.lang.String)}.
*
* @throws CommandParsingException if an error occured */
@Test
public void testSplitCommand() throws CommandParsingException {
public void testSplitCommandMultiSpaces() throws CommandParsingException {
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("Command 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));
}
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");
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("with"));
assertTrue("Elements should be preserved", res.get(2).equals("some"));
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");
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 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"));
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));
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"));
assertTrue("Elements should be preserved", res.get(2).equals("some arguments"));
assertEquals("Command should be preserved", "aCommand", res.get(0));
assertEquals("Command should be preserved", "with", res.get(1));
assertEquals("Command should be preserved", "some arguments", res.get(2));
}
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 {
// Wrong lines?
res = GCLCConstants.splitCommand("aCommand with \"some ar\"guments");

View File

@@ -71,11 +71,7 @@ package net.bigeon.gclc.command;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.util.HashSet;
import java.util.Set;

View File

@@ -82,7 +82,7 @@ import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -83,7 +83,7 @@ import net.bigeon.gclc.command.base.MockCommand;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -1,6 +1,39 @@
package net.bigeon.gclc.command;
import static org.junit.Assert.*;
/*-
* #%L
* Generic Command Ligne console
* %%
* Copyright (C) 2014 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.junit.Assert.fail;
import org.junit.Test;

View File

@@ -71,11 +71,7 @@ package net.bigeon.gclc.command;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
@@ -91,10 +87,12 @@ import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.InvalidParameterException;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.test.junitmt.ATestRunnable;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.ThreadTest;
import net.bigeon.test.junitmt.api.ATestRunnable;
import net.bigeon.test.junitmt.api.TestFunction;
/**
* <p>
@@ -511,11 +509,7 @@ public class ParametrizedCommandTest {
cmd.execute(out, in, "-" + str1, str2, "-" + addParam);
cmd.execute(out, in, "-" + str1, str2, "-" + addParam, addParam);
final ATestRunnable testConsole = new ATestRunnable() {
@Override
protected void testRun() {
try {
final TestFunction function = () -> {
assertEquals("value of " + str1 + "? ", buf.readLine());
in.type("");
assertEquals("value of " + str1 + "? (cannot be empty) ",
@@ -524,11 +518,9 @@ public class ParametrizedCommandTest {
assertEquals("value of " + str1 + "? (cannot be empty) ",
buf.readLine());
in.type(str2);
} catch (final IOException e) {
fail("IO exception in test");
}
}
};
final FunctionalTestRunnable testConsole = new FunctionalTestRunnable(
function);
final Thread th = new Thread(testConsole);
th.start();
@@ -544,18 +536,11 @@ public class ParametrizedCommandTest {
new InputStreamReader(pis, StandardCharsets.UTF_8));
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
final ATestRunnable testConsole = new ATestRunnable() {
@Override
protected void testRun() {
try {
final TestFunction function = () -> {
assertEquals("value of " + str1 + "? ", buf.readLine());
in.type(str2);
} catch (final IOException e) {
fail("IO exception in test");
}
}
};
final ATestRunnable testConsole = new FunctionalTestRunnable(function);
final Thread th = new Thread(testConsole);
th.start();
@@ -569,7 +554,6 @@ public class ParametrizedCommandTest {
final PipedConsoleInput test = new PipedConsoleInput(null);
test.close();
out.close();
cmd.execute(out, test, "-" + str1, str2);
cmd.execute(out, test, "-" + addParam);
fail("Closed manager shall cause error");
} catch (final CommandRunException e) {

View File

@@ -85,8 +85,8 @@ import net.bigeon.gclc.ConsoleTestApplication;
import net.bigeon.gclc.command.base.ScriptExecution;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.CommandRunExceptionType;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -71,10 +71,7 @@ package net.bigeon.gclc.command;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.io.IOException;
@@ -85,7 +82,7 @@ import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.exception.InvalidCommandName;
import net.bigeon.gclc.manager.ConsoleInput;
import net.bigeon.gclc.manager.ConsoleOutput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>

View File

@@ -1,5 +1,39 @@
package net.bigeon.gclc.command.base;
/*-
* #%L
* Generic Command Ligne console
* %%
* Copyright (C) 2014 - 2018 Bigeon
* %%
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -9,7 +43,7 @@ import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
public class EchoCommandTest {

View File

@@ -38,6 +38,7 @@
*/
package net.bigeon.gclc.manager;
import static org.junit.Assert.assertEquals;
/*-
* #%L
* Generic Command Ligne console
@@ -75,17 +76,24 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.junit.Before;
import org.junit.Test;
import net.bigeon.gclc.utils.ReadingRunnable;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.ThreadTest;
import net.bigeon.test.junitmt.api.TestFunction;
/**
* <p>
@@ -131,13 +139,13 @@ public class ReadingRunnableTest {
final ReadingRunnable runnable = new ReadingRunnable(reader);
final Thread th0 = new Thread(runnable, "read");
th0.start();
Thread th = new Thread(new Runnable() {
final Thread th = new Thread(new Runnable() {
@Override
public void run() {
try {
runnable.waitForDelivery("msg");
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@@ -186,4 +194,64 @@ public class ReadingRunnableTest {
}
}
/** Test method for {@link net.bigeon.gclc.utils.ReadingRunnable#hasMessage()}.
*
* @throws IOException if an error occurred
* @throws InterruptedException if an error occured in the reading thread */
@Test
public final void testGetPendingMessages() throws IOException, InterruptedException {
final PipedOutputStream out = new PipedOutputStream();
final BufferedReader reader = new BufferedReader(
new InputStreamReader(new PipedInputStream(out), StandardCharsets.UTF_8));
final ReadingRunnable runnable = new ReadingRunnable(reader);
final BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(out, StandardCharsets.UTF_8));
writer.write("one");
writer.newLine();
writer.write("two");
writer.close();
out.close();
final Thread th = new Thread(runnable);
th.start();
th.join();
assertEquals("Pending messages should be retrievable", "one",
runnable.getMessage());
assertEquals("Pending messages should be retrievable", "two",
runnable.getMessage());
try {
runnable.getMessage();
fail("reading from closed runnable");
} catch (final IOException e) {
// ok
}
}
@Test
public void testInterruption() throws IOException, InterruptedException {
final PipedOutputStream out = new PipedOutputStream();
final BufferedReader reader = new BufferedReader(
new InputStreamReader(new PipedInputStream(out), StandardCharsets.UTF_8));
final ReadingRunnable runnable = new ReadingRunnable(reader);
final FunctionalTestRunnable test = new FunctionalTestRunnable(
new TestFunction() {
@Override
public void apply() throws IOException {
try {
runnable.getMessage();
fail("Message interruption should cause an exception");
} catch (final InterruptedIOException e) {
// ok
}
}
});
final Thread th = new Thread(test, "Prompt wait");
th.start();
th.join(200);
runnable.interrupt();
ThreadTest.assertRuns(th, test);
}
}

View File

@@ -71,10 +71,7 @@ package net.bigeon.gclc.manager;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
@@ -85,8 +82,6 @@ import java.nio.charset.Charset;
import org.junit.Test;
import net.bigeon.gclc.utils.StreamConsoleInput;
/**
* <p>
* TODO
@@ -174,7 +169,7 @@ public class SystemConsoleManagerTest {
final String prt = "++";
manager.setPrompt(prt);
assertEquals(prt, manager.getPrompt().apply());
assertEquals(prt, manager.getPrompt().get());
}
}

View File

@@ -71,10 +71,7 @@ package net.bigeon.gclc.prompt;
* knowledge of the CeCILL license and that you accept its terms.
* #L%
*/
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 static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException;
@@ -92,10 +89,12 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import net.bigeon.gclc.utils.PipedConsoleInput;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.test.junitmt.ATestRunnable;
import net.bigeon.gclc.manager.PipedConsoleInput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
import net.bigeon.test.junitmt.FunctionalTestRunnable;
import net.bigeon.test.junitmt.ThreadTest;
import net.bigeon.test.junitmt.api.ATestRunnable;
import net.bigeon.test.junitmt.api.TestFunction;
/**
* <p>
@@ -128,20 +127,17 @@ public class CLIPrompterTest {
BufferedReader buf = new BufferedReader(
new InputStreamReader(pis, StandardCharsets.UTF_8));
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
final ATestRunnable target = new ATestRunnable() {
final TestFunction func = new TestFunction() {
@Override
public void testRun() {
try {
public void apply() throws Exception {
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
assertTrue(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
assertFalse(CLIPrompter.promptBoolean(out, in, "My message")); //$NON-NLS-1$
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
}
}
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
@@ -161,9 +157,12 @@ public class CLIPrompterTest {
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String, String)}.
*
* @throws IOException if an IO occurred */
@Test
public final void testPromptChoiceConsoleManagerListOfStringListOfUStringString() {
public final void testPromptChoiceConsoleManagerListOfStringListOfUStringString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -179,11 +178,10 @@ public class CLIPrompterTest {
final String cancel = "Cancel"; //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
choices.get(0), CLIPrompter.promptChoice(out, in, keys,
choices, message, cancel));
@@ -193,12 +191,10 @@ public class CLIPrompterTest {
assertEquals("Asserted provided value to be retrieved", null,
CLIPrompter.promptChoice(out, in, keys, choices, message,
cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0)));
@@ -242,15 +238,13 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, target);
}
}
@Test
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString() {
public final void testPromptChoiceConsoleManagerListOfUMapOfUTStringString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -265,27 +259,23 @@ public class CLIPrompterTest {
choices.put(keys.get(1), "The actual other"); //$NON-NLS-1$
final String cancel = "Cancel"; //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
in, keys, choices, message, cancel));
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
keys, choices, message, cancel));
assertEquals("Asserted provided value to be retrieved",
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
in, keys, choices, message, null));
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
keys, choices, message, null));
assertEquals("Asserted provided value to be retrieved", null,
CLIPrompter.promptChoice(out, in, keys, choices, message,
cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
@@ -329,15 +319,13 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, target);
}
}
@Test
public final void testPromptChoiceConsoleManagerListOfUStringString() {
public final void testPromptChoiceConsoleManagerListOfUStringString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -349,12 +337,10 @@ public class CLIPrompterTest {
keys.add("An other"); //$NON-NLS-1$
final String cancel = "Cancel"; //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
Integer.valueOf(0),
CLIPrompter.promptChoice(out, in, keys, message, cancel));
@@ -366,12 +352,11 @@ public class CLIPrompterTest {
CLIPrompter.promptChoice(out, in, keys, message, null));
assertEquals("Asserted provided value to be retrieved", null,
CLIPrompter.promptChoice(out, in, keys, message, cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
@@ -422,17 +407,17 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, target);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, Map, String, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, Map, String, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptChoiceConsoleManagerMapOfUTStringString() {
public final void testPromptChoiceConsoleManagerMapOfUTStringString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -448,26 +433,23 @@ public class CLIPrompterTest {
final String cancel = "Cancel"; //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
in, keys, choices, message, cancel));
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
keys, choices, message, cancel));
assertEquals("Asserted provided value to be retrieved",
choices.get(keys.get(0)), CLIPrompter.promptChoice(out,
in, keys, choices, message, null));
choices.get(keys.get(0)), CLIPrompter.promptChoice(out, in,
keys, choices, message, null));
assertEquals("Asserted provided value to be retrieved", null,
CLIPrompter.promptChoice(out, in, keys, choices, message,
cancel));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
assertTrue(out.readNextLine().startsWith(message));
final String readNextLine = out.readNextLine();
@@ -513,37 +495,33 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("2"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptInteger(net.bigeon.gclc.manager.ConsoleInput, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptInteger(net.bigeon.gclc.manager.ConsoleInput, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptInteger() {
public final void testPromptInteger() throws IOException {
try (PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
BufferedReader buf = new BufferedReader(
new InputStreamReader(pis, StandardCharsets.UTF_8));
PipedConsoleInput in = new PipedConsoleInput(new PrintStream(pout))) {
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved", 10,
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
assertEquals("Asserted provided value to be retrieved", -15,
CLIPrompter.promptInteger(in, "My message")); //$NON-NLS-1$
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type(""); //$NON-NLS-1$
@@ -553,18 +531,16 @@ public class CLIPrompterTest {
in.type("10"); //$NON-NLS-1$
assertTrue(buf.readLine().startsWith("My message")); //$NON-NLS-1$
in.type("-15"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptListConsoleManagerString() {
public final void testPromptListConsoleManagerString() throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -576,22 +552,19 @@ public class CLIPrompterTest {
keys.add("An other"); //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
new ArrayList<String>(),
CLIPrompter.promptList(out, in, message));
assertEquals("Asserted provided value to be retrieved", keys,
CLIPrompter.promptList(out, in, message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
String nLine = out.readNextLine();
assertTrue(nLine.startsWith(message));
@@ -615,17 +588,16 @@ public class CLIPrompterTest {
buf.readLine());
}
in.type(CLIPrompterMessages.getString("promptlist.exit.defaultkey")); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptList(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptListConsoleManagerStringString() {
public final void testPromptListConsoleManagerStringString() throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -638,22 +610,19 @@ public class CLIPrompterTest {
final String ender = "*"; //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved",
new ArrayList<String>(),
CLIPrompter.promptList(out, in, message, ender));
assertEquals("Asserted provided value to be retrieved", keys,
CLIPrompter.promptList(out, in, message, ender));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
String nLine = out.readNextLine();
assertTrue(nLine.startsWith(message));
@@ -675,17 +644,16 @@ public class CLIPrompterTest {
buf.readLine());
}
in.type(ender);
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptLongTextConsoleManagerString() {
public final void testPromptLongTextConsoleManagerString() throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -697,22 +665,19 @@ public class CLIPrompterTest {
+ "line feeds and other" + System.lineSeparator()
+ System.lineSeparator() + " \tspecial characters";
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved", "",
CLIPrompter.promptLongText(out, in, message));
assertEquals("Asserted provided value to be retrieved",
longText + System.lineSeparator(),
CLIPrompter.promptLongText(out, in, message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
String nLine = out.readNextLine();
assertTrue(nLine.startsWith(message));
@@ -737,17 +702,16 @@ public class CLIPrompterTest {
buf.readLine());
}
in.type(CLIPrompterMessages.getString("promptlongtext.exit.defaultkey"));
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptLongText(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, String, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptLongTextConsoleManagerStringString() {
public final void testPromptLongTextConsoleManagerStringString() throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -761,22 +725,19 @@ public class CLIPrompterTest {
final String longText = text[0] + System.lineSeparator() + text[1]
+ System.lineSeparator() + text[2];
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertEquals("Asserted provided value to be retrieved", //$NON-NLS-1$
"", CLIPrompter.promptLongText(out, in, message, ender));
assertEquals("Asserted provided value to be retrieved",
longText + System.lineSeparator(),
CLIPrompter.promptLongText(out, in, message, ender));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
String nLine = out.readNextLine();
assertTrue(nLine.startsWith(message));
@@ -798,17 +759,17 @@ public class CLIPrompterTest {
buf.readLine());
}
in.type(ender);
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, List, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptMultiChoiceConsoleManagerListOfStringListOfUString() {
public final void testPromptMultiChoiceConsoleManagerListOfStringListOfUString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -823,29 +784,24 @@ public class CLIPrompterTest {
choices.add("The actual other"); //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
assertTrue("Asserted provided value to be retrieved", CLIPrompter
.promptMultiChoice(out, in, keys, choices, message)
public void apply() throws Exception {
assertTrue("Asserted provided value to be retrieved",
CLIPrompter.promptMultiChoice(out, in, keys, choices, message)
.isEmpty());
final ArrayList<Object> l = new ArrayList<>();
l.add(choices.get(0));
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, choices,
message));
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
.promptMultiChoice(out, in, keys, choices, message));
l.add(choices.get(1));
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, choices,
message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
.promptMultiChoice(out, in, keys, choices, message));
}
}
});
};
final ATestRunnable runnable = new FunctionalTestRunnable(func);
final Thread th = new Thread(runnable);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0)));
@@ -886,17 +842,17 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, runnable);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, Map, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, Map, String)}.
*
* @throws IOException if errors */
@Test
public final void testPromptMultiChoiceConsoleManagerListOfUMapOfUTString() {
public final void testPromptMultiChoiceConsoleManagerListOfUMapOfUTString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -910,30 +866,24 @@ public class CLIPrompterTest {
keys.add("An other"); //$NON-NLS-1$
choices.put(keys.get(1), "The actual other"); //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
assertTrue("Asserted provided value to be retrieved", CLIPrompter
.promptMultiChoice(out, in, keys, choices, message)
public void apply() throws Exception {
assertTrue("Asserted provided value to be retrieved",
CLIPrompter.promptMultiChoice(out, in, keys, choices, message)
.isEmpty());
final ArrayList<Object> l = new ArrayList<>();
l.add(choices.get(keys.get(0)));
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, choices,
message));
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
.promptMultiChoice(out, in, keys, choices, message));
l.add(choices.get(keys.get(1)));
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, choices,
message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
assertEquals("Asserted provided value to be retrieved", l, CLIPrompter
.promptMultiChoice(out, in, keys, choices, message));
}
}
});
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
@@ -974,17 +924,17 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, target);
}
}
/** Test method for
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, String)}. */
* {@link net.bigeon.gclc.prompt.CLIPrompter#promptMultiChoice(net.bigeon.gclc.manager.ConsoleOutput, net.bigeon.gclc.manager.ConsoleInput, List, String)}.
*
* @throws IOException if error */
@Test
public final void testPromptMultiChoiceConsoleManagerListOfUString() {
public final void testPromptMultiChoiceConsoleManagerListOfUString()
throws IOException {
try (final PipedConsoleOutput out = new PipedConsoleOutput();
PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream(pout);
@@ -995,12 +945,10 @@ public class CLIPrompterTest {
keys.add("A choice"); //$NON-NLS-1$
keys.add("An other"); //$NON-NLS-1$
final String message = "My message"; //$NON-NLS-1$
final Thread th = new Thread(new Runnable() {
final TestFunction func = new TestFunction() {
@Override
public void run() {
try {
public void apply() throws Exception {
assertTrue("Asserted provided value to be retrieved", CLIPrompter
.promptMultiChoice(out, in, keys, message).isEmpty());
final ArrayList<Integer> l = new ArrayList<>();
@@ -1010,12 +958,10 @@ public class CLIPrompterTest {
l.add(1);
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
});
};
final ATestRunnable target = new FunctionalTestRunnable(func);
final Thread th = new Thread(target);
th.start();
assertTrue(out.readNextLine().startsWith(message));
assertTrue(out.readNextLine().contains(keys.get(0).toString()));
@@ -1056,10 +1002,7 @@ public class CLIPrompterTest {
assertEquals(CLIPrompterMessages.getString("prompt.lineprompt"), //$NON-NLS-1$
buf.readLine());
in.type("0 1"); //$NON-NLS-1$
th.join();
} catch (IOException | InterruptedException e) {
fail("Unexpected excpetion"); //$NON-NLS-1$
e.printStackTrace();
ThreadTest.assertRuns(th, target);
}
}
@@ -1084,8 +1027,7 @@ public class CLIPrompterTest {
final ATestRunnable target = new ATestRunnable() {
@Override
public void testRun() {
try {
public void testRun() throws IOException {
assertTrue("Asserted provided value to be retrieved", CLIPrompter
.promptMultiChoice(out, in, keys, choices, message)
.isEmpty());
@@ -1098,10 +1040,6 @@ public class CLIPrompterTest {
assertEquals("Asserted provided value to be retrieved", l,
CLIPrompter.promptMultiChoice(out, in, keys, choices,
message));
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
e.printStackTrace();
}
}
};
final Thread th = new Thread(target);
@@ -1157,14 +1095,10 @@ public class CLIPrompterTest {
final ATestRunnable target = new ATestRunnable() {
@Override
public void testRun() {
try {
public void testRun() throws IOException {
assertEquals("Expected provided message to be returned", res,
CLIPrompter.promptNonEmpty(in, "My message", //$NON-NLS-1$
"my reprompt")); //$NON-NLS-1$
} catch (final IOException e) {
fail("Unexpected io excpetion"); //$NON-NLS-1$
}
}
};
final Thread th = new Thread(target);

View File

@@ -77,8 +77,7 @@ import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.utils.AOutputForwardRunnable;
import net.bigeon.gclc.utils.PipedConsoleOutput;
import net.bigeon.gclc.manager.PipedConsoleOutput;
/**
* <p>
@@ -143,7 +142,7 @@ public class AOutputForwardRunnableTest {
}
/** Test method for
* {@link net.bigeon.gclc.utils.AOutputForwardRunnable#run()}. */
* {@link net.bigeon.gclc.tools.AOutputForwardRunnable#run()}. */
@Test
public final void testRun() {
try (PipedConsoleOutput manager = new PipedConsoleOutput()) {

Some files were not shown because too many files have changed in this diff Show More