diff --git a/CHANGES.txt b/CHANGES.txt index dbf8af17582..f9edb530f75 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -130,6 +130,9 @@ Trunk (unreleased changes) HADOOP-7019. Refactor build targets to enable faster cross project dev cycles. (Luke Lu via cos) + 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 INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/fs/FsShell.java b/src/java/org/apache/hadoop/fs/FsShell.java index c1e02b5ddaf..1734103ec0a 100644 --- a/src/java/org/apache/hadoop/fs/FsShell.java +++ b/src/java/org/apache/hadoop/fs/FsShell.java @@ -1954,11 +1954,9 @@ public class FsShell extends Configured implements Tool { } else if ("-count".equals(cmd)) { // TODO: next two lines are a temporary crutch until this entire // block is overhauled - LinkedList args = new LinkedList(Arrays.asList(argv)); - String cmdName = args.removeFirst(); 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)) { exitCode = doall(cmd, argv, i); } else if ("-touchz".equals(cmd)) { diff --git a/src/java/org/apache/hadoop/fs/shell/Command.java b/src/java/org/apache/hadoop/fs/shell/Command.java index 0dbd54f54c6..81461cfe7d8 100644 --- a/src/java/org/apache/hadoop/fs/shell/Command.java +++ b/src/java/org/apache/hadoop/fs/shell/Command.java @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -124,11 +125,12 @@ abstract public class Command extends Configured { * Most commands will chose to implement just * {@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 * @throws IllegalArgumentException if called with invalid arguments */ - public int run(LinkedList args) { + public int run(String...argv) { + LinkedList args = new LinkedList(Arrays.asList(argv)); try { processOptions(args); processArguments(expandArguments(args)); diff --git a/src/java/org/apache/hadoop/fs/shell/Count.java b/src/java/org/apache/hadoop/fs/shell/Count.java index a77dc4210da..6e2991d741e 100644 --- a/src/java/org/apache/hadoop/fs/shell/Count.java +++ b/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) { super(conf); setCommandName(NAME); - LinkedList parameters = new LinkedList(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 diff --git a/src/java/org/apache/hadoop/fs/shell/FsCommand.java b/src/java/org/apache/hadoop/fs/shell/FsCommand.java index 0cd354bb1c5..29ba4da050f 100644 --- a/src/java/org/apache/hadoop/fs/shell/FsCommand.java +++ b/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; } + // abstract method that normally is invoked by runall() which is + // overridden below protected void run(Path path) throws IOException { throw new RuntimeException("not supposed to get here"); } + + /** @deprecated use {@link #run(String...argv)} */ + @Deprecated + @Override + public int runAll() { + return run(args); + } }