Close stream with try-with-resources

This closes #997
This commit is contained in:
Andrey Bruykhov 2023-02-10 11:08:19 +03:00 committed by Michael Osipov
parent b82479bf11
commit b17c968a0b
1 changed files with 9 additions and 8 deletions

View File

@ -41,6 +41,7 @@ import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Stream;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
@ -346,14 +347,14 @@ public class MavenCli {
File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG); File configFile = new File(cliRequest.multiModuleProjectDirectory, MVN_MAVEN_CONFIG);
if (configFile.isFile()) { if (configFile.isFile()) {
String[] args = Files.lines(configFile.toPath(), Charset.defaultCharset()) try (Stream<String> lines = Files.lines(configFile.toPath(), Charset.defaultCharset())) {
.filter(arg -> !arg.isEmpty()) String[] args = lines.filter(arg -> !arg.isEmpty()).toArray(String[]::new);
.toArray(size -> new String[size]); mavenConfig = cliManager.parse(args);
mavenConfig = cliManager.parse(args); List<?> unrecognized = mavenConfig.getArgList();
List<?> unrecognized = mavenConfig.getArgList(); if (!unrecognized.isEmpty()) {
if (!unrecognized.isEmpty()) { // This file can only contain options, not args (goals or phases)
// This file can only contain options, not args (goals or phases) throw new ParseException("Unrecognized maven.config file entries: " + unrecognized);
throw new ParseException("Unrecognized maven.config file entries: " + unrecognized); }
} }
} }
} catch (ParseException e) { } catch (ParseException e) {