Removed deprecation, comments. Update major version
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
6a0e68d312
commit
e11d90378f
@ -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.4.1-SNAPSHOT</version>
|
||||
<version>1.5.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.bigeon.fr/emmanuel</url>
|
||||
<properties>
|
||||
|
@ -39,6 +39,7 @@
|
||||
package fr.bigeon.gclc.command;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -103,37 +104,6 @@ public abstract class ParametrizedCommand extends Command {
|
||||
this(null, name, strict);
|
||||
}
|
||||
|
||||
/** <p>
|
||||
* Add a parameter to the defined parameters
|
||||
*
|
||||
* @param param the parameter identification
|
||||
* @param stringParameter if the parameter is a parameter with an argument
|
||||
* @param needed if the parameter is required
|
||||
* @throws InvalidParameterException if the parameter was invalid
|
||||
* @deprecated since gclc-1.3.3, use the
|
||||
* {@link #addStringParameter(String, boolean)} and
|
||||
* {@link #addBooleanParameter(String)} */
|
||||
@Deprecated
|
||||
protected void addParameter(String param, boolean stringParameter,
|
||||
boolean needed) throws InvalidParameterException {
|
||||
if (params.containsKey(param)) {
|
||||
checkParam(param, stringParameter, needed);
|
||||
return;
|
||||
}
|
||||
if (stringParameter) {
|
||||
stringParams.put(param, Boolean.valueOf(needed));
|
||||
params.put(param, Boolean.valueOf(needed));
|
||||
} else {
|
||||
if (needed) {
|
||||
// ERROR the boolean parameters cannot be needed
|
||||
throw new InvalidParameterException(
|
||||
"Boolean parameter are present by their very nature. They should not be defined as needed"); //$NON-NLS-1$
|
||||
}
|
||||
boolParams.add(param);
|
||||
params.put(param, Boolean.valueOf(false));
|
||||
}
|
||||
}
|
||||
|
||||
/** Add a boolean parameter to defined parmaters.
|
||||
*
|
||||
* @param flag the boolean flag
|
||||
@ -164,31 +134,6 @@ public abstract class ParametrizedCommand extends Command {
|
||||
params.put(flag, Boolean.valueOf(needed));
|
||||
}
|
||||
|
||||
/** @param param the parameter
|
||||
* @param stringParameter the string parameter type
|
||||
* @param needed if the parameter is needed
|
||||
* @throws InvalidParameterException if the new definition is invalid
|
||||
* @deprecated since 1.3.3 */
|
||||
@Deprecated
|
||||
private void checkParam(String param, boolean stringParameter,
|
||||
boolean needed) throws InvalidParameterException {
|
||||
if (stringParameter) {
|
||||
if (stringParams.containsKey(param)) {
|
||||
Boolean need = Boolean.valueOf(
|
||||
needed || stringParams.get(param).booleanValue());
|
||||
stringParams.put(param, need);
|
||||
params.put(param, need);
|
||||
return;
|
||||
}
|
||||
throw new InvalidParameterException(
|
||||
"Parameter is already defined as boolean"); //$NON-NLS-1$
|
||||
}
|
||||
if (stringParams.containsKey(param) || needed) {
|
||||
throw new InvalidParameterException(
|
||||
"Parameter is already defined as string"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/** @param param the string parameter
|
||||
* @param needed if the parameter is needed
|
||||
* @throws InvalidParameterException if the new definition is invalid */
|
||||
@ -247,10 +192,13 @@ public abstract class ParametrizedCommand extends Command {
|
||||
for (final String string : toProvide) {
|
||||
String value;
|
||||
try {
|
||||
value = manager.prompt("value of " + string + "? ");
|
||||
value = manager
|
||||
.prompt(MessageFormat.format("value of {0}? ", string)); //$NON-NLS-1$
|
||||
while (value.isEmpty()) {
|
||||
value = manager.prompt(
|
||||
"value of " + string + "? (cannot be empty) ");
|
||||
MessageFormat.format(
|
||||
"value of {0}? (cannot be empty) ", //$NON-NLS-1$
|
||||
string));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
|
@ -210,6 +210,9 @@ public class ReadingRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/** @param timeout the read time out
|
||||
* @return The next message that was in the input
|
||||
* @throws IOException if the input was closed */
|
||||
public String getNextMessage(long timeout) throws IOException {
|
||||
synchronized (lock) {
|
||||
if (!running) {
|
||||
|
@ -38,13 +38,10 @@
|
||||
*/
|
||||
package fr.bigeon.gclc.proc;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
/** A listener for interruption
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public interface InterruptionListener {
|
||||
/** Notification of an interuption of a listened object */
|
||||
void interrupted();
|
||||
}
|
||||
|
@ -41,14 +41,11 @@ package fr.bigeon.gclc.proc;
|
||||
import fr.bigeon.gclc.command.Command;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
/** A command that will flag a task to stop
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ProcessKill extends Command {
|
||||
/** The taskpool */
|
||||
private final TaskPool pool;
|
||||
|
||||
/** @param name the command name
|
||||
@ -69,9 +66,10 @@ public class ProcessKill extends Command {
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip()
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String tip() {
|
||||
return "List all processes";
|
||||
return "Request a process to stop (softly)";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
package fr.bigeon.gclc.proc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@ -47,16 +48,14 @@ import fr.bigeon.gclc.exception.CommandRunException;
|
||||
import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
/** A command to list current processes
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ProcessList extends Command {
|
||||
/** The process pool */
|
||||
private final TaskPool pool;
|
||||
|
||||
/** the interaction object */
|
||||
private final ConsoleManager manager;
|
||||
|
||||
/** @param name the command name
|
||||
@ -78,13 +77,13 @@ public class ProcessList extends Command {
|
||||
Collections.sort(pids);
|
||||
for (String string : pids) {
|
||||
try {
|
||||
// XXX Format?
|
||||
manager.println(
|
||||
string + "\t" + pool.get(string).getName());
|
||||
MessageFormat.format("{0}\t{1}", string, //$NON-NLS-1$
|
||||
pool.get(string).getName()));
|
||||
} catch (IOException e) {
|
||||
throw new CommandRunException(
|
||||
CommandRunExceptionType.INTERACTION,
|
||||
"Unable to communicate with user", e, this);
|
||||
"Unable to communicate with user", e, this); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,6 +92,7 @@ public class ProcessList extends Command {
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip()
|
||||
*/
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String tip() {
|
||||
return "List all processes";
|
||||
|
@ -43,15 +43,20 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
/** <p>
|
||||
* TODO
|
||||
/** A process pool
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
public class TaskPool {
|
||||
/** The running processes */
|
||||
private final Map<String, Task> running = new HashMap<>();
|
||||
/** The count for process id */
|
||||
private int count = 0;
|
||||
/** The lock for pid attribution synchronization */
|
||||
private final Object lock = new Object();
|
||||
|
||||
/** Add a process in the pool
|
||||
*
|
||||
* @param cmd the process */
|
||||
public void add(final Task cmd) {
|
||||
final String pid = getPID();
|
||||
synchronized (lock) {
|
||||
@ -59,6 +64,7 @@ public class TaskPool {
|
||||
}
|
||||
cmd.addInterruptionListener(new InterruptionListener() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void interrupted() {
|
||||
synchronized (lock) {
|
||||
@ -81,6 +87,10 @@ public class TaskPool {
|
||||
}
|
||||
}
|
||||
|
||||
/** Get a process by it associated identifier
|
||||
*
|
||||
* @param pid the task id
|
||||
* @return the task, if any, associated to this id */
|
||||
public Task get(String pid) {
|
||||
synchronized (lock) {
|
||||
return running.get(pid);
|
||||
|
@ -41,14 +41,11 @@ package fr.bigeon.gclc.proc;
|
||||
import fr.bigeon.gclc.command.Command;
|
||||
import fr.bigeon.gclc.exception.CommandRunException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TODO
|
||||
/** An abstract command to generate a task and return the control to the user
|
||||
*
|
||||
* @author Emmanuel Bigeon
|
||||
*
|
||||
*/
|
||||
* @author Emmanuel Bigeon */
|
||||
public abstract class TaskSpawner extends Command {
|
||||
/** The process pool */
|
||||
private final TaskPool pool;
|
||||
|
||||
/** @param name the command name
|
||||
@ -69,6 +66,7 @@ public abstract class TaskSpawner extends Command {
|
||||
pool.add(task);
|
||||
}
|
||||
|
||||
/** @param args the arguments */
|
||||
/** @param args the arguments
|
||||
* @return the process to start and add to the pool */
|
||||
protected abstract Task createTask(String... args);
|
||||
}
|
||||
|
@ -196,32 +196,25 @@ public class ParametrizedCommandTest {
|
||||
};
|
||||
// XXX Boolean flag should not be specified mandatory! They are by
|
||||
// nature qualified
|
||||
try {
|
||||
cmd.addParameter("boolFlag", false, true);
|
||||
fail("Boolean parameters should never be needed specified");
|
||||
} catch (InvalidParameterException e) {
|
||||
// OK
|
||||
assertNotNull(e);
|
||||
}
|
||||
String str = "str";
|
||||
try {
|
||||
assertTrue(cmd.getBooleanParameters().isEmpty());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addParameter("boolFlag", false, false);
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertTrue(cmd.getStringParameters().isEmpty());
|
||||
cmd.addParameter(str, true, false);
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertFalse(cmd.isNeeded(str));
|
||||
cmd.addParameter("boolFlag", false, false);
|
||||
cmd.addBooleanParameter("boolFlag");
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
cmd.addParameter(str, true, true);
|
||||
cmd.addStringParameter(str, true);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
cmd.addParameter(str, true, false);
|
||||
cmd.addStringParameter(str, false);
|
||||
assertEquals(1, cmd.getBooleanParameters().size());
|
||||
assertEquals(1, cmd.getStringParameters().size());
|
||||
assertTrue(cmd.isNeeded(str));
|
||||
@ -229,34 +222,6 @@ public class ParametrizedCommandTest {
|
||||
fail("Unexpected error in addition of legitimate parameter");
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.addParameter(str, false, false);
|
||||
fail("parameter type conversion shall fail");
|
||||
} catch (InvalidParameterException e) {
|
||||
// OK
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.addParameter("boolFlag", true, false);
|
||||
fail("parameter type conversion shall fail");
|
||||
} catch (InvalidParameterException e) {
|
||||
// OK
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.addParameter("boolFlag", false, true);
|
||||
fail("parameter type conversion shall fail");
|
||||
} catch (InvalidParameterException e) {
|
||||
// OK
|
||||
assertNotNull(e);
|
||||
}
|
||||
try {
|
||||
cmd.addParameter("boolFlag", true, true);
|
||||
fail("parameter type conversion shall fail");
|
||||
} catch (InvalidParameterException e) {
|
||||
// OK
|
||||
assertNotNull(e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Test method for
|
||||
@ -306,10 +271,10 @@ public class ParametrizedCommandTest {
|
||||
{
|
||||
|
||||
try {
|
||||
addParameter(str1, true, false);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, false);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -371,10 +336,10 @@ public class ParametrizedCommandTest {
|
||||
{
|
||||
|
||||
try {
|
||||
addParameter(str1, true, false);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, false);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -443,10 +408,10 @@ public class ParametrizedCommandTest {
|
||||
{
|
||||
|
||||
try {
|
||||
addParameter(str1, true, true);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, true);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -484,10 +449,10 @@ public class ParametrizedCommandTest {
|
||||
{
|
||||
|
||||
try {
|
||||
addParameter(str1, true, true);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, true);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -541,10 +506,10 @@ public class ParametrizedCommandTest {
|
||||
cmd = new ParametrizedCommand(test, "name", false) {
|
||||
{
|
||||
try {
|
||||
addParameter(str1, true, true);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, true);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -631,10 +596,10 @@ public class ParametrizedCommandTest {
|
||||
cmd = new ParametrizedCommand(test, "name") {
|
||||
{
|
||||
try {
|
||||
addParameter(str1, true, true);
|
||||
addParameter(str2, true, false);
|
||||
addParameter(bool1, false, false);
|
||||
addParameter(bool2, false, false);
|
||||
addStringParameter(str1, true);
|
||||
addStringParameter(str2, false);
|
||||
addBooleanParameter(bool1);
|
||||
addBooleanParameter(bool2);
|
||||
} catch (InvalidParameterException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user