Search in sources :

Example 1 with DependencyVisitor

use of org.eclipse.aether.graph.DependencyVisitor in project byte-buddy by raphw.

the class ClassLoaderResolverTest method setUp.

@Before
public void setUp() throws Exception {
    classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
    when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
    when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
    when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
            dependencyVisitor.visitEnter(child);
            dependencyVisitor.visitLeave(child);
            return null;
        }
    });
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 2 with DependencyVisitor

use of org.eclipse.aether.graph.DependencyVisitor in project revapi by revapi.

the class ArtifactResolver method collectTransitiveDeps.

protected void collectTransitiveDeps(String gav, Set<Artifact> resolvedArtifacts, Set<Exception> failures) throws RepositoryException {
    final Artifact rootArtifact = resolveArtifact(gav);
    CollectRequest collectRequest = new CollectRequest(new Dependency(rootArtifact, null), repositories);
    DependencyRequest request = new DependencyRequest(collectRequest, null);
    DependencyResult result;
    try {
        result = repositorySystem.resolveDependencies(session, request);
    } catch (DependencyResolutionException dre) {
        result = dre.getResult();
    }
    result.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {

        @Override
        public boolean visitEnter(DependencyNode node) {
            return true;
        }

        @Override
        public boolean visitLeave(DependencyNode node) {
            Dependency dep = node.getDependency();
            if (dep == null || dep.getArtifact().equals(rootArtifact)) {
                return true;
            }
            resolvedArtifacts.add(dep.getArtifact());
            return true;
        }
    }));
    failures.addAll(result.getCollectExceptions());
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 3 with DependencyVisitor

use of org.eclipse.aether.graph.DependencyVisitor in project activemq-artemis by apache.

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 4 with DependencyVisitor

use of org.eclipse.aether.graph.DependencyVisitor in project meecrowave by apache.

the class MeecrowaveBundleMojo method addTransitiveDependencies.

private void addTransitiveDependencies(final File distroFolder, final Collection<String> includedArtifacts, final Dependency dependency) {
    final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
    request.setMavenProject(new MavenProject() {

        {
            getDependencies().add(dependency);
        }
    });
    request.setRepositorySession(session);
    try {
        dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() {

            @Override
            public boolean visitEnter(final DependencyNode node) {
                return true;
            }

            @Override
            public boolean visitLeave(final DependencyNode node) {
                final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
                if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) {
                    addLib(distroFolder, artifact.getFile());
                }
                return true;
            }
        });
    } catch (final DependencyResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) MavenProject(org.apache.maven.project.MavenProject) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 5 with DependencyVisitor

use of org.eclipse.aether.graph.DependencyVisitor in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method doResolveProject.

@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
    final File file = files.size() == 1 ? files.iterator().next() : null;
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
    final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
    executeWithMavenSession(request, new Runnable() {

        @Override
        public void run() {
            try {
                RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) repositorySession;
                    session.setTransferListener(new TransferListenerAdapter(myCurrentIndicator));
                    if (myWorkspaceMap != null) {
                        session.setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
                    }
                    session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
                    session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
                }
                List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
                for (ProjectBuildingResult buildingResult : buildingResults) {
                    MavenProject project = buildingResult.getProject();
                    if (project == null) {
                        List<Exception> exceptions = new ArrayList<Exception>();
                        for (ModelProblem problem : buildingResult.getProblems()) {
                            exceptions.add(problem.getException());
                        }
                        MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
                        executionResults.add(mavenExecutionResult);
                        continue;
                    }
                    List<Exception> exceptions = new ArrayList<Exception>();
                    loadExtensions(project, exceptions);
                    //Artifact projectArtifact = project.getArtifact();
                    //Map managedVersions = project.getManagedVersionMap();
                    //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                    project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                        addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
                    } else {
                        final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
                        final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
                        final Map<Dependency, Artifact> winnerDependencyMap = new IdentityHashMap<Dependency, Artifact>();
                        Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                        dependencyResolutionResult.getDependencyGraph().accept(new TreeDependencyVisitor(new DependencyVisitor() {

                            @Override
                            public boolean visitEnter(org.eclipse.aether.graph.DependencyNode node) {
                                final Object winner = node.getData().get(ConflictResolver.NODE_DATA_WINNER);
                                final Dependency dependency = node.getDependency();
                                if (dependency != null && winner == null) {
                                    Artifact winnerArtifact = Maven3AetherModelConverter.toArtifact(dependency);
                                    winnerDependencyMap.put(dependency, winnerArtifact);
                                }
                                return true;
                            }

                            @Override
                            public boolean visitLeave(org.eclipse.aether.graph.DependencyNode node) {
                                return true;
                            }
                        }));
                        for (Dependency dependency : dependencies) {
                            final Artifact artifact = winnerDependencyMap.get(dependency);
                            if (artifact != null) {
                                artifacts.add(artifact);
                                resolveAsModule(artifact);
                            }
                        }
                        project.setArtifacts(artifacts);
                        executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                    }
                }
            } catch (Exception e) {
                executionResults.add(handleException(e));
            }
        }
    });
    return executionResults;
}
Also used : THashSet(gnu.trove.THashSet) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) ModelProblem(org.apache.maven.model.building.ModelProblem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) Dependency(org.eclipse.aether.graph.Dependency) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Artifact(org.apache.maven.artifact.Artifact) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) File(java.io.File) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DependencyVisitor (org.eclipse.aether.graph.DependencyVisitor)6 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 File (java.io.File)3 Artifact (org.apache.maven.artifact.Artifact)3 CollectRequest (org.eclipse.aether.collection.CollectRequest)3 Dependency (org.eclipse.aether.graph.Dependency)3 DependencyNode (org.eclipse.aether.graph.DependencyNode)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 Artifact (org.eclipse.aether.artifact.Artifact)2 CollectResult (org.eclipse.aether.collection.CollectResult)2 Supplier (com.google.common.base.Supplier)1 Suppliers (com.google.common.base.Suppliers)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1