You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2022/12/26 17:29:30 UTC

[maven] branch MNG-5857_alt-2 created (now 9b8db2a8f)

This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a change to branch MNG-5857_alt-2
in repository https://gitbox.apache.org/repos/asf/maven.git


      at 9b8db2a8f [MNG-5857] Arguments from command line should override those in .mvn/maven.config

This branch includes the following new commits:

     new 9b8db2a8f [MNG-5857] Arguments from command line should override those in .mvn/maven.config

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven] 01/01: [MNG-5857] Arguments from command line should override those in .mvn/maven.config

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch MNG-5857_alt-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 9b8db2a8f6e1520e7b1a536a8effaba078cf18d7
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Mon Dec 26 18:29:11 2022 +0100

    [MNG-5857] Arguments from command line should override those in .mvn/maven.config
---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 26 +++++++---------------
 .../java/org/apache/maven/cli/MavenCliTest.java    |  6 ++---
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index 509b02ede..5efb346a0 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -367,7 +367,7 @@ public class MavenCli {
             if (mavenConfig == null) {
                 cliRequest.commandLine = cliManager.parse(cliRequest.args);
             } else {
-                cliRequest.commandLine = cliMerge(cliManager.parse(cliRequest.args), mavenConfig);
+                cliRequest.commandLine = cliMerge(mavenConfig, cliManager.parse(cliRequest.args));
             }
         } catch (ParseException e) {
             System.err.println("Unable to parse command line options: " + e.getMessage());
@@ -392,33 +392,23 @@ public class MavenCli {
         }
     }
 
-    private CommandLine cliMerge(CommandLine mavenArgs, CommandLine mavenConfig) {
+    private CommandLine cliMerge(CommandLine mavenConfig, CommandLine mavenCli) {
         CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
 
-        // the args are easy, cli first then config file
-        for (String arg : mavenArgs.getArgs()) {
-            commandLineBuilder.addArg(arg);
-        }
-        for (String arg : mavenConfig.getArgs()) {
+        // the args are easy, CLI only since maven.config can only contain options
+        for (String arg : mavenCli.getArgs()) {
             commandLineBuilder.addArg(arg);
         }
 
-        // now add all options, except for -D with cli first then config file
-        List<Option> setPropertyOptions = new ArrayList<>();
-        for (Option opt : mavenArgs.getOptions()) {
-            if (String.valueOf(CLIManager.SET_USER_PROPERTY).equals(opt.getOpt())) {
-                setPropertyOptions.add(opt);
-            } else {
-                commandLineBuilder.addOption(opt);
-            }
-        }
+        // now add all maven.config options
         for (Option opt : mavenConfig.getOptions()) {
             commandLineBuilder.addOption(opt);
         }
-        // finally add the CLI user properties
-        for (Option opt : setPropertyOptions) {
+        // finally add the CLI options
+        for (Option opt : mavenCli.getOptions()) {
             commandLineBuilder.addOption(opt);
         }
+
         return commandLineBuilder.build();
     }
 
diff --git a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
index 1f1da2e7c..54e937b31 100644
--- a/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
+++ b/maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java
@@ -244,7 +244,7 @@ public class MavenCliTest {
         cli.cli(request);
         cli.properties(request);
 
-        String revision = System.getProperty("revision");
+        String revision = request.getUserProperties().getProperty("revision");
         assertEquals("8.1.0", revision);
     }
 
@@ -273,7 +273,7 @@ public class MavenCliTest {
         cli.cli(request);
         cli.properties(request);
 
-        String revision = System.getProperty("revision");
+        String revision = request.getUserProperties().getProperty("revision");
         assertEquals("8.2.0", revision);
     }
 
@@ -308,7 +308,7 @@ public class MavenCliTest {
 
         assertEquals("3", request.commandLine.getOptionValue(CLIManager.THREADS));
 
-        String revision = System.getProperty("revision");
+        String revision = request.getUserProperties().getProperty("revision");
         assertEquals("8.2.0", revision);
 
         assertEquals("bar ", request.getUserProperties().getProperty("foo"));