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 2023/02/17 20:03:05 UTC
[maven] branch master updated: Close stream with try-with-resources
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new b17c968a0 Close stream with try-with-resources
b17c968a0 is described below
commit b17c968a0bad4c418f71015a8f721f21b29bfd98
Author: Andrey Bruykhov <an...@gmail.com>
AuthorDate: Fri Feb 10 11:08:19 2023 +0300
Close stream with try-with-resources
This closes #997
---
.../src/main/java/org/apache/maven/cli/MavenCli.java | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 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 fa38d0b84..df491025a 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
@@ -41,6 +41,7 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Stream;
import com.google.inject.AbstractModule;
import org.apache.commons.cli.CommandLine;
@@ -346,14 +347,14 @@ public class MavenCli {
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
if (configFile.isFile()) {
- String[] args = Files.lines(configFile.toPath(), Charset.defaultCharset())
- .filter(arg -> !arg.isEmpty())
- .toArray(size -> new String[size]);
- 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);
+ try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
+ String[] args = lines.filter(arg -> !arg.isEmpty()).toArray(String[]::new);
+ 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);
+ }
}
}
} catch (ParseException e) {