Compare commits
10 Commits
gclc-1.2.3
...
gclc-1.2.5
| Author | SHA1 | Date | |
|---|---|---|---|
| 70a71c06a7 | |||
| a0202de532 | |||
| caa00f2a61 | |||
| eed6f43aea | |||
| 59ab689a36 | |||
| 2bf1fa7c80 | |||
| 32e5f777fe | |||
| f8aeef14e3 | |||
| 763b7361ec | |||
| c151107207 |
@@ -87,7 +87,7 @@ of Emmanuel Bigeon. -->
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
|
||||
@@ -72,7 +72,8 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
try {
|
||||
manager.println("Test command ran fine");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("manager closed", e);
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -89,7 +90,8 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
||||
Thread.sleep(2000);
|
||||
manager.println("Test command ran fine");
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new CommandRunException("manager closed", e);
|
||||
throw new CommandRunException("manager closed", e,
|
||||
this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.bigeon</groupId>
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SWTConsoleShellTest {
|
||||
try {
|
||||
appl.getManager().prompt("Test");
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException("No input", e);
|
||||
throw new CommandRunException("No input", e, this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<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>
|
||||
<artifactId>gclc</artifactId>
|
||||
<version>1.2.3</version>
|
||||
<version>1.2.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.bigeon.fr/emmanuel</url>
|
||||
<properties>
|
||||
@@ -83,6 +83,6 @@
|
||||
<scm>
|
||||
|
||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||
<tag>gclc-1.2.3</tag>
|
||||
<tag>gclc-1.2.5</tag>
|
||||
</scm>
|
||||
</project>
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
* Created on: Aug 6, 2014 */
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
@@ -53,12 +53,12 @@ public class CommandProvider implements ICommandProvider {
|
||||
/** The space character */
|
||||
private static final String SPACE = " "; //$NON-NLS-1$
|
||||
/** The commands map */
|
||||
protected final Set<ICommand> commands;
|
||||
protected final List<ICommand> commands;
|
||||
|
||||
/** Create a command provider */
|
||||
public CommandProvider() {
|
||||
super();
|
||||
commands = new HashSet<>();
|
||||
commands = new ArrayList<>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -70,6 +70,9 @@ public class CommandProvider implements ICommandProvider {
|
||||
if (name == null || name.startsWith(MINUS) || name.contains(SPACE)) {
|
||||
throw new InvalidCommandName();
|
||||
}
|
||||
if (commands.contains(value)) {
|
||||
return true;
|
||||
}
|
||||
return commands.add(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,9 +84,8 @@ public class ScriptExecution extends Command {
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
"Expecting a file", this); //$NON-NLS-1$
|
||||
}
|
||||
List<String> argsList = Arrays.asList(args);
|
||||
String scriptFile = argsList.remove(0);
|
||||
Object[] params = argsList.toArray();
|
||||
String scriptFile = args[0];
|
||||
Object[] params = Arrays.copyOfRange(args, 1, args.length);
|
||||
try (FileReader fReader = new FileReader(new File(scriptFile));
|
||||
BufferedReader reader = new BufferedReader(fReader)) {
|
||||
String cmd;
|
||||
@@ -114,8 +113,7 @@ public class ScriptExecution extends Command {
|
||||
e.getLocalizedMessage() + ")", //$NON-NLS-1$
|
||||
e, this);
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
"Unable to read script (" + e.getLocalizedMessage() + ")", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
throw new CommandRunException("Unable to read script", //$NON-NLS-1$
|
||||
e, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,9 @@ public class SubedCommand implements ICommandProvider, ICommand {
|
||||
try {
|
||||
executeSub(args[0], Arrays.copyOfRange(args, 1, args.length));
|
||||
} catch (CommandRunException e) {
|
||||
if (e.getSource() != null) {
|
||||
throw e;
|
||||
}
|
||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||
e.getLocalizedMessage(), e, this);
|
||||
}
|
||||
|
||||
@@ -162,8 +162,11 @@ public class CLIPrompter {
|
||||
public static <U, T> T promptChoice(ConsoleManager manager, List<U> choices,
|
||||
Map<U, T> choicesMap, String message,
|
||||
String cancel) throws IOException {
|
||||
return choicesMap.get(choices.get(
|
||||
promptChoice(manager, choices, message, cancel).intValue()));
|
||||
Integer res = promptChoice(manager, choices, message, cancel);
|
||||
if (res == null) {
|
||||
return null;
|
||||
}
|
||||
return choicesMap.get(choices.get(res.intValue()));
|
||||
}
|
||||
|
||||
/** @param manager the manager
|
||||
|
||||
117
gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java
Normal file
117
gclc/src/test/java/fr/bigeon/gclc/CommandTestingApplication.java
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* gclc:fr.bigeon.gclc.command.CommandTestingApplication.java
|
||||
* Created on: Jun 12, 2016
|
||||
*/
|
||||
package fr.bigeon.gclc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import fr.bigeon.gclc.command.ICommand;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
import fr.bigeon.gclc.manager.SystemConsoleManager;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
public class CommandTestingApplication {
|
||||
|
||||
private final PrintWriter writer;
|
||||
private final ConsoleTestApplication application;
|
||||
private final Thread th;
|
||||
|
||||
/** @throws IOException if the streams cannot be build */
|
||||
public CommandTestingApplication() throws IOException {
|
||||
final PipedOutputStream src = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(src);
|
||||
|
||||
application = new ConsoleTestApplication(
|
||||
new SystemConsoleManager(System.out, in));
|
||||
th = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
application.start();
|
||||
}
|
||||
});
|
||||
|
||||
th.start();
|
||||
writer = new PrintWriter(src, true);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
application.exit();
|
||||
writer.println();
|
||||
}
|
||||
|
||||
public void sendCommand(String cmd) {
|
||||
writer.println(cmd);
|
||||
}
|
||||
|
||||
/** @param cmd the command
|
||||
* @return if the command was added
|
||||
* @throws InvalidCommandName if the command name is invalid
|
||||
* @see fr.bigeon.gclc.ConsoleApplication#add(fr.bigeon.gclc.command.ICommand) */
|
||||
public final boolean add(ICommand cmd) throws InvalidCommandName {
|
||||
return application.add(cmd);
|
||||
}
|
||||
|
||||
/** @return the application */
|
||||
public ConsoleTestApplication getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void waitAndStop() {
|
||||
writer.println(ConsoleTestApplication.EXIT);
|
||||
try {
|
||||
th.join();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,19 @@ public class ConsoleApplicationTest {
|
||||
|
||||
@Test
|
||||
public void executionTest() {
|
||||
try {
|
||||
CommandTestingApplication application = new CommandTestingApplication();
|
||||
|
||||
application.sendCommand("test");
|
||||
application.sendCommand("toto");
|
||||
application.sendCommand("long");
|
||||
application.sendCommand("exit");
|
||||
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
final PipedOutputStream src = new PipedOutputStream();
|
||||
InputStream in = new PipedInputStream(src);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright E. Bigeon (2015)
|
||||
* Copyright Bigeon Emmanuel (2014)
|
||||
*
|
||||
* emmanuel@bigeon.fr
|
||||
*
|
||||
* This software is a computer program whose purpose is to
|
||||
* provide a swt window for console applications.
|
||||
* 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,
|
||||
@@ -33,13 +33,20 @@
|
||||
* knowledge of the CeCILL license and that you accept its terms.
|
||||
*/
|
||||
/**
|
||||
* gclc-swt:fr.bigeon.gclc.swt.HistoryTextKeyListenerTest.java
|
||||
* Created on: Jun 9, 2016
|
||||
* gclc:fr.bigeon.gclc.command.ScriptExecutionTest.java
|
||||
* Created on: Jun 12, 2016
|
||||
*/
|
||||
package fr.bigeon.gclc.swt;
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import fr.bigeon.gclc.CommandTestingApplication;
|
||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
@@ -47,11 +54,31 @@ import org.junit.Test;
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
public class HistoryTextKeyListenerTest {
|
||||
public class ScriptExecutionTest {
|
||||
|
||||
/**
|
||||
* Test method for {@link fr.bigeon.gclc.command.ScriptExecution#execute(java.lang.String[])}.
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
public void testExecute() {
|
||||
try {
|
||||
CommandTestingApplication application = new CommandTestingApplication();
|
||||
|
||||
application.add(new ScriptExecution("script",
|
||||
application.getApplication(), "#"));
|
||||
|
||||
application.sendCommand("script src/test/resources/script1.txt");
|
||||
application.sendCommand("script src/test/resources/script2.txt");
|
||||
application.sendCommand("script src/test/resources/script3.txt");
|
||||
application.sendCommand("script src/test/resources/script4.txt");
|
||||
application
|
||||
.sendCommand("script src/test/resources/script5.txt test");
|
||||
|
||||
application.waitAndStop();
|
||||
|
||||
} catch (IOException | InvalidCommandName e) {
|
||||
fail("Unexpected exception");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
0
gclc/src/test/resources/script1.txt
Normal file
0
gclc/src/test/resources/script1.txt
Normal file
1
gclc/src/test/resources/script2.txt
Normal file
1
gclc/src/test/resources/script2.txt
Normal file
@@ -0,0 +1 @@
|
||||
# test only comment
|
||||
1
gclc/src/test/resources/script3.txt
Normal file
1
gclc/src/test/resources/script3.txt
Normal file
@@ -0,0 +1 @@
|
||||
test
|
||||
5
gclc/src/test/resources/script4.txt
Normal file
5
gclc/src/test/resources/script4.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# Test file with commands
|
||||
test
|
||||
# and comments
|
||||
long
|
||||
# interwined
|
||||
2
gclc/src/test/resources/script5.txt
Normal file
2
gclc/src/test/resources/script5.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
# A script with arguments
|
||||
{0}
|
||||
Reference in New Issue
Block a user