Removed deprecation, comments. Update major version

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2017-08-19 15:25:31 -04:00
parent 6a0e68d312
commit e11d90378f
9 changed files with 73 additions and 154 deletions

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"> <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.4.1-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<url>http://www.bigeon.fr/emmanuel</url> <url>http://www.bigeon.fr/emmanuel</url>
<properties> <properties>

View File

@ -39,6 +39,7 @@
package fr.bigeon.gclc.command; package fr.bigeon.gclc.command;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -103,37 +104,6 @@ public abstract class ParametrizedCommand extends Command {
this(null, name, strict); 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. /** Add a boolean parameter to defined parmaters.
* *
* @param flag the boolean flag * @param flag the boolean flag
@ -164,31 +134,6 @@ public abstract class ParametrizedCommand extends Command {
params.put(flag, Boolean.valueOf(needed)); 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 param the string parameter
* @param needed if the parameter is needed * @param needed if the parameter is needed
* @throws InvalidParameterException if the new definition is invalid */ * @throws InvalidParameterException if the new definition is invalid */
@ -247,10 +192,13 @@ public abstract class ParametrizedCommand extends Command {
for (final String string : toProvide) { for (final String string : toProvide) {
String value; String value;
try { try {
value = manager.prompt("value of " + string + "? "); value = manager
.prompt(MessageFormat.format("value of {0}? ", string)); //$NON-NLS-1$
while (value.isEmpty()) { while (value.isEmpty()) {
value = manager.prompt( value = manager.prompt(
"value of " + string + "? (cannot be empty) "); MessageFormat.format(
"value of {0}? (cannot be empty) ", //$NON-NLS-1$
string));
} }
} catch (IOException e) { } catch (IOException e) {
throw new CommandRunException( throw new CommandRunException(

View File

@ -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 { public String getNextMessage(long timeout) throws IOException {
synchronized (lock) { synchronized (lock) {
if (!running) { if (!running) {

View File

@ -38,13 +38,10 @@
*/ */
package fr.bigeon.gclc.proc; package fr.bigeon.gclc.proc;
/** /** A listener for interruption
* <p>
* TODO
* *
* @author Emmanuel Bigeon * @author Emmanuel Bigeon */
*
*/
public interface InterruptionListener { public interface InterruptionListener {
/** Notification of an interuption of a listened object */
void interrupted(); void interrupted();
} }

View File

@ -41,14 +41,11 @@ package fr.bigeon.gclc.proc;
import fr.bigeon.gclc.command.Command; import fr.bigeon.gclc.command.Command;
import fr.bigeon.gclc.exception.CommandRunException; import fr.bigeon.gclc.exception.CommandRunException;
/** /** A command that will flag a task to stop
* <p>
* TODO
* *
* @author Emmanuel Bigeon * @author Emmanuel Bigeon */
*
*/
public class ProcessKill extends Command { public class ProcessKill extends Command {
/** The taskpool */
private final TaskPool pool; private final TaskPool pool;
/** @param name the command name /** @param name the command name
@ -69,9 +66,10 @@ public class ProcessKill extends Command {
/* (non-Javadoc) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() * @see fr.bigeon.gclc.command.ICommand#tip()
*/ */
@SuppressWarnings("nls")
@Override @Override
public String tip() { public String tip() {
return "List all processes"; return "Request a process to stop (softly)";
} }
} }

View File

@ -39,6 +39,7 @@
package fr.bigeon.gclc.proc; package fr.bigeon.gclc.proc;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -47,16 +48,14 @@ import fr.bigeon.gclc.exception.CommandRunException;
import fr.bigeon.gclc.exception.CommandRunExceptionType; import fr.bigeon.gclc.exception.CommandRunExceptionType;
import fr.bigeon.gclc.manager.ConsoleManager; import fr.bigeon.gclc.manager.ConsoleManager;
/** /** A command to list current processes
* <p>
* TODO
* *
* @author Emmanuel Bigeon * @author Emmanuel Bigeon */
*
*/
public class ProcessList extends Command { public class ProcessList extends Command {
/** The process pool */
private final TaskPool pool; private final TaskPool pool;
/** the interaction object */
private final ConsoleManager manager; private final ConsoleManager manager;
/** @param name the command name /** @param name the command name
@ -78,13 +77,13 @@ public class ProcessList extends Command {
Collections.sort(pids); Collections.sort(pids);
for (String string : pids) { for (String string : pids) {
try { try {
// XXX Format?
manager.println( manager.println(
string + "\t" + pool.get(string).getName()); MessageFormat.format("{0}\t{1}", string, //$NON-NLS-1$
pool.get(string).getName()));
} catch (IOException e) { } catch (IOException e) {
throw new CommandRunException( throw new CommandRunException(
CommandRunExceptionType.INTERACTION, 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) /* (non-Javadoc)
* @see fr.bigeon.gclc.command.ICommand#tip() * @see fr.bigeon.gclc.command.ICommand#tip()
*/ */
@SuppressWarnings("nls")
@Override @Override
public String tip() { public String tip() {
return "List all processes"; return "List all processes";

View File

@ -43,15 +43,20 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
/** <p> /** A process pool
* TODO
* *
* @author Emmanuel Bigeon */ * @author Emmanuel Bigeon */
public class TaskPool { public class TaskPool {
/** The running processes */
private final Map<String, Task> running = new HashMap<>(); private final Map<String, Task> running = new HashMap<>();
/** The count for process id */
private int count = 0; private int count = 0;
/** The lock for pid attribution synchronization */
private final Object lock = new Object(); private final Object lock = new Object();
/** Add a process in the pool
*
* @param cmd the process */
public void add(final Task cmd) { public void add(final Task cmd) {
final String pid = getPID(); final String pid = getPID();
synchronized (lock) { synchronized (lock) {
@ -59,6 +64,7 @@ public class TaskPool {
} }
cmd.addInterruptionListener(new InterruptionListener() { cmd.addInterruptionListener(new InterruptionListener() {
@SuppressWarnings("synthetic-access")
@Override @Override
public void interrupted() { public void interrupted() {
synchronized (lock) { 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) { public Task get(String pid) {
synchronized (lock) { synchronized (lock) {
return running.get(pid); return running.get(pid);

View File

@ -41,14 +41,11 @@ package fr.bigeon.gclc.proc;
import fr.bigeon.gclc.command.Command; import fr.bigeon.gclc.command.Command;
import fr.bigeon.gclc.exception.CommandRunException; import fr.bigeon.gclc.exception.CommandRunException;
/** /** An abstract command to generate a task and return the control to the user
* <p>
* TODO
* *
* @author Emmanuel Bigeon * @author Emmanuel Bigeon */
*
*/
public abstract class TaskSpawner extends Command { public abstract class TaskSpawner extends Command {
/** The process pool */
private final TaskPool pool; private final TaskPool pool;
/** @param name the command name /** @param name the command name
@ -69,6 +66,7 @@ public abstract class TaskSpawner extends Command {
pool.add(task); 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); protected abstract Task createTask(String... args);
} }

View File

@ -196,32 +196,25 @@ public class ParametrizedCommandTest {
}; };
// XXX Boolean flag should not be specified mandatory! They are by // XXX Boolean flag should not be specified mandatory! They are by
// nature qualified // 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"; String str = "str";
try { try {
assertTrue(cmd.getBooleanParameters().isEmpty()); assertTrue(cmd.getBooleanParameters().isEmpty());
assertTrue(cmd.getStringParameters().isEmpty()); assertTrue(cmd.getStringParameters().isEmpty());
cmd.addParameter("boolFlag", false, false); cmd.addBooleanParameter("boolFlag");
assertEquals(1, cmd.getBooleanParameters().size()); assertEquals(1, cmd.getBooleanParameters().size());
assertTrue(cmd.getStringParameters().isEmpty()); assertTrue(cmd.getStringParameters().isEmpty());
cmd.addParameter(str, true, false); cmd.addStringParameter(str, false);
assertEquals(1, cmd.getBooleanParameters().size()); assertEquals(1, cmd.getBooleanParameters().size());
assertEquals(1, cmd.getStringParameters().size()); assertEquals(1, cmd.getStringParameters().size());
assertFalse(cmd.isNeeded(str)); assertFalse(cmd.isNeeded(str));
cmd.addParameter("boolFlag", false, false); cmd.addBooleanParameter("boolFlag");
assertEquals(1, cmd.getBooleanParameters().size()); assertEquals(1, cmd.getBooleanParameters().size());
assertEquals(1, cmd.getStringParameters().size()); assertEquals(1, cmd.getStringParameters().size());
cmd.addParameter(str, true, true); cmd.addStringParameter(str, true);
assertEquals(1, cmd.getBooleanParameters().size()); assertEquals(1, cmd.getBooleanParameters().size());
assertEquals(1, cmd.getStringParameters().size()); assertEquals(1, cmd.getStringParameters().size());
assertTrue(cmd.isNeeded(str)); assertTrue(cmd.isNeeded(str));
cmd.addParameter(str, true, false); cmd.addStringParameter(str, false);
assertEquals(1, cmd.getBooleanParameters().size()); assertEquals(1, cmd.getBooleanParameters().size());
assertEquals(1, cmd.getStringParameters().size()); assertEquals(1, cmd.getStringParameters().size());
assertTrue(cmd.isNeeded(str)); assertTrue(cmd.isNeeded(str));
@ -229,34 +222,6 @@ public class ParametrizedCommandTest {
fail("Unexpected error in addition of legitimate parameter"); fail("Unexpected error in addition of legitimate parameter");
assertNotNull(e); 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 /** Test method for
@ -306,10 +271,10 @@ public class ParametrizedCommandTest {
{ {
try { try {
addParameter(str1, true, false); addStringParameter(str1, false);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -371,10 +336,10 @@ public class ParametrizedCommandTest {
{ {
try { try {
addParameter(str1, true, false); addStringParameter(str1, false);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -443,10 +408,10 @@ public class ParametrizedCommandTest {
{ {
try { try {
addParameter(str1, true, true); addStringParameter(str1, true);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -484,10 +449,10 @@ public class ParametrizedCommandTest {
{ {
try { try {
addParameter(str1, true, true); addStringParameter(str1, true);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -541,10 +506,10 @@ public class ParametrizedCommandTest {
cmd = new ParametrizedCommand(test, "name", false) { cmd = new ParametrizedCommand(test, "name", false) {
{ {
try { try {
addParameter(str1, true, true); addStringParameter(str1, true);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -631,10 +596,10 @@ public class ParametrizedCommandTest {
cmd = new ParametrizedCommand(test, "name") { cmd = new ParametrizedCommand(test, "name") {
{ {
try { try {
addParameter(str1, true, true); addStringParameter(str1, true);
addParameter(str2, true, false); addStringParameter(str2, false);
addParameter(bool1, false, false); addBooleanParameter(bool1);
addParameter(bool2, false, false); addBooleanParameter(bool2);
} catch (InvalidParameterException e) { } catch (InvalidParameterException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();