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:
parent
cffee556e4
commit
7a1dc1ab70
|
@ -44,12 +44,12 @@ import org.apache.hadoop.util.StringUtils;
|
||||||
@InterfaceStability.Evolving
|
@InterfaceStability.Evolving
|
||||||
|
|
||||||
abstract public class Command extends Configured {
|
abstract public class Command extends Configured {
|
||||||
/** default name of the command */
|
/** field name indicating the default name of the command */
|
||||||
public static String NAME;
|
public static final String COMMAND_NAME_FIELD = "NAME";
|
||||||
/** the command's usage switches and arguments format */
|
/** field name indicating the command's usage switches and arguments format */
|
||||||
public static String USAGE;
|
public static final String COMMAND_USAGE_FIELD = "USAGE";
|
||||||
/** the command's long description */
|
/** field name indicating the command's long description */
|
||||||
public static String DESCRIPTION;
|
public static final String COMMAND_DESCRIPTION_FIELD = "DESCRIPTION";
|
||||||
|
|
||||||
protected String[] args;
|
protected String[] args;
|
||||||
protected String name;
|
protected String name;
|
||||||
|
@ -397,7 +397,7 @@ abstract public class Command extends Configured {
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return (name == null)
|
return (name == null)
|
||||||
? getCommandField("NAME")
|
? getCommandField(COMMAND_NAME_FIELD)
|
||||||
: name.startsWith("-") ? name.substring(1) : name;
|
: name.startsWith("-") ? name.substring(1) : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ abstract public class Command extends Configured {
|
||||||
*/
|
*/
|
||||||
public String getUsage() {
|
public String getUsage() {
|
||||||
String cmd = "-" + getName();
|
String cmd = "-" + getName();
|
||||||
String usage = isDeprecated() ? "" : getCommandField("USAGE");
|
String usage = isDeprecated() ? "" : getCommandField(COMMAND_USAGE_FIELD);
|
||||||
return usage.isEmpty() ? cmd : cmd + " " + usage;
|
return usage.isEmpty() ? cmd : cmd + " " + usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ abstract public class Command extends Configured {
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return isDeprecated()
|
return isDeprecated()
|
||||||
? "(DEPRECATED) Same as '" + getReplacementCommand() + "'"
|
? "(DEPRECATED) Same as '" + getReplacementCommand() + "'"
|
||||||
: getCommandField("DESCRIPTION");
|
: getCommandField(COMMAND_DESCRIPTION_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,6 +48,10 @@ public class TestCommandFactory {
|
||||||
factory.addClass(TestCommand3.class, "tc3");
|
factory.addClass(TestCommand3.class, "tc3");
|
||||||
names = factory.getNames();
|
names = factory.getNames();
|
||||||
assertArrayEquals(new String []{"tc1", "tc2", "tc2.1", "tc3"}, names);
|
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
|
@Test
|
||||||
|
@ -72,6 +76,15 @@ public class TestCommandFactory {
|
||||||
assertNotNull(instance);
|
assertNotNull(instance);
|
||||||
assertEquals(TestCommand2.class, instance.getClass());
|
assertEquals(TestCommand2.class, instance.getClass());
|
||||||
assertEquals("tc2.1", instance.getCommandName());
|
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 {
|
static class TestRegistrar {
|
||||||
|
@ -84,4 +97,10 @@ public class TestCommandFactory {
|
||||||
static class TestCommand1 extends FsCommand {}
|
static class TestCommand1 extends FsCommand {}
|
||||||
static class TestCommand2 extends FsCommand {}
|
static class TestCommand2 extends FsCommand {}
|
||||||
static class TestCommand3 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";
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -200,6 +200,9 @@ Trunk (unreleased changes)
|
||||||
HDFS-3827. TestHASafeMode#assertSafemode method should be made static.
|
HDFS-3827. TestHASafeMode#assertSafemode method should be made static.
|
||||||
(Jing Zhao via suresh)
|
(Jing Zhao via suresh)
|
||||||
|
|
||||||
|
HDFS-3834. Remove unused static fields NAME, DESCRIPTION and Usage from
|
||||||
|
Command. (Jing Zhao via suresh)
|
||||||
|
|
||||||
Branch-2 ( Unreleased changes )
|
Branch-2 ( Unreleased changes )
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
Loading…
Reference in New Issue