Search in sources :

Example 16 with RepositorySystemSession

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

the class FindAvailableVersions method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(FindAvailableVersions.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:[0,)");
    RemoteRepository repo = Booter.newCentralRepository();
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.addRepository(repo);
    VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
    List<Version> versions = rangeResult.getVersions();
    System.out.println("Available versions " + versions);
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) Version(org.sonatype.aether.version.Version) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) VersionRangeRequest(org.sonatype.aether.resolution.VersionRangeRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 17 with RepositorySystemSession

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

the class GetDependencyTree method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(GetDependencyTree.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 repo = Booter.newCentralRepository();
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.addRepository(repo);
    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) 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 18 with RepositorySystemSession

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

the class DefaultArtifactResolverTest method testLocalArtifactAvailable.

@Test
public void testLocalArtifactAvailable() throws ArtifactResolutionException {
    session.setLocalRepositoryManager(new LocalRepositoryManager() {

        public LocalRepository getRepository() {
            return null;
        }

        public String getPathForRemoteMetadata(Metadata metadata, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForRemoteArtifact(Artifact artifact, RemoteRepository repository, String context) {
            return null;
        }

        public String getPathForLocalMetadata(Metadata metadata) {
            return null;
        }

        public String getPathForLocalArtifact(Artifact artifact) {
            return null;
        }

        public LocalArtifactResult find(RepositorySystemSession session, LocalArtifactRequest request) {
            LocalArtifactResult result = new LocalArtifactResult(request);
            result.setAvailable(true);
            try {
                result.setFile(TestFileUtils.createTempFile(""));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        public void add(RepositorySystemSession session, LocalArtifactRegistration request) {
        }

        public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
            LocalMetadataResult result = new LocalMetadataResult(request);
            try {
                result.setFile(TestFileUtils.createTempFile(""));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    ArtifactResult result = resolver.resolveArtifact(session, request);
    assertTrue(result.getExceptions().isEmpty());
    Artifact resolved = result.getArtifact();
    assertNotNull(resolved.getFile());
    resolved = resolved.setFile(null);
    assertEquals(artifact, resolved);
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) LocalArtifactRegistration(org.sonatype.aether.repository.LocalArtifactRegistration) LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) LocalMetadataRegistration(org.sonatype.aether.repository.LocalMetadataRegistration) LocalRepository(org.sonatype.aether.repository.LocalRepository) Metadata(org.sonatype.aether.metadata.Metadata) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) IOException(java.io.IOException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 19 with RepositorySystemSession

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

the class DefaultArtifactResolverTest method testVersionResolverFails.

@Test
public void testVersionResolverFails() {
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            throw new VersionResolutionException(new VersionResult(request));
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        connector.assertSeenExpected();
        assertNotNull(e.getResults());
        assertEquals(1, e.getResults().size());
        ArtifactResult result = e.getResults().get(0);
        assertSame(request, result.getRequest());
        assertFalse(result.getExceptions().isEmpty());
        assertTrue(result.getExceptions().get(0) instanceof VersionResolutionException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) VersionRequest(org.sonatype.aether.resolution.VersionRequest) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) LocalArtifactResult(org.sonatype.aether.repository.LocalArtifactResult) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 20 with RepositorySystemSession

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

the class DefaultDependencyCollectorTest method testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion.

@Test
public void testArtifactDescriptorResolutionNotRestrictedToRepoHostingSelectedVersion() throws Exception {
    RemoteRepository repo2 = new RemoteRepository("test", "default", "file:///");
    final List<RemoteRepository> repos = new ArrayList<RemoteRepository>();
    collector.setArtifactDescriptorReader(new ArtifactDescriptorReader() {

        public ArtifactDescriptorResult readArtifactDescriptor(RepositorySystemSession session, ArtifactDescriptorRequest request) throws ArtifactDescriptorException {
            repos.addAll(request.getRepositories());
            return new ArtifactDescriptorResult(request);
        }
    });
    DependencyNode root = parser.parseLiteral("verrange:parent:jar:[1,):compile");
    List<Dependency> dependencies = Arrays.asList(root.getDependency());
    CollectRequest request = new CollectRequest(dependencies, null, Arrays.asList(repository, repo2));
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    assertEquals(2, repos.size());
    assertEquals("id", repos.get(0).getId());
    assertEquals("test", repos.get(1).getId());
}
Also used : RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) TestRepositorySystemSession(org.sonatype.aether.test.impl.TestRepositorySystemSession) CollectResult(org.sonatype.aether.collection.CollectResult) ArrayList(java.util.ArrayList) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) DependencyNode(org.sonatype.aether.graph.DependencyNode) ArtifactDescriptorException(org.sonatype.aether.resolution.ArtifactDescriptorException) ArtifactDescriptorResult(org.sonatype.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorRequest(org.sonatype.aether.resolution.ArtifactDescriptorRequest) ArtifactDescriptorReader(org.sonatype.aether.impl.ArtifactDescriptorReader) Test(org.junit.Test)

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