Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRESOLVER-447] Expose flatten method w/ filter #389

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 filter to apply, may 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,8 @@ 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 =
doFlattenDependencyNodes(session, result.getRoot(), request.getFilter());

final List<ArtifactRequest> requests = dependencyNodes.stream()
.map(n -> {
Expand Down Expand Up @@ -306,8 +301,27 @@ public List<DependencyNode> flattenDependencyNodes(RepositorySystemSession sessi
validateSession(session);
requireNonNull(root, "root cannot be null");

return doFlattenDependencyNodes(session, root, null);
}

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

return doFlattenDependencyNodes(session, root, dependencyFilter);
}

private List<DependencyNode> doFlattenDependencyNodes(
RepositorySystemSession session, DependencyNode root, DependencyFilter dependencyFilter) {
final ArrayList<DependencyNode> 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;
}

Expand Down