Search in sources :

Example 31 with Artifact

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

the class SparkDependencyResolver 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 Exception {
    Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(inferScalaVersion(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));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 32 with Artifact

use of org.sonatype.aether.artifact.Artifact in project storm by apache.

the class AetherUtils method parseDependency.

public static Dependency parseDependency(String dependency) {
    List<String> dependencyAndExclusions = Arrays.asList(dependency.split("\\^"));
    Collection<Exclusion> exclusions = new ArrayList<>();
    for (int idx = 1; idx < dependencyAndExclusions.size(); idx++) {
        exclusions.add(AetherUtils.createExclusion(dependencyAndExclusions.get(idx)));
    }
    Artifact artifact = new DefaultArtifact(dependencyAndExclusions.get(0));
    return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions);
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 33 with Artifact

use of org.sonatype.aether.artifact.Artifact in project storm by apache.

the class DependencyResolverMain method transformArtifactResultToArtifactToPaths.

private static Map<String, String> transformArtifactResultToArtifactToPaths(List<ArtifactResult> artifactResults) {
    Map<String, String> artifactToPath = new LinkedHashMap<>();
    for (ArtifactResult artifactResult : artifactResults) {
        Artifact artifact = artifactResult.getArtifact();
        artifactToPath.put(AetherUtils.artifactToString(artifact), artifact.getFile().getAbsolutePath());
    }
    return artifactToPath;
}
Also used : Artifact(org.sonatype.aether.artifact.Artifact) LinkedHashMap(java.util.LinkedHashMap) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 34 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class NodeBuilder method reloc.

public NodeBuilder reloc(String artifactId) {
    Artifact relocation = new StubArtifact(groupId, artifactId, classifier, ext, version);
    relocations.add(relocation);
    return this;
}
Also used : StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact)

Example 35 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class PatternInclusionsDependencyFilter method accept.

public boolean accept(final DependencyNode node, List<DependencyNode> parents) {
    final Dependency dependency = node.getDependency();
    if (dependency == null) {
        return true;
    }
    final Artifact artifact = dependency.getArtifact();
    for (final String pattern : patterns) {
        final boolean matched = accept(artifact, pattern);
        if (matched) {
            return true;
        }
    }
    return false;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Aggregations

Artifact (org.sonatype.aether.artifact.Artifact)116 Test (org.junit.Test)63 File (java.io.File)33 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)30 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)28 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)27 Dependency (org.sonatype.aether.graph.Dependency)22 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)17 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)16 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)15 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)15 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)14 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)13 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)13 ArrayList (java.util.ArrayList)12 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)12 Metadata (org.sonatype.aether.metadata.Metadata)10 RepositorySystem (org.sonatype.aether.RepositorySystem)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8