Search in sources :

Example 11 with Metadata

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

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

the class DefaultDeployer method deploy.

private DeployResult deploy(SyncContext syncContext, RepositorySystemSession session, DeployRequest request) throws DeploymentException {
    DeployResult result = new DeployResult(request);
    RequestTrace trace = DefaultRequestTrace.newChild(request.getTrace(), request);
    RemoteRepository repository = request.getRepository();
    RepositoryConnector connector;
    try {
        connector = remoteRepositoryManager.getRepositoryConnector(session, repository);
    } catch (NoRepositoryConnectorException e) {
        throw new DeploymentException("Failed to deploy artifacts/metadata: " + e.getMessage(), e);
    }
    List<MetadataGenerator> generators = getMetadataGenerators(session, request);
    try {
        List<ArtifactUpload> artifactUploads = new ArrayList<ArtifactUpload>();
        List<MetadataUpload> metadataUploads = new ArrayList<MetadataUpload>();
        IdentityHashMap<Metadata, Object> processedMetadata = new IdentityHashMap<Metadata, Object>();
        EventCatapult catapult = new EventCatapult(session, trace, repository, repositoryEventDispatcher);
        List<Artifact> artifacts = new ArrayList<Artifact>(request.getArtifacts());
        List<Metadata> metadatas = Utils.prepareMetadata(generators, artifacts);
        syncContext.acquire(artifacts, Utils.combine(request.getMetadata(), metadatas));
        for (Metadata metadata : metadatas) {
            upload(metadataUploads, session, metadata, repository, connector, catapult);
            processedMetadata.put(metadata, null);
        }
        for (int i = 0; i < artifacts.size(); i++) {
            Artifact artifact = artifacts.get(i);
            for (MetadataGenerator generator : generators) {
                artifact = generator.transformArtifact(artifact);
            }
            artifacts.set(i, artifact);
            artifactUploads.add(new ArtifactUploadEx(artifact, artifact.getFile(), catapult));
        }
        connector.put(artifactUploads, null);
        for (ArtifactUpload upload : artifactUploads) {
            if (upload.getException() != null) {
                throw new DeploymentException("Failed to deploy artifacts: " + upload.getException().getMessage(), upload.getException());
            }
            result.addArtifact(upload.getArtifact());
        }
        metadatas = Utils.finishMetadata(generators, artifacts);
        syncContext.acquire(null, metadatas);
        for (Metadata metadata : metadatas) {
            upload(metadataUploads, session, metadata, repository, connector, catapult);
            processedMetadata.put(metadata, null);
        }
        for (Metadata metadata : request.getMetadata()) {
            if (!processedMetadata.containsKey(metadata)) {
                upload(metadataUploads, session, metadata, repository, connector, catapult);
                processedMetadata.put(metadata, null);
            }
        }
        connector.put(null, metadataUploads);
        for (MetadataUpload upload : metadataUploads) {
            if (upload.getException() != null) {
                throw new DeploymentException("Failed to deploy metadata: " + upload.getException().getMessage(), upload.getException());
            }
            result.addMetadata(upload.getMetadata());
        }
    } finally {
        connector.close();
    }
    return result;
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) MergeableMetadata(org.sonatype.aether.metadata.MergeableMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) RequestTrace(org.sonatype.aether.RequestTrace) DefaultRequestTrace(org.sonatype.aether.util.DefaultRequestTrace) Artifact(org.sonatype.aether.artifact.Artifact) DeployResult(org.sonatype.aether.deployment.DeployResult) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) DeploymentException(org.sonatype.aether.deployment.DeploymentException) MetadataGenerator(org.sonatype.aether.impl.MetadataGenerator)

Example 13 with Metadata

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

the class PutTest method testMetadataUpload.

@Test
public void testMetadataUpload() throws Exception {
    String content = "metadata";
    addExpectation("gid/aid/version/maven-metadata.xml", content);
    addExpectation("gid/aid/version/maven-metadata.xml.sha1", sha1(content));
    addExpectation("gid/aid/version/maven-metadata.xml.md5", md5(content));
    Metadata metadata = metadata(content);
    List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
    connector().put(null, uploads);
    assertExpectations();
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Example 14 with Metadata

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

the class PutTest method testCloseAfterMetadataUpload.

@Test
public void testCloseAfterMetadataUpload() throws Exception {
    Metadata metadata = metadata("metadata");
    List<MetadataUpload> uploads = Arrays.asList(new MetadataUpload(metadata, metadata.getFile()));
    connector().put(null, uploads);
    connector().close();
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) Test(org.junit.Test)

Example 15 with Metadata

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

the class FileRepositoryWorker method newResource.

private DefaultTransferResource newResource(TransferWrapper transfer, RemoteRepository repository) {
    String resourceName = null;
    switch(transfer.getType()) {
        case ARTIFACT:
            Artifact artifact = transfer.getArtifact();
            resourceName = layout.getPath(artifact).getPath();
            break;
        case METADATA:
            Metadata metadata = transfer.getMetadata();
            resourceName = layout.getPath(metadata).getPath();
            break;
    }
    return new DefaultTransferResource(PathUtils.decode(repository.getUrl()), resourceName, transfer.getFile(), transfer.getTrace());
}
Also used : Metadata(org.sonatype.aether.metadata.Metadata) Artifact(org.sonatype.aether.artifact.Artifact) DefaultTransferResource(org.sonatype.aether.util.listener.DefaultTransferResource)

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