Compare commits

..

10 Commits

Author SHA1 Message Date
70a71c06a7 [maven-release-plugin] prepare release gclc-1.2.5 2016-06-20 20:12:50 -04:00
a0202de532 Removed faulty test class
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-06-20 20:11:35 -04:00
caa00f2a61 Order of commands preserved in command provider implementation
Minor correction in the CLIPrompter to avoid null pointer exception when
cancel on promptChoice

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
2016-06-13 15:49:05 -04:00
eed6f43aea Fixed error message for SubedCommand run exceptions 2016-06-12 23:02:03 -04:00
59ab689a36 [maven-release-plugin] prepare for next development iteration 2016-06-12 22:39:43 -04:00
2bf1fa7c80 [maven-release-plugin] prepare release gclc-1.2.4 2016-06-12 22:39:36 -04:00
32e5f777fe licensing 2016-06-12 22:38:53 -04:00
f8aeef14e3 Corrected ScriptExecution and added tests 2016-06-12 22:36:09 -04:00
763b7361ec Update gclc-swt and -socket for gclc-1.2.3 2016-06-12 16:11:44 -04:00
c151107207 [maven-release-plugin] prepare for next development iteration 2016-06-12 16:08:19 -04:00
17 changed files with 200 additions and 25 deletions

View File

@@ -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>

View File

@@ -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);
}
}
});

View File

@@ -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>

View File

@@ -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);
}
}
});

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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);
}

View File

@@ -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

View 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();
}
}
}

View File

@@ -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);

View File

@@ -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");
}
}
}

View File

View File

@@ -0,0 +1 @@
# test only comment

View File

@@ -0,0 +1 @@
test

View File

@@ -0,0 +1,5 @@
# Test file with commands
test
# and comments
long
# interwined

View File

@@ -0,0 +1,2 @@
# A script with arguments
{0}