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 2021/10/24 18:02:31 UTC

[maven] branch maven.config-from-start-scripts created (now 140f36c)

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

michaelo pushed a change to branch maven.config-from-start-scripts
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 140f36c  Update startup scripts

This branch includes the following new commits:

     new 6acc6d7  Remove non-usable test
     new 1c10e5a  Remove Java code for parsing
     new 140f36c  Update startup scripts

The 3 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/03: Remove non-usable test

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

michaelo pushed a commit to branch maven.config-from-start-scripts
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 6acc6d75226caa70f1c0d5cc0ff44623dfc8e16f
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Oct 24 19:46:49 2021 +0200

    Remove non-usable test
---
 .../java/org/apache/maven/cli/MavenCliTest.java    | 160 ---------------------
 .../test/projects/config-illegal/.mvn/maven.config |   1 -
 .../src/test/projects/config/.mvn/maven.config     |   3 -
 .../mavenConfigProperties/.mvn/maven.config        |   5 -
 4 files changed, 169 deletions(-)

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 4191e88..952033e 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
@@ -161,166 +161,6 @@ public class MavenCliTest
     }
 
     @Test
-    public void testMavenConfig()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/config" ).getCanonicalPath() );
-        CliRequest request = new CliRequest( new String[0], null );
-
-        // read .mvn/maven.config
-        cli.initialize( request );
-        cli.cli( request );
-        assertEquals( "multithreaded", request.commandLine.getOptionValue( CLIManager.BUILDER ) );
-        assertEquals( "8", request.commandLine.getOptionValue( CLIManager.THREADS ) );
-
-        // override from command line
-        request = new CliRequest( new String[]{ "--builder", "foobar" }, null );
-        cli.cli( request );
-        assertEquals( "foobar", request.commandLine.getOptionValue( "builder" ) );
-    }
-
-    @Test
-    public void testMavenConfigInvalid()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/config-illegal" ).getCanonicalPath() );
-        CliRequest request = new CliRequest( new String[0], null );
-
-        cli.initialize( request );
-        assertThrows( ParseException.class, () -> cli.cli( request ) );
-    }
-
-    /**
-     * Read .mvn/maven.config with the following definitions:
-     * <pre>
-     *   -T
-     *   3
-     *   -Drevision=1.3.0
-     *   "-Dlabel=Apache Maven"
-     * </pre>
-     * and check if the {@code -T 3} option can be overwritten via command line
-     * argument.
-     *
-     * @throws Exception in case of failure.
-     */
-    @Test
-    public void testMVNConfigurationThreadCanBeOverwrittenViaCommandLine()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
-        CliRequest request = new CliRequest( new String[]{ "-T", "5" }, null );
-
-        cli.initialize( request );
-        // read .mvn/maven.config
-        cli.cli( request );
-
-        assertEquals( "5", request.commandLine.getOptionValue( CLIManager.THREADS ) );
-    }
-
-    /**
-     * Read .mvn/maven.config with the following definitions:
-     * <pre>
-     *   -T
-     *   3
-     *   -Drevision=1.3.0
-     *   "-Dlabel=Apache Maven"
-     * </pre>
-     * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line
-     * argument.
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testMVNConfigurationDefinedPropertiesCanBeOverwrittenViaCommandLine()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
-        CliRequest request = new CliRequest( new String[]{ "-Drevision=8.1.0" }, null );
-
-        cli.initialize( request );
-        // read .mvn/maven.config
-        cli.cli( request );
-        cli.properties( request );
-
-        String revision = System.getProperty( "revision" );
-        assertEquals( "8.1.0", revision );
-    }
-
-    /**
-     * Read .mvn/maven.config with the following definitions:
-     * <pre>
-     *   -T
-     *   3
-     *   -Drevision=1.3.0
-     *   "-Dlabel=Apache Maven"
-     * </pre>
-     * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line
-     * argument.
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testMVNConfigurationCLIRepeatedPropertiesLastWins()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
-        CliRequest request = new CliRequest( new String[]{ "-Drevision=8.1.0", "-Drevision=8.2.0" }, null );
-
-        cli.initialize( request );
-        // read .mvn/maven.config
-        cli.cli( request );
-        cli.properties( request );
-
-        String revision = System.getProperty( "revision" );
-        assertEquals( "8.2.0", revision );
-    }
-
-    /**
-     * Read .mvn/maven.config with the following definitions:
-     * <pre>
-     *   -T
-     *   3
-     *   -Drevision=1.3.0
-     *   "-Dlabel=Apache Maven"
-     * </pre>
-     * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line argument when there are
-     * funky arguments present.
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testMVNConfigurationFunkyArguments()
-        throws Exception
-    {
-        System.setProperty( MavenCli.MULTIMODULE_PROJECT_DIRECTORY,
-                            new File( "src/test/projects/mavenConfigProperties" ).getCanonicalPath() );
-        CliRequest request = new CliRequest(
-            new String[]{ "-Drevision=8.1.0", "--file=-Dpom.xml", "\"-Dfoo=bar ", "\"-Dfoo2=bar two\"",
-                "-Drevision=8.2.0" }, null );
-
-        cli.initialize( request );
-        // read .mvn/maven.config
-        cli.cli( request );
-        cli.properties( request );
-
-        assertEquals( "3", request.commandLine.getOptionValue( CLIManager.THREADS ) );
-
-        String revision = System.getProperty( "revision" );
-        assertEquals( "8.2.0", revision );
-
-        assertEquals( "bar ", request.getSystemProperties().getProperty( "foo" ) );
-        assertEquals( "bar two", request.getSystemProperties().getProperty( "foo2" ) );
-        assertEquals( "Apache Maven", request.getSystemProperties().getProperty( "label" ) );
-
-        assertEquals( "-Dpom.xml", request.getCommandLine().getOptionValue( CLIManager.ALTERNATE_POM_FILE ) );
-    }
-
-    @Test
     public void testStyleColors()
         throws Exception
     {
diff --git a/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config b/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
deleted file mode 100644
index 8541464..0000000
--- a/maven-embedder/src/test/projects/config-illegal/.mvn/maven.config
+++ /dev/null
@@ -1 +0,0 @@
-deploy
diff --git a/maven-embedder/src/test/projects/config/.mvn/maven.config b/maven-embedder/src/test/projects/config/.mvn/maven.config
deleted file mode 100644
index 280d577..0000000
--- a/maven-embedder/src/test/projects/config/.mvn/maven.config
+++ /dev/null
@@ -1,3 +0,0 @@
--T8
---builder
-multithreaded
diff --git a/maven-embedder/src/test/projects/mavenConfigProperties/.mvn/maven.config b/maven-embedder/src/test/projects/mavenConfigProperties/.mvn/maven.config
deleted file mode 100644
index 8257023..0000000
--- a/maven-embedder/src/test/projects/mavenConfigProperties/.mvn/maven.config
+++ /dev/null
@@ -1,5 +0,0 @@
--T
-3
--Drevision=1.3.0
-"-Dlabel=Apache Maven"
-

[maven] 02/03: Remove Java code for parsing

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

michaelo pushed a commit to branch maven.config-from-start-scripts
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 1c10e5aaded62ca80b5a1133282802fed2f97b4f
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Oct 24 19:47:19 2021 +0200

    Remove Java code for parsing
---
 .../main/java/org/apache/maven/cli/MavenCli.java   | 84 +---------------------
 1 file changed, 1 insertion(+), 83 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 ead1331..d4a06ee 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
@@ -21,7 +21,6 @@ package org.apache.maven.cli;
 
 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;
@@ -104,8 +103,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -148,8 +145,6 @@ public class MavenCli
 
     private static final String EXTENSIONS_FILENAME = ".mvn/extensions.xml";
 
-    private static final String MVN_MAVEN_CONFIG = ".mvn/maven.config";
-
     public static final String STYLE_COLOR_PROPERTY = "style.color";
 
     private ClassWorld classWorld;
@@ -386,47 +381,9 @@ public class MavenCli
 
         cliManager = new CLIManager();
 
-        List<String> args = new ArrayList<>();
-        CommandLine mavenConfig = null;
         try
         {
-            File configFile = new File( cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG );
-
-            if ( configFile.isFile() )
-            {
-                for ( String arg : Files.readAllLines( configFile.toPath(), Charset.defaultCharset() ) )
-                {
-                    if ( !arg.isEmpty() )
-                    {
-                        args.add( arg );
-                    }
-                }
-
-                mavenConfig = cliManager.parse( args.toArray( new String[0] ) );
-                List<?> unrecongized = mavenConfig.getArgList();
-                if ( !unrecongized.isEmpty() )
-                {
-                    throw new ParseException( "Unrecognized maven.config entries: " + unrecongized );
-                }
-            }
-        }
-        catch ( ParseException e )
-        {
-            System.err.println( "Unable to parse maven.config: " + e.getMessage() );
-            cliManager.displayHelp( System.out );
-            throw e;
-        }
-
-        try
-        {
-            if ( mavenConfig == null )
-            {
-                cliRequest.commandLine = cliManager.parse( cliRequest.args );
-            }
-            else
-            {
-                cliRequest.commandLine = cliMerge( cliManager.parse( cliRequest.args ), mavenConfig );
-            }
+            cliRequest.commandLine = cliManager.parse( cliRequest.args );
         }
         catch ( ParseException e )
         {
@@ -458,45 +415,6 @@ 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
      */

[maven] 03/03: Update startup scripts

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

michaelo pushed a commit to branch maven.config-from-start-scripts
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 140f36c5318f36d24410f8bcae138952a86d576e
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Oct 24 20:02:20 2021 +0200

    Update startup scripts
---
 apache-maven/src/assembly/shared/init     |  1 +
 apache-maven/src/assembly/shared/init.cmd | 12 ++++++++++--
 apache-maven/src/assembly/shared/run      |  4 +++-
 apache-maven/src/assembly/shared/run.cmd  |  4 +++-
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/apache-maven/src/assembly/shared/init b/apache-maven/src/assembly/shared/init
index 619bc4d..d38f5db 100755
--- a/apache-maven/src/assembly/shared/init
+++ b/apache-maven/src/assembly/shared/init
@@ -84,3 +84,4 @@ concat_lines() {
 
 MAVEN_PROJECTBASEDIR="`find_maven_basedir "$@"`"
 MAVEN_OPTS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config"` $MAVEN_OPTS"
+MAVEN_ARGS="`concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/maven.config"` $MAVEN_ARGS"
diff --git a/apache-maven/src/assembly/shared/init.cmd b/apache-maven/src/assembly/shared/init.cmd
index 8b1eb67..d1f6988 100755
--- a/apache-maven/src/assembly/shared/init.cmd
+++ b/apache-maven/src/assembly/shared/init.cmd
@@ -84,11 +84,19 @@ cd /d "%EXEC_DIR%"
 :endDetectBaseDir
 
 set "jvmConfig=\.mvn\jvm.config"
-if not exist "%MAVEN_PROJECTBASEDIR%%jvmConfig%" goto endReadAdditionalConfig
+if not exist "%MAVEN_PROJECTBASEDIR%%jvmConfig%" goto endReadJvmConfig
 
 @setlocal EnableExtensions EnableDelayedExpansion
 for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
 @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
 
-:endReadAdditionalConfig
+:endReadJvmConfig
 
+set "mavenConfig=\.mvn\maven.config"
+if not exist "%MAVEN_PROJECTBASEDIR%%mavenConfig%" goto endReadMavenConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\maven.config") do set MAVEN_CONFIG_MAVEN_PROPS=!MAVEN_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set MAVEN_CONFIG_MAVEN_PROPS=%MAVEN_CONFIG_MAVEN_PROPS%
+
+:endReadMavenConfig
diff --git a/apache-maven/src/assembly/shared/run b/apache-maven/src/assembly/shared/run
index 69535d6..28814a8 100755
--- a/apache-maven/src/assembly/shared/run
+++ b/apache-maven/src/assembly/shared/run
@@ -16,4 +16,6 @@ exec "$JAVACMD" \
   "-Dmaven.home=$MAVEN_HOME" \
   "-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
   "-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR" \
-  $LAUNCHER_CLASS "$@"
+  $LAUNCHER_CLASS \
+  $MAVEN_ARGS \
+  "$@"
diff --git a/apache-maven/src/assembly/shared/run.cmd b/apache-maven/src/assembly/shared/run.cmd
index ac526f8..dd81c38 100755
--- a/apache-maven/src/assembly/shared/run.cmd
+++ b/apache-maven/src/assembly/shared/run.cmd
@@ -7,7 +7,9 @@
   "-Dmaven.home=%MAVEN_HOME%" ^
   "-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
   "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
-  %LAUNCHER_CLASS% %*
+  %LAUNCHER_CLASS% ^
+  %MAVEN_CONFIG_MAVEN_PROPS% ^
+  %*
 if ERRORLEVEL 1 goto error
 goto end