HDFS-3834. Remove unused static fields NAME, DESCRIPTION and Usage from Command. Contributed by Jing Zhao.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1377001 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Suresh Srinivas 2012-08-24 17:36:22 +00:00
parent cffee556e4
commit 7a1dc1ab70
3 changed files with 32 additions and 10 deletions

View File

@ -44,12 +44,12 @@ import org.apache.hadoop.util.StringUtils;
@InterfaceStability.Evolving
abstract public class Command extends Configured {
/** default name of the command */
public static String NAME;
/** the command's usage switches and arguments format */
public static String USAGE;
/** the command's long description */
public static String DESCRIPTION;
/** field name indicating the default name of the command */
public static final String COMMAND_NAME_FIELD = "NAME";
/** field name indicating the command's usage switches and arguments format */
public static final String COMMAND_USAGE_FIELD = "USAGE";
/** field name indicating the command's long description */
public static final String COMMAND_DESCRIPTION_FIELD = "DESCRIPTION";
protected String[] args;
protected String name;
@ -397,7 +397,7 @@ abstract public class Command extends Configured {
*/
public String getName() {
return (name == null)
? getCommandField("NAME")
? getCommandField(COMMAND_NAME_FIELD)
: name.startsWith("-") ? name.substring(1) : name;
}
@ -415,7 +415,7 @@ abstract public class Command extends Configured {
*/
public String getUsage() {
String cmd = "-" + getName();
String usage = isDeprecated() ? "" : getCommandField("USAGE");
String usage = isDeprecated() ? "" : getCommandField(COMMAND_USAGE_FIELD);
return usage.isEmpty() ? cmd : cmd + " " + usage;
}
@ -426,7 +426,7 @@ abstract public class Command extends Configured {
public String getDescription() {
return isDeprecated()
? "(DEPRECATED) Same as '" + getReplacementCommand() + "'"
: getCommandField("DESCRIPTION");
: getCommandField(COMMAND_DESCRIPTION_FIELD);
}
/**

View File

@ -48,6 +48,10 @@ public class TestCommandFactory {
factory.addClass(TestCommand3.class, "tc3");
names = factory.getNames();
assertArrayEquals(new String []{"tc1", "tc2", "tc2.1", "tc3"}, names);
factory.addClass(TestCommand4.class, (new TestCommand4()).getName());
names = factory.getNames();
assertArrayEquals(new String[]{"tc1", "tc2", "tc2.1", "tc3", "tc4"}, names);
}
@Test
@ -72,8 +76,17 @@ public class TestCommandFactory {
assertNotNull(instance);
assertEquals(TestCommand2.class, instance.getClass());
assertEquals("tc2.1", instance.getCommandName());
factory.addClass(TestCommand4.class, "tc4");
instance = factory.getInstance("tc4");
assertNotNull(instance);
assertEquals(TestCommand4.class, instance.getClass());
assertEquals("tc4", instance.getCommandName());
String usage = instance.getUsage();
assertEquals("-tc4 tc4_usage", usage);
assertEquals("tc4_description", instance.getDescription());
}
static class TestRegistrar {
public static void registerCommands(CommandFactory factory) {
factory.addClass(TestCommand1.class, "tc1");
@ -84,4 +97,10 @@ public class TestCommandFactory {
static class TestCommand1 extends FsCommand {}
static class TestCommand2 extends FsCommand {}
static class TestCommand3 extends FsCommand {}
static class TestCommand4 extends FsCommand {
static final String NAME = "tc4";
static final String USAGE = "tc4_usage";
static final String DESCRIPTION = "tc4_description";
}
}

View File

@ -200,6 +200,9 @@ Trunk (unreleased changes)
HDFS-3827. TestHASafeMode#assertSafemode method should be made static.
(Jing Zhao via suresh)
HDFS-3834. Remove unused static fields NAME, DESCRIPTION and Usage from
Command. (Jing Zhao via suresh)
Branch-2 ( Unreleased changes )
INCOMPATIBLE CHANGES