use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.
the class ReplaceConflictingVersionResolver method updateNonSelectedVersions.
private void updateNonSelectedVersions(ConflictGroup group, Map<?, ?> conflictIds) {
for (Position pos : group.positions) {
DependencyNode parent = pos.parent;
List<DependencyNode> children = parent.getChildren();
List<DependencyNode> toAdd = new ArrayList<DependencyNode>();
for (Iterator<DependencyNode> it = children.iterator(); it.hasNext(); ) {
DependencyNode child = it.next();
Object key = conflictIds.get(child);
if (group.key.equals(key)) {
if (!group.pruned && group.position != null && group.version != null && group.position.depth == pos.depth && group.version.equals(child.getVersion())) {
group.pruned = true;
} else {
it.remove();
// now lets add the common dependency
if (group.versionDependency == null) {
throw new IllegalStateException("Should have a versionDependency for group: " + group + " and version: " + group.version);
}
toAdd.add(group.versionDependency);
}
}
}
children.addAll(toAdd);
}
}
use of org.eclipse.aether.graph.DependencyNode in project mule by mulesoft.
the class DependencyResolver method resolveDependencies.
/**
* Resolves and filters transitive dependencies for the root and direct dependencies.
* <p/>
* If both a root dependency and direct dependencies are given, the direct dependencies will be merged with the direct
* dependencies from the root dependency's artifact descriptor, giving higher priority to the dependencies from the root.
*
* @param root {@link Dependency} node from to collect its dependencies, may be {@code null}
* @param directDependencies {@link List} of direct {@link Dependency} to collect its transitive dependencies, may be
* {@code null}
* @param managedDependencies {@link List} of managed {@link Dependency}s to be used for resolving the depedency graph, may be
* {@code null}
* @param dependencyFilter {@link DependencyFilter} to include/exclude dependency nodes during collection and resolve operation.
* May be {@code null} to no filter
* @param remoteRepositories {@link RemoteRepository} to be used when resolving dependencies in addition to the ones already defined in the context.
* @return a {@link List} of {@link File}s for each dependency resolved
* @throws {@link DependencyCollectionException} if the dependency tree could not be built
* @thwows {@link DependencyResolutionException} if the dependency tree could not be built or any dependency artifact could not
* be resolved
*/
public List<File> resolveDependencies(Dependency root, List<Dependency> directDependencies, List<Dependency> managedDependencies, DependencyFilter dependencyFilter, List<RemoteRepository> remoteRepositories) throws DependencyCollectionException, DependencyResolutionException {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(root);
collectRequest.setDependencies(directDependencies);
collectRequest.setManagedDependencies(managedDependencies);
collectRequest.setRepositories(resolutionContext.getRemoteRepositories());
// Has to set authentication to these remote repositories as they may come from a pom descriptor
remoteRepositories.forEach(remoteRepository -> {
RemoteRepository authenticatedRemoteRepository = setAuthentication(remoteRepository);
if (!collectRequest.getRepositories().contains(authenticatedRemoteRepository)) {
collectRequest.addRepository(authenticatedRemoteRepository);
}
});
DependencyNode node;
try {
logger.debug("Collecting dependencies for '{}'", printCollectRequest(collectRequest));
node = repositoryState.getSystem().collectDependencies(repositoryState.getSession(), collectRequest).getRoot();
logDependencyGraph(node, collectRequest);
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
dependencyRequest.setCollectRequest(collectRequest);
if (dependencyFilter != null) {
dependencyRequest.setFilter(dependencyFilter);
}
node = repositoryState.getSystem().resolveDependencies(repositoryState.getSession(), dependencyRequest).getRoot();
} catch (DependencyResolutionException e) {
logger.warn("Dependencies couldn't be resolved for request '{}', {}", collectRequest, e.getMessage());
node = e.getResult().getRoot();
logUnresolvedArtifacts(node, e);
throw e;
}
List<File> files = getFiles(node);
return files;
}
use of org.eclipse.aether.graph.DependencyNode in project revapi by revapi.
the class ArtifactResolver method collectTransitiveDeps.
protected void collectTransitiveDeps(String gav, Set<Artifact> resolvedArtifacts, Set<Exception> failures) throws RepositoryException {
final Artifact rootArtifact = resolveArtifact(gav);
CollectRequest collectRequest = new CollectRequest(new Dependency(rootArtifact, null), repositories);
DependencyRequest request = new DependencyRequest(collectRequest, null);
DependencyResult result;
try {
result = repositorySystem.resolveDependencies(session, request);
} catch (DependencyResolutionException dre) {
result = dre.getResult();
}
result.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {
@Override
public boolean visitEnter(DependencyNode node) {
return true;
}
@Override
public boolean visitLeave(DependencyNode node) {
Dependency dep = node.getDependency();
if (dep == null || dep.getArtifact().equals(rootArtifact)) {
return true;
}
resolvedArtifacts.add(dep.getArtifact());
return true;
}
}));
failures.addAll(result.getCollectExceptions());
}
use of org.eclipse.aether.graph.DependencyNode in project activemq-artemis by apache.
the class ArtemisAbstractPlugin method explodeDependencies.
protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
final List<Artifact> dependencies = new LinkedList<>();
CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
final AtomicInteger level = new AtomicInteger(0);
DependencyNode node = result.getRoot();
StringWriter writer = new StringWriter();
final PrintWriter strPrint = new PrintWriter(writer);
strPrint.println("Dependencies explored for " + artifact + ":");
if (node != null) {
node.accept(new DependencyVisitor() {
@Override
public boolean visitEnter(DependencyNode node) {
for (int i = 0; i < level.get(); i++) {
strPrint.print("!...");
}
level.incrementAndGet();
strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
dependencies.add(node.getArtifact());
return true;
}
@Override
public boolean visitLeave(DependencyNode node) {
level.decrementAndGet();
return true;
}
});
}
getLog().info(writer.toString());
return dependencies;
}
use of org.eclipse.aether.graph.DependencyNode in project druid by druid-io.
the class PullDependencies method downloadExtension.
private void downloadExtension(Artifact versionedArtifact, File toLocation, Dependencies exclusions) {
final CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), (node, parents) -> {
String scope = node.getDependency().getScope();
if (scope != null) {
scope = StringUtils.toLowerCase(scope);
if ("provided".equals(scope)) {
return false;
}
if ("test".equals(scope)) {
return false;
}
if ("system".equals(scope)) {
return false;
}
}
if (exclusions.contain(node.getArtifact())) {
return false;
}
for (DependencyNode parent : parents) {
if (exclusions.contain(parent.getArtifact())) {
return false;
}
}
return true;
}));
try {
log.info("Start downloading extension [%s]", versionedArtifact);
final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
for (Artifact artifact : artifacts) {
if (exclusions.contain(artifact)) {
log.debug("Skipped Artifact[%s]", artifact);
} else {
log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
org.apache.commons.io.FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
}
}
} catch (Exception e) {
log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
throw new RuntimeException(e);
}
log.info("Finish downloading extension [%s]", versionedArtifact);
}
Aggregations