You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2021/11/03 14:24:20 UTC
[GitHub] [maven] michael-o commented on a change in pull request #605: [MNG-7217] Update Commons CLI to 1.5.0
michael-o commented on a change in pull request #605:
URL: https://github.com/apache/maven/pull/605#discussion_r741987540
##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -1759,27 +1757,8 @@ static void populateProperties( CommandLine commandLine, Properties systemProper
systemProperties.setProperty( "maven.build.version", mavenBuildVersion );
}
- private static void setCliProperty( String property, Properties properties )
+ private static void setCliProperty( String name, String value, 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 );
Review comment:
Since there is only one line left, does it make sense to keep this method at all if it is not used anywhere else?
##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -1730,18 +1731,15 @@ static void populateProperties( CommandLine commandLine, Properties systemProper
// are most dominant.
// ----------------------------------------------------------------------
- if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
- {
- String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
-
- if ( defStrs != null )
- {
- for ( String defStr : defStrs )
+ Arrays.stream( commandLine.getOptions() )
+ .filter( option -> CLIManager.SET_SYSTEM_PROPERTY == option.getOpt().charAt( 0 ) )
+ .map( option -> option.getValues() )
+ .forEach( values ->
{
- setCliProperty( defStr, userProperties );
- }
- }
- }
+ final String key = values[0].trim();
Review comment:
I am bit confused how this magic works because it will deliver you a consequitve array of even/odd indices representing a map actually because `getValues()` results all values and not just value pairs.
##########
File path: maven-embedder/src/test/java/org/apache/maven/cli/CLIManagerTest.java
##########
@@ -43,8 +43,10 @@ public void spacedOptions()
{
CommandLine cmdLine = cliManager.parse( "-X -Dx=1 -D y=2 test".split( " " ) );
Review comment:
Also add a test for `-Dz` (implicit `true`)
##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -1730,18 +1731,15 @@ static void populateProperties( CommandLine commandLine, Properties systemProper
// are most dominant.
// ----------------------------------------------------------------------
- if ( commandLine.hasOption( CLIManager.SET_SYSTEM_PROPERTY ) )
- {
- String[] defStrs = commandLine.getOptionValues( CLIManager.SET_SYSTEM_PROPERTY );
-
- if ( defStrs != null )
- {
- for ( String defStr : defStrs )
+ Arrays.stream( commandLine.getOptions() )
Review comment:
For consistency reasons with the rest I would retain the if clause.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org