Compare commits
5 Commits
gclc-1.2.3
...
gclc-1.2.4
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bf1fa7c80 | |||
| 32e5f777fe | |||
| f8aeef14e3 | |||
| 763b7361ec | |||
| c151107207 |
@@ -87,7 +87,7 @@ of Emmanuel Bigeon. -->
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.2.2</version>
|
<version>1.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ public class ConsoleTestApplication extends ConsoleApplication {
|
|||||||
try {
|
try {
|
||||||
manager.println("Test command ran fine");
|
manager.println("Test command ran fine");
|
||||||
} catch (IOException e) {
|
} 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);
|
Thread.sleep(2000);
|
||||||
manager.println("Test command ran fine");
|
manager.println("Test command ran fine");
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
throw new CommandRunException("manager closed", e);
|
throw new CommandRunException("manager closed", e,
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.2.2</version>
|
<version>1.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class SWTConsoleShellTest {
|
|||||||
try {
|
try {
|
||||||
appl.getManager().prompt("Test");
|
appl.getManager().prompt("Test");
|
||||||
} catch (IOException e) {
|
} 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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.2.3</version>
|
<version>1.2.4</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<url>http://www.bigeon.fr/emmanuel</url>
|
<url>http://www.bigeon.fr/emmanuel</url>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -83,6 +83,6 @@
|
|||||||
<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-1.2.3</tag>
|
<tag>gclc-1.2.4</tag>
|
||||||
</scm>
|
</scm>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -84,9 +84,8 @@ public class ScriptExecution extends Command {
|
|||||||
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
throw new CommandRunException(CommandRunExceptionType.USAGE,
|
||||||
"Expecting a file", this); //$NON-NLS-1$
|
"Expecting a file", this); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
List<String> argsList = Arrays.asList(args);
|
String scriptFile = args[0];
|
||||||
String scriptFile = argsList.remove(0);
|
Object[] params = Arrays.copyOfRange(args, 1, args.length);
|
||||||
Object[] params = argsList.toArray();
|
|
||||||
try (FileReader fReader = new FileReader(new File(scriptFile));
|
try (FileReader fReader = new FileReader(new File(scriptFile));
|
||||||
BufferedReader reader = new BufferedReader(fReader)) {
|
BufferedReader reader = new BufferedReader(fReader)) {
|
||||||
String cmd;
|
String cmd;
|
||||||
|
|||||||
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
|
@Test
|
||||||
public void executionTest() {
|
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 {
|
try {
|
||||||
final PipedOutputStream src = new PipedOutputStream();
|
final PipedOutputStream src = new PipedOutputStream();
|
||||||
InputStream in = new PipedInputStream(src);
|
InputStream in = new PipedInputStream(src);
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.ScriptExecutionTest.java
|
||||||
|
* Created on: Jun 12, 2016
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ScriptExecutionTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link fr.bigeon.gclc.command.ScriptExecution#execute(java.lang.String[])}.
|
||||||
|
*/
|
||||||
|
@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