Package org.gradle.internal.hash

Examples of org.gradle.internal.hash.HashValue


        URI checksumDestination = URI.create(destination + "." + algorithm.toLowerCase());
        doPut(checksumFile, checksumDestination);
    }

    private byte[] createChecksumFile(File src, String algorithm, int checksumlength) {
        HashValue hash = HashUtil.createHash(src, algorithm);
        String formattedHashString = formatHashString(hash.asHexString(), checksumlength);
        try {
            return formattedHashString.getBytes("US-ASCII");
        } catch (UnsupportedEncodingException e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
View Full Code Here


        // Either no cached, or it's changed. See if we can find something local with the same checksum
        boolean hasLocalCandidates = localCandidates != null && !localCandidates.isNone();
        if (hasLocalCandidates) {
            // The “remote” may have already given us the checksum
            HashValue remoteChecksum = remoteMetaData.getSha1();

            if (remoteChecksum == null) {
                remoteChecksum = delegate.getResourceSha1(location);
            }
View Full Code Here

            fileInfo = cachedFiles.getIfPresent(source);
            if (fileInfo == null || !fileInfo.cachedFile.exists()) {
                // TODO - use the hashing service for this
                long lastModified = source.lastModified();
                long length = source.length();
                HashValue hashValue = HashUtil.createHash(source, "sha1");
                fileInfo = copyIntoCache(baseDirFactory, source, lastModified, length, hashValue);
            } else {
                // TODO - use the change detection service for this
                long lastModified = source.lastModified();
                long length = source.length();
                if (lastModified != fileInfo.lastModified || length != fileInfo.length) {
                    HashValue hashValue = HashUtil.createHash(source, "sha1");
                    if (!hashValue.equals(fileInfo.hashValue)) {
                        fileInfo = copyIntoCache(baseDirFactory, source, lastModified, length, hashValue);
                    }
                }
            }
        } finally {
View Full Code Here

    }
   
    private static HashValue getSha1(HttpResponse response, String etag) {
        Header sha1Header = response.getFirstHeader("X-Checksum-Sha1");
        if (sha1Header != null) {
            return new HashValue(sha1Header.getValue());   
        }

        // Nexus uses sha1 etags, with a constant prefix
        // e.g {SHA1{b8ad5573a5e9eba7d48ed77a48ad098e3ec2590b}}
        if (etag != null && etag.startsWith("{SHA1{")) {
            String hash = etag.substring(6, etag.length() - 2);
            return new HashValue(hash);
        }

        return null;
    }
View Full Code Here

    public boolean isNone() {
        return getFiles().isEmpty();
    }

    public LocallyAvailableResource findByHashValue(HashValue targetHash) {
        HashValue thisHash;
        for (File file : getFiles()) {
            thisHash = HashUtil.sha1(file);
            if (thisHash.equals(targetHash)) {
                return new DefaultLocallyAvailableResource(file, thisHash);
            }
        }

        return null;
View Full Code Here

TOP

Related Classes of org.gradle.internal.hash.HashValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.