Skip to content

Commit

Permalink
Add a flattenDependencyNodes method accepting a DependencyFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Dec 5, 2023
1 parent 45c5bdf commit ecfef19
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,19 @@ DependencyResult resolveDependencies(RepositorySystemSession session, Dependency
*/
List<DependencyNode> flattenDependencyNodes(RepositorySystemSession session, DependencyNode root);

/**
* Flattens the provided graph as {@link DependencyNode} into a {@link List}{@code <DependencyNode>} 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 optional dependency filter, can be {@code null}.
* @return The flattened list of dependency nodes, never {@code null}.
* @since 2.0.0
*/
List<DependencyNode> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,9 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep
throw new NullPointerException("dependency node and collect request cannot be null");
}

final ArrayList<DependencyNode> 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<DependencyNode> dependencyNodes = result.getRoot() != null
? flattenDependencyNodes(session, request.getRoot(), request.getFilter())
: new ArrayList<>();

final List<ArtifactRequest> requests = dependencyNodes.stream()
.map(n -> {
Expand Down Expand Up @@ -303,11 +299,19 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep

@Override
public List<DependencyNode> flattenDependencyNodes(RepositorySystemSession session, DependencyNode root) {
return flattenDependencyNodes(session, root, null);
}

@Override
public List<DependencyNode> flattenDependencyNodes(
RepositorySystemSession session, DependencyNode root, DependencyFilter filter) {
validateSession(session);
requireNonNull(root, "root cannot be null");

final ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
root.accept(getDependencyVisitor(session, dependencyNodes::add));
DependencyVisitor builder = getDependencyVisitor(session, dependencyNodes::add);
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
root.accept(visitor);
return dependencyNodes;
}

Expand Down

0 comments on commit ecfef19

Please sign in to comment.