Search in sources :

Example 1 with ExternalResource

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);
}
Also used : MissingResourceException(org.gradle.api.resources.MissingResourceException) ExternalResource(org.gradle.internal.resource.ExternalResource)

Example 2 with ExternalResource

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);
    }
}
Also used : InputStream(java.io.InputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) ResourceException(org.gradle.api.resources.ResourceException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) HashValue(org.gradle.internal.hash.HashValue) URI(java.net.URI) DefaultLocallyAvailableExternalResource(org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) ExternalResource(org.gradle.internal.resource.ExternalResource) CachedExternalResource(org.gradle.internal.resource.cached.CachedExternalResource) UncheckedIOException(org.gradle.api.UncheckedIOException) ResourceException(org.gradle.api.resources.ResourceException) IOException(java.io.IOException)

Example 3 with ExternalResource

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;
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) ExternalResource(org.gradle.internal.resource.ExternalResource)

Example 4 with ExternalResource

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;
    }
}
Also used : ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) HashCode(org.gradle.internal.hash.HashCode) LocallyAvailableExternalResource(org.gradle.internal.resource.local.LocallyAvailableExternalResource) ExternalResource(org.gradle.internal.resource.ExternalResource) CachedExternalResource(org.gradle.internal.resource.cached.CachedExternalResource) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

ExternalResource (org.gradle.internal.resource.ExternalResource)4 IOException (java.io.IOException)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 ExternalResourceName (org.gradle.internal.resource.ExternalResourceName)2 CachedExternalResource (org.gradle.internal.resource.cached.CachedExternalResource)2 LocallyAvailableExternalResource (org.gradle.internal.resource.local.LocallyAvailableExternalResource)2 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Nullable (javax.annotation.Nullable)1 MissingResourceException (org.gradle.api.resources.MissingResourceException)1 ResourceException (org.gradle.api.resources.ResourceException)1 HashCode (org.gradle.internal.hash.HashCode)1 HashValue (org.gradle.internal.hash.HashValue)1 DefaultLocallyAvailableExternalResource (org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource)1