Search in sources :

Example 11 with Dependency

use of org.eclipse.aether.graph.Dependency in project buck by facebook.

the class Resolver method buildDependencyGraph.

private MutableDirectedGraph<Artifact> buildDependencyGraph(Map<String, Artifact> knownDeps) throws ArtifactDescriptorException {
    MutableDirectedGraph<Artifact> graph;
    graph = new MutableDirectedGraph<>();
    for (Map.Entry<String, Artifact> entry : knownDeps.entrySet()) {
        String key = entry.getKey();
        Artifact artifact = entry.getValue();
        graph.addNode(artifact);
        List<Dependency> dependencies = getDependenciesOf(artifact);
        for (Dependency dependency : dependencies) {
            if (dependency.getArtifact() == null) {
                System.out.println("Skipping because artifact missing: " + dependency);
                continue;
            }
            String depKey = buildKey(dependency.getArtifact());
            Artifact actualDep = knownDeps.get(depKey);
            if (actualDep == null) {
                continue;
            }
            // It's possible that the runtime dep of an artifact is the test time dep of another.
            if (isTestTime(dependency)) {
                continue;
            }
            // TODO(shs96c): Do we always want optional dependencies?
            //        if (dependency.isOptional()) {
            //          continue;
            //        }
            Preconditions.checkNotNull(actualDep, key + " -> " + artifact + " in " + knownDeps.keySet());
            graph.addNode(actualDep);
            graph.addEdge(actualDep, artifact);
        }
    }
    return graph;
}
Also used : STGroupString(org.stringtemplate.v4.STGroupString) Dependency(org.eclipse.aether.graph.Dependency) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 12 with Dependency

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

the class ClassLoaderResolver method doResolve.

/**
     * Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
     *
     * @param mavenCoordinate The Maven coordinate to resolve.
     * @return A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
     * @throws MojoExecutionException If the user configuration results in an error.
     * @throws MojoFailureException   If the plugin application raises an error.
     */
private ClassLoader doResolve(MavenCoordinate mavenCoordinate) throws MojoExecutionException, MojoFailureException {
    List<URL> urls = new ArrayList<URL>();
    log.info("Resolving transformer dependency: " + mavenCoordinate);
    try {
        DependencyNode root = repositorySystem.collectDependencies(repositorySystemSession, new CollectRequest(new Dependency(mavenCoordinate.asArtifact(), "runtime"), remoteRepositories)).getRoot();
        repositorySystem.resolveDependencies(repositorySystemSession, new DependencyRequest().setRoot(root));
        PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator();
        root.accept(preorderNodeListGenerator);
        for (Artifact artifact : preorderNodeListGenerator.getArtifacts(false)) {
            urls.add(artifact.getFile().toURI().toURL());
        }
    } catch (DependencyCollectionException exception) {
        throw new MojoExecutionException("Could not collect dependencies for " + mavenCoordinate, exception);
    } catch (DependencyResolutionException exception) {
        throw new MojoExecutionException("Could not resolve dependencies for " + mavenCoordinate, exception);
    } catch (MalformedURLException exception) {
        throw new MojoFailureException("Could not resolve file as URL for " + mavenCoordinate, exception);
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), ByteBuddy.class.getClassLoader());
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ByteBuddy(net.bytebuddy.ByteBuddy) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) URLClassLoader(java.net.URLClassLoader) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException)

Example 13 with Dependency

use of org.eclipse.aether.graph.Dependency in project pinpoint by naver.

the class DependencyResolver method resolveArtifactsAndDependencies.

public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws ArtifactResolutionException, DependencyResolutionException {
    List<Dependency> dependencies = new ArrayList<Dependency>();
    for (Artifact artifact : artifacts) {
        dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
    }
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    DependencyResult result = system.resolveDependencies(session, dependencyRequest);
    List<File> files = new ArrayList<File>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 14 with Dependency

use of org.eclipse.aether.graph.Dependency 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

Dependency (org.eclipse.aether.graph.Dependency)14 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 Artifact (org.eclipse.aether.artifact.Artifact)8 File (java.io.File)6 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)5 ArrayList (java.util.ArrayList)4 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)4 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)4 Exclusion (org.eclipse.aether.graph.Exclusion)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 MalformedURLException (java.net.MalformedURLException)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)3 STGroupString (org.stringtemplate.v4.STGroupString)3 IOException (java.io.IOException)2 Path (java.nio.file.Path)2