Search in sources :

Example 1 with HashValue

use of org.gradle.internal.hash.HashValue in project gradle by gradle.

the class ExternalResourceResolver method createChecksumFile.

private byte[] createChecksumFile(File src, String algorithm, int checksumLength) {
    HashValue hash = HashUtil.createHash(src, algorithm);
    String formattedHashString = hash.asZeroPaddedHexString(checksumLength);
    try {
        return formattedHashString.getBytes("US-ASCII");
    } catch (UnsupportedEncodingException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HashValue(org.gradle.internal.hash.HashValue)

Example 2 with HashValue

use of org.gradle.internal.hash.HashValue in project gradle by gradle.

the class DefaultCacheAwareExternalResourceAccessor method copyCandidateToCache.

private LocallyAvailableExternalResource copyCandidateToCache(URI source, ResourceFileStore fileStore, ExternalResourceMetaData remoteMetaData, HashValue remoteChecksum, LocallyAvailableResource local) throws IOException {
    final File destination = temporaryFileProvider.createTemporaryFile("gradle_download", "bin");
    try {
        Files.copy(local.getFile(), destination);
        HashValue localChecksum = HashUtil.createHash(destination, "SHA1");
        if (!localChecksum.equals(remoteChecksum)) {
            return null;
        }
        return moveIntoCache(source, destination, fileStore, remoteMetaData);
    } finally {
        destination.delete();
    }
}
Also used : HashValue(org.gradle.internal.hash.HashValue) File(java.io.File)

Example 3 with HashValue

use of org.gradle.internal.hash.HashValue 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)

Aggregations

HashValue (org.gradle.internal.hash.HashValue)3 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ResourceException (org.gradle.api.resources.ResourceException)1 ExternalResource (org.gradle.internal.resource.ExternalResource)1 CachedExternalResource (org.gradle.internal.resource.cached.CachedExternalResource)1 DefaultLocallyAvailableExternalResource (org.gradle.internal.resource.local.DefaultLocallyAvailableExternalResource)1 LocallyAvailableExternalResource (org.gradle.internal.resource.local.LocallyAvailableExternalResource)1