Search in sources :

Example 26 with Metadata

use of org.sonatype.aether.metadata.Metadata 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 27 with Metadata

use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.

the class SimpleLocalRepositoryManager method find.

public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
    LocalMetadataResult result = new LocalMetadataResult(request);
    String path;
    Metadata metadata = request.getMetadata();
    String context = request.getContext();
    RemoteRepository remote = request.getRepository();
    if (remote != null) {
        path = getPathForRemoteMetadata(metadata, remote, context);
    } else {
        path = getPathForLocalMetadata(metadata);
    }
    File file = new File(getRepository().getBasedir(), path);
    if (file.isFile()) {
        result.setFile(file);
    }
    return result;
}
Also used : LocalMetadataResult(org.sonatype.aether.repository.LocalMetadataResult) Metadata(org.sonatype.aether.metadata.Metadata) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) File(java.io.File)

Aggregations

Metadata (org.sonatype.aether.metadata.Metadata)27 Test (org.junit.Test)15 Artifact (org.sonatype.aether.artifact.Artifact)10 File (java.io.File)9 StubMetadata (org.sonatype.aether.test.util.impl.StubMetadata)9 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)8 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)7 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)7 IOException (java.io.IOException)6 LocalMetadataResult (org.sonatype.aether.repository.LocalMetadataResult)6 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)6 ArrayList (java.util.ArrayList)5 LocalMetadataRequest (org.sonatype.aether.repository.LocalMetadataRequest)5 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)5 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)5 LocalRepository (org.sonatype.aether.repository.LocalRepository)4 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)3 RequestTrace (org.sonatype.aether.RequestTrace)3 LocalArtifactRegistration (org.sonatype.aether.repository.LocalArtifactRegistration)3