Skip to content

Commit e56c41b

Browse files
author
John Keyes
committed
create the parser using a classname parameter instead of a system property
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129789 13f79535-47bb-0310-9956-ffa450edef68
1 parent cf3a774 commit e56c41b

3 files changed

Lines changed: 11 additions & 14 deletions

File tree

src/java/org/apache/commons/cli/CommandLineParserFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Attic/CommandLineParserFactory.java,v 1.1 2002/07/04 22:32:12 jkeyes Exp $
3-
* $Revision: 1.1 $
4-
* $Date: 2002/07/04 22:32:12 $
2+
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//cli/src/java/org/apache/commons/cli/Attic/CommandLineParserFactory.java,v 1.2 2002/07/25 21:40:08 jkeyes Exp $
3+
* $Revision: 1.2 $
4+
* $Date: 2002/07/25 21:40:08 $
55
*
66
* ====================================================================
77
*
@@ -76,9 +76,12 @@ public class CommandLineParserFactory {
7676
* @return the CommandLineParser
7777
*/
7878
public static CommandLineParser newParser() {
79-
String parserImpl = System.getProperty( "org.apache.commons.cli.parser" );
79+
return newParser( DEFAULT_PARSER );
80+
}
81+
82+
public static CommandLineParser newParser( String classname ) {
8083
try {
81-
return (CommandLineParser)Class.forName( parserImpl ).newInstance();
84+
return (CommandLineParser)Class.forName( classname ).newInstance();
8285
}
8386
catch( Exception exp ) {
8487
// could not create according to parserImpl so default to

src/test/org/apache/commons/cli/ApplicationTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ public ApplicationTest(String name)
3535
*/
3636
public void testAnt() {
3737
// use the GNU parser
38-
System.setProperty( "org.apache.commons.cli.parser",
39-
"org.apache.commons.cli.GnuParser");
40-
41-
CommandLineParser parser = CommandLineParserFactory.newParser();
38+
CommandLineParser parser = CommandLineParserFactory.newParser( "org.apache.commons.cli.GnuParser" );
4239
Options options = new Options();
4340
options.addOption( "help", false, "print this message" );
4441
options.addOption( "projecthelp", false, "print project help information" );

src/test/org/apache/commons/cli/GnuParseTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* version 1.1, a copy of which has been included with this distribution in
66
* the LICENSE file.
77
*
8-
* $Id: GnuParseTest.java,v 1.1 2002/07/04 22:32:12 jkeyes Exp $
8+
* $Id: GnuParseTest.java,v 1.2 2002/07/25 21:40:08 jkeyes Exp $
99
*/
1010

1111
package org.apache.commons.cli;
@@ -30,9 +30,6 @@ public GnuParseTest( String name )
3030

3131
public void setUp()
3232
{
33-
System.setProperty( "org.apache.commons.cli.parser",
34-
"org.apache.commons.cli.GnuParser");
35-
3633
_options = new Options()
3734
.addOption("a",
3835
"enable-a",
@@ -47,7 +44,7 @@ public void setUp()
4744
false,
4845
"turn [c] on or off");
4946

50-
_parser = CommandLineParserFactory.newParser();
47+
_parser = CommandLineParserFactory.newParser( "org.apache.commons.cli.GnuParser" );
5148
}
5249

5350
public void tearDown()

0 commit comments

Comments
 (0)