You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Anatoly Zaretsky (Jira)" <ji...@apache.org> on 2019/10/20 13:18:00 UTC

[jira] [Created] (MNG-6790) Redundant code in MavenCli.cliMerge

Anatoly Zaretsky created MNG-6790:
-------------------------------------

             Summary: Redundant code in MavenCli.cliMerge
                 Key: MNG-6790
                 URL: https://issues.apache.org/jira/browse/MNG-6790
             Project: Maven
          Issue Type: Task
          Components: Embedding
    Affects Versions: 3.6.3
            Reporter: Anatoly Zaretsky


cliMerge has a code to append all unrecognized arguments (i.e. goals)
from maven.config to the resulting CommandLine object:
{code}
    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 );
        }
...
{code}
But this code always does nothing since the result of maven.config parsing is checked
for absence of any such unrecognized arguments right before the merging
is performed:
{code}    void cli( CliRequest cliRequest )
        throws Exception
    {
...
                mavenConfig = cliManager.parse( args.toArray( new String[0] ) );
                List<?> unrecongized = mavenConfig.getArgList();
                if ( !unrecongized.isEmpty() )
                {
                    throw new ParseException( "Unrecognized maven.config entries: " + unrecongized );
                }
...
{code}

Note to the above snippets: [CommandLine.getArgs()|https://commons.apache.org/proper/commons-cli/javadocs/api-release/org/apache/commons/cli/CommandLine.html#getArgs--] is almost the same as [CommandLine.getArgList()|https://commons.apache.org/proper/commons-cli/javadocs/api-release/org/apache/commons/cli/CommandLine.html#getArgList--] - the only difference is that getArgs() returns String[] while getArgList() returns List<String>.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)