Search in sources :

Example 6 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project bnd by bndtools.

the class AetherRepository method put.

@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
    init();
    DigestInputStream digestStream = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
    final File tmpFile = IO.createTempFile(cacheDir, "put", ".bnd");
    try {
        IO.copy(digestStream, tmpFile);
        byte[] digest = digestStream.getMessageDigest().digest();
        if (options.digest != null && !Arrays.equals(options.digest, digest))
            throw new IOException("Retrieved artifact digest doesn't match specified digest");
        // Get basic info about the bundle we're deploying
        Jar jar = new Jar(tmpFile);
        Artifact artifact = ConversionUtils.fromBundleJar(jar);
        artifact = artifact.setFile(tmpFile);
        // Setup the Aether repo session and create the deployment request
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
        session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
        final DeployRequest request = new DeployRequest();
        request.addArtifact(artifact);
        request.setRepository(remoteRepo);
        // Capture the result including remote resource URI
        final ResultHolder resultHolder = new ResultHolder();
        session.setTransferListener(new AbstractTransferListener() {

            @Override
            public void transferSucceeded(TransferEvent event) {
                TransferResource resource = event.getResource();
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(resource.getFile())) {
                    PutResult result = new PutResult();
                    result.artifact = URI.create(resource.getRepositoryUrl() + resource.getResourceName());
                    resultHolder.result = result;
                    System.out.println("UPLOADED to: " + URI.create(resource.getRepositoryUrl() + resource.getResourceName()));
                }
            }

            @Override
            public void transferFailed(TransferEvent event) {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }

            @Override
            public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
                if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
                    resultHolder.error = event.getException();
            }
        });
        // Do the deploy and report results
        repoSystem.deploy(session, request);
        if (resultHolder.result != null) {
            if (indexedRepo != null)
                indexedRepo.reset();
            return resultHolder.result;
        } else if (resultHolder.error != null) {
            throw new Exception("Error during artifact upload", resultHolder.error);
        } else {
            throw new Exception("Artifact was not uploaded");
        }
    } finally {
        if (tmpFile != null && tmpFile.isFile())
            IO.delete(tmpFile);
    }
}
Also used : DigestInputStream(java.security.DigestInputStream) DeployRequest(org.eclipse.aether.deployment.DeployRequest) AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) URISyntaxException(java.net.URISyntaxException) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) TransferResource(org.eclipse.aether.transfer.TransferResource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 7 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project unleash-maven-plugin by shillner.

the class ArtifactDeployer method deployArtifacts.

/**
 * Deploys the given artifacts to the configured remote Maven repositories.
 *
 * @param artifacts the artifacts to deploy.
 * @return the artifacts that have been deployed successfully.
 * @throws DeploymentException if anything goes wrong during the deployment process.
 */
public Collection<Artifact> deployArtifacts(Collection<Artifact> artifacts) throws DeploymentException {
    DeployRequest request = new DeployRequest();
    request.setArtifacts(artifacts);
    request.setRepository(this.metadata.getDeploymentRepository());
    DeployResult result = this.deployer.deploy(this.repoSession, request);
    return result.getArtifacts();
}
Also used : DeployResult(org.eclipse.aether.deployment.DeployResult) DeployRequest(org.eclipse.aether.deployment.DeployRequest)

Example 8 with DeployRequest

use of org.eclipse.aether.deployment.DeployRequest in project unleash-maven-plugin by shillner.

the class ArtifactDeployer method deploy.

private Collection<Artifact> deploy(Collection<Artifact> artifacts, RemoteRepository repo) throws DeploymentException {
    DeployRequest request = new DeployRequest();
    request.setArtifacts(artifacts);
    request.setRepository(repo);
    DeployResult result = this.deployer.deploy(this.repoSession, request);
    return result.getArtifacts();
}
Also used : DeployResult(org.eclipse.aether.deployment.DeployResult) DeployRequest(org.eclipse.aether.deployment.DeployRequest)

Aggregations

DeployRequest (org.eclipse.aether.deployment.DeployRequest)8 Artifact (org.eclipse.aether.artifact.Artifact)5 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)5 File (java.io.File)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 DeployResult (org.eclipse.aether.deployment.DeployResult)3 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)3 RepositorySystem (org.eclipse.aether.RepositorySystem)2 DeploymentException (org.eclipse.aether.deployment.DeploymentException)2 Jar (aQute.bnd.osgi.Jar)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 DigestInputStream (java.security.DigestInputStream)1 LinkedList (java.util.LinkedList)1 Dependency (org.eclipse.aether.graph.Dependency)1 LocalRepository (org.eclipse.aether.repository.LocalRepository)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 ArtifactDescriptorRequest (org.eclipse.aether.resolution.ArtifactDescriptorRequest)1 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)1