Skip to content

Commit a2dda0c

Browse files
authored
HADOOP-18359. Update commons-cli from 1.2 to 1.5. (#5095). Contributed by Shilun Fan.
Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
1 parent 03bf8f9 commit a2dda0c

File tree

23 files changed

+385
-434
lines changed

23 files changed

+385
-434
lines changed

LICENSE-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ com.squareup.okhttp3:okhttp:4.10.0
245245
com.squareup.okio:okio:3.2.0
246246
com.zaxxer:HikariCP:4.0.3
247247
commons-beanutils:commons-beanutils:1.9.4
248-
commons-cli:commons-cli:1.2
248+
commons-cli:commons-cli:1.5.0
249249
commons-codec:commons-codec:1.11
250250
commons-collections:commons-collections:3.2.2
251251
commons-daemon:commons-daemon:1.0.13

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/service/launcher/ServiceLauncher.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import org.apache.commons.cli.CommandLine;
3535
import org.apache.commons.cli.Option;
36-
import org.apache.commons.cli.OptionBuilder;
3736
import org.apache.commons.cli.Options;
3837
import org.apache.hadoop.conf.Configuration;
3938
import org.apache.hadoop.fs.audit.CommonAuditContext;
@@ -362,29 +361,28 @@ protected String getUsageMessage() {
362361
/**
363362
* Override point: create an options instance to combine with the
364363
* standard options set.
365-
* <i>Important. Synchronize uses of {@link OptionBuilder}</i>
366-
* with {@code OptionBuilder.class}
364+
* <i>Important. Synchronize uses of {@link Option}</i>
365+
* with {@code Option.class}
367366
* @return the new options
368367
*/
369368
@SuppressWarnings("static-access")
370369
protected Options createOptions() {
371-
synchronized (OptionBuilder.class) {
370+
synchronized (Option.class) {
372371
Options options = new Options();
373-
Option oconf = OptionBuilder.withArgName("configuration file")
372+
Option oconf = Option.builder(ARG_CONF_SHORT).argName("configuration file")
374373
.hasArg()
375-
.withDescription("specify an application configuration file")
376-
.withLongOpt(ARG_CONF)
377-
.create(ARG_CONF_SHORT);
378-
Option confclass = OptionBuilder.withArgName("configuration classname")
374+
.desc("specify an application configuration file")
375+
.longOpt(ARG_CONF)
376+
.build();
377+
Option confclass = Option.builder(ARG_CONFCLASS_SHORT).argName("configuration classname")
379378
.hasArg()
380-
.withDescription(
381-
"Classname of a Hadoop Configuration subclass to load")
382-
.withLongOpt(ARG_CONFCLASS)
383-
.create(ARG_CONFCLASS_SHORT);
384-
Option property = OptionBuilder.withArgName("property=value")
379+
.desc("Classname of a Hadoop Configuration subclass to load")
380+
.longOpt(ARG_CONFCLASS)
381+
.build();
382+
Option property = Option.builder("D").argName("property=value")
385383
.hasArg()
386-
.withDescription("use value for given property")
387-
.create('D');
384+
.desc("use value for given property")
385+
.build();
388386
options.addOption(oconf);
389387
options.addOption(property);
390388
options.addOption(confclass);

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ConfTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.commons.cli.GnuParser;
4747
import org.apache.commons.cli.MissingArgumentException;
4848
import org.apache.commons.cli.Option;
49-
import org.apache.commons.cli.OptionBuilder;
5049
import org.apache.commons.cli.Options;
5150
import org.apache.commons.cli.ParseException;
5251
import org.apache.hadoop.classification.InterfaceAudience;
@@ -230,8 +229,8 @@ public static void main(String[] args) throws IOException {
230229
GenericOptionsParser genericParser = new GenericOptionsParser(args);
231230
String[] remainingArgs = genericParser.getRemainingArgs();
232231

233-
Option conf = OptionBuilder.hasArg().create("conffile");
234-
Option help = OptionBuilder.withLongOpt("help").create('h');
232+
Option conf = Option.builder("conffile").hasArg().build();
233+
Option help = Option.builder("h").longOpt("help").hasArg().build();
235234
Options opts = new Options().addOption(conf).addOption(help);
236235
CommandLineParser specificParser = new GnuParser();
237236
CommandLine cmd = null;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.apache.commons.cli.GnuParser;
3333
import org.apache.commons.cli.HelpFormatter;
3434
import org.apache.commons.cli.Option;
35-
import org.apache.commons.cli.OptionBuilder;
3635
import org.apache.commons.cli.Options;
3736
import org.apache.commons.cli.ParseException;
3837
import org.apache.hadoop.classification.InterfaceAudience;
@@ -225,51 +224,50 @@ public boolean isParseSuccessful() {
225224

226225
/**
227226
* @return Specify properties of each generic option.
228-
* <i>Important</i>: as {@link OptionBuilder} is not thread safe, subclasses
229-
* must synchronize use on {@code OptionBuilder.class}
227+
* <i>Important</i>: as {@link Option} is not thread safe, subclasses
228+
* must synchronize use on {@code Option.class}
230229
* @param opts input opts.
231230
*/
232231
@SuppressWarnings("static-access")
233232
protected Options buildGeneralOptions(Options opts) {
234-
synchronized (OptionBuilder.class) {
235-
Option fs = OptionBuilder.withArgName("file:///|hdfs://namenode:port")
233+
synchronized (Option.class) {
234+
Option fs = Option.builder("fs").argName("file:///|hdfs://namenode:port")
236235
.hasArg()
237-
.withDescription("specify default filesystem URL to use, "
236+
.desc("specify default filesystem URL to use, "
238237
+ "overrides 'fs.defaultFS' property from configurations.")
239-
.create("fs");
240-
Option jt = OptionBuilder.withArgName("local|resourcemanager:port")
238+
.build();
239+
Option jt = Option.builder("jt").argName("local|resourcemanager:port")
241240
.hasArg()
242-
.withDescription("specify a ResourceManager")
243-
.create("jt");
244-
Option oconf = OptionBuilder.withArgName("configuration file")
241+
.desc("specify a ResourceManager")
242+
.build();
243+
Option oconf = Option.builder("conf").argName("configuration file")
245244
.hasArg()
246-
.withDescription("specify an application configuration file")
247-
.create("conf");
248-
Option property = OptionBuilder.withArgName("property=value")
245+
.desc("specify an application configuration file")
246+
.build();
247+
Option property = Option.builder("D").argName("property=value")
249248
.hasArg()
250-
.withDescription("use value for given property")
251-
.create('D');
252-
Option libjars = OptionBuilder.withArgName("paths")
249+
.desc("use value for given property")
250+
.build();
251+
Option libjars = Option.builder("libjars").argName("paths")
253252
.hasArg()
254-
.withDescription(
255-
"comma separated jar files to include in the classpath.")
256-
.create("libjars");
257-
Option files = OptionBuilder.withArgName("paths")
253+
.desc("comma separated jar files to include in the classpath.")
254+
.build();
255+
Option files = Option.builder("files").argName("paths")
258256
.hasArg()
259-
.withDescription("comma separated files to be copied to the " +
257+
.desc("comma separated files to be copied to the " +
260258
"map reduce cluster")
261-
.create("files");
262-
Option archives = OptionBuilder.withArgName("paths")
259+
.build();
260+
Option archives = Option.builder("archives").argName("paths")
263261
.hasArg()
264-
.withDescription("comma separated archives to be unarchived" +
262+
.desc("comma separated archives to be unarchived" +
265263
" on the compute machines.")
266-
.create("archives");
264+
.build();
267265

268266
// file with security tokens
269-
Option tokensFile = OptionBuilder.withArgName("tokensFile")
267+
Option tokensFile = Option.builder("tokenCacheFile").argName("tokensFile")
270268
.hasArg()
271-
.withDescription("name of the file with the tokens")
272-
.create("tokenCacheFile");
269+
.desc("name of the file with the tokens")
270+
.build();
273271

274272

275273
opts.addOption(fs);

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileSeek.java

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929

3030
import org.apache.commons.cli.CommandLine;
3131
import org.apache.commons.cli.CommandLineParser;
32-
import org.apache.commons.cli.GnuParser;
32+
import org.apache.commons.cli.DefaultParser;
3333
import org.apache.commons.cli.HelpFormatter;
3434
import org.apache.commons.cli.Option;
35-
import org.apache.commons.cli.OptionBuilder;
3635
import org.apache.commons.cli.Options;
3736
import org.apache.commons.cli.ParseException;
3837
import org.apache.hadoop.conf.Configuration;
@@ -272,7 +271,7 @@ public MyOptions(String[] args) {
272271

273272
try {
274273
Options opts = buildOptions();
275-
CommandLineParser parser = new GnuParser();
274+
CommandLineParser parser = new DefaultParser();
276275
CommandLine line = parser.parse(opts, args, true);
277276
processOptions(line, opts);
278277
validateOptions();
@@ -290,81 +289,56 @@ public boolean proceed() {
290289

291290
private Options buildOptions() {
292291
Option compress =
293-
OptionBuilder.withLongOpt("compress").withArgName("[none|lzo|gz]")
294-
.hasArg().withDescription("compression scheme").create('c');
292+
Option.builder("c").longOpt("compress").argName("[none|lzo|gz]")
293+
.hasArg().desc("compression scheme").build();
295294

296295
Option fileSize =
297-
OptionBuilder.withLongOpt("file-size").withArgName("size-in-MB")
298-
.hasArg().withDescription("target size of the file (in MB).")
299-
.create('s');
296+
Option.builder("s").longOpt("file-size").argName("size-in-MB")
297+
.hasArg().desc("target size of the file (in MB).").build();
300298

301299
Option fsInputBufferSz =
302-
OptionBuilder.withLongOpt("fs-input-buffer").withArgName("size")
303-
.hasArg().withDescription(
304-
"size of the file system input buffer (in bytes).").create(
305-
'i');
300+
Option.builder("i").longOpt("fs-input-buffer").argName("size")
301+
.hasArg().desc("size of the file system input buffer (in bytes).").build();
306302

307303
Option fsOutputBufferSize =
308-
OptionBuilder.withLongOpt("fs-output-buffer").withArgName("size")
309-
.hasArg().withDescription(
310-
"size of the file system output buffer (in bytes).").create(
311-
'o');
304+
Option.builder("o").longOpt("fs-output-buffer").argName("size")
305+
.hasArg().desc("size of the file system output buffer (in bytes).").build();
312306

313307
Option keyLen =
314-
OptionBuilder
315-
.withLongOpt("key-length")
316-
.withArgName("min,max")
317-
.hasArg()
318-
.withDescription(
319-
"the length range of the key (in bytes)")
320-
.create('k');
308+
Option.builder("k").longOpt("key-length").argName("min,max")
309+
.hasArg().desc("the length range of the key (in bytes)").build();
321310

322311
Option valueLen =
323-
OptionBuilder
324-
.withLongOpt("value-length")
325-
.withArgName("min,max")
326-
.hasArg()
327-
.withDescription(
328-
"the length range of the value (in bytes)")
329-
.create('v');
312+
Option.builder("v").longOpt("value-length").argName("min,max")
313+
.hasArg().desc("the length range of the value (in bytes)").build();
330314

331315
Option blockSz =
332-
OptionBuilder.withLongOpt("block").withArgName("size-in-KB").hasArg()
333-
.withDescription("minimum block size (in KB)").create('b');
316+
Option.builder("b").longOpt("block").argName("size-in-KB").hasArg()
317+
.desc("minimum block size (in KB)").build();
334318

335319
Option seed =
336-
OptionBuilder.withLongOpt("seed").withArgName("long-int").hasArg()
337-
.withDescription("specify the seed").create('S');
320+
Option.builder("S").longOpt("seed").argName("long-int").hasArg()
321+
.desc("specify the seed").build();
338322

339323
Option operation =
340-
OptionBuilder.withLongOpt("operation").withArgName("r|w|rw").hasArg()
341-
.withDescription(
342-
"action: seek-only, create-only, seek-after-create").create(
343-
'x');
324+
Option.builder("x").longOpt("operation").argName("r|w|rw").hasArg()
325+
.desc("action: seek-only, create-only, seek-after-create").build();
344326

345327
Option rootDir =
346-
OptionBuilder.withLongOpt("root-dir").withArgName("path").hasArg()
347-
.withDescription(
348-
"specify root directory where files will be created.")
349-
.create('r');
328+
Option.builder("r").longOpt("root-dir").argName("path").hasArg()
329+
.desc("specify root directory where files will be created.").build();
350330

351331
Option file =
352-
OptionBuilder.withLongOpt("file").withArgName("name").hasArg()
353-
.withDescription("specify the file name to be created or read.")
354-
.create('f');
332+
Option.builder("f").longOpt("file").argName("name").hasArg()
333+
.desc("specify the file name to be created or read.").build();
355334

356335
Option seekCount =
357-
OptionBuilder
358-
.withLongOpt("seek")
359-
.withArgName("count")
360-
.hasArg()
361-
.withDescription(
362-
"specify how many seek operations we perform (requires -x r or -x rw.")
363-
.create('n');
336+
Option.builder("n").longOpt("seek").argName("count").hasArg()
337+
.desc("specify how many seek operations we perform (requires -x r or -x rw.").build();
364338

365339
Option help =
366-
OptionBuilder.withLongOpt("help").hasArg(false).withDescription(
367-
"show this screen").create("h");
340+
Option.builder("h").longOpt("help").hasArg(false)
341+
.desc("show this screen").build();
368342

369343
return new Options().addOption(compress).addOption(fileSize).addOption(
370344
fsInputBufferSz).addOption(fsOutputBufferSize).addOption(keyLen)

0 commit comments

Comments
 (0)