Search in sources :

Example 26 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project sts4 by spring-projects.

the class MavenCore method resolveDependencies.

/**
 * Calculates dependency graph for a Maven project provided the scope.
 *
 * @param project Maven Project descriptor
 * @param scope Dependency scope
 * @return Set of all dependencies including transient ones
 * @throws MavenException
 */
public Set<Artifact> resolveDependencies(MavenProject project, String scope) throws MavenException {
    MavenExecutionRequest request = maven.createExecutionRequest();
    DefaultRepositorySystemSession session = maven.createRepositorySession(request);
    DependencyNode graph = readDependencyTree(maven.lookupComponent(org.eclipse.aether.RepositorySystem.class), session, project, scope);
    if (graph != null) {
        ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
        graph.accept(new DependencyVisitor() {

            public boolean visitEnter(DependencyNode node) {
                if (node.getDependency() != null) {
                    dependencyNodes.add(node);
                }
                return true;
            }

            public boolean visitLeave(DependencyNode dependencynode) {
                return true;
            }
        });
        LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
        RepositoryUtils.toArtifacts(artifacts, dependencyNodes, Collections.singletonList(project.getArtifact().getId()), null);
        return artifacts.parallelStream().map(artifact -> {
            if (!artifact.isResolved()) {
                try {
                    artifact = maven.resolve(artifact, project.getRemoteArtifactRepositories(), request);
                } catch (MavenException e) {
                    Log.log(e);
                    // Maven 2.x quirk: an artifact always points at the local repo,
                    // regardless whether resolved or not
                    LocalRepositoryManager lrm = session.getLocalRepositoryManager();
                    String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
                    artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
                }
            }
            return artifact;
        }).collect(Collectors.toSet());
    }
    return Collections.emptySet();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Arrays(java.util.Arrays) ArtifactTypeRegistry(org.eclipse.aether.artifact.ArtifactTypeRegistry) URL(java.net.URL) DependencyManagement(org.apache.maven.model.DependencyManagement) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) MavenProject(org.apache.maven.project.MavenProject) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Artifact(org.apache.maven.artifact.Artifact) JandexIndex(org.springframework.ide.vscode.commons.jandex.JandexIndex) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) FilteringDependencyVisitor(org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor) Collection(java.util.Collection) Set(java.util.Set) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) SourceUrlProviderFromSourceContainer(org.springframework.ide.vscode.commons.javadoc.SourceUrlProviderFromSourceContainer) Collectors(java.util.stream.Collectors) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) List(java.util.List) Stream(java.util.stream.Stream) RepositoryUtils(org.apache.maven.RepositoryUtils) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) DependencyManagerUtils(org.eclipse.aether.util.graph.manager.DependencyManagerUtils) CloningDependencyVisitor(org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor) HtmlJavadocProvider(org.springframework.ide.vscode.commons.javadoc.HtmlJavadocProvider) Supplier(com.google.common.base.Supplier) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) Suppliers(com.google.common.base.Suppliers) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) LinkedHashSet(java.util.LinkedHashSet) CollectRequest(org.eclipse.aether.collection.CollectRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) Log(org.springframework.ide.vscode.commons.util.Log) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) IOException(java.io.IOException) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) InputStreamReader(java.io.InputStreamReader) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Paths(java.nio.file.Paths) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) InputStream(java.io.InputStream) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) FilteringDependencyVisitor(org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor) CloningDependencyVisitor(org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) File(java.io.File)

Example 27 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project druid by druid-io.

the class PullDependenciesTest method getArtifactsForExtension.

private List<Artifact> getArtifactsForExtension(Artifact artifact, DependencyFilter filter) {
    final List<String> names = extensionToDependency.get(artifact);
    final List<Artifact> artifacts = new ArrayList<>();
    for (String name : names) {
        final File jarFile = new File(localRepo, name + ".jar");
        try {
            jarFile.createNewFile();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        DependencyNode node = new DefaultDependencyNode(new Dependency(new DefaultArtifact(DEPENDENCY_GROUPID, name, null, "jar", "1.0", null, jarFile), "compile"));
        if (filter.accept(node, Collections.emptyList())) {
            artifacts.add(node.getArtifact());
        }
    }
    return artifacts;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) ArrayList(java.util.ArrayList) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) IOException(java.io.IOException) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 28 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project jqa-core-framework by buschmais.

the class AetherPluginResolverImpl method logDependencyTree.

private void logDependencyTree(DependencyNode node, int indent) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < indent; i++) {
        builder.append(' ');
    }
    Artifact artifact = node.getArtifact();
    if (artifact != null) {
        log.info("{}{}", builder, artifact);
    }
    for (DependencyNode child : node.getChildren()) {
        logDependencyTree(child, indent + 2);
    }
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

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