Search in sources :

Example 1 with DefaultArtifact

use of org.sonatype.aether.util.artifact.DefaultArtifact 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 2 with DefaultArtifact

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

the class DependencyResolverTest method resolveValid.

@Test
public void resolveValid() throws Exception {
    // please pick small artifact which has small transitive dependency
    // and let's mark as Ignore if we want to run test even without internet or maven central is often not stable
    Dependency dependency = new Dependency(new DefaultArtifact("org.apache.storm:flux-core:1.0.0"), JavaScopes.COMPILE);
    List<ArtifactResult> results = sut.resolve(Lists.newArrayList(dependency));
    assertTrue(results.size() > 0);
    // it should be org.apache.storm:flux-core:jar:1.0.0 and commons-cli:commons-cli:jar:1.2
    assertContains(results, "org.apache.storm", "flux-core", "1.0.0");
    assertContains(results, "commons-cli", "commons-cli", "1.2");
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 3 with DefaultArtifact

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

the class DependencyContext method fetchArtifactWithDep.

private List<ArtifactResult> fetchArtifactWithDep(Dependency dep) throws DependencyResolutionException, ArtifactResolutionException {
    Artifact artifact = new DefaultArtifact(dep.getGroupArtifactVersion());
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(dep.getExclusions());
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new org.sonatype.aether.graph.Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(mavenCentral);
    collectRequest.addRepository(mavenLocal);
    for (Repository repo : repositories) {
        RemoteRepository rr = new RemoteRepository(repo.getId(), "default", repo.getUrl());
        rr.setPolicy(repo.isSnapshot(), null);
        collectRequest.addRepository(rr);
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) 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) 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 4 with DefaultArtifact

use of org.sonatype.aether.util.artifact.DefaultArtifact 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 ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency));
    }
}
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) RepositoryException(org.sonatype.aether.RepositoryException) 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 5 with DefaultArtifact

use of org.sonatype.aether.util.artifact.DefaultArtifact 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)

Aggregations

DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)33 Artifact (org.sonatype.aether.artifact.Artifact)23 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)18 Test (org.junit.Test)10 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)10 File (java.io.File)9 RepositorySystem (org.sonatype.aether.RepositorySystem)9 Dependency (org.sonatype.aether.graph.Dependency)9 CollectRequest (org.sonatype.aether.collection.CollectRequest)8 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)6 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)5 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)4 PatternExclusionsDependencyFilter (org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)4 Before (org.junit.Before)3 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)3 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)3 DefaultMetadata (org.sonatype.aether.util.metadata.DefaultMetadata)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 CollectResult (org.sonatype.aether.collection.CollectResult)2 DeployRequest (org.sonatype.aether.deployment.DeployRequest)2