From aa10f303e3cb5b8b533e3407a6be6d2b4d81217c Mon Sep 17 00:00:00 2001 From: Sharad Agarwal Date: Thu, 27 Aug 2009 13:55:19 +0000 Subject: [PATCH] HADOOP-6215. fix GenericOptionParser to deal with -D with '=' in the value. Contributed by Amar Kamat. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@808415 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ src/java/org/apache/hadoop/util/GenericOptionsParser.java | 2 +- src/test/core/org/apache/hadoop/util/TestGenericsUtil.java | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index c3a38afa52..58dd9246c9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -944,6 +944,9 @@ Trunk (unreleased changes) HADOOP-6152. Fix classpath variables in bin/hadoop-config.sh and some other scripts. (Aaron Kimball via szetszwo) + HADOOP-6215. fix GenericOptionParser to deal with -D with '=' in the + value. (Amar Kamat via sharad) + Release 0.20.1 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/util/GenericOptionsParser.java b/src/java/org/apache/hadoop/util/GenericOptionsParser.java index 2c9432d8d8..55ede028b5 100644 --- a/src/java/org/apache/hadoop/util/GenericOptionsParser.java +++ b/src/java/org/apache/hadoop/util/GenericOptionsParser.java @@ -281,7 +281,7 @@ private void processGeneralOptions(Configuration conf, if (line.hasOption('D')) { String[] property = line.getOptionValues('D'); for(String prop : property) { - String[] keyval = prop.split("="); + String[] keyval = prop.split("=", 2); if (keyval.length == 2) { conf.set(keyval[0], keyval[1]); } diff --git a/src/test/core/org/apache/hadoop/util/TestGenericsUtil.java b/src/test/core/org/apache/hadoop/util/TestGenericsUtil.java index af494c909d..cf90332084 100644 --- a/src/test/core/org/apache/hadoop/util/TestGenericsUtil.java +++ b/src/test/core/org/apache/hadoop/util/TestGenericsUtil.java @@ -103,6 +103,12 @@ public void testGenericOptionsParser() throws Exception { GenericOptionsParser parser = new GenericOptionsParser( new Configuration(), new String[] {"-jt"}); assertEquals(parser.getRemainingArgs().length, 0); + + // test if -D accepts -Dx=y=z + parser = + new GenericOptionsParser(new Configuration(), + new String[] {"-Dx=y=z"}); + assertEquals(parser.getConfiguration().get("x"), "y=z"); } public void testGetClass() {