mirror of https://github.com/apache/maven.git
Revert [MNG-6069] Migrate to non deprecated parts of Commons CLI
This reverts commit 396291bba0
due to regression
This commit is contained in:
parent
15c647182a
commit
b7249aff22
|
@ -24,9 +24,9 @@ import java.io.PrintWriter;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
import org.apache.commons.cli.DefaultParser;
|
import org.apache.commons.cli.GnuParser;
|
||||||
import org.apache.commons.cli.HelpFormatter;
|
import org.apache.commons.cli.HelpFormatter;
|
||||||
import org.apache.commons.cli.Option;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
|
|
||||||
|
@ -103,92 +103,50 @@ public class CLIManager
|
||||||
|
|
||||||
protected Options options;
|
protected Options options;
|
||||||
|
|
||||||
// CHECKSTYLE_OFF: LineLength
|
@SuppressWarnings( { "static-access", "checkstyle:linelength" } )
|
||||||
public CLIManager()
|
public CLIManager()
|
||||||
{
|
{
|
||||||
options = new Options();
|
options = new Options();
|
||||||
options.addOption( Option.builder( Character.toString( HELP ) ).longOpt( "help" )
|
options.addOption( OptionBuilder.withLongOpt( "help" ).withDescription( "Display help information" ).create( HELP ) );
|
||||||
.desc( "Display help information" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "file" ).hasArg().withDescription( "Force the use of an alternate POM file (or directory with pom.xml)" ).create( ALTERNATE_POM_FILE ) );
|
||||||
options.addOption( Option.builder( Character.toString( ALTERNATE_POM_FILE ) ).longOpt( "file" ).hasArg()
|
options.addOption( OptionBuilder.withLongOpt( "define" ).hasArg().withDescription( "Define a system property" ).create( SET_SYSTEM_PROPERTY ) );
|
||||||
.desc( "Force the use of an alternate POM file (or directory with pom.xml)" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "offline" ).withDescription( "Work offline" ).create( OFFLINE ) );
|
||||||
options.addOption( Option.builder( Character.toString( SET_SYSTEM_PROPERTY ) ).longOpt( "define" ).hasArgs()
|
options.addOption( OptionBuilder.withLongOpt( "version" ).withDescription( "Display version information" ).create( VERSION ) );
|
||||||
.valueSeparator( ( char ) 0 )
|
options.addOption( OptionBuilder.withLongOpt( "quiet" ).withDescription( "Quiet output - only show errors" ).create( QUIET ) );
|
||||||
.desc( "Define a system property" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "debug" ).withDescription( "Produce execution debug output" ).create( DEBUG ) );
|
||||||
options.addOption( Option.builder( Character.toString( OFFLINE ) ).longOpt( "offline" )
|
options.addOption( OptionBuilder.withLongOpt( "errors" ).withDescription( "Produce execution error messages" ).create( ERRORS ) );
|
||||||
.desc( "Work offline" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "non-recursive" ).withDescription( "Do not recurse into sub-projects" ).create( NON_RECURSIVE ) );
|
||||||
options.addOption( Option.builder( Character.toString( VERSION ) ).longOpt( "version" )
|
options.addOption( OptionBuilder.withLongOpt( "update-snapshots" ).withDescription( "Forces a check for missing releases and updated snapshots on remote repositories" ).create( UPDATE_SNAPSHOTS ) );
|
||||||
.desc( "Display version information" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "activate-profiles" ).withDescription( "Comma-delimited list of profiles to activate" ).hasArg().create( ACTIVATE_PROFILES ) );
|
||||||
options.addOption( Option.builder( Character.toString( QUIET ) ).longOpt( "quiet" )
|
options.addOption( OptionBuilder.withLongOpt( "batch-mode" ).withDescription( "Run in non-interactive (batch) mode (disables output color)" ).create( BATCH_MODE ) );
|
||||||
.desc( "Quiet output - only show errors" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "no-snapshot-updates" ).withDescription( "Suppress SNAPSHOT updates" ).create( SUPRESS_SNAPSHOT_UPDATES ) );
|
||||||
options.addOption( Option.builder( Character.toString( DEBUG ) ).longOpt( "debug" )
|
options.addOption( OptionBuilder.withLongOpt( "strict-checksums" ).withDescription( "Fail the build if checksums don't match" ).create( CHECKSUM_FAILURE_POLICY ) );
|
||||||
.desc( "Produce execution debug output" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "lax-checksums" ).withDescription( "Warn if checksums don't match" ).create( CHECKSUM_WARNING_POLICY ) );
|
||||||
options.addOption( Option.builder( Character.toString( ERRORS ) ).longOpt( "errors" )
|
options.addOption( OptionBuilder.withLongOpt( "settings" ).withDescription( "Alternate path for the user settings file" ).hasArg().create( ALTERNATE_USER_SETTINGS ) );
|
||||||
.desc( "Produce execution error messages" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "global-settings" ).withDescription( "Alternate path for the global settings file" ).hasArg().create( ALTERNATE_GLOBAL_SETTINGS ) );
|
||||||
options.addOption( Option.builder( Character.toString( NON_RECURSIVE ) ).longOpt( "non-recursive" )
|
options.addOption( OptionBuilder.withLongOpt( "toolchains" ).withDescription( "Alternate path for the user toolchains file" ).hasArg().create( ALTERNATE_USER_TOOLCHAINS ) );
|
||||||
.desc( "Do not recurse into sub-projects" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "global-toolchains" ).withDescription( "Alternate path for the global toolchains file" ).hasArg().create( ALTERNATE_GLOBAL_TOOLCHAINS ) );
|
||||||
options.addOption( Option.builder( Character.toString( UPDATE_SNAPSHOTS ) ).longOpt( "update-snapshots" )
|
options.addOption( OptionBuilder.withLongOpt( "fail-fast" ).withDescription( "Stop at first failure in reactorized builds" ).create( FAIL_FAST ) );
|
||||||
.desc( "Forces a check for missing releases and updated snapshots on remote repositories" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "fail-at-end" ).withDescription( "Only fail the build afterwards; allow all non-impacted builds to continue" ).create( FAIL_AT_END ) );
|
||||||
options.addOption( Option.builder( Character.toString( ACTIVATE_PROFILES ) ).longOpt( "activate-profiles" )
|
options.addOption( OptionBuilder.withLongOpt( "fail-never" ).withDescription( "NEVER fail the build, regardless of project result" ).create( FAIL_NEVER ) );
|
||||||
.desc( "Comma-delimited list of profiles to activate" ).hasArg().build() );
|
options.addOption( OptionBuilder.withLongOpt( "resume-from" ).hasArg().withDescription( "Resume reactor from specified project" ).create( RESUME_FROM ) );
|
||||||
options.addOption( Option.builder( Character.toString( BATCH_MODE ) ).longOpt( "batch-mode" )
|
options.addOption( OptionBuilder.withLongOpt( "projects" ).withDescription( "Comma-delimited list of specified reactor projects to build instead of all projects. A project can be specified by [groupId]:artifactId or by its relative path" ).hasArg().create( PROJECT_LIST ) );
|
||||||
.desc( "Run in non-interactive (batch) mode (disables output color)" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "also-make" ).withDescription( "If project list is specified, also build projects required by the list" ).create( ALSO_MAKE ) );
|
||||||
options.addOption( Option.builder( SUPRESS_SNAPSHOT_UPDATES ).longOpt( "no-snapshot-updates" )
|
options.addOption( OptionBuilder.withLongOpt( "also-make-dependents" ).withDescription( "If project list is specified, also build projects that depend on projects on the list" ).create( ALSO_MAKE_DEPENDENTS ) );
|
||||||
.desc( "Suppress SNAPSHOT updates" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription( "Log file where all build output will go (disables output color)" ).create( LOG_FILE ) );
|
||||||
options.addOption( Option.builder( Character.toString( CHECKSUM_FAILURE_POLICY ) ).longOpt( "strict-checksums" )
|
options.addOption( OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create( SHOW_VERSION ) );
|
||||||
.desc( "Fail the build if checksums don't match" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "encrypt-master-password" ).hasOptionalArg().withDescription( "Encrypt master security password" ).create( ENCRYPT_MASTER_PASSWORD ) );
|
||||||
options.addOption( Option.builder( Character.toString( CHECKSUM_WARNING_POLICY ) ).longOpt( "lax-checksums" )
|
options.addOption( OptionBuilder.withLongOpt( "encrypt-password" ).hasOptionalArg().withDescription( "Encrypt server password" ).create( ENCRYPT_PASSWORD ) );
|
||||||
.desc( "Warn if checksums don't match" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription( "Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) );
|
||||||
options.addOption( Option.builder( Character.toString( ALTERNATE_USER_SETTINGS ) ).longOpt( "settings" ).hasArg().
|
options.addOption( OptionBuilder.withLongOpt( "legacy-local-repository" ).withDescription( "Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true" ).create( LEGACY_LOCAL_REPOSITORY ) );
|
||||||
desc( "Alternate path for the user settings file" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "builder" ).hasArg().withDescription( "The id of the build strategy to use" ).create( BUILDER ) );
|
||||||
options.addOption( Option.builder( ALTERNATE_GLOBAL_SETTINGS ).longOpt( "global-settings" ).hasArg()
|
|
||||||
.desc( "Alternate path for the global settings file" ).build() );
|
|
||||||
options.addOption( Option.builder( Character.toString( ALTERNATE_USER_TOOLCHAINS ) ).longOpt( "toolchains" ).hasArg()
|
|
||||||
.desc( "Alternate path for the user toolchains file" ).hasArg().build() );
|
|
||||||
options.addOption( Option.builder( ALTERNATE_GLOBAL_TOOLCHAINS ).longOpt( "global-toolchains" )
|
|
||||||
.desc( "Alternate path for the global toolchains file" ).hasArg().build() );
|
|
||||||
options.addOption( Option.builder( FAIL_FAST ).longOpt( "fail-fast" )
|
|
||||||
.desc( "Stop at first failure in reactorized builds" ).build() );
|
|
||||||
options.addOption( Option.builder( FAIL_AT_END ).longOpt( "fail-at-end" )
|
|
||||||
.desc( "Only fail the build afterwards; allow all non-impacted builds to continue" ).build() );
|
|
||||||
options.addOption( Option.builder( FAIL_NEVER ).longOpt( "fail-never" )
|
|
||||||
.desc( "NEVER fail the build, regardless of project result" ).build() );
|
|
||||||
options.addOption( Option.builder( RESUME_FROM ).longOpt( "resume-from" ).hasArg()
|
|
||||||
.desc( "Resume reactor from specified project" ).build() );
|
|
||||||
options.addOption( Option.builder( PROJECT_LIST ).longOpt( "projects" )
|
|
||||||
.desc( "Comma-delimited list of specified reactor projects to build instead of all projects. "
|
|
||||||
+ "A project can be specified by [groupId]:artifactId or by its relative path." ).hasArg().build() );
|
|
||||||
options.addOption( Option.builder( ALSO_MAKE ).longOpt( "also-make" )
|
|
||||||
.desc( "If project list is specified, also build projects required by the list" ).build() );
|
|
||||||
options.addOption( Option.builder( ALSO_MAKE_DEPENDENTS ).longOpt( "also-make-dependents" )
|
|
||||||
.desc( "If project list is specified, also build projects that depend on projects on the list" ).build() );
|
|
||||||
options.addOption( Option.builder( LOG_FILE ).longOpt( "log-file" ).hasArg()
|
|
||||||
.desc( "Log file where all build output will go" ).build() );
|
|
||||||
options.addOption( Option.builder( Character.toString( SHOW_VERSION ) ).longOpt( "show-version" )
|
|
||||||
.desc( "Display version information WITHOUT stopping build" ).build() );
|
|
||||||
options.addOption( Option.builder( ENCRYPT_MASTER_PASSWORD ).longOpt( "encrypt-master-password" ).hasArg().optionalArg( true )
|
|
||||||
.desc( "Encrypt master security password" ).build() );
|
|
||||||
options.addOption( Option.builder( ENCRYPT_PASSWORD ).longOpt( "encrypt-password" ).hasArg().optionalArg( true )
|
|
||||||
.desc( "Encrypt server password" ).build() );
|
|
||||||
options.addOption( Option.builder( THREADS ).longOpt( "threads" ).hasArg()
|
|
||||||
.desc( "Thread count, for instance 2.0C where C is core multiplied" ).build() );
|
|
||||||
options.addOption( Option.builder( LEGACY_LOCAL_REPOSITORY ).longOpt( "legacy-local-repository" )
|
|
||||||
.desc( "Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. "
|
|
||||||
+ "Can also be activated by using -Dmaven.legacyLocalRepo=true" ).build() );
|
|
||||||
options.addOption( Option.builder( BUILDER ).longOpt( "builder" ).hasArg()
|
|
||||||
.desc( "The id of the build strategy to use" ).build() );
|
|
||||||
|
|
||||||
// Adding this back in for compatibility with the verifier that hard codes this option.
|
// Adding this back in for compatibility with the verifier that hard codes this option.
|
||||||
options.addOption( Option.builder( "npr" ).longOpt( "no-plugin-registry" )
|
options.addOption( OptionBuilder.withLongOpt( "no-plugin-registry" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "npr" ) );
|
||||||
.desc( "Ineffective, only kept for backward compatibility" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "check-plugin-updates" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "cpu" ) );
|
||||||
options.addOption( Option.builder( "cpu" ).longOpt( "check-plugin-updates" )
|
options.addOption( OptionBuilder.withLongOpt( "update-plugins" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "up" ) );
|
||||||
.desc( "Ineffective, only kept for backward compatibility" ).build() );
|
options.addOption( OptionBuilder.withLongOpt( "no-plugin-updates" ).withDescription( "Ineffective, only kept for backward compatibility" ).create( "npu" ) );
|
||||||
options.addOption( Option.builder( "up" ).longOpt( "update-plugins" )
|
|
||||||
.desc( "Ineffective, only kept for backward compatibility" ).build() );
|
|
||||||
options.addOption( Option.builder( "npu" ).longOpt( "no-plugin-updates" )
|
|
||||||
.desc( "Ineffective, only kept for backward compatibility" ).build() );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// CHECKSTYLE_ON: LineLength
|
|
||||||
|
|
||||||
public CommandLine parse( String[] args )
|
public CommandLine parse( String[] args )
|
||||||
throws ParseException
|
throws ParseException
|
||||||
|
@ -196,7 +154,7 @@ public class CLIManager
|
||||||
// We need to eat any quotes surrounding arguments...
|
// We need to eat any quotes surrounding arguments...
|
||||||
String[] cleanArgs = CleanArgument.cleanArgs( args );
|
String[] cleanArgs = CleanArgument.cleanArgs( args );
|
||||||
|
|
||||||
CommandLineParser parser = new DefaultParser();
|
CommandLineParser parser = new GnuParser();
|
||||||
|
|
||||||
return parser.parse( options, cleanArgs );
|
return parser.parse( options, cleanArgs );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1650,19 +1650,14 @@ public class MavenCli
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
|
if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
|
||||||
{
|
{
|
||||||
Properties lineOptionProperties = commandLine.getOptionProperties(
|
String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
|
||||||
Character.toString( CLIManager.SET_SYSTEM_PROPERTY ) );
|
|
||||||
|
if ( defStrs != null )
|
||||||
for ( String defStr : lineOptionProperties.stringPropertyNames( ) )
|
|
||||||
{
|
{
|
||||||
String optValue = lineOptionProperties.getProperty( defStr );
|
for ( String defStr : defStrs )
|
||||||
userProperties.setProperty( defStr, optValue );
|
{
|
||||||
|
setCliProperty( defStr, userProperties );
|
||||||
// ----------------------------------------------------------------------
|
}
|
||||||
// I'm leaving the setting of system properties here as not to break
|
|
||||||
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
System.setProperty( defStr, optValue );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1682,6 +1677,37 @@ public class MavenCli
|
||||||
systemProperties.setProperty( "maven.build.version", mavenBuildVersion );
|
systemProperties.setProperty( "maven.build.version", mavenBuildVersion );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setCliProperty( String property, Properties properties )
|
||||||
|
{
|
||||||
|
String name;
|
||||||
|
|
||||||
|
String value;
|
||||||
|
|
||||||
|
int i = property.indexOf( '=' );
|
||||||
|
|
||||||
|
if ( i <= 0 )
|
||||||
|
{
|
||||||
|
name = property.trim();
|
||||||
|
|
||||||
|
value = "true";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
name = property.substring( 0, i ).trim();
|
||||||
|
|
||||||
|
value = property.substring( i + 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
properties.setProperty( name, value );
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// I'm leaving the setting of system properties here as not to break
|
||||||
|
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
System.setProperty( name, value );
|
||||||
|
}
|
||||||
|
|
||||||
static class ExitException
|
static class ExitException
|
||||||
extends Exception
|
extends Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -231,7 +231,7 @@ public class MavenCliTest
|
||||||
new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
|
new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
|
||||||
CliRequest request = new CliRequest(
|
CliRequest request = new CliRequest(
|
||||||
new String[]{ "-Drevision=8.1.0", "--file=-Dpom.xml", "\"-Dfoo=bar ", "\"-Dfoo2=bar two\"",
|
new String[]{ "-Drevision=8.1.0", "--file=-Dpom.xml", "\"-Dfoo=bar ", "\"-Dfoo2=bar two\"",
|
||||||
"\"-Dtest.prop=&x=y<>\"", "-Drevision=8.2.0" }, null );
|
"-Drevision=8.2.0" }, null );
|
||||||
|
|
||||||
cli.initialize( request );
|
cli.initialize( request );
|
||||||
// read .mvn/maven.config
|
// read .mvn/maven.config
|
||||||
|
@ -244,8 +244,6 @@ public class MavenCliTest
|
||||||
assertEquals( "bar ", request.getSystemProperties().getProperty( "foo" ) );
|
assertEquals( "bar ", request.getSystemProperties().getProperty( "foo" ) );
|
||||||
assertEquals( "bar two", request.getSystemProperties().getProperty( "foo2" ) );
|
assertEquals( "bar two", request.getSystemProperties().getProperty( "foo2" ) );
|
||||||
|
|
||||||
assertEquals( "&x=y<>", request.getSystemProperties().getProperty( "test.prop" ) );
|
|
||||||
|
|
||||||
assertEquals( "-Dpom.xml", request.getCommandLine().getOptionValue( CLIManager.ALTERNATE_POM_FILE ) );
|
assertEquals( "-Dpom.xml", request.getCommandLine().getOptionValue( CLIManager.ALTERNATE_POM_FILE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
pom.xml
10
pom.xml
|
@ -368,6 +368,16 @@ under the License.
|
||||||
<groupId>commons-cli</groupId>
|
<groupId>commons-cli</groupId>
|
||||||
<artifactId>commons-cli</artifactId>
|
<artifactId>commons-cli</artifactId>
|
||||||
<version>${commonsCliVersion}</version>
|
<version>${commonsCliVersion}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-lang</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-jxpath</groupId>
|
<groupId>commons-jxpath</groupId>
|
||||||
|
|
Loading…
Reference in New Issue