Search in sources :

Example 31 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class GetDependencyTreeWithMirror method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDependencyTreeWithMirror.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.apache.maven:maven-aether-provider:3.0.2");
    RemoteRepository central = new RemoteRepository("central", "default", "http://repo1.maven.org/maven2/");
    DefaultMirrorSelector dms = (DefaultMirrorSelector) session.getMirrorSelector();
    dms.add("mirror", "http://repo1.maven.org/maven2/", "default", true, "central", "*");
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.addRepository(central);
    CollectResult collectResult = system.collectDependencies(session, collectRequest);
    collectResult.getRoot().accept(new ConsoleDependencyGraphDumper());
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) CollectResult(org.sonatype.aether.collection.CollectResult) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DefaultMirrorSelector(org.sonatype.aether.util.repository.DefaultMirrorSelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ConsoleDependencyGraphDumper(demo.util.ConsoleDependencyGraphDumper) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 32 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class GetDirectDependencies method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDirectDependencies.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-impl:1.9");
    RemoteRepository repo = Booter.newCentralRepository();
    ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
    descriptorRequest.setArtifact(artifact);
    descriptorRequest.addRepository(repo);
    ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor(session, descriptorRequest);
    for (Dependency dependency : descriptorResult.getDependencies()) {
        System.out.println(dependency);
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest)

Example 33 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class ResolveArtifact method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(ResolveArtifact.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:1.9");
    RemoteRepository repo = Booter.newCentralRepository();
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.addRepository(repo);
    ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
    artifact = artifactResult.getArtifact();
    System.out.println(artifact + " resolved to  " + artifact.getFile());
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 34 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class Aether method deploy.

public void deploy(Artifact artifact, Artifact pom, String remoteRepository) throws DeploymentException {
    RepositorySystemSession session = newSession();
    RemoteRepository nexus = new RemoteRepository("nexus", "default", remoteRepository);
    Authentication authentication = new Authentication("admin", "admin123");
    nexus.setAuthentication(authentication);
    DeployRequest deployRequest = new DeployRequest();
    deployRequest.addArtifact(artifact).addArtifact(pom);
    deployRequest.setRepository(nexus);
    repositorySystem.deploy(session, deployRequest);
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) Authentication(org.sonatype.aether.repository.Authentication) DeployRequest(org.sonatype.aether.deployment.DeployRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 35 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class SparkDependencyContext method fetchArtifactWithDep.

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

Aggregations

RemoteRepository (org.sonatype.aether.repository.RemoteRepository)71 Artifact (org.sonatype.aether.artifact.Artifact)30 Test (org.junit.Test)27 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)18 File (java.io.File)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)15 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)13 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)13 Dependency (org.sonatype.aether.graph.Dependency)12 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)12 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)11 CollectRequest (org.sonatype.aether.collection.CollectRequest)10 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)10 ArrayList (java.util.ArrayList)8 RepositorySystem (org.sonatype.aether.RepositorySystem)8 IOException (java.io.IOException)7 Before (org.junit.Before)7 Metadata (org.sonatype.aether.metadata.Metadata)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7