Search in sources :

Example 6 with HashCode

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

the class JarSnapshotDataSerializer method read.

@Override
public JarSnapshotData read(Decoder decoder) throws Exception {
    HashCode hash = hashCodeSerializer.read(decoder);
    Map<String, HashCode> hashes = mapSerializer.read(decoder);
    ClassSetAnalysisData data = analysisSerializer.read(decoder);
    return new JarSnapshotData(hash, hashes, data);
}
Also used : HashCode(org.gradle.internal.hash.HashCode) ClassSetAnalysisData(org.gradle.api.internal.tasks.compile.incremental.deps.ClassSetAnalysisData)

Example 7 with HashCode

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

the class CompilationStateSerializer method read.

@Override
public CompilationState read(Decoder decoder) throws Exception {
    // Deduplicates the include file states, as these are often shared between source files
    Map<Integer, IncludeFileState> ids = new HashMap<Integer, IncludeFileState>();
    int sourceFileCount = decoder.readSmallInt();
    ImmutableMap.Builder<File, SourceFileState> builder = ImmutableMap.builder();
    for (int i = 0; i < sourceFileCount; i++) {
        File sourceFile = fileSerializer.read(decoder);
        HashCode sourceHashCode = hashSerializer.read(decoder);
        int includeFileCount = decoder.readSmallInt();
        ImmutableSet.Builder<IncludeFileState> includeFileStateBuilder = ImmutableSet.builder();
        for (int j = 0; j < includeFileCount; j++) {
            int id = decoder.readSmallInt();
            IncludeFileState includeFileState = ids.get(id);
            if (includeFileState == null) {
                File includeFile = fileSerializer.read(decoder);
                HashCode includeHashCode = hashSerializer.read(decoder);
                includeFileState = new IncludeFileState(includeHashCode, includeFile);
                ids.put(id, includeFileState);
            }
            includeFileStateBuilder.add(includeFileState);
        }
        builder.put(sourceFile, new SourceFileState(sourceHashCode, includeFileStateBuilder.build()));
    }
    return new CompilationState(builder.build());
}
Also used : HashMap(java.util.HashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashCode(org.gradle.internal.hash.HashCode) ImmutableSet(com.google.common.collect.ImmutableSet) File(java.io.File)

Example 8 with HashCode

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

the class GradleUserHomeScopeServices method createClasspathHasher.

ClasspathHasher createClasspathHasher(StringInterner stringInterner, DirectoryFileTreeFactory directoryFileTreeFactory, TaskHistoryStore store, FileSystemSnapshotter fileSystemSnapshotter) {
    PersistentIndexedCache<HashCode, HashCode> jarCache = store.createCache("resourceHashesCache", HashCode.class, new HashCodeSerializer(), 400000, true);
    ClasspathSnapshotter snapshotter = new DefaultClasspathSnapshotter(new ResourceSnapshotterCacheService(jarCache), directoryFileTreeFactory, fileSystemSnapshotter, stringInterner);
    return new DefaultClasspathHasher(snapshotter);
}
Also used : ResourceSnapshotterCacheService(org.gradle.api.internal.changedetection.state.ResourceSnapshotterCacheService) HashCode(org.gradle.internal.hash.HashCode) ClasspathSnapshotter(org.gradle.api.internal.changedetection.state.ClasspathSnapshotter) DefaultClasspathSnapshotter(org.gradle.api.internal.changedetection.state.DefaultClasspathSnapshotter) DefaultClasspathSnapshotter(org.gradle.api.internal.changedetection.state.DefaultClasspathSnapshotter) DefaultClasspathHasher(org.gradle.api.internal.initialization.loadercache.DefaultClasspathHasher) HashCodeSerializer(org.gradle.internal.serialize.HashCodeSerializer)

Example 9 with HashCode

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

the class CrossBuildInMemoryCachingScriptClassCache method getOrCompile.

public <T extends Script, M> CompiledScript<T, M> getOrCompile(ScriptSource source, ClassLoader classLoader, ClassLoaderId classLoaderId, CompileOperation<M> operation, Class<T> scriptBaseClass, Action<? super ClassNode> verifier, ScriptClassCompiler delegate) {
    ScriptCacheKey key = new ScriptCacheKey(source.getClassName(), classLoader, operation.getId());
    CachedCompiledScript cached = cachedCompiledScripts.get(key);
    HashCode hash = hasher.hash(source);
    if (cached != null) {
        if (hash.equals(cached.hash)) {
            return Cast.uncheckedCast(cached.compiledScript);
        }
    }
    CompiledScript<T, M> compiledScript = delegate.compile(source, classLoader, classLoaderId, operation, scriptBaseClass, verifier);
    cachedCompiledScripts.put(key, new CachedCompiledScript(hash, compiledScript));
    return compiledScript;
}
Also used : HashCode(org.gradle.internal.hash.HashCode)

Example 10 with HashCode

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

the class FileCacheBackedScriptClassCompiler method compile.

@Override
public <T extends Script, M> CompiledScript<T, M> compile(final ScriptSource source, final ClassLoader classLoader, final ClassLoaderId classLoaderId, final CompileOperation<M> operation, final Class<T> scriptBaseClass, final Action<? super ClassNode> verifier) {
    assert source.getResource().isContentCached();
    if (source.getResource().getHasEmptyContent()) {
        return emptyCompiledScript(classLoaderId, operation);
    }
    HashCode sourceHashCode = hasher.hash(source);
    final String sourceHash = HashUtil.compactStringFor(sourceHashCode);
    final String dslId = operation.getId();
    HashCode classLoaderHash = classLoaderHierarchyHasher.getClassLoaderHash(classLoader);
    if (classLoaderHash == null) {
        throw new IllegalArgumentException("Unknown classloader: " + classLoader);
    }
    final String classpathHash = dslId + classLoaderHash;
    final RemappingScriptSource remapped = new RemappingScriptSource(source);
    // Caching involves 2 distinct caches, so that 2 scripts with the same (hash, classpath) do not get compiled twice
    // 1. First, we look for a cache script which (path, hash) matches. This cache is invalidated when the compile classpath of the script changes
    // 2. Then we look into the 2d cache for a "generic script" with the same hash, that will be remapped to the script class name
    // Both caches can be closed directly after use because:
    // For 1, if the script changes or its compile classpath changes, a different directory will be used
    // For 2, if the script changes, a different cache is used. If the classpath changes, the cache is invalidated, but classes are remapped to 1. anyway so never directly used
    PersistentCache remappedClassesCache = cacheRepository.cache("scripts-remapped/" + source.getClassName() + "/" + sourceHash + "/" + classpathHash).withDisplayName(dslId + " remapped class cache for " + sourceHash).withValidator(validator).withInitializer(new ProgressReportingInitializer(progressLoggerFactory, new RemapBuildScriptsAction<M, T>(remapped, classpathHash, sourceHash, dslId, classLoader, operation, verifier, scriptBaseClass), "Compiling script into cache", "Compiling " + source.getFileName() + " into local compilation cache")).open();
    remappedClassesCache.close();
    File remappedClassesDir = classesDir(remappedClassesCache);
    File remappedMetadataDir = metadataDir(remappedClassesCache);
    return scriptCompilationHandler.loadFromDir(source, sourceHashCode, classLoader, remappedClassesDir, remappedMetadataDir, operation, scriptBaseClass, classLoaderId);
}
Also used : PersistentCache(org.gradle.cache.PersistentCache) HashCode(org.gradle.internal.hash.HashCode) File(java.io.File)

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