[MNG-7131] maven.config doesn't handle arguments with spaces in them

Since we don't have a clear specification of the file format change
reading of the file to a one-arg-per-line basis just like Java's
@argfiles or Python's argparse would handle it.
Consider that jvm.config suffers from the same issue its parsing is not
portable between Bourne shell and Windows Command prompt.
This commit is contained in:
Michael Osipov 2021-07-15 18:55:16 +02:00
parent f582ce88fc
commit 0696cf14ad
4 changed files with 23 additions and 8 deletions

View File

@ -104,6 +104,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -387,7 +388,7 @@ public class MavenCli
if ( configFile.isFile() ) if ( configFile.isFile() )
{ {
for ( String arg : new String( Files.readAllBytes( configFile.toPath() ) ).split( "\\s+" ) ) for ( String arg : Files.readAllLines( configFile.toPath(), Charset.defaultCharset() ) )
{ {
if ( !arg.isEmpty() ) if ( !arg.isEmpty() )
{ {

View File

@ -195,8 +195,10 @@ public class MavenCliTest
/** /**
* Read .mvn/maven.config with the following definitions: * Read .mvn/maven.config with the following definitions:
* <pre> * <pre>
* -T 3 * -T
* 3
* -Drevision=1.3.0 * -Drevision=1.3.0
* "-Dlabel=Apache Maven"
* </pre> * </pre>
* and check if the {@code -T 3} option can be overwritten via command line * and check if the {@code -T 3} option can be overwritten via command line
* argument. * argument.
@ -221,8 +223,10 @@ public class MavenCliTest
/** /**
* Read .mvn/maven.config with the following definitions: * Read .mvn/maven.config with the following definitions:
* <pre> * <pre>
* -T 3 * -T
* 3
* -Drevision=1.3.0 * -Drevision=1.3.0
* "-Dlabel=Apache Maven"
* </pre> * </pre>
* and check if the {@code -Drevision-1.3.0} option can be overwritten via command line * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line
* argument. * argument.
@ -249,8 +253,10 @@ public class MavenCliTest
/** /**
* Read .mvn/maven.config with the following definitions: * Read .mvn/maven.config with the following definitions:
* <pre> * <pre>
* -T 3 * -T
* 3
* -Drevision=1.3.0 * -Drevision=1.3.0
* "-Dlabel=Apache Maven"
* </pre> * </pre>
* and check if the {@code -Drevision-1.3.0} option can be overwritten via command line * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line
* argument. * argument.
@ -277,8 +283,10 @@ public class MavenCliTest
/** /**
* Read .mvn/maven.config with the following definitions: * Read .mvn/maven.config with the following definitions:
* <pre> * <pre>
* -T 3 * -T
* 3
* -Drevision=1.3.0 * -Drevision=1.3.0
* "-Dlabel=Apache Maven"
* </pre> * </pre>
* and check if the {@code -Drevision-1.3.0} option can be overwritten via command line argument when there are * and check if the {@code -Drevision-1.3.0} option can be overwritten via command line argument when there are
* funky arguments present. * funky arguments present.
@ -300,11 +308,14 @@ public class MavenCliTest
cli.cli( request ); cli.cli( request );
cli.properties( request ); cli.properties( request );
assertEquals( "3", request.commandLine.getOptionValue( CLIManager.THREADS ) );
String revision = System.getProperty( "revision" ); String revision = System.getProperty( "revision" );
assertEquals( "8.2.0", revision ); assertEquals( "8.2.0", revision );
assertEquals( "bar ", request.getSystemProperties().getProperty( "foo" ) ); assertEquals( "bar ", request.getSystemProperties().getProperty( "foo" ) );
assertEquals( "bar two", request.getSystemProperties().getProperty( "foo2" ) ); assertEquals( "bar two", request.getSystemProperties().getProperty( "foo2" ) );
assertEquals( "Apache Maven", request.getSystemProperties().getProperty( "label" ) );
assertEquals( "-Dpom.xml", request.getCommandLine().getOptionValue( CLIManager.ALTERNATE_POM_FILE ) ); assertEquals( "-Dpom.xml", request.getCommandLine().getOptionValue( CLIManager.ALTERNATE_POM_FILE ) );
} }

View File

@ -1,2 +1,3 @@
-T8 --builder -T8
multithreaded --builder
multithreaded

View File

@ -1,3 +1,5 @@
-T 3 -T
3
-Drevision=1.3.0 -Drevision=1.3.0
"-Dlabel=Apache Maven"