Compare commits
11 Commits
gclc-2.1.1
...
gclc-2.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| a0a1dfe91e | |||
| 04902c9868 | |||
| 9cf30ef7d2 | |||
| 3960b10e8e | |||
| d3bb6fa5a0 | |||
| b6b6ab9d36 | |||
| 92a664d193 | |||
| c230a23f81 | |||
| e5c3bb0152 | |||
| 24e57eca2f | |||
| da8765dd7b |
@@ -77,6 +77,8 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
|||||||
/** The application. */
|
/** The application. */
|
||||||
private ConsoleApplication app;
|
private ConsoleApplication app;
|
||||||
|
|
||||||
|
private final Object initLock = new Object();
|
||||||
|
|
||||||
/** The server socket. */
|
/** The server socket. */
|
||||||
private ServerSocket serverSocket;
|
private ServerSocket serverSocket;
|
||||||
/** THe server address. */
|
/** THe server address. */
|
||||||
@@ -123,7 +125,10 @@ public final class SocketConsoleApplicationShell implements Runnable {
|
|||||||
// Create the server
|
// Create the server
|
||||||
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
|
try (ServerSocket actualServerSocket = new ServerSocket(port, 1, addr)) {
|
||||||
serverSocket = actualServerSocket;
|
serverSocket = actualServerSocket;
|
||||||
running = true;
|
synchronized (initLock) {
|
||||||
|
running = true;
|
||||||
|
initLock.notifyAll();
|
||||||
|
}
|
||||||
// Create the streams
|
// Create the streams
|
||||||
runSokectServer();
|
runSokectServer();
|
||||||
} catch (final IOException e) {
|
} 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$
|
LOGGER.log(Level.SEVERE, "Exception in closing socket server", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A method to wait for the socket server initialization.
|
||||||
|
*
|
||||||
|
* @param timeout the timeout */
|
||||||
|
public void waitStartUp(final long timeout) {
|
||||||
|
synchronized (initLock) {
|
||||||
|
final long tic = System.currentTimeMillis() + timeout;
|
||||||
|
long tac;
|
||||||
|
while (!running && (tac = System.currentTimeMillis()) < tic) {
|
||||||
|
final long idle = tic - tac;
|
||||||
|
try {
|
||||||
|
initLock.wait(idle);
|
||||||
|
} catch (final InterruptedException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Thread interruption", e);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,8 +123,14 @@ public final class RemoteDisconnectCommand<T> extends Command {
|
|||||||
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
* @see fr.bigeon.gclc.command.Command#usageDetail() */
|
||||||
@Override
|
@Override
|
||||||
protected String usageDetail() {
|
protected String usageDetail() {
|
||||||
return MessageFormat.format(
|
final StringBuilder builder = new StringBuilder(
|
||||||
" If arguments are provided the corresponding connexions are closed, otherwise\n{0} are.",
|
" If arguments are provided the corresponding connexions are closed, otherwise\n");
|
||||||
all ? "all connexions" : "none");
|
if (all) {
|
||||||
|
builder.append("all connections");
|
||||||
|
} else {
|
||||||
|
builder.append("none");
|
||||||
|
}
|
||||||
|
builder.append(" are.");
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public class TestServer {
|
|||||||
if (server == null) {
|
if (server == null) {
|
||||||
server = new Thread(getShell(), "gclcServer");
|
server = new Thread(getShell(), "gclcServer");
|
||||||
server.start();
|
server.start();
|
||||||
|
getShell().waitStartUp(500);
|
||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
@@ -82,13 +83,7 @@ public class TestServer {
|
|||||||
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
SHELL.setInterface(new SocketConsoleInterface(input, output));
|
||||||
SHELL.setConnexionManager(manager);
|
SHELL.setConnexionManager(manager);
|
||||||
SHELL.setApplication(app);
|
SHELL.setApplication(app);
|
||||||
final Thread th = new Thread(new Runnable() {
|
final Thread th = new Thread(() -> app.start());
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
app.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
th.start();
|
th.start();
|
||||||
try {
|
try {
|
||||||
final Object waiting = new Object();
|
final Object waiting = new Object();
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
||||||
|
|
||||||
/** A shell containing a {@link SWTConsoleView}
|
/** A shell containing a {@link SWTConsoleView}
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
import net.bigeon.gclc.ConsoleApplication;
|
import net.bigeon.gclc.ConsoleApplication;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||||
|
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
||||||
|
|
||||||
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
/** A SWT component to connect to gclc {@link ConsoleApplication}.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
|
* gclc-swt:net.bigeon.gclc.swt.ConsoleDelayIO.java
|
||||||
* Created on: Nov 19, 2016
|
* Created on: Nov 19, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.api;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bigeon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt.api;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.io;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -42,6 +42,7 @@ import java.io.IOException;
|
|||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
|
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||||
|
|
||||||
/** The object managing the console input.
|
/** The object managing the console input.
|
||||||
*
|
*
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.io;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -40,6 +40,8 @@ package net.bigeon.gclc.swt;
|
|||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
||||||
|
import net.bigeon.gclc.swt.tools.TextAppendingRunnable;
|
||||||
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
import net.bigeon.gclc.swt.tools.ToSWTConsoleForwardRunnable;
|
||||||
|
|
||||||
/** The manager for console output to insert in a text.
|
/** The manager for console output to insert in a text.
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.io;
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* #%L
|
* #%L
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bigeon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt.io;
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
|
* gclc-swt:net.bigeon.gclc.swt.HistoryTextKeyListener.java
|
||||||
* Created on: Jun 9, 2016
|
* Created on: Jun 9, 2016
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.tools;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -78,6 +78,7 @@ import org.eclipse.swt.events.KeyEvent;
|
|||||||
|
|
||||||
import net.bigeon.collections.Ribbon;
|
import net.bigeon.collections.Ribbon;
|
||||||
import net.bigeon.collections.ribbon.ArrayRibbon;
|
import net.bigeon.collections.ribbon.ArrayRibbon;
|
||||||
|
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||||
|
|
||||||
/** A key listener to validate commands and manage the history of commands.
|
/** A key listener to validate commands and manage the history of commands.
|
||||||
*
|
*
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.bigeon.gclc.swt;
|
package net.bigeon.gclc.swt.tools;
|
||||||
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
@@ -7,13 +7,12 @@ import org.eclipse.swt.widgets.Widget;
|
|||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
import net.bigeon.gclc.manager.forwarding.AOutputForwardRunnable;
|
||||||
import net.bigeon.gclc.swt.ConsoleOutputDisplay;
|
import net.bigeon.gclc.swt.api.ConsoleOutputDisplay;
|
||||||
|
|
||||||
/** The local implementation of the forwarding runnable.
|
/** The local implementation of the forwarding runnable.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class ToSWTConsoleForwardRunnable
|
public final class ToSWTConsoleForwardRunnable extends AOutputForwardRunnable {
|
||||||
extends AOutputForwardRunnable {
|
|
||||||
/** The running status. */
|
/** The running status. */
|
||||||
private boolean running = true;
|
private boolean running = true;
|
||||||
/** The console output. */
|
/** The console output. */
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.eclipse.swt.widgets.Text;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleInput;
|
import net.bigeon.gclc.manager.PipedConsoleInput;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleInputManager;
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class ConsoleInputManagerTest {
|
public class ConsoleInputManagerTest {
|
||||||
@@ -55,7 +56,7 @@ public class ConsoleInputManagerTest {
|
|||||||
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
private final ConsoleInputManager cim = new ConsoleInputManager(text);
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#setInput(java.lang.String)}. */
|
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#setInput(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testSetText() {
|
public void testSetText() {
|
||||||
cim.setInput("Text");
|
cim.setInput("Text");
|
||||||
@@ -63,7 +64,7 @@ public class ConsoleInputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#validateInput()}.
|
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#validateInput()}.
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurred */
|
* @throws IOException if an error occurred */
|
||||||
@Test
|
@Test
|
||||||
@@ -101,7 +102,7 @@ public class ConsoleInputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.ConsoleInputManager#getText()}. */
|
* {@link net.bigeon.gclc.swt.io.ConsoleInputManager#getText()}. */
|
||||||
@Test
|
@Test
|
||||||
public void testGetText() {
|
public void testGetText() {
|
||||||
assertEquals("Text component should be preserved", text, cim.getText());
|
assertEquals("Text component should be preserved", text, cim.getText());
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.mockito.invocation.InvocationOnMock;
|
|||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
import net.bigeon.gclc.manager.PipedConsoleOutput;
|
||||||
|
import net.bigeon.gclc.swt.io.ConsoleOutputManager;
|
||||||
|
|
||||||
/** @author Emmanuel Bigeon */
|
/** @author Emmanuel Bigeon */
|
||||||
public class ConsoleOutputManagerTest {
|
public class ConsoleOutputManagerTest {
|
||||||
@@ -71,7 +72,7 @@ public class ConsoleOutputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
* {@link net.bigeon.gclc.swt.io.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testAppendConsoleOutput() {
|
public void testAppendConsoleOutput() {
|
||||||
when(text.getText()).thenReturn("", "abc",
|
when(text.getText()).thenReturn("", "abc",
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ import java.io.BufferedReader;
|
|||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.swt.io.ConsolePromptManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bigeon
|
* @author Emmanuel Bigeon
|
||||||
*
|
*
|
||||||
@@ -56,7 +58,7 @@ public class ConsolePromptManagerTest {
|
|||||||
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
private final ConsolePromptManager manager = new ConsolePromptManager(label);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setPrompt(java.lang.String)}.
|
* Test method for {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setPrompt(java.lang.String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetPrompt() {
|
public void testSetPrompt() {
|
||||||
@@ -65,7 +67,7 @@ public class ConsolePromptManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link net.bigeon.gclc.swt.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
* Test method for {@link net.bigeon.gclc.swt.io.ConsolePromptManager#setStream(java.io.BufferedReader)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetStream() {
|
public void testSetStream() {
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ import org.eclipse.swt.SWT;
|
|||||||
import org.eclipse.swt.events.KeyEvent;
|
import org.eclipse.swt.events.KeyEvent;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.bigeon.gclc.swt.api.ConsoleDelayIO;
|
||||||
|
import net.bigeon.gclc.swt.tools.HistoryTextKeyListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* TODO
|
* TODO
|
||||||
@@ -83,7 +86,7 @@ import org.junit.Test;
|
|||||||
public class HistoryTextKeyListenerTest {
|
public class HistoryTextKeyListenerTest {
|
||||||
|
|
||||||
/** Test method for
|
/** 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
|
@Test
|
||||||
public final void testKeyPressedKeyEvent() {
|
public final void testKeyPressedKeyEvent() {
|
||||||
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
final ConsoleDelayIO io = new ConsoleDelayIO() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>net.bigeon</groupId>
|
<groupId>net.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>2.1.1</version>
|
<version>2.1.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Generic Command Ligne console</name>
|
<name>Generic Command Ligne console</name>
|
||||||
<description>A generic framework for console applications, with customized command input and output streams.</description>
|
<description>A generic framework for console applications, with customized command input and output streams.</description>
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
</developers>
|
</developers>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>gclc-2.1.1</tag>
|
<tag>gclc-2.1.2</tag>
|
||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ public abstract class Command implements ICommand {
|
|||||||
* @param name the command name */
|
* @param name the command name */
|
||||||
public Command(final String name) {
|
public Command(final String name) {
|
||||||
super();
|
super();
|
||||||
|
if (name == null) {
|
||||||
|
throw new IllegalArgumentException("The command name is mandatory");
|
||||||
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ public final class ScriptExecution extends Command {
|
|||||||
try (InputStreamReader fReader = new InputStreamReader(
|
try (InputStreamReader fReader = new InputStreamReader(
|
||||||
Files.newInputStream(Paths.get(scriptFile)), charset);
|
Files.newInputStream(Paths.get(scriptFile)), charset);
|
||||||
BufferedReader reader = new BufferedReader(fReader)) {
|
BufferedReader reader = new BufferedReader(fReader)) {
|
||||||
String[] emptyArray = new String[0];
|
final String[] emptyArray = new String[0];
|
||||||
while ((cmd = reader.readLine()) != null) {
|
while ((cmd = reader.readLine()) != null) {
|
||||||
lineNo++;
|
lineNo++;
|
||||||
final String cmdLine = readCommandLine(cmd, params);
|
final String cmdLine = readCommandLine(cmd, params);
|
||||||
@@ -237,10 +237,16 @@ public final class ScriptExecution extends Command {
|
|||||||
* @return the exception to actually throw */
|
* @return the exception to actually throw */
|
||||||
private static CommandRunException manageRunException(final CommandRunException e,
|
private static CommandRunException manageRunException(final CommandRunException e,
|
||||||
final int lineNo) {
|
final int lineNo) {
|
||||||
|
final StringBuilder builder = new StringBuilder(e.getLocalizedMessage());
|
||||||
|
int index = builder.indexOf("\n");
|
||||||
|
while (index > 0) {
|
||||||
|
builder.insert(index + 1, " ");
|
||||||
|
index = builder.indexOf("\n", index + 1);
|
||||||
|
}
|
||||||
return new CommandRunException(CommandRunExceptionType.EXECUTION,
|
return new CommandRunException(CommandRunExceptionType.EXECUTION,
|
||||||
MessageFormat.format(
|
MessageFormat.format(
|
||||||
"The script could not complete due to command failure at line {0} ({1})", //$NON-NLS-1$
|
"The script could not complete due to command failure at line {0}\n {1})", //$NON-NLS-1$
|
||||||
Integer.valueOf(lineNo), e.getLocalizedMessage()),
|
Integer.valueOf(lineNo + 1), builder),
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,48 +40,12 @@ package net.bigeon.gclc.manager;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/*-
|
|
||||||
* #%L
|
|
||||||
* Generic Command Ligne console
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2014 - 2018 Bigeon
|
|
||||||
* %%
|
|
||||||
* This software is governed by the CeCILL license under French law and
|
|
||||||
* abiding by the rules of distribution of free software. You can use,
|
|
||||||
* modify and/ or redistribute the software under the terms of the CeCILL
|
|
||||||
* license as circulated by CEA, CNRS and INRIA at the following URL
|
|
||||||
* "http://www.cecill.info".
|
|
||||||
*
|
|
||||||
* As a counterpart to the access to the source code and rights to copy,
|
|
||||||
* modify and redistribute granted by the license, users are provided only
|
|
||||||
* with a limited warranty and the software's author, the holder of the
|
|
||||||
* economic rights, and the successive licensors have only limited
|
|
||||||
* liability.
|
|
||||||
*
|
|
||||||
* In this respect, the user's attention is drawn to the risks associated
|
|
||||||
* with loading, using, modifying and/or developing or reproducing the
|
|
||||||
* software by the user in light of its specific status of free software,
|
|
||||||
* that may mean that it is complicated to manipulate, and that also
|
|
||||||
* therefore means that it is reserved for developers and experienced
|
|
||||||
* professionals having in-depth computer knowledge. Users are therefore
|
|
||||||
* encouraged to load and test the software's suitability as regards their
|
|
||||||
* requirements in conditions enabling the security of their systems and/or
|
|
||||||
* data to be ensured and, more generally, to use and operate it in the
|
|
||||||
* same conditions as regards security.
|
|
||||||
*
|
|
||||||
* The fact that you are presently reading this means that you have had
|
|
||||||
* knowledge of the CeCILL license and that you accept its terms.
|
|
||||||
* #L%
|
|
||||||
*/
|
|
||||||
|
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
|
||||||
|
|
||||||
/** A console input that return empty to all prompting.
|
/** A console input that return empty to all prompting.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class EmptyInput implements ConsoleInput {
|
public final class EmptyInput implements ConsoleInput {
|
||||||
|
|
||||||
private static final ConstantString CONSTANT_STRING = new ConstantString("");
|
private static final Supplier<String> CONSTANT_STRING = () -> "";
|
||||||
/** The empty prompter. */
|
/** The empty prompter. */
|
||||||
public static final ConsoleInput INSTANCE = new EmptyInput();
|
public static final ConsoleInput INSTANCE = new EmptyInput();
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ import java.io.PrintStream;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.bigeon.gclc.tools.ConstantString;
|
|
||||||
import net.bigeon.gclc.utils.ReadingRunnable;
|
import net.bigeon.gclc.utils.ReadingRunnable;
|
||||||
|
|
||||||
/** A console using the input stream and print stream.
|
/** A console using the input stream and print stream.
|
||||||
@@ -90,7 +89,7 @@ import net.bigeon.gclc.utils.ReadingRunnable;
|
|||||||
public final class StreamConsoleInput implements ConsoleInput {
|
public final class StreamConsoleInput implements ConsoleInput {
|
||||||
|
|
||||||
/** The default prompt. */
|
/** The default prompt. */
|
||||||
public static final Supplier<String> DEFAULT_PROMPT = new ConstantString("> "); //$NON-NLS-1$
|
public static final Supplier<String> DEFAULT_PROMPT = () -> ("> "); //$NON-NLS-1$
|
||||||
|
|
||||||
/** The command prompt. It can be changed. */
|
/** The command prompt. It can be changed. */
|
||||||
private Supplier<String> prompt = DEFAULT_PROMPT;
|
private Supplier<String> prompt = DEFAULT_PROMPT;
|
||||||
@@ -213,7 +212,7 @@ public final class StreamConsoleInput implements ConsoleInput {
|
|||||||
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
* @see net.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||||
@Override
|
@Override
|
||||||
public void setPrompt(final String prompt) {
|
public void setPrompt(final String prompt) {
|
||||||
this.prompt = new ConstantString(prompt);
|
this.prompt = () -> (prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -73,7 +73,9 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
/** A supplier of string that hold a constant string.
|
/** A supplier of string that hold a constant string.
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon
|
||||||
|
* @deprecated since 2.1.2, use a lambda expression instead */
|
||||||
|
@Deprecated
|
||||||
public class ConstantString implements Supplier<String> {
|
public class ConstantString implements Supplier<String> {
|
||||||
private final String string;
|
private final String string;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user