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);
}
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());
}
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);
}
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;
}
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);
}
Aggregations