Search in sources :

Example 11 with DefaultArtifact

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

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

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

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

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

the class AetherDemo method installAndDeploy.

public void installAndDeploy() throws InstallationException, DeploymentException {
    Aether aether = new Aether("http://localhost:8081/nexus/content/groups/public", "/Users/jvanzyl/aether-repo");
    Artifact artifact = new DefaultArtifact("com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT");
    artifact = artifact.setFile(new File("jar-from-whatever-process.jar"));
    Artifact pom = new SubArtifact(artifact, null, "pom");
    pom = pom.setFile(new File("pom-from-whatever-process.xml"));
    // Install into the local repository specified
    //
    aether.install(artifact, pom);
    // Deploy to a remote reposistory
    //
    aether.deploy(artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/");
}
Also used : 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)

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