Search in sources :

Example 6 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession 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 7 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession 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 8 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.

the class InstallArtifacts method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(InstallArtifacts.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact jarArtifact = new DefaultArtifact("test", "demo", "", "jar", "0.1-SNAPSHOT");
    jarArtifact = jarArtifact.setFile(new File("demo.jar"));
    Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom");
    pomArtifact = pomArtifact.setFile(new File("pom.xml"));
    InstallRequest installRequest = new InstallRequest();
    installRequest.addArtifact(jarArtifact).addArtifact(pomArtifact);
    system.install(session, installRequest);
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) InstallRequest(org.sonatype.aether.installation.InstallRequest) SubArtifact(org.sonatype.aether.util.artifact.SubArtifact) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) SubArtifact(org.sonatype.aether.util.artifact.SubArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 9 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession 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 10 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession in project sonatype-aether by sonatype.

the class Aether method install.

public void install(Artifact artifact, Artifact pom) throws InstallationException {
    RepositorySystemSession session = newSession();
    InstallRequest installRequest = new InstallRequest();
    installRequest.addArtifact(artifact).addArtifact(pom);
    repositorySystem.install(session, installRequest);
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) InstallRequest(org.sonatype.aether.installation.InstallRequest)

Aggregations

RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)25 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)15 Artifact (org.sonatype.aether.artifact.Artifact)13 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)10 RepositorySystem (org.sonatype.aether.RepositorySystem)9 Test (org.junit.Test)8 Dependency (org.sonatype.aether.graph.Dependency)7 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)7 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)6 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)6 File (java.io.File)5 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)5 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)5 CollectRequest (org.sonatype.aether.collection.CollectRequest)4 VersionResolver (org.sonatype.aether.impl.VersionResolver)4 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)4 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)4 VersionRequest (org.sonatype.aether.resolution.VersionRequest)4 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)4 VersionResult (org.sonatype.aether.resolution.VersionResult)4