use of org.eclipse.aether.graph.DependencyNode in project bnd by bndtools.
the class DependencyResolver method discoverArtifacts.
private void discoverArtifacts(Map<File, ArtifactResult> files, List<DependencyNode> nodes, String parent, List<RemoteRepository> remoteRepositories) throws MojoExecutionException {
for (DependencyNode node : nodes) {
// Ensure that the file is downloaded so we can index it
try {
ArtifactResult resolvedArtifact = postProcessor.postProcessResult(system.resolveArtifact(session, new ArtifactRequest(node.getArtifact(), remoteRepositories, parent)));
logger.debug("Located file: {} for artifact {}", resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
files.put(resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve the dependency " + node.getArtifact().toString(), e);
}
if (includeTransitive) {
discoverArtifacts(files, node.getChildren(), node.getRequestContext(), remoteRepositories);
} else {
logger.debug("Ignoring transitive dependencies of {}", node.getDependency());
}
}
}
use of org.eclipse.aether.graph.DependencyNode in project atlasmap by atlasmap.
the class GenerateInspectionsMojo method resolveClasspath.
private List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
final List<URL> urls = new ArrayList<>();
try {
for (String gav : artifacts) {
Artifact artifact = new DefaultArtifact(gav);
getLog().debug("Resolving dependencies for artifact: " + artifact);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, ""));
collectRequest.setRepositories(remoteRepos);
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setCollectRequest(collectRequest);
DependencyResult dependencyResult = system.resolveDependencies(repoSession, dependencyRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
dependencyResult.getRoot().accept(nlg);
Iterator<DependencyNode> it = nlg.getNodes().iterator();
while (it.hasNext()) {
DependencyNode node = it.next();
if (node.getDependency() != null) {
Artifact x = node.getDependency().getArtifact();
if (x.getFile() != null) {
getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
urls.add(x.getFile().toURI().toURL());
}
}
}
}
} catch (IllegalArgumentException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (DependencyResolutionException e) {
throw new MojoFailureException(e.getMessage(), e);
} catch (MalformedURLException e) {
throw new MojoFailureException(e.getMessage(), e);
}
return urls;
}
use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.
the class AetherBasedResolver method collectDependencies.
protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
final DefaultRepositorySystemSession session = newSession();
try {
List<RemoteRepository> repos = selectRepositories();
assignProxyAndMirrors(repos);
ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
repos.addAll(artifactDescriptorResult.getRepositories());
Dependency rootDependency = new Dependency(root, null);
List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
GenericVersionScheme versionScheme = new GenericVersionScheme();
rootNode.setVersion(versionScheme.parseVersion(pomVersion));
rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
DependencyNode pomNode = rootNode;
// final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
@Override
public boolean selectDependency(Dependency dependency) {
try {
return !DependencyFilters.matches(dependency, shouldExclude);
} catch (Exception e) {
failedToMakeDependencyTree(dependency, e);
return false;
}
}
});
session.setDependencySelector(dependencySelector);
// work on the root dependency directly?
if (true) {
for (Dependency dependency : dependencies) {
DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
if (node != null) {
pomNode.getChildren().add(node);
}
}
} else {
DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
if (node != null) {
pomNode = node;
}
}
// now lets transform the dependency tree to remove different versions for the same artifact
final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {
Map<Object, Object> map = new HashMap<>();
public RepositorySystemSession getSession() {
return session;
}
public Object get(Object key) {
return map.get(key);
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
};
DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
pomNode = transformer.transformGraph(pomNode, tranformContext);
transformer = new DuplicateTransformer();
pomNode = transformer.transformGraph(pomNode, tranformContext);
return pomNode;
} finally {
releaseSession(session);
}
}
use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.
the class DuplicateTransformer method visit.
private void visit(DependencyNode node, Set<DependencyNode> visited) {
List<DependencyNode> newChildren = new ArrayList<>();
for (DependencyNode childNode : node.getChildren()) {
if (visited.add(childNode)) {
newChildren.add(childNode);
visit(childNode, visited);
}
}
node.setChildren(newChildren);
}
use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.
the class ReplaceConflictingVersionResolver method selectVersion.
private void selectVersion(DependencyNode node, DependencyNode parent, int depth, Map<DependencyNode, Integer> depths, ConflictGroup group, Map<?, ?> conflictIds) throws RepositoryException {
Integer smallestDepth = depths.get(node);
if (smallestDepth == null || smallestDepth > depth) {
depths.put(node, depth);
} else {
return;
}
Object key = conflictIds.get(node);
if (group.key.equals(key)) {
Position pos = new Position(parent, depth);
if (parent != null) {
group.positions.add(pos);
}
if (!group.isAcceptable(node.getVersion())) {
return;
}
group.candidates.put(node, pos);
VersionConstraint versionConstraint = node.getVersionConstraint();
if (versionConstraint != null && versionConstraint.getRange() != null && isNotEmpty(versionConstraint.getRange())) {
group.constraints.add(versionConstraint);
}
if (group.version == null || isNearer(pos, node.getVersion(), group.position, group.version)) {
group.version = node.getVersion();
group.versionDependency = node;
group.position = pos;
}
if (!group.isAcceptable(group.version)) {
group.version = null;
group.versionDependency = null;
for (Iterator<Map.Entry<DependencyNode, Position>> it = group.candidates.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<DependencyNode, Position> entry = it.next();
Version version = entry.getKey().getVersion();
pos = entry.getValue();
if (!group.isAcceptable(version)) {
it.remove();
} else if (group.version == null || isNearer(pos, version, group.position, group.version)) {
group.version = version;
group.versionDependency = entry.getKey();
group.position = pos;
}
}
if (group.version == null) {
Collection<String> versions = new LinkedHashSet<String>();
for (VersionConstraint constraint : group.constraints) {
versions.add(constraint.toString());
}
// TODO, FIXME
throw new UnsolvableVersionConflictException(Collections.<List<DependencyNode>>emptyList());
}
}
}
for (DependencyNode child : node.getChildren()) {
selectVersion(child, node, depth + 1, depths, group, conflictIds);
}
}
Aggregations