Search in sources :

Example 76 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project activemq-artemis by rh-messaging.

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;
}
Also used : StringWriter(java.io.StringWriter) CollectResult(org.eclipse.aether.collection.CollectResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter)

Example 77 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project quarkus-platform by quarkusio.

the class QuarkusProjectStateMojoBase method ensureResolvable.

private Collection<Path> ensureResolvable(Artifact a) throws MojoExecutionException {
    final DependencyNode root;
    try {
        root = artifactResolver().collectDependencies(a, Collections.emptyList()).getRoot();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to collect dependencies of " + a, e);
    }
    final List<Path> createdDirs = new ArrayList<>();
    ensureResolvableModule(root, artifactResolver().getMavenContext().getWorkspace(), createdDirs);
    return createdDirs;
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 78 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project quarkus-platform by quarkusio.

the class GoOfflineMojo method ensureResolvableModule.

private static void ensureResolvableModule(DependencyNode node, LocalWorkspace workspace, List<Path> createdDirs) throws MojoExecutionException {
    Artifact artifact = node.getArtifact();
    if (artifact != null) {
        final LocalProject module = workspace.getProject(artifact.getGroupId(), artifact.getArtifactId());
        if (module != null && !module.getRawModel().getPackaging().equals(ArtifactCoords.TYPE_POM)) {
            final Path classesDir = module.getClassesDir();
            if (!Files.exists(classesDir)) {
                Path topDirToCreate = classesDir;
                while (!Files.exists(topDirToCreate.getParent())) {
                    topDirToCreate = topDirToCreate.getParent();
                }
                try {
                    Files.createDirectories(classesDir);
                    createdDirs.add(topDirToCreate);
                } catch (IOException e) {
                    throw new MojoExecutionException("Failed to create " + classesDir, e);
                }
            }
        }
    }
    for (DependencyNode c : node.getChildren()) {
        ensureResolvableModule(c, workspace, createdDirs);
    }
}
Also used : Path(java.nio.file.Path) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DependencyNode(org.eclipse.aether.graph.DependencyNode) IOException(java.io.IOException) LocalProject(io.quarkus.bootstrap.resolver.maven.workspace.LocalProject) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 79 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project bacon by project-ncl.

the class QuarkusCommunityDepAnalyzer method collectNonOptionalDependencies.

private void collectNonOptionalDependencies(DependencyNode depNode, Set<GAV> dependencies, Multimap<GAV, GAV> dependenciesBySource, GAV extension, HashSet<GAV> visitedNodes) {
    GAV current = gavFromDepNode(depNode);
    if (!visitedNodes.add(current)) {
        return;
    }
    depNode.getChildren().stream().filter(d -> !d.getDependency().isOptional()).peek(d -> {
        GAV gav = gavFromDepNode(d);
        if (!gav.getVersion().contains("redhat")) {
            dependenciesBySource.put(gav, extension);
            dependencies.add(gav);
        }
    }).forEach(d -> collectNonOptionalDependencies(d, dependencies, dependenciesBySource, extension, visitedNodes));
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) AddOn(org.jboss.pnc.bacon.pig.impl.addons.AddOn) CommunityDepAnalyzer(org.jboss.pnc.bacon.pig.impl.addons.runtime.CommunityDepAnalyzer) GAV(org.jboss.pnc.bacon.pig.impl.utils.GAV) Dependency(org.apache.maven.model.Dependency) MavenRepositoryUtils(org.jboss.pnc.bacon.pig.impl.utils.MavenRepositoryUtils) LoggerFactory(org.slf4j.LoggerFactory) FileUtils.mkTempDir(org.jboss.pnc.bacon.pig.impl.utils.FileUtils.mkTempDir) BootstrapMavenException(io.quarkus.bootstrap.resolver.maven.BootstrapMavenException) PigConfiguration(org.jboss.pnc.bacon.pig.impl.config.PigConfiguration) MavenArtifactResolver(io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver) Multimap(com.google.common.collect.Multimap) Indy(org.jboss.pnc.bacon.pig.impl.utils.indy.Indy) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) TreeSet(java.util.TreeSet) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) HashSet(java.util.HashSet) PigContext(org.jboss.pnc.bacon.pig.impl.PigContext) Deliverables(org.jboss.pnc.bacon.pig.impl.documents.Deliverables) Map(java.util.Map) PncBuild(org.jboss.pnc.bacon.pig.impl.pnc.PncBuild) Path(java.nio.file.Path) FileUtils(org.jboss.pnc.bacon.pig.impl.utils.FileUtils) Logger(org.slf4j.Logger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Artifact(org.eclipse.aether.artifact.Artifact) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) List(java.util.List) Paths(java.nio.file.Paths) Optional(java.util.Optional) FileReader(java.io.FileReader) Collections(java.util.Collections) FilenameUtils(org.apache.commons.io.FilenameUtils) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) DependencyResult(org.eclipse.aether.resolution.DependencyResult) Model(org.apache.maven.model.Model) GAV(org.jboss.pnc.bacon.pig.impl.utils.GAV)

Example 80 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project lsp4mp by eclipse.

the class DependencyUtil method getDependencies.

public static Set<org.eclipse.lsp4mp.jdt.core.ArtifactResolver.Artifact> getDependencies(String groupId, String artifactId, String version, IProgressMonitor monitor) throws CoreException {
    org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(groupId, artifactId, null, version);
    CollectResult result = MavenPlugin.getMaven().execute((context, progress) -> {
        try {
            return collectDependencies(artifact, context.getRepositorySession());
        } catch (ArtifactDescriptorException | DependencyCollectionException e) {
            ArtifactKey key = new ArtifactKey(groupId, artifactId, version, null);
            throw new CoreException(new Status(IStatus.ERROR, MicroProfileCorePlugin.PLUGIN_ID, "Error while collecting dependencies for " + key, e));
        }
    }, monitor);
    if (result != null) {
        Set<org.eclipse.lsp4mp.jdt.core.ArtifactResolver.Artifact> dependencies = new HashSet<>();
        result.getRoot().accept(new DependencyVisitor() {

            @Override
            public boolean visitLeave(DependencyNode node) {
                org.eclipse.aether.artifact.Artifact dep = node.getDependency().getArtifact();
                dependencies.add(new org.eclipse.lsp4mp.jdt.core.ArtifactResolver.Artifact(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier()));
                return true;
            }

            @Override
            public boolean visitEnter(DependencyNode node) {
                return true;
            }
        });
        return dependencies;
    }
    return Collections.emptySet();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) CollectResult(org.eclipse.aether.collection.CollectResult) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) CoreException(org.eclipse.core.runtime.CoreException) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) HashSet(java.util.HashSet)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)267 Test (org.junit.Test)107 Artifact (org.eclipse.aether.artifact.Artifact)63 Dependency (org.eclipse.aether.graph.Dependency)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)53 CollectRequest (org.eclipse.aether.collection.CollectRequest)53 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)53 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)28 List (java.util.List)26 CollectResult (org.eclipse.aether.collection.CollectResult)24 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)24 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)22 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)21 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)19 File (java.io.File)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)17 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)17 Path (java.nio.file.Path)16 NodeBuilder (org.eclipse.aether.internal.test.util.NodeBuilder)16