Skip to content

Commit 4728546

Browse files
author
Vincent Potucek
committed
Pull apache#2287: Modernize codebase with Java improvements - ReplaceStreamToListWithCollect
1 parent 3706aa1 commit 4728546

File tree

46 files changed

+110
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+110
-82
lines changed

api/maven-api-core/src/main/java/org/apache/maven/api/services/ProblemCollector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.concurrent.CopyOnWriteArrayList;
2727
import java.util.concurrent.atomic.AtomicInteger;
2828
import java.util.concurrent.atomic.LongAdder;
29+
import java.util.stream.Collectors;
2930
import java.util.stream.Stream;
3031

3132
import org.apache.maven.api.Constants;
@@ -216,7 +217,7 @@ class Impl<P extends BuilderProblem> implements ProblemCollector<P> {
216217
private static final List<BuilderProblem.Severity> REVERSED_ORDER = Arrays.stream(
217218
BuilderProblem.Severity.values())
218219
.sorted(Comparator.reverseOrder())
219-
.toList();
220+
.collect(Collectors.toList());
220221

221222
private Impl(int maxCountLimit) {
222223
if (maxCountLimit < 0) {

compat/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleBindingsInjector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Optional;
27+
import java.util.stream.Collectors;
2728

2829
import org.apache.maven.api.Lifecycle;
2930
import org.apache.maven.api.Packaging;
@@ -126,7 +127,7 @@ private static Plugin newPlugin(String artifactId, String... goals) {
126127
.id("default-" + goal)
127128
.goals(List.of(goal))
128129
.build())
129-
.toList())
130+
.collect(Collectors.toList()))
130131
.build();
131132
}
132133

compat/maven-model-builder/src/test/java/org/apache/maven/model/building/FileToRawModelMergerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void testOverriddenMergeMethods() {
5858
}
5959
})
6060
.map(Method::getName)
61-
.toList();
61+
.collect(Collectors.toList());
6262

6363
List<String> overriddenMethods = Stream.of(FileToRawModelMerger.class.getDeclaredMethods())
6464
.map(Method::getName)

compat/maven-model/src/test/java/org/apache/maven/model/pom/PomMemoryAnalyzer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private List<ValueFrequency> getMostFrequentValues(Map<String, StringStats> stat
219219
.map(e -> new ValueFrequency(e.getKey(), e.getValue().getOccurrences()))
220220
.sorted((a, b) -> Long.compare(b.frequency, a.frequency))
221221
.limit(limit)
222-
.toList();
222+
.collect(Collectors.toList());
223223
}
224224

225225
public void printAnalysis() {
@@ -270,7 +270,7 @@ public void printAnalysis() {
270270
groupName, paths, totalUnique, totalOccurrences, totalMemory, totalSavings, topValues);
271271
})
272272
.sorted((a, b) -> Long.compare(b.totalSavings, a.totalSavings))
273-
.toList();
273+
.collect(Collectors.toList());
274274

275275
// Print each group
276276
for (GroupAnalysis group : sortedGroups) {
@@ -290,7 +290,7 @@ public void printAnalysis() {
290290
System.out.println("----------------------------------------");
291291
for (PathAnalysis path : group.paths.stream()
292292
.sorted((a, b) -> Long.compare(b.potentialSavings, a.potentialSavings))
293-
.toList()) {
293+
.collect(Collectors.toList())) {
294294
System.out.printf(
295295
"%-90s %6dKB %6dKB%n", path.path, path.totalMemory / 1024, path.potentialSavings / 1024);
296296
}

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LayeredOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Optional;
2626
import java.util.function.Consumer;
2727
import java.util.function.Function;
28+
import java.util.stream.Collectors;
2829

2930
import org.apache.maven.api.cli.Options;
3031
import org.apache.maven.api.cli.ParserRequest;
@@ -49,7 +50,7 @@ public Optional<Map<String, String>> userProperties() {
4950
@Override
5051
public String source() {
5152
return String.format(
52-
"layered(%s)", options.stream().map(Options::source).toList());
53+
"layered(%s)", options.stream().map(Options::source).collect(Collectors.toList()));
5354
}
5455

5556
@Override

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Properties;
3838
import java.util.function.Consumer;
3939
import java.util.function.UnaryOperator;
40+
import java.util.stream.Collectors;
4041

4142
import org.apache.maven.api.Constants;
4243
import org.apache.maven.api.ProtoSession;
@@ -700,7 +701,7 @@ protected Runnable settings(C context, boolean emitSettingsWarnings, SettingsBui
700701

701702
if (context.invokerRequest.options().showErrors().orElse(false)) {
702703
for (BuilderProblem problem :
703-
settingsResult.getProblems().problems().toList()) {
704+
settingsResult.getProblems().problems().collect(Collectors.toList())) {
704705
context.logger.warn(problem.getMessage() + " @ " + problem.getLocation());
705706
}
706707
}
@@ -892,7 +893,7 @@ protected void populateRequestFromSettings(MavenExecutionRequest request, Settin
892893
}
893894
})
894895
.filter(Objects::nonNull)
895-
.toList());
896+
.collect(Collectors.toList()));
896897
request.setPluginArtifactRepositories(remotePluginRepositories.values().stream()
897898
.map(r -> {
898899
try {
@@ -904,7 +905,7 @@ protected void populateRequestFromSettings(MavenExecutionRequest request, Settin
904905
}
905906
})
906907
.filter(Objects::nonNull)
907-
.toList());
908+
.collect(Collectors.toList()));
908909
}
909910

910911
protected int calculateDegreeOfConcurrency(String threadConfiguration) {

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/PlexusContainerCapsuleFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import java.util.Set;
2828
import java.util.function.UnaryOperator;
29+
import java.util.stream.Collectors;
2930

3031
import com.google.inject.AbstractModule;
3132
import com.google.inject.Module;
@@ -94,7 +95,7 @@ protected DefaultPlexusContainer container(
9495
coreEntry.getExportedArtifacts(),
9596
coreExtensionSelector.selectCoreExtensions(invoker, context));
9697
List<CoreExtensionEntry> loadedExtensionsEntries =
97-
loadedExtensions.stream().map(LoadedCoreExtension::entry).toList();
98+
loadedExtensions.stream().map(LoadedCoreExtension::entry).collect(Collectors.toList());
9899
ClassRealm containerRealm =
99100
setupContainerRealm(context.logger, classWorld, coreRealm, extClassPath, loadedExtensionsEntries);
100101
ContainerConfiguration cc = new DefaultContainerConfiguration()

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/LayeredMavenOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Objects;
2525
import java.util.Optional;
2626
import java.util.function.UnaryOperator;
27+
import java.util.stream.Collectors;
2728

2829
import org.apache.maven.api.cli.mvn.MavenOptions;
2930
import org.apache.maven.cling.invoker.LayeredOptions;
@@ -35,7 +36,7 @@
3536
*/
3637
public class LayeredMavenOptions<O extends MavenOptions> extends LayeredOptions<O> implements MavenOptions {
3738
public static MavenOptions layerMavenOptions(Collection<MavenOptions> options) {
38-
List<MavenOptions> o = options.stream().filter(Objects::nonNull).toList();
39+
List<MavenOptions> o = options.stream().filter(Objects::nonNull).collect(Collectors.toList());
3940
if (o.isEmpty()) {
4041
throw new IllegalArgumentException("No options specified (or all were null)");
4142
} else if (o.size() == 1) {

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ protected void toolchains(MavenContext context, MavenExecutionRequest request) t
213213

214214
if (context.invokerRequest.options().showErrors().orElse(false)) {
215215
for (BuilderProblem problem :
216-
toolchainsResult.getProblems().problems().toList()) {
216+
toolchainsResult.getProblems().problems().collect(Collectors.toList())) {
217217
context.logger.warn(problem.getMessage() + " @ " + problem.getLocation());
218218
}
219219
}

impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.file.Path;
2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.stream.Collectors;
2728
import java.util.stream.Stream;
2829

2930
import org.apache.commons.cli.ParseException;
@@ -67,7 +68,7 @@ protected MavenOptions parseMavenCliOptions(List<String> args) {
6768
protected MavenOptions parseMavenAtFileOptions(Path atFile) {
6869
try (Stream<String> lines = Files.lines(atFile, Charset.defaultCharset())) {
6970
List<String> args =
70-
lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")).toList();
71+
lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")).collect(Collectors.toList());
7172
return parseArgs("atFile", args);
7273
} catch (ParseException e) {
7374
throw new IllegalArgumentException(
@@ -80,7 +81,7 @@ protected MavenOptions parseMavenAtFileOptions(Path atFile) {
8081
protected MavenOptions parseMavenConfigOptions(Path configFile) {
8182
try (Stream<String> lines = Files.lines(configFile, Charset.defaultCharset())) {
8283
List<String> args =
83-
lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")).toList();
84+
lines.filter(arg -> !arg.isEmpty() && !arg.startsWith("#")).collect(Collectors.toList());
8485
MavenOptions options = parseArgs("maven.config", args);
8586
if (options.goals().isPresent()) {
8687
// This file can only contain options, not args (goals or phases)

0 commit comments

Comments
 (0)