HADOOP-7216. Add FsCommand.runAll() with deprecated annotation for the transition of Command base class improvement. Contributed by Daryn Sharp

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1090485 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2011-04-08 23:07:34 +00:00
parent a65753ddac
commit 7568e9c88c
5 changed files with 19 additions and 10 deletions

View File

@ -130,6 +130,9 @@ Trunk (unreleased changes)
HADOOP-7019. Refactor build targets to enable faster cross project dev HADOOP-7019. Refactor build targets to enable faster cross project dev
cycles. (Luke Lu via cos) 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 Release 0.22.0 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -1954,11 +1954,9 @@ public int run(String argv[]) throws Exception {
} 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 runner.setCommandName(cmd); // TODO: will change with factory
exitCode = runner.run(args); 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)) {

View File

@ -21,6 +21,7 @@
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 @@ public int runAll() {
* 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));

View File

@ -60,10 +60,7 @@ public Count() {
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)); this.args = Arrays.copyOfRange(cmd, pos, cmd.length);
parameters.subList(0, pos).clear();
processOptions(parameters);
this.args = parameters.toArray(new String[0]);
} }
@Override @Override

View File

@ -47,7 +47,16 @@ public String getCommandName() {
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);
}
} }