Search in sources :

Example 6 with LocalMetadataRequest

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

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

the class EnhancedLocalRepositoryManagerTest method testFindLocalMetadataNoVersion.

@Test
public void testFindLocalMetadataNoVersion() throws Exception {
    addMetadata(noVerMetadata, null);
    LocalMetadataRequest request = new LocalMetadataRequest(noVerMetadata, null, testContext);
    LocalMetadataResult result = manager.find(session, request);
    assertNotNull(result.getFile());
}
Also used : LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) Test(org.junit.Test)

Example 8 with LocalMetadataRequest

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

the class EnhancedLocalRepositoryManagerTest method testDoNotFindRemoteMetadataDifferentContext.

@Test
public void testDoNotFindRemoteMetadataDifferentContext() throws Exception {
    addMetadata(noVerMetadata, repository);
    addMetadata(metadata, repository);
    LocalMetadataRequest request = new LocalMetadataRequest(noVerMetadata, repository, "different");
    LocalMetadataResult result = manager.find(session, request);
    assertNull(result.getFile());
    request = new LocalMetadataRequest(metadata, repository, "different");
    result = manager.find(session, request);
    assertNull(result.getFile());
}
Also used : LocalMetadataRequest(org.sonatype.aether.repository.LocalMetadataRequest) LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) Test(org.junit.Test)

Aggregations

LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)8 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)8 Test (org.junit.Test)6 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 Metadata (org.sonatype.aether.metadata.Metadata)4 LocalRepository (org.sonatype.aether.repository.LocalRepository)4 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 IOException (java.io.IOException)3 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 Artifact (org.sonatype.aether.artifact.Artifact)3 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)3 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)3 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)3 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)3 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)3 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)3 TestLocalRepositoryManager (org.sonatype.aether.test.impl.TestLocalRepositoryManager)3 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)3 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)3 File (java.io.File)2