mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-21 19:35:08 +00:00
[MNG-7131] maven.config doesn't handle arguments with spaces in them (backport to mvnd)
This commit is contained in:
@@ -22,6 +22,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
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.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -266,23 +267,20 @@ public class DaemonMavenCli implements DaemonCli {
|
|||||||
void cli(CliRequest cliRequest) throws Exception {
|
void cli(CliRequest cliRequest) throws Exception {
|
||||||
CLIManager cliManager = newCLIManager();
|
CLIManager cliManager = newCLIManager();
|
||||||
|
|
||||||
List<String> args = new ArrayList<>();
|
|
||||||
CommandLine mavenConfig = null;
|
CommandLine mavenConfig = null;
|
||||||
try {
|
try {
|
||||||
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
|
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
|
||||||
|
|
||||||
if (configFile.isFile()) {
|
if (configFile.isFile()) {
|
||||||
for (String arg : new String(Files.readAllBytes(configFile.toPath())).split("\\s+")) {
|
try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
|
||||||
if (!arg.isEmpty()) {
|
String[] args = lines.filter(arg -> !arg.isEmpty()).toArray(String[]::new);
|
||||||
args.add(arg);
|
mavenConfig = cliManager.parse(args);
|
||||||
|
List<?> unrecognized = mavenConfig.getArgList();
|
||||||
|
if (!unrecognized.isEmpty()) {
|
||||||
|
// This file can only contain options, not args (goals or phases)
|
||||||
|
throw new ParseException("Unrecognized maven.config file entries: " + unrecognized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
} catch (ParseException e) {
|
||||||
buildEventListener.log("Unable to parse maven.config: " + e.getMessage());
|
buildEventListener.log("Unable to parse maven.config: " + e.getMessage());
|
||||||
|
@@ -22,6 +22,7 @@ import java.io.File;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
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;
|
||||||
@@ -253,23 +254,20 @@ public class DaemonMavenCli implements DaemonCli {
|
|||||||
void cli(CliRequest cliRequest) throws Exception {
|
void cli(CliRequest cliRequest) throws Exception {
|
||||||
CLIManager cliManager = newCLIManager();
|
CLIManager cliManager = newCLIManager();
|
||||||
|
|
||||||
List<String> args = new ArrayList<>();
|
|
||||||
CommandLine mavenConfig = null;
|
CommandLine mavenConfig = null;
|
||||||
try {
|
try {
|
||||||
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
|
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
|
||||||
|
|
||||||
if (configFile.isFile()) {
|
if (configFile.isFile()) {
|
||||||
for (String arg : new String(Files.readAllBytes(configFile.toPath())).split("\\s+")) {
|
try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
|
||||||
if (!arg.isEmpty()) {
|
String[] args = lines.filter(arg -> !arg.isEmpty()).toArray(String[]::new);
|
||||||
args.add(arg);
|
mavenConfig = cliManager.parse(args);
|
||||||
|
List<?> unrecognized = mavenConfig.getArgList();
|
||||||
|
if (!unrecognized.isEmpty()) {
|
||||||
|
// This file can only contain options, not args (goals or phases)
|
||||||
|
throw new ParseException("Unrecognized maven.config file entries: " + unrecognized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
} catch (ParseException e) {
|
||||||
buildEventListener.log("Unable to parse maven.config: " + e.getMessage());
|
buildEventListener.log("Unable to parse maven.config: " + e.getMessage());
|
||||||
|
Reference in New Issue
Block a user