request.setProgressListener(new UploadListener(credentials, bucket, key, bytesToTransfer));
request.setMetadata(meta);
// Schedule put object request
getLog().info("Uploading " + key + " (" + FileUtils.byteCountToDisplaySize((int) bytesToTransfer) + ")");
Upload upload = transfers.upload(request);
uploads.add(upload);
items ++;
}
} catch (AmazonServiceException e) {
getLog().error("Uploading resources failed: " + e.getMessage());
} catch (AmazonClientException e) {
getLog().error("Uploading resources failed: " + e.getMessage());
}
// Wait for uploads to be finished
String currentUpload = null;
try {
Thread.sleep(1000);
getLog().info("Waiting for " + uploads.size() + " uploads to finish...");
while (!uploads.isEmpty()) {
Upload upload = uploads.poll();
currentUpload = upload.getDescription().substring("Uploading to ".length());
if (TransferState.InProgress.equals(upload.getState()))
getLog().debug("Waiting for upload " + currentUpload + " to finish");
upload.waitForUploadResult();
}
} catch (AmazonServiceException e) {
throw new MojoExecutionException("Error while uploading " + currentUpload);
} catch (AmazonClientException e) {
throw new MojoExecutionException("Error while uploading " + currentUpload);