use of org.gradle.internal.resource.ExternalResource in project gradle by gradle.
the class MavenMetadataLoader method parseMavenMetadataInfo.
private void parseMavenMetadataInfo(final ExternalResourceName metadataLocation, final MavenMetadata metadata) throws IOException {
ExternalResource resource = cacheAwareExternalResourceAccessor.getResource(metadataLocation, null, new DefaultResourceFileStore<String>(resourcesFileStore) {
@Override
protected String computeKey() {
return metadataLocation.toString();
}
}, null);
if (resource == null) {
throw new MissingResourceException(metadataLocation.getUri(), String.format("Maven meta-data not available at %s", metadataLocation));
}
parseMavenMetadataInto(resource, metadata);
}
use of org.gradle.internal.resource.ExternalResource in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.
private HashValue getResourceSha1(URI location, boolean revalidate) {
try {
URI sha1Location = new URI(location.toASCIIString() + ".sha1");
ExternalResource resource = delegate.getResource(sha1Location, revalidate);
if (resource == null) {
return null;
}
try {
return resource.withContent(new Transformer<HashValue, InputStream>() {
@Override
public HashValue transform(InputStream inputStream) {
try {
String sha = IOUtils.toString(inputStream, "us-ascii");
return HashValue.parse(sha);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
});
} finally {
resource.close();
}
} catch (Exception e) {
throw new ResourceException(location, String.format("Failed to download SHA1 for resource '%s'.", location), e);
}
}
use of org.gradle.internal.resource.ExternalResource in project gradle by gradle.
the class RepositoryTransportWagonAdapter method getRemoteFile.
public boolean getRemoteFile(File destination, String resourceName) throws ResourceException {
ExternalResourceName location = getLocationForResource(resourceName);
ExternalResource resource = transport.getRepository().resource(location);
return resource.writeToIfPresent(destination) != null;
}
use of org.gradle.internal.resource.ExternalResource in project gradle by gradle.
the class DefaultCacheAwareExternalResourceAccessor method getResourceSha1.
@Nullable
private HashCode getResourceSha1(ExternalResourceName location, boolean revalidate) {
try {
ExternalResourceName sha1Location = location.append(".sha1");
ExternalResource resource = delegate.resource(sha1Location, revalidate);
ExternalResourceReadResult<HashCode> result = resource.withContentIfPresent(inputStream -> {
String sha = IOUtils.toString(inputStream, StandardCharsets.US_ASCII);
// Servers may return SHA-1 with leading zeros stripped
sha = StringUtils.leftPad(sha, Hashing.sha1().getHexDigits(), '0');
return HashCode.fromString(sha);
});
return result == null ? null : result.getResult();
} catch (Exception e) {
LOGGER.debug(String.format("Failed to download SHA1 for resource '%s'.", location), e);
return null;
}
}
Aggregations