From 7a1dc1ab70b066ee85bc50ef1e5e237ef5d36ca0 Mon Sep 17 00:00:00 2001 From: Suresh Srinivas Date: Fri, 24 Aug 2012 17:36:22 +0000 Subject: [PATCH] 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 --- .../org/apache/hadoop/fs/shell/Command.java | 18 ++++++++-------- .../hadoop/fs/shell/TestCommandFactory.java | 21 ++++++++++++++++++- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java index f3f32fcc309..8638e85cd57 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Command.java @@ -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); } /** diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCommandFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCommandFactory.java index ccface37718..db7fc2488c8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCommandFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestCommandFactory.java @@ -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"; + } } \ No newline at end of file diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index a89eb51c32a..3cd3efa3bf5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -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