Search in sources :

Example 51 with Dependency

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

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

the class AetherPluginResolverImpl method createClassLoader.

@Override
public PluginClassLoader createClassLoader(ClassLoader parent, List<Plugin> plugins) {
    List<Dependency> requiredPlugins = getRequiredPluginDependencies(plugins);
    DependencyResult dependencyResult = resolvePlugins(requiredPlugins);
    return new PluginClassLoader(getDependencyURLs(dependencyResult), parent);
}
Also used : DependencyResult(org.eclipse.aether.resolution.DependencyResult) Dependency(org.eclipse.aether.graph.Dependency) PluginClassLoader(com.buschmais.jqassistant.core.plugin.api.PluginClassLoader)

Example 53 with Dependency

use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.

the class MavenResolverGrapeEngine method resolve.

@Override
public URI[] resolve(Map args, List depsInfo, Map... dependencyMaps) {
    List<Exclusion> exclusions = createExclusions(args);
    List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
    try {
        List<File> files = resolve(dependencies);
        List<URI> uris = new ArrayList<>(files.size());
        for (File file : files) {
            uris.add(file.toURI());
        }
        return uris.toArray(new URI[0]);
    } catch (Exception ex) {
        throw new DependencyResolutionFailedException(ex);
    }
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Example 54 with Dependency

use of org.eclipse.aether.graph.Dependency in project atlasmap by atlasmap.

the class AbstractAtlasMapMojo method resolveClasspath.

/**
 * Resolves the classpath.
 * @param artifacts artifacts
 * @return resolved
 * @throws MojoFailureException unexpected error
 */
protected List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
    final List<URL> urls = new ArrayList<>();
    try {
        for (String gav : artifacts) {
            Artifact artifact = new DefaultArtifact(gav);
            getLog().debug("Resolving dependencies for artifact: " + artifact);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRoot(new Dependency(artifact, ""));
            collectRequest.setRepositories(getRemoteRepos());
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setCollectRequest(collectRequest);
            DependencyResult dependencyResult = getSystem().resolveDependencies(getRepoSession(), dependencyRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            dependencyResult.getRoot().accept(nlg);
            Iterator<DependencyNode> it = nlg.getNodes().iterator();
            while (it.hasNext()) {
                DependencyNode node = it.next();
                if (node.getDependency() != null) {
                    Artifact x = node.getDependency().getArtifact();
                    if (x.getFile() != null) {
                        getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
                        urls.add(x.getFile().toURI().toURL());
                    }
                }
            }
        }
    } catch (IllegalArgumentException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 55 with Dependency

use of org.eclipse.aether.graph.Dependency in project qpid-broker-j by apache.

the class ClasspathQuery method getJarFiles.

private static Set<File> getJarFiles(final Collection<String> gavs) {
    Set<File> jars = new HashSet<>();
    for (final String gav : gavs) {
        Artifact artifact = new DefaultArtifact(gav);
        DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
        collectRequest.setRepositories(Booter.newRepositories());
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
        List<ArtifactResult> artifactResults = null;
        try {
            artifactResults = _mavenRepositorySystem.resolveDependencies(_mavenRepositorySession, dependencyRequest).getArtifactResults();
        } catch (DependencyResolutionException e) {
            throw new RuntimeException(String.format("Error while dependency resolution for '%s'", gav), e);
        }
        if (artifactResults == null) {
            throw new RuntimeException(String.format("Could not resolve dependency for '%s'", gav));
        }
        for (ArtifactResult artifactResult : artifactResults) {
            System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
        }
        jars.addAll(artifactResults.stream().map(result -> result.getArtifact().getFile()).collect(Collectors.toSet()));
    }
    return jars;
}
Also used : DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) HashSet(java.util.HashSet)

Aggregations

Dependency (org.eclipse.aether.graph.Dependency)55 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)37 Artifact (org.eclipse.aether.artifact.Artifact)34 File (java.io.File)25 CollectRequest (org.eclipse.aether.collection.CollectRequest)20 ArrayList (java.util.ArrayList)19 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)16 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)16 DependencyNode (org.eclipse.aether.graph.DependencyNode)15 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)15 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)13 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)13 MalformedURLException (java.net.MalformedURLException)12 Exclusion (org.eclipse.aether.graph.Exclusion)12 IOException (java.io.IOException)11 List (java.util.List)10 URL (java.net.URL)9 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)9 DependencyResult (org.eclipse.aether.resolution.DependencyResult)9