Search in sources :

Example 61 with Artifact

use of org.eclipse.aether.artifact.Artifact in project zeppelin by apache.

the class DependencyResolver method getArtifactsWithDep.

/**
 * @param dependency
 * @param excludes list of pattern can either be of the form groupId:artifactId
 * @return
 * @throws Exception
 */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
    Artifact artifact = new DefaultArtifact(dependency);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    try {
        return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    } catch (NullPointerException | DependencyResolutionException ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) RepositoryException(org.eclipse.aether.RepositoryException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter)

Example 62 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bazel by bazelbuild.

the class Resolver method resolveArtifact.

/**
   * Resolves an artifact as a root of a dependency graph.
   */
public void resolveArtifact(String artifactCoord) {
    Artifact artifact;
    ModelSource modelSource;
    try {
        artifact = getArtifact(artifactCoord);
        modelSource = modelResolver.resolveModel(artifact);
    } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) {
        handler.handle(Event.error(e.getMessage()));
        return;
    }
    Rule rule = new Rule(artifact);
    // add the artifact rule to the workspace
    deps.put(rule.name(), rule);
    resolveEffectiveModel(modelSource, Sets.<String>newHashSet(), rule);
}
Also used : UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) FileModelSource(org.apache.maven.model.building.FileModelSource) ModelSource(org.apache.maven.model.building.ModelSource)

Example 63 with Artifact

use of org.eclipse.aether.artifact.Artifact in project buck by facebook.

the class ResolverIntegrationTest method shouldDetectNewestJar.

@Test
public void shouldDetectNewestJar() throws Exception {
    Path groupDir = thirdParty.resolve("example");
    Path existingNewerJar = groupDir.resolve("no-deps-1.1.jar");
    Path existingNewestJar = groupDir.resolve("no-deps-1.2.jar");
    Files.createDirectories(groupDir);
    Path sourceJar = repo.resolve("com/example/no-deps/1.0/no-deps-1.0.jar");
    Files.copy(sourceJar, existingNewerJar);
    Files.copy(sourceJar, existingNewestJar);
    Artifact artifact = new DefaultArtifact("com.example", "no-deps", "jar", "1.0");
    Optional<Path> result = new Resolver(newConfig()).getNewerVersionFile(artifact, groupDir);
    assertTrue(result.isPresent());
    assertThat(result.get(), equalTo(existingNewestJar));
}
Also used : Path(java.nio.file.Path) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 64 with Artifact

use of org.eclipse.aether.artifact.Artifact 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 65 with Artifact

use of org.eclipse.aether.artifact.Artifact in project buck by facebook.

the class Resolver method downloadArtifact.

private Map.Entry<Path, Prebuilt> downloadArtifact(final Artifact artifactToDownload, TraversableGraph<Artifact> graph, ImmutableMap<String, Dependency> specifiedDependencies) throws IOException, ArtifactResolutionException {
    String projectName = getProjectName(artifactToDownload);
    Path project = buckRepoRoot.resolve(buckThirdPartyRelativePath).resolve(projectName);
    Files.createDirectories(project);
    Prebuilt library = resolveLib(artifactToDownload, project);
    // Populate deps
    Iterable<Artifact> incoming = graph.getIncomingNodesFor(artifactToDownload);
    for (Artifact artifact : incoming) {
        String groupName = getProjectName(artifact);
        if (projectName.equals(groupName)) {
            library.addDep(String.format(":%s", artifact.getArtifactId()));
        } else {
            library.addDep(buckThirdPartyRelativePath, artifact);
        }
    }
    // Populate visibility
    Iterable<Artifact> outgoing = graph.getOutgoingNodesFor(artifactToDownload);
    for (Artifact artifact : outgoing) {
        String groupName = getProjectName(artifact);
        if (!groupName.equals(projectName)) {
            library.addVisibility(buckThirdPartyRelativePath, artifact);
        }
    }
    if (specifiedDependencies.containsKey(buildKey(artifactToDownload))) {
        for (String rule : visibility) {
            library.addVisibility(rule);
        }
    }
    return Maps.immutableEntry(project, library);
}
Also used : Path(java.nio.file.Path) STGroupString(org.stringtemplate.v4.STGroupString) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)122 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)97 File (java.io.File)51 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)34 Dependency (org.eclipse.aether.graph.Dependency)32 IOException (java.io.IOException)29 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 ArrayList (java.util.ArrayList)23 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)22 List (java.util.List)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)18 CollectRequest (org.eclipse.aether.collection.CollectRequest)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)15 DependencyNode (org.eclipse.aether.graph.DependencyNode)14 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 URL (java.net.URL)12 Map (java.util.Map)12 RepositorySystem (org.eclipse.aether.RepositorySystem)11