Update socket and swt dependency on gclc last stable

This commit is contained in:
Emmanuel Bigeon 2016-06-02 13:00:59 -04:00
parent 38322d4fed
commit df159e4ca6
8 changed files with 161 additions and 149 deletions

View File

@ -87,7 +87,7 @@ of Emmanuel Bigeon. -->
<dependency>
<groupId>fr.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>fr.bigeon</groupId>

View File

@ -50,7 +50,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.smu.StringEncoder;
/** This is a socket communicating console consoleManager

View File

@ -44,7 +44,7 @@ import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.smu.StringEncoder;
/** The console manager for socket communication
@ -154,5 +154,11 @@ public class ThreadedServerConsoleManager implements ConsoleManager {
return prompt;
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#close() */
@Override
public void close() throws IOException {
// Do nothing
}
}

View File

@ -38,39 +38,35 @@
*/
package fr.bigeon.gclc.socket;
import java.io.IOException;
import org.junit.Test;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.system.SystemConsoleManager;
import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.gclc.manager.SystemConsoleManager;
/** Test class for {@link ConsoleRunnable}
*
* @author Emmanuel Bigeon */
@SuppressWarnings({"static-method", "unused"})
@SuppressWarnings({"static-method", "unused", "javadoc"})
public class ConsoleRunnableTest {
/**
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#ConsoleRunnable(fr.bigeon.gclc.ConsoleApplication, java.lang.Object)}.
*/
@Test
public void testConsoleRunnable() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new SystemConsoleManager());
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
/** <p>
* TODO
*
* @author Emmanuel Bigeon */
private static final class ConsoleManagerTestImplementation
implements ConsoleManager {
int i = 0;
String[] cmds;
/** @param cmds */
public ConsoleManagerTestImplementation(String[] cmds) {
super();
this.cmds = cmds;
}
/**
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}.
*/
@Test
public void testRunFlow() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManager() {
@Override
public void setPrompt(String prompt) {
// do nothing
@ -89,7 +85,11 @@ public class ConsoleRunnableTest {
} catch (InterruptedException e) { // NOSONAR
// do nothing
}
return "mock"; //$NON-NLS-1$
i++;
if (i == cmds.length) {
i = 0;
}
return cmds[i];
}
@Override
@ -111,7 +111,32 @@ public class ConsoleRunnableTest {
public void print(String text) {
// do nothing
}
});
@Override
public void close() throws IOException {
// do nothing
}
}
/** Test method for
* {@link fr.bigeon.gclc.socket.ConsoleRunnable#ConsoleRunnable(fr.bigeon.gclc.ConsoleApplication, java.lang.Object)}
* . */
@Test
public void testConsoleRunnable() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new SystemConsoleManager());
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
}
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#run()}. */
@Test
public void testRunFlow() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT}));
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
Thread th = new Thread(runnable);
@ -120,55 +145,13 @@ public class ConsoleRunnableTest {
runnable.stop();
}
/**
* Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}.
*/
/** Test method for {@link fr.bigeon.gclc.socket.ConsoleRunnable#stop()}. */
@Test
public void testStop() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManager() {
@Override
public void setPrompt(String prompt) {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public String getPrompt() {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public String prompt() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "mock"; //$NON-NLS-1$
}
@Override
public String prompt(String message) {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public void println(String message) {
//
}
@Override
public void println() {
//
}
@Override
public void print(String text) {
//
}
});
new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT}));
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
runnable.stop();
Thread th = new Thread(runnable);
@ -182,48 +165,8 @@ public class ConsoleRunnableTest {
public void testRun() {
Object lock = new Object();
ConsoleApplication app = new ConsoleTestApplication(
new ConsoleManager() {
@Override
public void setPrompt(String prompt) {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public String getPrompt() {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public String prompt() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "exit"; //$NON-NLS-1$
}
@Override
public String prompt(String message) {
throw new RuntimeException("Not implemented yet"); //$NON-NLS-1$
}
@Override
public void println(String message) {
//
}
@Override
public void println() {
//
}
@Override
public void print(String text) {
//
}
});
new ConsoleManagerTestImplementation(
new String[] {"test", ConsoleTestApplication.EXIT}));
ConsoleRunnable runnable = new ConsoleRunnable(app, lock);
runnable.run();
}

View File

@ -35,9 +35,11 @@
package fr.bigeon.gclc.socket;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.command.Command;
import fr.bigeon.gclc.command.ICommand;
import fr.bigeon.gclc.exception.InvalidCommandName;
import fr.bigeon.gclc.manager.ConsoleManager;
import fr.bigeon.gclc.prompt.CLIPrompterMessages;
/** A test-purpose application
*
@ -50,11 +52,11 @@ public class ConsoleTestApplication extends ConsoleApplication {
/** @param manager the manager */
@SuppressWarnings("nls")
public ConsoleTestApplication(final ConsoleManager manager) {
super(manager, EXIT,
"Welcome to the test application. Type help or test.",
super(manager, "Welcome to the test application. Type help or test.",
"See you");
addHelpCommand("help");
try {
add(new ExitCommand(EXIT, this));
addHelpCommand("help");
add(new Command("test") {
@Override
@ -71,4 +73,55 @@ public class ConsoleTestApplication extends ConsoleApplication {
e.printStackTrace();
}
}
/** <p>
* A command to exit a {@link ConsoleApplication}.
*
* @author Emmanuel BIGEON */
class ExitCommand implements ICommand {
/** The exit command manual message key */
private static final String EXIT_MAN = "exit.man"; //$NON-NLS-1$
/** The tip of the exit command */
private static final String EXIT_TIP = "exit.tip"; //$NON-NLS-1$
/** The application that will be exited when this command runs */
private final ConsoleApplication app;
/** The exit command name */
private final String name;
/** @param name the name of the command
* @param app the application to exit */
public ExitCommand(String name, ConsoleApplication app) {
this.name = name;
this.app = app;
}
/** The actions to take before exiting */
public void beforeExit() {
// Do nothing by default
}
@Override
public final void execute(String... args) {
beforeExit();
app.exit();
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#getCommandName() */
@Override
public String getCommandName() {
return name;
}
@Override
public void help(ConsoleManager helpManager, String... args) {
helpManager.println(
CLIPrompterMessages.getString(EXIT_MAN, (Object[]) args));
}
@Override
public String tip() {
return CLIPrompterMessages.getString(EXIT_TIP);
}
}
}

View File

@ -51,7 +51,7 @@
<dependency>
<groupId>fr.bigeon</groupId>
<artifactId>gclc</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>

View File

@ -38,6 +38,8 @@
*/
package fr.bigeon.gclc.swt;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
@ -53,7 +55,7 @@ import org.eclipse.swt.widgets.Text;
import fr.bigeon.collections.ArrayRibbon;
import fr.bigeon.collections.Ribbon;
import fr.bigeon.gclc.ConsoleApplication;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.manager.ConsoleManager;
/** A SWT component to connect to gclc {@link ConsoleApplication}
* <p>
@ -320,4 +322,12 @@ public class SWTConsole extends Composite implements ConsoleManager {
});
}
/* (non-Javadoc)
* @see fr.bigeon.gclc.manager.ConsoleManager#close() */
@Override
public void close() throws IOException {
consoleInput.setEnabled(false);
consoleOutput.setEnabled(false);
}
}

View File

@ -43,7 +43,7 @@ import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import fr.bigeon.gclc.ConsoleManager;
import fr.bigeon.gclc.manager.ConsoleManager;
/** A shell containing a {@link SWTConsole}
* <p>