use of org.eclipse.aether.collection.CollectResult in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method resolveAll.
@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
if (specs.isEmpty()) {
return Collections.emptySet();
}
List<DependencyNode> nodes;
if (transitive) {
final CollectRequest request = new CollectRequest();
request.setRepositories(this.remoteRepositories);
// SWARM-1031
if (this.dependencyManagement != null) {
List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
return new Dependency(artifact, mavenDep.getScope());
}).collect(Collectors.toList());
request.setManagedDependencies(managedDependencies);
}
specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
CollectResult result = this.system.collectDependencies(tempSession, request);
PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
result.getRoot().accept(gen);
nodes = gen.getNodes();
} else {
nodes = new ArrayList<>();
for (ArtifactSpec spec : specs) {
Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
DefaultDependencyNode node = new DefaultDependencyNode(dependency);
nodes.add(node);
}
}
List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
nodes.addAll(extraDependencies);
resolveDependenciesInParallel(nodes);
return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
final Artifact artifact = node.getArtifact();
return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
}).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
Aggregations