mirror of https://github.com/apache/maven.git
[MNG-6078] Confirm commons-cli 1.4-SNAPSHOT before official release
This commit is contained in:
parent
0e7e3eeb59
commit
f661fc298e
|
@ -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;
|
||||
|
@ -463,7 +464,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 )
|
||||
|
@ -486,6 +487,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
|
||||
*/
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
2
pom.xml
2
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>
|
||||
|
|
Loading…
Reference in New Issue