瀏覽代碼

svn merge -c 1090485 from trunk for HADOOP-7216.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/yahoo-merge@1126766 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 14 年之前
父節點
當前提交
0b15849e7b

+ 3 - 0
CHANGES.txt

@@ -40,6 +40,9 @@ Trunk (unreleased changes)
     HADOOP-7268. FileContext.getLocalFSFileContext() behavior needs to be 
     HADOOP-7268. FileContext.getLocalFSFileContext() behavior needs to be 
     fixed w.r.t tokens. (jitendra)
     fixed w.r.t tokens. (jitendra)
 
 
+    HADOOP-7216. Add FsCommand.runAll() with deprecated annotation for the
+    transition of Command base class improvement.  (Daryn Sharp via szetszwo)
+
 Release 0.22.0 - Unreleased
 Release 0.22.0 - Unreleased
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 2 - 4
src/java/org/apache/hadoop/fs/FsShell.java

@@ -1937,11 +1937,9 @@ public class FsShell extends Configured implements Tool {
       } else if ("-count".equals(cmd)) {
       } else if ("-count".equals(cmd)) {
         // TODO: next two lines are a temporary crutch until this entire
         // TODO: next two lines are a temporary crutch until this entire
         // block is overhauled
         // block is overhauled
-        LinkedList<String> args = new LinkedList<String>(Arrays.asList(argv));
-        String cmdName = args.removeFirst();
         Count runner = ReflectionUtils.newInstance(Count.class, getConf());
         Count runner = ReflectionUtils.newInstance(Count.class, getConf());
-        runner.setCommandName(cmdName); // TODO: will change with factory
-        exitCode = runner.run(args);
+        runner.setCommandName(cmd); // TODO: will change with factory
+        exitCode = runner.run(Arrays.copyOfRange(argv, 1, argv.length));
       } else if ("-mkdir".equals(cmd)) {
       } else if ("-mkdir".equals(cmd)) {
         exitCode = doall(cmd, argv, i);
         exitCode = doall(cmd, argv, i);
       } else if ("-touchz".equals(cmd)) {
       } else if ("-touchz".equals(cmd)) {

+ 4 - 2
src/java/org/apache/hadoop/fs/shell/Command.java

@@ -21,6 +21,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.List;
 
 
@@ -124,11 +125,12 @@ abstract public class Command extends Configured {
    * Most commands will chose to implement just
    * Most commands will chose to implement just
    * {@link #processOptions(LinkedList)} and {@link #processPath(PathData)}
    * {@link #processOptions(LinkedList)} and {@link #processPath(PathData)}
    * 
    * 
-   * @param args the list of command line arguments
+   * @param argv the list of command line arguments
    * @return the exit code for the command
    * @return the exit code for the command
    * @throws IllegalArgumentException if called with invalid arguments
    * @throws IllegalArgumentException if called with invalid arguments
    */
    */
-  public int run(LinkedList<String> args) {
+  public int run(String...argv) {
+    LinkedList<String> args = new LinkedList<String>(Arrays.asList(argv));
     try {
     try {
       processOptions(args);
       processOptions(args);
       processArguments(expandArguments(args));
       processArguments(expandArguments(args));

+ 1 - 4
src/java/org/apache/hadoop/fs/shell/Count.java

@@ -60,10 +60,7 @@ public class Count extends FsCommand {
   public Count(String[] cmd, int pos, Configuration conf) {
   public Count(String[] cmd, int pos, Configuration conf) {
     super(conf);
     super(conf);
     setCommandName(NAME);
     setCommandName(NAME);
-    LinkedList<String> parameters = new LinkedList<String>(Arrays.asList(cmd));
-    parameters.subList(0, pos).clear();
-    processOptions(parameters);
-    this.args = parameters.toArray(new String[0]);
+    this.args = Arrays.copyOfRange(cmd, pos, cmd.length);
   }
   }
 
 
   @Override
   @Override

+ 9 - 0
src/java/org/apache/hadoop/fs/shell/FsCommand.java

@@ -47,7 +47,16 @@ abstract public class FsCommand extends Command {
     return name.startsWith("-") ? name.substring(1) : name; 
     return name.startsWith("-") ? name.substring(1) : name; 
   }
   }
   
   
+  // abstract method that normally is invoked by runall() which is
+  // overridden below
   protected void run(Path path) throws IOException {
   protected void run(Path path) throws IOException {
     throw new RuntimeException("not supposed to get here");
     throw new RuntimeException("not supposed to get here");
   }
   }
+  
+  /** @deprecated use {@link #run(String...argv)} */
+  @Deprecated
+  @Override
+  public int runAll() {
+    return run(args);
+  }
 }
 }