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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -153,10 +154,12 @@ DependencyResult resolveDependencies(RepositorySystemSession session, Dependency
*
* @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);
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
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 @@ -302,12 +297,23 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep
}

@Override
public List<DependencyNode> flattenDependencyNodes(RepositorySystemSession session, DependencyNode root) {
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