Skip to content

Commit

Permalink
pool: Fix command string output for migration commands
Browse files Browse the repository at this point in the history
Addresses the issue that 'migration move' and 'migration cache' commands
are shown as 'migration copy' commands in the output of 'migration ls',
'migration info' and when saved to the setup file.

Target: trunk
Request: 2.7
Request: 2.6
Require-notes: yes
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: http://rb.dcache.org/r/6278/
  • Loading branch information
gbehrmann committed Nov 25, 2013
1 parent c5ab9ad commit a6500bb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Expand Up @@ -65,7 +65,7 @@ public AnnotatedCommandExecutor(Object parent, Command command,
_parent = parent;
_command = command;
_constructor = constructor;
_handlers = createFieldHandlers(_constructor.getDeclaringClass());
_handlers = createFieldHandlers(command, _constructor.getDeclaringClass());
}

@Override
Expand Down Expand Up @@ -219,19 +219,19 @@ private static Handler createFieldHandler(Field field, Argument argument)
}
}

private static Handler createFieldHandler(Field field, CommandLine commandLine)
private static Handler createFieldHandler(Command command, Field field, CommandLine commandLine)
{
Class<?> type = field.getType();
if (type.isAssignableFrom(Args.class)) {
return new ArgsHandler(field);
} else if (type.isAssignableFrom(String.class)) {
return new CommandLineHandler(field);
return new CommandLineHandler(command, field);
} else {
throw new IllegalArgumentException("CommandLine annotation is only applicable to Args and String fields");
}
}

private static List<Handler> createFieldHandlers(Class<? extends Callable<?>> clazz)
private static List<Handler> createFieldHandlers(Command command, Class<? extends Callable<?>> clazz)
{
Set<String> names = new HashSet<>();

Expand All @@ -251,7 +251,7 @@ private static List<Handler> createFieldHandlers(Class<? extends Callable<?>> cl

CommandLine commandLine = field.getAnnotation(CommandLine.class);
if (commandLine != null) {
handlers.add(createFieldHandler(field, commandLine));
handlers.add(createFieldHandler(command, field, commandLine));
}
}
}
Expand Down Expand Up @@ -631,16 +631,16 @@ private static class CommandLineHandler extends FieldHandler
{
private final String command;

private CommandLineHandler(Field field)
private CommandLineHandler(Command command, Field field)
{
super(field);
command = field.getDeclaringClass().getAnnotation(Command.class).name();
this.command = command.name();
}

@Override
protected Object getValue(Args args)
{
return command + " " + args;
return (args.optc() == 0 && args.argc() == 0) ? command : (command + " " + args);
}

@Override
Expand Down
Expand Up @@ -651,4 +651,41 @@ class TestCommand extends AbstractCommand

_scanner.scan(new SUT());
}

@Test
public void shouldUseCommandOfSubClassWhenInjectingCommandLine() throws Exception
{
class SUT
{
@Command(name = "base")
class BaseCommand implements Callable<String>
{
@CommandLine
public String line;

@Override
public String call() throws Exception
{
assertThat(line, is("base"));
return null;
}
}

@Command(name = "test")
class TestCommand extends BaseCommand
{
@Override
public String call() throws Exception
{
assertThat(line, is("test"));
return null;
}
}
}

Map<List<String>,? extends CommandExecutor> commands =
_scanner.scan(new SUT());
commands.get(asList("base")).execute(new Args(""), CommandInterpreter.ASCII);
commands.get(asList("test")).execute(new Args(""), CommandInterpreter.ASCII);
}
}

0 comments on commit a6500bb

Please sign in to comment.