From 07278b49f03e483f18dff2adb717a66d0d20dfd8 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 6 Dec 2023 10:41:18 +0100 Subject: [PATCH 1/2] [MRESOLVER-447] Expose flatten method w/ filter As this now exposes full "second step" in resolveDependencies, so client code can reuse and have all of it. --- https://issues.apache.org/jira/browse/MRESOLVER-447 --- .../org/eclipse/aether/RepositorySystem.java | 14 +++++++++ .../impl/DefaultRepositorySystem.java | 30 ++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java index c71c08b2a..1e13b8bb1 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java @@ -29,6 +29,7 @@ import org.eclipse.aether.deployment.DeployRequest; import org.eclipse.aether.deployment.DeployResult; import org.eclipse.aether.deployment.DeploymentException; +import org.eclipse.aether.graph.DependencyFilter; import org.eclipse.aether.graph.DependencyNode; import org.eclipse.aether.installation.InstallRequest; import org.eclipse.aether.installation.InstallResult; @@ -158,6 +159,19 @@ DependencyResult resolveDependencies(RepositorySystemSession session, Dependency */ List flattenDependencyNodes(RepositorySystemSession session, DependencyNode root); + /** + * Flattens the provided graph as {@link DependencyNode} into a {@link List}{@code } according to session + * configuration. + * + * @param session The repository session, must not be {@code null}. + * @param root The dependency node root of the graph, must not be {@code null}. + * @param filter The filter to apply, may be {@code null}. + * @return The flattened list of dependency nodes, never {@code null}. + * @since 2.0.0 + */ + List flattenDependencyNodes( + RepositorySystemSession session, DependencyNode root, DependencyFilter filter); + /** * Resolves the path for an artifact. The artifact will be downloaded to the local repository if necessary. An * artifact that is already resolved will be skipped and is not re-resolved. In general, callers must not assume any diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java index 20f98dc22..073d3173e 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java @@ -260,13 +260,8 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep throw new NullPointerException("dependency node and collect request cannot be null"); } - final ArrayList dependencyNodes = new ArrayList<>(); - DependencyVisitor builder = getDependencyVisitor(session, dependencyNodes::add); - DependencyFilter filter = request.getFilter(); - DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder; - if (result.getRoot() != null) { - result.getRoot().accept(visitor); - } + final List dependencyNodes = + doFlattenDependencyNodes(session, result.getRoot(), request.getFilter()); final List requests = dependencyNodes.stream() .map(n -> { @@ -306,8 +301,27 @@ public List flattenDependencyNodes(RepositorySystemSession sessi validateSession(session); requireNonNull(root, "root cannot be null"); + return doFlattenDependencyNodes(session, root, null); + } + + @Override + public List flattenDependencyNodes( + RepositorySystemSession session, DependencyNode root, DependencyFilter dependencyFilter) { + validateSession(session); + requireNonNull(root, "root cannot be null"); + + return doFlattenDependencyNodes(session, root, dependencyFilter); + } + + private List doFlattenDependencyNodes( + RepositorySystemSession session, DependencyNode root, DependencyFilter dependencyFilter) { final ArrayList dependencyNodes = new ArrayList<>(); - root.accept(getDependencyVisitor(session, dependencyNodes::add)); + if (root != null) { + DependencyVisitor builder = getDependencyVisitor(session, dependencyNodes::add); + DependencyVisitor visitor = + (dependencyFilter != null) ? new FilteringDependencyVisitor(builder, dependencyFilter) : builder; + root.accept(visitor); + } return dependencyNodes; } From 4d2443249a393b9873e9e9cbb1b997ce1d9c0d4b Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 6 Dec 2023 11:33:31 +0100 Subject: [PATCH 2/2] Remove redundant method The removed one was added in alpha-1, the new one w/ filter now, and both are since 2.0.0. --- .../java/org/eclipse/aether/RepositorySystem.java | 11 ----------- .../aether/internal/impl/DefaultRepositorySystem.java | 8 -------- 2 files changed, 19 deletions(-) diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java index 1e13b8bb1..ddad8726d 100644 --- a/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java +++ b/maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java @@ -148,17 +148,6 @@ CollectResult collectDependencies(RepositorySystemSession session, CollectReques DependencyResult resolveDependencies(RepositorySystemSession session, DependencyRequest request) throws DependencyResolutionException; - /** - * Flattens the provided graph as {@link DependencyNode} into a {@link List}{@code } according to session - * configuration. - * - * @param session The repository session, must not be {@code null}. - * @param root The dependency node root of the graph, must not be {@code null}. - * @return The flattened list of dependency nodes, never {@code null}. - * @since 2.0.0 - */ - List flattenDependencyNodes(RepositorySystemSession session, DependencyNode root); - /** * Flattens the provided graph as {@link DependencyNode} into a {@link List}{@code } according to session * configuration. diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java index 073d3173e..d9a3254a6 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultRepositorySystem.java @@ -296,14 +296,6 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep return result; } - @Override - public List flattenDependencyNodes(RepositorySystemSession session, DependencyNode root) { - validateSession(session); - requireNonNull(root, "root cannot be null"); - - return doFlattenDependencyNodes(session, root, null); - } - @Override public List flattenDependencyNodes( RepositorySystemSession session, DependencyNode root, DependencyFilter dependencyFilter) {