Search in sources :

Example 11 with HashCode

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);
}
Also used : DirectoryFileSnapshot(org.gradle.api.internal.changedetection.state.DirectoryFileSnapshot) RelativePath(org.gradle.api.file.RelativePath) HashCode(org.gradle.internal.hash.HashCode) RegularFileSnapshot(org.gradle.api.internal.changedetection.state.RegularFileSnapshot) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileHashSnapshot(org.gradle.api.internal.changedetection.state.FileHashSnapshot) File(java.io.File) OutputType(org.gradle.api.internal.tasks.OutputType)

Example 12 with HashCode

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();
}
Also used : ValueSnapshot(org.gradle.api.internal.changedetection.state.ValueSnapshot) DefaultBuildCacheHasher(org.gradle.caching.internal.DefaultBuildCacheHasher) HashCode(org.gradle.internal.hash.HashCode) FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 13 with HashCode

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);
}
Also used : HashCode(org.gradle.internal.hash.HashCode)

Example 14 with HashCode

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);
}
Also used : HashCode(org.gradle.internal.hash.HashCode) ClassAnalysis(org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)

Example 15 with HashCode

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()));
}
Also used : HashCode(org.gradle.internal.hash.HashCode) FileVisitDetails(org.gradle.api.file.FileVisitDetails) ClassDependentsAccumulator(org.gradle.api.internal.tasks.compile.incremental.deps.ClassDependentsAccumulator) InputStream(java.io.InputStream) FileVisitor(org.gradle.api.file.FileVisitor) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ClassAnalysis(org.gradle.api.internal.tasks.compile.incremental.deps.ClassAnalysis)

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