Search in sources :

Example 6 with CollectResult

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());
}
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)

Aggregations

CollectRequest (org.eclipse.aether.collection.CollectRequest)6 CollectResult (org.eclipse.aether.collection.CollectResult)6 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 Dependency (org.eclipse.aether.graph.Dependency)4 Artifact (org.eclipse.aether.artifact.Artifact)3 DependencyNode (org.eclipse.aether.graph.DependencyNode)3 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)2 DependencyVisitor (org.eclipse.aether.graph.DependencyVisitor)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)2 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)2 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)2 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)2 Before (org.junit.Before)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1