Search in sources :

Example 1 with HashCode

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

the class JarCache method getCachedJar.

/**
 * Returns a cached copy of the given file. The cached copy is guaranteed to not be modified or removed.
 *
 * @param original The source file.
 * @param baseDirFactory A factory that can provide a base directory for the file cache.
 * @return The cached file.
 */
public File getCachedJar(File original, Factory<File> baseDirFactory) {
    HashCode hashValue = fileHasher.hash(original);
    File baseDir = baseDirFactory.create();
    File cachedFile = new File(baseDir, hashValue.toString() + '/' + original.getName());
    if (!cachedFile.isFile()) {
        GFileUtils.copyFile(original, cachedFile);
    }
    return cachedFile;
}
Also used : HashCode(org.gradle.internal.hash.HashCode) File(java.io.File)

Example 2 with HashCode

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

the class ResourceSnapshotterCacheService method hashFile.

public HashCode hashFile(RegularFileSnapshot fileSnapshot, RegularFileHasher hasher, HashCode configurationHash) {
    HashCode resourceHashCacheKey = resourceHashCacheKey(fileSnapshot, configurationHash);
    HashCode resourceHash = persistentCache.get(resourceHashCacheKey);
    if (resourceHash != null) {
        if (resourceHash.equals(NO_HASH)) {
            return null;
        }
        return resourceHash;
    }
    resourceHash = hasher.hash(fileSnapshot);
    if (resourceHash != null) {
        persistentCache.put(resourceHashCacheKey, resourceHash);
    } else {
        persistentCache.put(resourceHashCacheKey, NO_HASH);
    }
    return resourceHash;
}
Also used : HashCode(org.gradle.internal.hash.HashCode)

Example 3 with HashCode

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

the class DefaultTaskOutputCachingBuildCacheKeyBuilder method build.

@Override
public TaskOutputCachingBuildCacheKey build() {
    BuildCacheKeyInputs inputs = new BuildCacheKeyInputs(taskClass, classLoaderHash, actionClassLoaderHashes, actionTypes, inputHashes.build(), inputPropertiesLoadedByUnknownClassLoader.build(), outputPropertyNames.build());
    HashCode hash;
    if (!valid) {
        hash = null;
    } else {
        hash = hasher.hash();
    }
    return new DefaultTaskOutputCachingBuildCacheKey(taskPath, hash, inputs);
}
Also used : HashCode(org.gradle.internal.hash.HashCode)

Example 4 with HashCode

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

the class DefaultTaskOutputCachingBuildCacheKeyBuilder method appendTaskImplementation.

@Override
public void appendTaskImplementation(ImplementationSnapshot taskImplementation) {
    this.taskClass = taskImplementation.getTypeName();
    hasher.putString(taskClass);
    if (taskImplementation.hasUnknownClassLoader()) {
        valid = false;
    } else {
        HashCode hashCode = taskImplementation.getClassLoaderHash();
        this.classLoaderHash = hashCode;
        hasher.putHash(hashCode);
    }
}
Also used : HashCode(org.gradle.internal.hash.HashCode)

Example 5 with HashCode

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

the class DefaultTaskOutputCachingBuildCacheKeyBuilder method appendTaskActionImplementations.

@Override
public void appendTaskActionImplementations(Collection<ImplementationSnapshot> taskActionImplementations) {
    ImmutableList.Builder<String> actionTypes = ImmutableList.builder();
    List<HashCode> actionClassLoaderHashes = Lists.newArrayListWithCapacity(taskActionImplementations.size());
    for (ImplementationSnapshot actionImpl : taskActionImplementations) {
        String actionType = actionImpl.getTypeName();
        actionTypes.add(actionType);
        hasher.putString(actionType);
        HashCode hashCode;
        if (actionImpl.hasUnknownClassLoader()) {
            hashCode = null;
            valid = false;
        } else {
            hashCode = actionImpl.getClassLoaderHash();
            hasher.putHash(hashCode);
        }
        actionClassLoaderHashes.add(hashCode);
    }
    this.actionTypes = actionTypes.build();
    this.actionClassLoaderHashes = Collections.unmodifiableList(actionClassLoaderHashes);
}
Also used : HashCode(org.gradle.internal.hash.HashCode) ImmutableList(com.google.common.collect.ImmutableList) ImplementationSnapshot(org.gradle.api.internal.changedetection.state.ImplementationSnapshot)

Aggregations

HashCode (org.gradle.internal.hash.HashCode)19 File (java.io.File)4 ImmutableList (com.google.common.collect.ImmutableList)2 Map (java.util.Map)2 ClassAnalysis (org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SortedMap (java.util.SortedMap)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 FileVisitDetails (org.gradle.api.file.FileVisitDetails)1