Search in sources :

Example 21 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project fabric8 by jboss-fuse.

the class ReplaceConflictingVersionResolver method transformGraph.

public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
    List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    if (sortedConflictIds == null) {
        ConflictIdSorter sorter = new ConflictIdSorter();
        sorter.transformGraph(node, context);
        sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    }
    Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
    if (conflictIds == null) {
        throw new RepositoryException("conflict groups have not been identified");
    }
    Map<DependencyNode, Integer> depths = new TreeMap<DependencyNode, Integer>(DependencyNodeComparator.INSTANCE);
    for (Object key : sortedConflictIds) {
        ConflictGroup group = new ConflictGroup(key);
        depths.clear();
        selectVersion(node, null, 0, depths, group, conflictIds);
        updateNonSelectedVersions(group, conflictIds);
    }
    return node;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) ConflictIdSorter(org.eclipse.aether.util.graph.transformer.ConflictIdSorter) RepositoryException(org.eclipse.aether.RepositoryException) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 22 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode 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());
}
Also used : LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) Proxy(org.eclipse.aether.repository.Proxy) Dependency(org.eclipse.aether.graph.Dependency) DependencyManagement(org.apache.maven.model.DependencyManagement) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest) CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) Authentication(org.apache.maven.artifact.repository.Authentication) Artifact(org.eclipse.aether.artifact.Artifact) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) Set(java.util.Set) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Collectors(java.util.stream.Collectors) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) Objects(java.util.Objects) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) List(java.util.List) ArtifactResolver(org.eclipse.aether.impl.ArtifactResolver) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Collections(java.util.Collections) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) CollectResult(org.eclipse.aether.collection.CollectResult) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 23 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project wildfly-swarm by wildfly-swarm.

the class ExtraArtifactsHandlerTest method shouldGetWithClassifierAndExtension.

private void shouldGetWithClassifierAndExtension(String classifier, String extension) {
    DependencyNode dependency = dependencyNode();
    List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(Collections.singletonList(dependency));
    assertThat(extraDependencies).hasSize(1);
    DependencyNode extraDependency = extraDependencies.get(0);
    Artifact artifact = extraDependency.getDependency().getArtifact();
    assertThat(artifact.getGroupId()).isEqualTo(GROUP_ID);
    assertThat(artifact.getArtifactId()).isEqualTo(ARTIFACT_ID);
    assertThat(artifact.getVersion()).isEqualTo(VERSION);
    assertThat(artifact.getClassifier()).isEqualTo(classifier);
    assertThat(artifact.getExtension()).isEqualTo(extension);
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 24 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project gate-core by GateNLP.

the class SimpleMavenCache method cacheArtifact.

public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException {
    List<RemoteRepository> repos = getRepositoryList();
    Dependency dependency = new Dependency(artifact, "runtime");
    RepositorySystem repoSystem = getRepositorySystem();
    RepositorySystemSession repoSession = getRepositorySession(repoSystem, null);
    CollectRequest collectRequest = new CollectRequest(dependency, repos);
    DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setRoot(node);
    DependencyResult result = repoSystem.resolveDependencies(repoSession, dependencyRequest);
    for (ArtifactResult ar : result.getArtifactResults()) {
        // generate output file name from the *requested* artifact rather
        // than the resolved one (e.g. if we requested a -SNAPSHOT version
        // but got a timestamped one)
        File file = getArtifactFile(ar.getRequest().getArtifact());
        FileUtils.copyFile(ar.getArtifact().getFile(), file);
        // get the POM corresponding to the specific resolved JAR
        Artifact pomArtifact = new SubArtifact(ar.getArtifact(), "", "pom");
        ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
        ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
        // but copy it to a file named for the original requested version number
        file = getArtifactFile(new SubArtifact(ar.getRequest().getArtifact(), "", "pom"));
        FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
        cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DependencyResult(org.eclipse.aether.resolution.DependencyResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Utils.getRepositorySystem(gate.util.maven.Utils.getRepositorySystem) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) File(java.io.File)

Example 25 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project mule by mulesoft.

the class DependencyResolver method logUnresolvedArtifacts.

/**
 * Logs the paths for each dependency not found
 *
 * @param node root {@link DependencyNode}, can be a "null" root (imaginary root)
 * @param e {@link DependencyResolutionException} the error to collect paths.
 */
private void logUnresolvedArtifacts(DependencyNode node, DependencyResolutionException e) {
    List<ArtifactResult> artifactResults = e.getResult().getArtifactResults().stream().filter(artifactResult -> !artifactResult.getExceptions().isEmpty()).collect(toList());
    final List<String> patternInclusion = artifactResults.stream().map(artifactResult -> toId(artifactResult.getRequest().getArtifact())).collect(toList());
    PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(new PatternInclusionsDependencyFilter(patternInclusion), node.getArtifact() != null);
    node.accept(visitor);
    visitor.getPaths().stream().forEach(path -> {
        List<DependencyNode> unresolvedArtifactPath = path.stream().filter(dependencyNode -> dependencyNode.getArtifact() != null).collect(toList());
        if (!unresolvedArtifactPath.isEmpty()) {
            logger.warn("Dependency path to not resolved artifacts -> {}", unresolvedArtifactPath.toString());
        }
    });
}
Also used : DependencyFilter(org.eclipse.aether.graph.DependencyFilter) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) MavenConfiguration(org.mule.maven.client.api.model.MavenConfiguration) Dependency(org.eclipse.aether.graph.Dependency) LoggerFactory(org.slf4j.LoggerFactory) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) PatternInclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternInclusionsDependencyFilter) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) AetherResolutionContext(org.mule.maven.client.internal.AetherResolutionContext) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) ArtifactIdUtils.toId(org.eclipse.aether.util.artifact.ArtifactIdUtils.toId) CollectRequest(org.eclipse.aether.collection.CollectRequest) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReflectionToStringBuilder(org.apache.commons.lang3.builder.ReflectionToStringBuilder) DependencyNode(org.eclipse.aether.graph.DependencyNode) Artifact(org.eclipse.aether.artifact.Artifact) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) Preconditions.checkNotNull(org.mule.runtime.api.util.Preconditions.checkNotNull) AetherRepositoryState(org.mule.maven.client.internal.AetherRepositoryState) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) Joiner.on(com.google.common.base.Joiner.on) File(java.io.File) WorkspaceReader(org.eclipse.aether.repository.WorkspaceReader) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Optional(java.util.Optional) PathRecordingDependencyVisitor(org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) RepositorySystem(org.eclipse.aether.RepositorySystem) PatternInclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternInclusionsDependencyFilter) PathRecordingDependencyVisitor(org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)28 Artifact (org.eclipse.aether.artifact.Artifact)14 CollectRequest (org.eclipse.aether.collection.CollectRequest)14 Dependency (org.eclipse.aether.graph.Dependency)13 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)12 ArrayList (java.util.ArrayList)11 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)10 File (java.io.File)8 List (java.util.List)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)8 IOException (java.io.IOException)7 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)6 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)5 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)5 MalformedURLException (java.net.MalformedURLException)4 RepositorySystem (org.eclipse.aether.RepositorySystem)4