use of org.gradle.internal.hash.HashCode in project gradle by gradle.
the class TarTaskOutputPacker method unpackPropertyEntry.
private void unpackPropertyEntry(ResolvedTaskOutputFilePropertySpec propertySpec, InputStream input, TarArchiveEntry entry, String childPath, boolean missing, ImmutableMultimap.Builder<String, FileSnapshot> fileSnapshots) throws IOException {
File propertyRoot = propertySpec.getOutputFile();
String propertyName = propertySpec.getPropertyName();
if (propertyRoot == null) {
throw new IllegalStateException("Optional property should have a value: " + propertyName);
}
File outputFile;
boolean isDirEntry = entry.isDirectory();
boolean root = Strings.isNullOrEmpty(childPath);
if (root) {
// We are handling the root of the property here
if (missing) {
if (!makeDirectory(propertyRoot.getParentFile())) {
// Make sure output is removed if it exists already
if (propertyRoot.exists()) {
FileUtils.forceDelete(propertyRoot);
}
}
return;
}
OutputType outputType = propertySpec.getOutputType();
if (isDirEntry) {
if (outputType != OutputType.DIRECTORY) {
throw new IllegalStateException("Property should be an output directory property: " + propertyName);
}
} else {
if (outputType == OutputType.DIRECTORY) {
throw new IllegalStateException("Property should be an output file property: " + propertyName);
}
}
ensureDirectoryForProperty(outputType, propertyRoot);
outputFile = propertyRoot;
} else {
outputFile = new File(propertyRoot, childPath);
}
String internedPath = stringInterner.intern(outputFile.getAbsolutePath());
RelativePath relativePath = root ? RelativePath.parse(!isDirEntry, outputFile.getName()) : RelativePath.parse(!isDirEntry, childPath);
if (isDirEntry) {
FileUtils.forceMkdir(outputFile);
fileSnapshots.put(propertyName, new DirectoryFileSnapshot(internedPath, relativePath, root));
} else {
OutputStream output = new FileOutputStream(outputFile);
HashCode hash;
try {
hash = streamHasher.hashCopy(input, output);
} finally {
IOUtils.closeQuietly(output);
}
FileHashSnapshot contentSnapshot = new FileHashSnapshot(hash, outputFile.lastModified());
fileSnapshots.put(propertyName, new RegularFileSnapshot(internedPath, relativePath, root, contentSnapshot));
}
fileSystem.chmod(outputFile, entry.getMode() & FILE_PERMISSION_MASK);
}
use of org.gradle.internal.hash.HashCode in project gradle by gradle.
the class TaskCacheKeyCalculator method calculate.
public TaskOutputCachingBuildCacheKey calculate(TaskInternal task, TaskExecution execution) {
TaskOutputCachingBuildCacheKeyBuilder builder = new DefaultTaskOutputCachingBuildCacheKeyBuilder(task.getIdentityPath());
if (buildCacheDebugLogging) {
builder = new DebuggingTaskOutputCachingBuildCacheKeyBuilder(builder);
}
builder.appendTaskImplementation(execution.getTaskImplementation());
builder.appendTaskActionImplementations(execution.getTaskActionImplementations());
SortedMap<String, ValueSnapshot> inputProperties = execution.getInputProperties();
for (Map.Entry<String, ValueSnapshot> entry : inputProperties.entrySet()) {
DefaultBuildCacheHasher newHasher = new DefaultBuildCacheHasher();
entry.getValue().appendToHasher(newHasher);
if (newHasher.isValid()) {
HashCode hash = newHasher.hash();
builder.appendInputPropertyHash(entry.getKey(), hash);
} else {
builder.inputPropertyLoadedByUnknownClassLoader(entry.getKey());
}
}
SortedMap<String, FileCollectionSnapshot> inputFilesSnapshots = execution.getInputFilesSnapshot();
for (Map.Entry<String, FileCollectionSnapshot> entry : inputFilesSnapshots.entrySet()) {
FileCollectionSnapshot snapshot = entry.getValue();
builder.appendInputPropertyHash(entry.getKey(), snapshot.getHash());
}
SortedSet<String> outputPropertyNamesForCacheKey = execution.getOutputPropertyNamesForCacheKey();
for (String cacheableOutputPropertyName : outputPropertyNamesForCacheKey) {
builder.appendOutputPropertyName(cacheableOutputPropertyName);
}
return builder.build();
}
use of org.gradle.internal.hash.HashCode in project gradle by gradle.
the class TaskExecutionSnapshotSerializer method readImplementation.
private static ImplementationSnapshot readImplementation(Decoder decoder) throws IOException {
String typeName = decoder.readString();
HashCode classLoaderHash = decoder.readBoolean() ? HashCode.fromBytes(decoder.readBinary()) : null;
return new ImplementationSnapshot(typeName, classLoaderHash);
}
use of org.gradle.internal.hash.HashCode in project gradle by gradle.
the class CompilationResultAnalyzer method visitFile.
@Override
public void visitFile(FileVisitDetails fileDetails) {
if (!fileDetails.getName().endsWith(".class")) {
return;
}
HashCode hash = hasher.hash(fileDetails);
ClassAnalysis analysis = analyzer.getClassAnalysis(hash, fileDetails);
accumulator.addClass(fileDetails.getFile(), analysis);
}
use of org.gradle.internal.hash.HashCode in project gradle by gradle.
the class DefaultJarSnapshotter method createSnapshot.
public JarSnapshot createSnapshot(HashCode hash, JarArchive jarArchive) {
final Map<String, HashCode> hashes = Maps.newHashMap();
final ClassDependentsAccumulator accumulator = new ClassDependentsAccumulator();
jarArchive.contents.visit(new FileVisitor() {
public void visitDir(FileVisitDetails dirDetails) {
}
public void visitFile(FileVisitDetails fileDetails) {
if (!fileDetails.getName().endsWith(".class")) {
return;
}
HashCode classFileHash;
InputStream inputStream = fileDetails.open();
try {
classFileHash = hasher.hash(inputStream);
} finally {
try {
inputStream.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
ClassAnalysis analysis = analyzer.getClassAnalysis(classFileHash, fileDetails);
accumulator.addClass(analysis);
hashes.put(analysis.getClassName(), classFileHash);
}
});
return new JarSnapshot(new JarSnapshotData(hash, hashes, accumulator.getAnalysis()));
}
Aggregations