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);
}
}
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();
}
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();
}
Aggregations