use of org.gradle.caching.BuildCacheException in project gradle by gradle.
the class DispatchingBuildCacheService method writeCacheEntryLocally.
private void writeCacheEntryLocally(BuildCacheEntryWriter writer, File destination) throws IOException {
OutputStream fileOutputStream = null;
try {
fileOutputStream = new BufferedOutputStream(new FileOutputStream(destination));
writer.writeTo(fileOutputStream);
} catch (FileNotFoundException e) {
throw new BuildCacheException("Couldn't create local file for cache entry", e);
} finally {
IOUtils.closeQuietly(fileOutputStream);
}
}
use of org.gradle.caching.BuildCacheException in project gradle-s3-build-cache by myniva.
the class AwsS3BuildCacheService method store.
@Override
public void store(BuildCacheKey key, BuildCacheEntryWriter writer) {
final String bucketPath = getBucketPath(key);
logger.info("Start storing cache entry '{}' in S3 bucket", bucketPath);
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(BUILD_CACHE_CONTENT_TYPE);
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
writer.writeTo(os);
meta.setContentLength(os.size());
try (InputStream is = new ByteArrayInputStream(os.toByteArray())) {
PutObjectRequest request = getPutObjectRequest(bucketPath, meta, is);
if (this.reducedRedundancy) {
request.withStorageClass(StorageClass.ReducedRedundancy);
}
s3.putObject(request);
}
} catch (IOException e) {
throw new BuildCacheException("Error while storing cache object in S3 bucket", e);
}
}
use of org.gradle.caching.BuildCacheException in project gradle-s3-build-cache by myniva.
the class AwsS3BuildCacheService method load.
@Override
public boolean load(BuildCacheKey key, BuildCacheEntryReader reader) {
final String bucketPath = getBucketPath(key);
if (s3.doesObjectExist(bucketName, bucketPath)) {
logger.info("Found cache item '{}' in S3 bucket", bucketPath);
S3Object object = s3.getObject(bucketName, bucketPath);
try (InputStream is = object.getObjectContent()) {
reader.readFrom(is);
return true;
} catch (IOException e) {
throw new BuildCacheException("Error while reading cache object from S3 bucket", e);
}
} else {
logger.info("Did not find cache item '{}' in S3 bucket", bucketPath);
return false;
}
}
Aggregations