Skip to content

Commit b3c9f06

Browse files
author
Vincent Potucek
committed
Pull #2287: Modernize codebase with Java improvements: Use modern Java collections API (toList() instead of collect(Collectors.toList()))
1 parent 3706aa1 commit b3c9f06

File tree

39 files changed

+63
-87
lines changed

39 files changed

+63
-87
lines changed

impl/maven-cli/src/main/java/org/apache/maven/cling/extensions/BootstrapCoreExtensionManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.NoSuchElementException;
2626
import java.util.Set;
2727
import java.util.function.UnaryOperator;
28-
import java.util.stream.Collectors;
2928

3029
import org.apache.maven.RepositoryUtils;
3130
import org.apache.maven.api.Service;
@@ -231,7 +230,7 @@ private List<Artifact> resolveExtension(
231230
return result.getArtifactResults().stream()
232231
.filter(ArtifactResult::isResolved)
233232
.map(ArtifactResult::getArtifact)
234-
.collect(Collectors.toList());
233+
.toList();
235234
} catch (PluginResolutionException | InterpolatorException e) {
236235
throw new ExtensionResolutionException(extension, e);
237236
}

impl/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.Map;
2828
import java.util.Objects;
2929
import java.util.Optional;
30-
import java.util.stream.Collectors;
3130

3231
import org.apache.maven.artifact.handler.ArtifactHandler;
3332
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
@@ -171,14 +170,14 @@ public static Dependency toDependency(
171170

172171
List<Exclusion> excl = Optional.ofNullable(exclusions).orElse(Collections.emptyList()).stream()
173172
.map(RepositoryUtils::toExclusion)
174-
.collect(Collectors.toList());
173+
.toList();
175174
return new Dependency(result, artifact.getScope(), artifact.isOptional(), excl);
176175
}
177176

178177
public static List<RemoteRepository> toRepos(List<ArtifactRepository> repos) {
179178
return Optional.ofNullable(repos).orElse(Collections.emptyList()).stream()
180179
.map(RepositoryUtils::toRepo)
181-
.collect(Collectors.toList());
180+
.toList();
182181
}
183182

184183
public static RemoteRepository toRepo(ArtifactRepository repo) {
@@ -294,7 +293,7 @@ public static Dependency toDependency(
294293

295294
List<Exclusion> exclusions = dependency.getExclusions().stream()
296295
.map(RepositoryUtils::toExclusion)
297-
.collect(Collectors.toList());
296+
.toList();
298297

299298
return new Dependency(
300299
artifact,
@@ -326,7 +325,7 @@ public ArtifactType get(String stereotypeId) {
326325
}
327326

328327
public static Collection<Artifact> toArtifacts(Collection<org.apache.maven.artifact.Artifact> artifactsToConvert) {
329-
return artifactsToConvert.stream().map(RepositoryUtils::toArtifact).collect(Collectors.toList());
328+
return artifactsToConvert.stream().map(RepositoryUtils::toArtifact).toList();
330329
}
331330

332331
public static WorkspaceRepository getWorkspace(RepositorySystemSession session) {

impl/maven-core/src/main/java/org/apache/maven/artifact/resolver/filter/ExclusionArtifactFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.nio.file.PathMatcher;
2525
import java.util.List;
2626
import java.util.function.Predicate;
27-
import java.util.stream.Collectors;
2827

2928
import org.apache.maven.artifact.Artifact;
3029
import org.apache.maven.model.Exclusion;
@@ -40,7 +39,7 @@ public class ExclusionArtifactFilter implements ArtifactFilter {
4039
public ExclusionArtifactFilter(List<Exclusion> exclusions) {
4140
this.exclusions = exclusions;
4241
this.predicates =
43-
exclusions.stream().map(ExclusionArtifactFilter::toPredicate).collect(Collectors.toList());
42+
exclusions.stream().map(ExclusionArtifactFilter::toPredicate).toList();
4443
}
4544

4645
@Override

impl/maven-core/src/main/java/org/apache/maven/execution/DefaultBuildResumptionAnalyzer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.util.List;
2525
import java.util.Optional;
26-
import java.util.stream.Collectors;
2726

2827
import org.apache.maven.project.MavenProject;
2928
import org.slf4j.Logger;
@@ -56,7 +55,7 @@ public Optional<BuildResumptionData> determineBuildResumptionData(final MavenExe
5655
.filter(project -> result.getBuildSummary(project) == null
5756
|| result.getBuildSummary(project) instanceof BuildFailure)
5857
.map(project -> project.getGroupId() + ":" + project.getArtifactId())
59-
.collect(Collectors.toList());
58+
.toList();
6059

6160
if (remainingProjects.isEmpty()) {
6261
LOGGER.info("No remaining projects found, resuming the build would not make sense.");

impl/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Properties;
2929
import java.util.concurrent.ConcurrentHashMap;
3030
import java.util.concurrent.ConcurrentMap;
31-
import java.util.stream.Collectors;
3231

3332
import org.apache.maven.api.Session;
3433
import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -423,13 +422,13 @@ private static Settings adaptSettings(MavenExecutionRequest request) {
423422
.localRepository(localRepo != null ? localRepo.getAbsolutePath() : null)
424423
.interactiveMode(request.isInteractiveMode())
425424
.offline(request.isOffline())
426-
.proxies(request.getProxies().stream().map(Proxy::getDelegate).collect(Collectors.toList()))
427-
.servers(request.getServers().stream().map(Server::getDelegate).collect(Collectors.toList()))
428-
.mirrors(request.getMirrors().stream().map(Mirror::getDelegate).collect(Collectors.toList()))
425+
.proxies(request.getProxies().stream().map(Proxy::getDelegate).toList())
426+
.servers(request.getServers().stream().map(Server::getDelegate).toList())
427+
.mirrors(request.getMirrors().stream().map(Mirror::getDelegate).toList())
429428
.profiles(request.getProfiles().stream()
430429
.map(Profile::getDelegate)
431430
.map(SettingsUtilsV4::convertToSettingsProfile)
432-
.collect(Collectors.toList()))
431+
.toList())
433432
.activeProfiles(request.getActiveProfiles())
434433
.pluginGroups(request.getPluginGroups())
435434
.build());

impl/maven-core/src/main/java/org/apache/maven/graph/DefaultProjectDependencyGraph.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Map;
2929
import java.util.Objects;
3030
import java.util.Set;
31-
import java.util.stream.Collectors;
3231

3332
import org.apache.maven.execution.ProjectDependencyGraph;
3433
import org.apache.maven.project.CycleDetectedException;
@@ -153,7 +152,7 @@ private List<MavenProject> getSortedProjects(Set<String> projectIds) {
153152
return projectIds.stream()
154153
.map(projects::get)
155154
.sorted(Comparator.comparingInt(order::get))
156-
.collect(Collectors.toList());
155+
.toList();
157156
}
158157

159158
@Override

impl/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request)
231231
XmlNode dom = server.getDelegate().getConfiguration();
232232
List<XmlNode> children = dom.children().stream()
233233
.filter(c -> !"wagonProvider".equals(c.name()))
234-
.collect(Collectors.toList());
234+
.toList();
235235
dom = XmlNode.newInstance(dom.name(), children);
236236
PlexusConfiguration config = XmlPlexusConfiguration.toPlexusConfiguration(dom);
237237
configProps.put("aether.transport.wagon.config." + server.getId(), config);

impl/maven-core/src/main/java/org/apache/maven/internal/impl/CoreUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.List;
2323
import java.util.Objects;
2424
import java.util.function.Function;
25-
import java.util.stream.Collectors;
2625

2726
class CoreUtils {
2827

@@ -37,6 +36,6 @@ public static <T> T cast(Class<T> clazz, Object o, String name) {
3736
}
3837

3938
public static <U, V> List<V> map(Collection<U> list, Function<U, V> mapper) {
40-
return list.stream().map(mapper).filter(Objects::nonNull).collect(Collectors.toList());
39+
return list.stream().map(mapper).filter(Objects::nonNull).toList();
4140
}
4241
}

impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.Objects;
3535
import java.util.Optional;
3636
import java.util.Set;
37-
import java.util.stream.Collectors;
3837
import java.util.stream.Stream;
3938

4039
import org.apache.maven.api.DependencyScope;
@@ -143,7 +142,7 @@ public List<String> computePhases(Lifecycle lifecycle) {
143142
List<String> allPhases = graph.visitAll();
144143
Collections.reverse(allPhases);
145144
List<String> computed =
146-
allPhases.stream().filter(s -> !s.startsWith("$")).collect(Collectors.toList());
145+
allPhases.stream().filter(s -> !s.startsWith("$")).toList();
147146
return computed;
148147
}
149148

@@ -211,7 +210,7 @@ public Collection<Lifecycle> provides() {
211210
&& !Lifecycle.DEFAULT.equals(id)
212211
&& !Lifecycle.SITE.equals(id))
213212
.map(id -> wrap(all.get(id)))
214-
.collect(Collectors.toList());
213+
.toList();
215214
} catch (ComponentLookupException e) {
216215
throw new LookupException(e);
217216
}

impl/maven-core/src/main/java/org/apache/maven/internal/transformation/impl/DefaultConsumerPomBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ private static List<Profile> prune(List<Profile> profiles) {
288288
return builder.build(null).build();
289289
})
290290
.filter(p -> !isEmpty(p))
291-
.collect(Collectors.toList());
291+
.toList();
292292
}
293293

294294
private static boolean isEmpty(Profile profile) {
@@ -324,6 +324,6 @@ private static <T extends ModelBase.Builder> T prune(T builder, ModelBase model)
324324
private static List<Repository> pruneRepositories(List<Repository> repositories) {
325325
return repositories.stream()
326326
.filter(r -> !org.apache.maven.api.Repository.CENTRAL_ID.equals(r.getId()))
327-
.collect(Collectors.toList());
327+
.toList();
328328
}
329329
}

impl/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycles.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public List<Lifecycle> getLifeCycles() {
161161
return lifecyclesMap.values().stream()
162162
.peek(l -> Objects.requireNonNull(l.getId(), "A lifecycle must have an id."))
163163
.sorted(Comparator.comparing(Lifecycle::getId, comparator))
164-
.collect(Collectors.toList());
164+
.toList();
165165
}
166166

167167
private Map<String, Lifecycle> lookupLifecycles() {

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
27-
import java.util.stream.Collectors;
2827
import java.util.stream.Stream;
2928

3029
import org.apache.maven.api.Lifecycle;
@@ -84,7 +83,7 @@ public List<TaskSegment> calculateTaskSegments(MavenSession session)
8483
&& !rootProject.getDefaultGoal().isEmpty())) {
8584
tasks = Stream.of(rootProject.getDefaultGoal().split("\\s+"))
8685
.filter(g -> !g.isEmpty())
87-
.collect(Collectors.toList());
86+
.toList();
8887
}
8988

9089
return calculateTaskSegments(session, tasks);

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131
import java.util.Map;
3232
import java.util.Set;
33-
import java.util.stream.Collectors;
3433

3534
import org.apache.maven.RepositoryUtils;
3635
import org.apache.maven.api.services.MessageBuilderFactory;
@@ -96,7 +95,7 @@ public static List<MavenProject> getProjects(MavenProject project, MavenSession
9695
projectAndSubmodules.add(project);
9796
return session.getProjects().stream() // sorted all
9897
.filter(projectAndSubmodules::contains)
99-
.collect(Collectors.toList()); // sorted and filtered to what we need
98+
.toList(); // sorted and filtered to what we need
10099
} else {
101100
return Collections.singletonList(project);
102101
}

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Collection;
2727
import java.util.Collections;
2828
import java.util.List;
29-
import java.util.stream.Collectors;
3029

3130
import org.apache.maven.api.xml.XmlNode;
3231
import org.apache.maven.execution.MavenSession;
@@ -102,7 +101,7 @@ public static XmlNode convert(org.apache.maven.api.plugin.descriptor.MojoDescrip
102101
: null,
103102
null,
104103
null))
105-
.collect(Collectors.toList());
104+
.toList();
106105
return XmlNode.newInstance("configuration", children);
107106
}
108107

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/ProjectBuildList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ProjectBuildList(List<ProjectSegment> items) {
5555
*/
5656
public ProjectBuildList getByTaskSegment(TaskSegment taskSegment) {
5757
return new ProjectBuildList(
58-
items.stream().filter(pb -> taskSegment == pb.getTaskSegment()).collect(Collectors.toList()));
58+
items.stream().filter(pb -> taskSegment == pb.getTaskSegment()).toList());
5959
}
6060

6161
public Map<MavenProject, ProjectSegment> selectSegment(TaskSegment taskSegment) {

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/ConcurrentLifecycleStarter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
27-
import java.util.stream.Collectors;
2827
import java.util.stream.Stream;
2928

3029
import org.apache.maven.api.Lifecycle;
@@ -128,7 +127,7 @@ public List<TaskSegment> calculateTaskSegments(MavenSession session) throws Exce
128127
&& !rootProject.getDefaultGoal().isEmpty())) {
129128
tasks = Stream.of(rootProject.getDefaultGoal().split("\\s+"))
130129
.filter(g -> !g.isEmpty())
131-
.collect(Collectors.toList());
130+
.toList();
132131
}
133132

134133
return calculateTaskSegments(session, tasks);

impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/PluginLifecycle.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import java.util.Collection;
2222
import java.util.Collections;
2323
import java.util.List;
24-
import java.util.stream.Collectors;
2524
import java.util.stream.Stream;
2625

2726
import org.apache.maven.api.Lifecycle;
2827
import org.apache.maven.api.model.Plugin;
28+
import org.apache.maven.api.model.PluginExecution;
2929
import org.apache.maven.plugin.descriptor.PluginDescriptor;
3030

3131
class PluginLifecycle implements Lifecycle {
@@ -47,7 +47,7 @@ public String id() {
4747
@Override
4848
public Collection<Phase> phases() {
4949
return lifecycleOverlay.getPhases().stream()
50-
.map(phase -> new Phase() {
50+
.<Phase>map(phase -> new Phase() {
5151
@Override
5252
public String name() {
5353
return phase.getId();
@@ -61,11 +61,11 @@ public List<Plugin> plugins() {
6161
.version(pluginDescriptor.getVersion())
6262
.configuration(phase.getConfiguration())
6363
.executions(phase.getExecutions().stream()
64-
.map(exec -> org.apache.maven.api.model.PluginExecution.newBuilder()
64+
.map(exec -> PluginExecution.newBuilder()
6565
.goals(exec.getGoals())
6666
.configuration(exec.getConfiguration())
6767
.build())
68-
.collect(Collectors.toList()))
68+
.toList())
6969
.build());
7070
}
7171

@@ -84,7 +84,7 @@ public Stream<Phase> allPhases() {
8484
return Stream.concat(Stream.of(this), phases().stream().flatMap(Phase::allPhases));
8585
}
8686
})
87-
.collect(Collectors.toList());
87+
.toList();
8888
}
8989

9090
@Override

impl/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void set(String goals) {
5656

5757
if (goals != null && !goals.isEmpty()) {
5858
String[] mojoGoals = goals.split(",");
59-
mojos = Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).collect(Collectors.toList());
59+
mojos = Arrays.stream(mojoGoals).map(fromGoalIntoLifecycleMojo).toList();
6060
}
6161
}
6262

impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.LinkedHashMap;
2626
import java.util.List;
2727
import java.util.Map;
28-
import java.util.stream.Collectors;
2928
import java.util.stream.Stream;
3029

3130
import org.apache.maven.RepositoryUtils;
@@ -240,7 +239,7 @@ private DependencyResult resolveInternal(
240239
e.getResult().getArtifactResults().stream()
241240
.filter(r -> !r.isResolved())
242241
.flatMap(r -> r.getExceptions().stream()))
243-
.collect(Collectors.toList());
242+
.toList();
244243
throw new PluginResolutionException(plugin, exceptions, e);
245244
} finally {
246245
RequestTraceHelper.exit(trace);

impl/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginValidationManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.util.Map;
3737
import java.util.Set;
3838
import java.util.concurrent.ConcurrentHashMap;
39-
import java.util.stream.Collectors;
4039

4140
import org.apache.maven.api.Constants;
4241
import org.apache.maven.eventspy.AbstractEventSpy;
@@ -109,7 +108,7 @@ private List<String> parsePluginExcludes(RepositorySystemSession session) {
109108
return Arrays.stream(excludes.split(","))
110109
.map(String::trim)
111110
.filter(s -> !s.isEmpty())
112-
.collect(Collectors.toList());
111+
.toList();
113112
}
114113

115114
private ValidationReportLevel validationReportLevel(RepositorySystemSession session) {

0 commit comments

Comments
 (0)