Skip to content

Commit

Permalink
Expose both, DependencyNode as graph but also flattened.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Jul 28, 2023
1 parent 501d11e commit e3f9de4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public final class DependencyResult {

private List<Exception> collectExceptions;

private List<DependencyNode> dependencyNodeResults;

private List<ArtifactResult> artifactResults;

/**
Expand All @@ -56,6 +58,7 @@ public DependencyResult(DependencyRequest request) {
root = request.getRoot();
cycles = Collections.emptyList();
collectExceptions = Collections.emptyList();
this.dependencyNodeResults = Collections.emptyList();
artifactResults = Collections.emptyList();
}

Expand Down Expand Up @@ -140,6 +143,32 @@ public DependencyResult setCollectExceptions(List<Exception> exceptions) {
return this;
}

/**
* Gets the resolution results for the dependency nodes that matched {@link DependencyRequest#getFilter()}.
*
* @return The resolution results for the dependency nodes, never {@code null}.
* @since TBD
*/
public List<DependencyNode> getDependencyNodeResults() {
return dependencyNodeResults;
}

/**
* Sets the resolution results for the dependency nodes that matched {@link DependencyRequest#getFilter()}.
*
* @param results The resolution results for the dependency nodes, may be {@code null}.
* @return This result for chaining, never {@code null}.
* @since TBD
*/
public DependencyResult setDependencyNodeResults(List<DependencyNode> results) {
if (results == null) {
this.dependencyNodeResults = Collections.emptyList();
} else {
this.dependencyNodeResults = results;
}
return this;
}

/**
* Gets the resolution results for the dependency artifacts that matched {@link DependencyRequest#getFilter()}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import org.eclipse.aether.ConfigurationProperties;
import org.eclipse.aether.RepositorySystem;
Expand Down Expand Up @@ -342,36 +344,45 @@ public DependencyResult resolveDependencies(RepositorySystemSession session, Dep
throw new NullPointerException("dependency node and collect request cannot be null");
}

final ArrayList<ArtifactRequest> requests = new ArrayList<>();
ResettableDependencyNodeConsumer builderConsumer = new ResettableDependencyNodeConsumer() {
final ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
ResettableDependencyNodeConsumer consumer = new ResettableDependencyNodeConsumer() {
@Override
public void reset() {
requests.clear();
dependencyNodes.clear();
}

@Override
public void accept(DependencyNode n) {
if (n.getDependency() != null) {
ArtifactRequest artifactRequest = new ArtifactRequest(n);
artifactRequest.setTrace(trace);
requests.add(artifactRequest);
}
dependencyNodes.add(n);
}
};
DependencyVisitor builder = getDependencyVisitor(session, builderConsumer);
DependencyVisitor builder = getDependencyVisitor(session, consumer);
DependencyFilter filter = request.getFilter();
DependencyVisitor visitor = (filter != null) ? new FilteringDependencyVisitor(builder, filter) : builder;
if (result.getRoot() != null) {
result.getRoot().accept(visitor);
}

final List<ArtifactRequest> requests = dependencyNodes.stream()
.map(n -> {
if (n.getDependency() != null) {
ArtifactRequest artifactRequest = new ArtifactRequest(n);
artifactRequest.setTrace(trace);
return artifactRequest;
} else {
return null;
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
List<ArtifactResult> results;
try {
results = artifactResolver.resolveArtifacts(session, requests);
} catch (ArtifactResolutionException e) {
are = e;
results = e.getResults();
}
result.setDependencyNodeResults(dependencyNodes);
result.setArtifactResults(results);

updateNodesWithResolvedArtifacts(results);
Expand Down

0 comments on commit e3f9de4

Please sign in to comment.