Repository: maven
Updated Branches:
  refs/heads/MNG-6078 [created] d0d34dfd4
  refs/heads/MNG-6181 [created] e0da20a1f


[MNG-6078] Confirm commons-cli 1.4-SNAPSHOT before official release


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/d0d34dfd
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/d0d34dfd
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/d0d34dfd

Branch: refs/heads/MNG-6078
Commit: d0d34dfd416acf138e206c6bdf38b41ff43b0cc8
Parents: 34afec6
Author: rfscholte <rfscho...@apache.org>
Authored: Wed Mar 8 21:38:08 2017 +0100
Committer: rfscholte <rfscho...@apache.org>
Committed: Wed Mar 8 21:38:08 2017 +0100

----------------------------------------------------------------------
 .../java/org/apache/maven/cli/MavenCli.java     | 42 ++++++++++-
 .../org/apache/maven/cli/MergedCommandLine.java | 75 --------------------
 pom.xml                                         |  2 +-
 3 files changed, 42 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/d0d34dfd/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
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 8d38ab0..0ac416a 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
@@ -23,6 +23,7 @@ import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 import com.google.inject.AbstractModule;
 import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.UnrecognizedOptionException;
 import org.apache.maven.BuildAbort;
@@ -421,7 +422,7 @@ public class MavenCli
             }
             else
             {
-                cliRequest.commandLine = new MergedCommandLine( 
cliManager.parse( cliRequest.args ), mavenConfig );
+                cliRequest.commandLine = cliMerge( cliManager.parse( 
cliRequest.args ), mavenConfig );
             }
         }
         catch ( ParseException e )
@@ -444,6 +445,45 @@ public class MavenCli
         }
     }
 
+    private CommandLine cliMerge( CommandLine mavenArgs, CommandLine 
mavenConfig )
+    {
+        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() )
+        {
+            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_SYSTEM_PROPERTY ).equals( 
opt.getOpt() ) )
+            {
+                setPropertyOptions.add( opt );
+            }
+            else
+            {
+                commandLineBuilder.addOption( opt );
+            }
+        }
+        for ( Option opt : mavenConfig.getOptions() )
+        {
+            commandLineBuilder.addOption( opt );
+        }
+        // finally add the CLI system properties
+        for ( Option opt : setPropertyOptions )
+        {
+            commandLineBuilder.addOption( opt );
+        }
+        return commandLineBuilder.build();
+    }
+
     /**
      * configure logging
      */

http://git-wip-us.apache.org/repos/asf/maven/blob/d0d34dfd/maven-embedder/src/main/java/org/apache/maven/cli/MergedCommandLine.java
----------------------------------------------------------------------
diff --git 
a/maven-embedder/src/main/java/org/apache/maven/cli/MergedCommandLine.java 
b/maven-embedder/src/main/java/org/apache/maven/cli/MergedCommandLine.java
deleted file mode 100644
index cb0a587..0000000
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MergedCommandLine.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.apache.maven.cli;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Option;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A {@link CommandLine} instance that represents a merged command line 
combining CLI arguments with those from the
- * {@code .mvn/maven.config} while reflecting the handling of {@link 
CLIManager#SET_SYSTEM_PROPERTY} versus all the
- * other command line options (last wins vs first wins respectively).
- */
-class MergedCommandLine
-    extends CommandLine
-{
-    MergedCommandLine( CommandLine commandLine, CommandLine configFile )
-    {
-        // such a pity that Commons CLI does not offer either a builder or a 
formatter and we need to extend
-        // to perform the merge. A formatter would mean we could unparse and 
reparse (not ideal but would work).
-        // A builder would be ideal for this kind of merge like processing.
-        super();
-        // the args are easy, cli first then config file
-        for ( String arg : commandLine.getArgs() )
-        {
-            addArg( arg );
-        }
-        for ( String arg : configFile.getArgs() )
-        {
-            addArg( arg );
-        }
-        // now add all options, except for -D with cli first then config file
-        List<Option> setPropertyOptions = new ArrayList<>();
-        for ( Option opt : commandLine.getOptions() )
-        {
-            if ( String.valueOf( CLIManager.SET_SYSTEM_PROPERTY ).equals( 
opt.getOpt() ) )
-            {
-                setPropertyOptions.add( opt );
-            }
-            else
-            {
-                addOption( opt );
-            }
-        }
-        for ( Option opt : configFile.getOptions() )
-        {
-            addOption( opt );
-        }
-        // finally add the CLI system properties
-        for ( Option opt : setPropertyOptions )
-        {
-            addOption( opt );
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/maven/blob/d0d34dfd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index ba06feb..5efdfc1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,7 +50,7 @@ under the License.
     <maven.compiler.source>1.7</maven.compiler.source>
     <maven.compiler.target>1.7</maven.compiler.target>
     <classWorldsVersion>2.5.2</classWorldsVersion>
-    <commonsCliVersion>1.3.1</commonsCliVersion>
+    <commonsCliVersion>1.4-SNAPSHOT</commonsCliVersion>
     <commonsLangVersion>3.5</commonsLangVersion>
     <junitVersion>4.12</junitVersion>
     <mockitoVersion>1.10.19</mockitoVersion>

Reply via email to