From eafb3d1e8a2f700a87eb6083a94cc2253cdc7200 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 12 Feb 2024 07:59:27 +0100 Subject: [PATCH] Small cleanup --- .../services/DependencyResolverResult.java | 2 +- .../impl/DefaultDependencyResolver.java | 46 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java index 60468046145e..cb1c32031d81 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyResolverResult.java @@ -77,7 +77,7 @@ public interface DependencyResolverResult extends DependencyCollectorResult { * @param type the desired type of path (class-path, module-path, …) * @return the option to pass to Java tools */ - default Optional formatOption(final PathType type) { + default Optional formatOption(PathType type) { List paths = getDispatchedPaths().get(type); if (paths != null) { String option = type.option(paths); diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolver.java b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolver.java index 65a1a18ea05f..c66c2cb03de0 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolver.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultDependencyResolver.java @@ -83,26 +83,26 @@ private static DependencyFilter getScopeDependencyFilter(PathScope scope) { * @return the result of the resolution */ @Override - public DependencyResolverResult resolve(final DependencyResolverRequest request) + public DependencyResolverResult resolve(DependencyResolverRequest request) throws DependencyCollectorException, DependencyResolverException, ArtifactResolverException { nonNull(request, "request"); - final InternalSession session = InternalSession.from(request.getSession()); - final Predicate filter = request.getPathTypeFilter(); - final PathModularizationCache cache = new PathModularizationCache(); // TODO: should be project-wide cache. + InternalSession session = InternalSession.from(request.getSession()); + Predicate filter = request.getPathTypeFilter(); + PathModularizationCache cache = new PathModularizationCache(); // TODO: should be project-wide cache. if (request.getProject().isPresent()) { - final DependencyResolutionResult resolved = resolveDependencies( + DependencyResolutionResult resolved = resolveDependencies( request.getSession(), request.getProject().get(), request.getPathScope()); - final Map nodes = stream( + Map nodes = stream( resolved.getDependencyGraph()) .filter(n -> n.getDependency() != null) .collect(Collectors.toMap(DependencyNode::getDependency, n -> n)); - final Node root = session.getNode(resolved.getDependencyGraph()); - final List deprendencies = resolved.getResolvedDependencies(); - final DefaultDependencyResolverResult result = - new DefaultDependencyResolverResult(resolved.getCollectionErrors(), root, deprendencies.size()); - for (org.eclipse.aether.graph.Dependency dep : deprendencies) { + Node root = session.getNode(resolved.getDependencyGraph()); + List dependencies = resolved.getResolvedDependencies(); + DefaultDependencyResolverResult result = + new DefaultDependencyResolverResult(resolved.getCollectionErrors(), root, dependencies.size()); + for (org.eclipse.aether.graph.Dependency dep : dependencies) { Node node = session.getNode(nodes.get(dep)); Path path = dep.getArtifact().getFile().toPath(); try { @@ -114,16 +114,16 @@ public DependencyResolverResult resolve(final DependencyResolverRequest request) return result; } - final DependencyCollectorResult collectorResult = + DependencyCollectorResult collectorResult = session.getService(DependencyCollector.class).collect(request); - final List nodes = flatten(session, collectorResult.getRoot(), request.getPathScope()); - final List coordinates = nodes.stream() + List nodes = flatten(session, collectorResult.getRoot(), request.getPathScope()); + List coordinates = nodes.stream() .map(Node::getDependency) .filter(Objects::nonNull) .map(Artifact::toCoordinate) .collect(Collectors.toList()); - final Map artifacts = session.resolveArtifacts(coordinates); - final DefaultDependencyResolverResult result = new DefaultDependencyResolverResult( + Map artifacts = session.resolveArtifacts(coordinates); + DefaultDependencyResolverResult result = new DefaultDependencyResolverResult( collectorResult.getExceptions(), collectorResult.getRoot(), nodes.size()); for (Node node : nodes) { Dependency d = node.getDependency(); @@ -137,10 +137,6 @@ public DependencyResolverResult resolve(final DependencyResolverRequest request) return result; } - private static Stream stream(final DependencyNode node) { - return Stream.concat(Stream.of(node), node.getChildren().stream().flatMap(DefaultDependencyResolver::stream)); - } - private DependencyResolutionResult resolveDependencies(Session session, Project project, PathScope scope) { Collection toResolve = toScopes(scope); try { @@ -158,15 +154,19 @@ private DependencyResolutionResult resolveDependencies(Session session, Project } } - private static MavenProject getMavenProject(final Project project) { + private static Stream stream(DependencyNode node) { + return Stream.concat(Stream.of(node), node.getChildren().stream().flatMap(DefaultDependencyResolver::stream)); + } + + private static MavenProject getMavenProject(Project project) { return ((DefaultProject) project).getProject(); } - private Collection toScopes(PathScope scope) { + private static Collection toScopes(PathScope scope) { return map(scope.dependencyScopes(), DependencyScope::id); } - private static DependencyResolverException cannotReadModuleInfo(final Path path, final IOException cause) { + private static DependencyResolverException cannotReadModuleInfo(Path path, IOException cause) { return new DependencyResolverException("Cannot read module information of " + path, cause); } }