Search in sources :

Example 1 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveLocalArtifactSuccessful.

@Test
public void testResolveLocalArtifactSuccessful() throws IOException, ArtifactResolutionException {
    File tmpFile = TestFileUtils.createTempFile("tmp");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
    artifact = artifact.setProperties(properties);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    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 : ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) HashMap(java.util.HashMap) File(java.io.File) 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 2 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository.

@Test
public void testFindInLocalRepositoryWhenVersionRangeWasResolvedFromLocalRepository() 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(false);
            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);
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            return new VersionResult(request).setVersion(request.getArtifact().getVersion());
        }
    });
    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) VersionRequest(org.sonatype.aether.resolution.VersionRequest) 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) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Example 3 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testRepositoryEventsSuccessfulLocal.

@Test
public void testRepositoryEventsSuccessfulLocal() throws ArtifactResolutionException, IOException {
    RecordingRepositoryListener listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);
    File tmpFile = TestFileUtils.createTempFile("tmp");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
    artifact = artifact.setProperties(properties);
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    resolver.resolveArtifact(session, request);
    List<EventWrapper> events = listener.getEvents();
    assertEquals(2, events.size());
    EventWrapper event = events.get(0);
    assertEquals(RecordingRepositoryListener.Type.ARTIFACT_RESOLVING, event.getType());
    assertNull(event.getEvent().getException());
    assertEquals(artifact, event.getEvent().getArtifact());
    event = events.get(1);
    assertEquals(RecordingRepositoryListener.Type.ARTIFACT_RESOLVED, event.getType());
    assertNull(event.getEvent().getException());
    assertEquals(artifact, event.getEvent().getArtifact().setFile(null));
}
Also used : ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) HashMap(java.util.HashMap) RecordingRepositoryListener(org.sonatype.aether.test.impl.RecordingRepositoryListener) File(java.io.File) EventWrapper(org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper) Test(org.junit.Test)

Example 4 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testResolveLocalArtifactUnsuccessful.

@Test
public void testResolveLocalArtifactUnsuccessful() throws IOException, ArtifactResolutionException {
    File tmpFile = TestFileUtils.createTempFile("tmp");
    Map<String, String> properties = new HashMap<String, String>();
    properties.put(ArtifactProperties.LOCAL_PATH, tmpFile.getAbsolutePath());
    artifact = artifact.setProperties(properties);
    tmpFile.delete();
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    try {
        resolver.resolveArtifact(session, request);
        fail("expected exception");
    } catch (ArtifactResolutionException e) {
        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 ArtifactNotFoundException);
        Artifact resolved = result.getArtifact();
        assertNull(resolved);
    }
}
Also used : ArtifactResolutionException(org.sonatype.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.sonatype.aether.resolution.ArtifactRequest) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) HashMap(java.util.HashMap) File(java.io.File) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) 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 5 with ArtifactRequest

use of org.sonatype.aether.resolution.ArtifactRequest in project sonatype-aether by sonatype.

the class DefaultArtifactResolverTest method testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository.

@Test
public void testFindInLocalRepositoryWhenVersionWasFoundInLocalRepository() 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(false);
            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);
            return result;
        }

        public void add(RepositorySystemSession session, LocalMetadataRegistration request) {
        }
    });
    ArtifactRequest request = new ArtifactRequest(artifact, null, "");
    request.addRepository(new RemoteRepository("id", "default", "file:///"));
    resolver.setVersionResolver(new VersionResolver() {

        public VersionResult resolveVersion(RepositorySystemSession session, VersionRequest request) throws VersionResolutionException {
            return new VersionResult(request).setRepository(new LocalRepository("id")).setVersion(request.getArtifact().getVersion());
        }
    });
    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) VersionRequest(org.sonatype.aether.resolution.VersionRequest) 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) VersionResolver(org.sonatype.aether.impl.VersionResolver) VersionResult(org.sonatype.aether.resolution.VersionResult) LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) TestLocalRepositoryManager(org.sonatype.aether.test.impl.TestLocalRepositoryManager) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) VersionResolutionException(org.sonatype.aether.resolution.VersionResolutionException) LocalArtifactRequest(org.sonatype.aether.repository.LocalArtifactRequest) Test(org.junit.Test)

Aggregations

ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)25 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)18 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)18 Test (org.junit.Test)16 Artifact (org.sonatype.aether.artifact.Artifact)14 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)12 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 ArtifactResolutionException (org.sonatype.aether.resolution.ArtifactResolutionException)12 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)11 File (java.io.File)8 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)7 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)6 IOException (java.io.IOException)5 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 VersionRequest (org.sonatype.aether.resolution.VersionRequest)5 VersionResolutionException (org.sonatype.aether.resolution.VersionResolutionException)5 VersionResult (org.sonatype.aether.resolution.VersionResult)5 RecordingRepositoryListener (org.sonatype.aether.test.impl.RecordingRepositoryListener)5 EventWrapper (org.sonatype.aether.test.impl.RecordingRepositoryListener.EventWrapper)5 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)5