hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgho...@apache.org
Subject svn commit: r986971 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/util/GenericOptionsParser.java src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java
Date Wed, 18 Aug 2010 22:50:58 GMT
Author: jghoman
Date: Wed Aug 18 22:50:57 2010
New Revision: 986971

URL: http://svn.apache.org/viewvc?rev=986971&view=rev
Log:
HADOOP-6482. GenericOptionsParser constructor that takes Options and String[] ignores options.
Contributed by Eli Collins.

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/util/GenericOptionsParser.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=986971&r1=986970&r2=986971&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Wed Aug 18 22:50:57 2010
@@ -202,6 +202,9 @@ Trunk (unreleased changes)
     HADOOP-6885. Fix java doc warnings in Groups and RefreshUserMappingsProtocol.
     (Eli Collins via jghoman) 
 
+    HADOOP-6482. GenericOptionsParser constructor that takes Options and 
+    String[] ignores options. (Eli Collins via jghoman)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/util/GenericOptionsParser.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/util/GenericOptionsParser.java?rev=986971&r1=986970&r2=986971&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/util/GenericOptionsParser.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/util/GenericOptionsParser.java Wed Aug
18 22:50:57 2010
@@ -86,8 +86,8 @@ import org.apache.hadoop.fs.Path;
  * $ bin/hadoop dfs -D fs.default.name=darwin:8020 -ls /data
  * list /data directory in dfs with namenode darwin:8020
  *     
- * $ bin/hadoop dfs -conf hadoop-site.xml -ls /data
- * list /data directory in dfs with conf specified in hadoop-site.xml
+ * $ bin/hadoop dfs -conf core-site.xml -conf hdfs-site.xml -ls /data
+ * list /data directory in dfs with multiple conf files specified.
  *     
  * $ bin/hadoop job -D mapred.job.tracker=darwin:50020 -submit job.xml
  * submit a job to job tracker darwin:50020
@@ -122,7 +122,7 @@ public class GenericOptionsParser {
    */
   public GenericOptionsParser(Options opts, String[] args) 
       throws IOException {
-    this(new Configuration(), new Options(), args);
+    this(new Configuration(), opts, args);
   }
 
   /**
@@ -400,25 +400,23 @@ public class GenericOptionsParser {
   /**
    * Parse the user-specified options, get the generic options, and modify
    * configuration accordingly
+   * @param opts Options to use for parsing args.
    * @param conf Configuration to be modified
    * @param args User-specified arguments
-   * @return Command-specific arguments
    */
-  private String[] parseGeneralOptions(Options opts, Configuration conf, 
+  private void parseGeneralOptions(Options opts, Configuration conf, 
       String[] args) throws IOException {
     opts = buildGeneralOptions(opts);
     CommandLineParser parser = new GnuParser();
     try {
       commandLine = parser.parse(opts, args, true);
       processGeneralOptions(conf, commandLine);
-      return commandLine.getArgs();
     } catch(ParseException e) {
       LOG.warn("options parsing failed: "+e.getMessage());
 
       HelpFormatter formatter = new HelpFormatter();
       formatter.printHelp("general options are: ", opts);
     }
-    return args;
   }
 
   /**

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java?rev=986971&r1=986970&r2=986971&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java
(original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/util/TestGenericOptionsParser.java
Wed Aug 18 22:50:57 2010
@@ -27,6 +27,9 @@ import junit.framework.TestCase;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
 
 public class TestGenericOptionsParser extends TestCase {
   File testDir;
@@ -76,6 +79,42 @@ public class TestGenericOptionsParser ex
     files = conf2.get("tmpfiles");
     assertNull("files is not null", files);
   }
+
+  /**
+   * Test that options passed to the constructor are used.
+   */
+  @SuppressWarnings("static-access")
+  public void testCreateWithOptions() throws Exception {
+    // Create new option newOpt
+    Option opt = OptionBuilder.withArgName("int")
+    .hasArg()
+    .withDescription("A new option")
+    .create("newOpt");
+    Options opts = new Options();
+    opts.addOption(opt);
+
+    // Check newOpt is actually used to parse the args
+    String[] args = new String[2];
+    args[0] = "--newOpt";
+    args[1] = "7";
+    GenericOptionsParser g = new GenericOptionsParser(opts, args);
+    assertEquals("New option was ignored",
+      "7", g.getCommandLine().getOptionValues("newOpt")[0]);
+  }
+
+  /**
+   * Test that multiple conf arguments can be used.
+   */
+  public void testConfWithMultipleOpts() throws Exception {
+    String[] args = new String[2];
+    args[0] = "--conf=foo";
+    args[1] = "--conf=bar";
+    GenericOptionsParser g = new GenericOptionsParser(args);
+    assertEquals("1st conf param is incorrect",
+      "foo", g.getCommandLine().getOptionValues("conf")[0]);
+    assertEquals("2st conf param is incorrect",
+      "bar", g.getCommandLine().getOptionValues("conf")[1]);
+  }
   
   @Override
   protected void setUp() throws Exception {



Mime
View raw message