Search in sources :

Example 11 with FileSystemLocationFingerprint

use of org.gradle.internal.fingerprint.FileSystemLocationFingerprint in project gradle by gradle.

the class RelativePathFingerprintingStrategy method collectFingerprints.

@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
    ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
    HashSet<String> processedEntries = new HashSet<>();
    roots.accept(new RelativePathTracker(), (snapshot, relativePath) -> {
        String absolutePath = snapshot.getAbsolutePath();
        if (processedEntries.add(absolutePath) && getDirectorySensitivity().shouldFingerprint(snapshot)) {
            FileSystemLocationFingerprint fingerprint;
            if (relativePath.isRoot()) {
                if (snapshot.getType() == FileType.Directory) {
                    return SnapshotVisitResult.CONTINUE;
                } else {
                    fingerprint = fingerprint(snapshot.getName(), snapshot.getType(), snapshot);
                }
            } else {
                fingerprint = fingerprint(stringInterner.intern(relativePath.toRelativePath()), snapshot.getType(), snapshot);
            }
            if (fingerprint != null) {
                builder.put(absolutePath, fingerprint);
            }
        }
        return SnapshotVisitResult.CONTINUE;
    });
    return builder.build();
}
Also used : FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) RelativePathTracker(org.gradle.internal.snapshot.RelativePathTracker) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 12 with FileSystemLocationFingerprint

use of org.gradle.internal.fingerprint.FileSystemLocationFingerprint in project gradle by gradle.

the class ClasspathFingerprintingStrategy method collectFingerprints.

@Override
public Map<String, FileSystemLocationFingerprint> collectFingerprints(FileSystemSnapshot roots) {
    ImmutableMap.Builder<String, FileSystemLocationFingerprint> builder = ImmutableMap.builder();
    HashSet<String> processedEntries = new HashSet<>();
    roots.accept(new RelativePathTracker(), new ClasspathFingerprintingVisitor(processedEntries, builder));
    return builder.build();
}
Also used : IgnoredPathFileSystemLocationFingerprint(org.gradle.internal.fingerprint.impl.IgnoredPathFileSystemLocationFingerprint) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) DefaultFileSystemLocationFingerprint(org.gradle.internal.fingerprint.impl.DefaultFileSystemLocationFingerprint) RelativePathTracker(org.gradle.internal.snapshot.RelativePathTracker) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 13 with FileSystemLocationFingerprint

use of org.gradle.internal.fingerprint.FileSystemLocationFingerprint in project gradle by gradle.

the class ZipHasher method fingerprintZipEntries.

private void fingerprintZipEntries(String parentName, String rootParentName, List<FileSystemLocationFingerprint> fingerprints, ZipInput input) throws IOException {
    fingerprints.add(newZipMarker(parentName));
    for (ZipEntry zipEntry : input) {
        if (zipEntry.isDirectory()) {
            continue;
        }
        String fullName = parentName.isEmpty() ? zipEntry.getName() : parentName + "/" + zipEntry.getName();
        ZipEntryContext zipEntryContext = new DefaultZipEntryContext(zipEntry, fullName, rootParentName);
        if (isZipFile(zipEntry.getName())) {
            zipEntryContext.getEntry().withInputStream((ZipEntry.InputStreamAction<Void>) inputStream -> {
                fingerprintZipEntries(fullName, rootParentName, fingerprints, new StreamZipInput(inputStream));
                return null;
            });
        } else {
            fingerprintZipEntry(zipEntryContext, fingerprints);
        }
    }
}
Also used : Hashing(org.gradle.internal.hash.Hashing) LoggerFactory(org.slf4j.LoggerFactory) ZipInput(org.gradle.api.internal.file.archive.ZipInput) ResourceHasher(org.gradle.internal.fingerprint.hashing.ResourceHasher) RegularFileSnapshotContextHasher(org.gradle.internal.fingerprint.hashing.RegularFileSnapshotContextHasher) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) FileZipInput(org.gradle.api.internal.file.archive.impl.FileZipInput) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ZipEntryContext(org.gradle.internal.fingerprint.hashing.ZipEntryContext) Set(java.util.Set) IOException(java.io.IOException) FingerprintHashingStrategy(org.gradle.internal.fingerprint.FingerprintHashingStrategy) Hasher(org.gradle.internal.hash.Hasher) HashCode(org.gradle.internal.hash.HashCode) File(java.io.File) ConfigurableNormalizer(org.gradle.internal.fingerprint.hashing.ConfigurableNormalizer) StreamZipInput(org.gradle.api.internal.file.archive.impl.StreamZipInput) List(java.util.List) DefaultFileSystemLocationFingerprint(org.gradle.internal.fingerprint.impl.DefaultFileSystemLocationFingerprint) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) ZipEntry(org.gradle.api.internal.file.archive.ZipEntry) FileType(org.gradle.internal.file.FileType) FilenameUtils(org.apache.commons.io.FilenameUtils) RegularFileSnapshotContext(org.gradle.internal.fingerprint.hashing.RegularFileSnapshotContext) ZipEntry(org.gradle.api.internal.file.archive.ZipEntry) StreamZipInput(org.gradle.api.internal.file.archive.impl.StreamZipInput) ZipEntryContext(org.gradle.internal.fingerprint.hashing.ZipEntryContext)

Example 14 with FileSystemLocationFingerprint

use of org.gradle.internal.fingerprint.FileSystemLocationFingerprint in project gradle by gradle.

the class ZipHasher method fingerprintZipEntries.

private List<FileSystemLocationFingerprint> fingerprintZipEntries(String zipFile) throws IOException {
    try (ZipInput input = FileZipInput.create(new File(zipFile))) {
        List<FileSystemLocationFingerprint> fingerprints = Lists.newArrayList();
        fingerprintZipEntries("", zipFile, fingerprints, input);
        return fingerprints;
    }
}
Also used : FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) DefaultFileSystemLocationFingerprint(org.gradle.internal.fingerprint.impl.DefaultFileSystemLocationFingerprint) ZipInput(org.gradle.api.internal.file.archive.ZipInput) FileZipInput(org.gradle.api.internal.file.archive.impl.FileZipInput) StreamZipInput(org.gradle.api.internal.file.archive.impl.StreamZipInput) File(java.io.File)

Example 15 with FileSystemLocationFingerprint

use of org.gradle.internal.fingerprint.FileSystemLocationFingerprint in project gradle by gradle.

the class IgnoredPathCompareStrategy method visitChangesSince.

/**
 * Determines changes by:
 *
 * <ul>
 *     <li>Determining which content fingerprints are only in the previous or current fingerprint collection.</li>
 *     <li>Those only in the previous fingerprint collection are reported as removed.</li>
 * </ul>
 */
private static boolean visitChangesSince(Map<String, FileSystemLocationFingerprint> previous, Map<String, FileSystemLocationFingerprint> current, String propertyTitle, ChangeVisitor visitor) {
    ListMultimap<HashCode, FilePathWithType> unaccountedForPreviousFiles = MultimapBuilder.hashKeys(previous.size()).linkedListValues().build();
    for (Map.Entry<String, FileSystemLocationFingerprint> entry : previous.entrySet()) {
        String absolutePath = entry.getKey();
        FileSystemLocationFingerprint previousFingerprint = entry.getValue();
        unaccountedForPreviousFiles.put(previousFingerprint.getNormalizedContentHash(), new FilePathWithType(absolutePath, previousFingerprint.getType()));
    }
    for (Map.Entry<String, FileSystemLocationFingerprint> entry : current.entrySet()) {
        String currentAbsolutePath = entry.getKey();
        FileSystemLocationFingerprint currentFingerprint = entry.getValue();
        HashCode normalizedContentHash = currentFingerprint.getNormalizedContentHash();
        List<FilePathWithType> previousFilesForContent = unaccountedForPreviousFiles.get(normalizedContentHash);
        if (previousFilesForContent.isEmpty()) {
            DefaultFileChange added = DefaultFileChange.added(currentAbsolutePath, propertyTitle, currentFingerprint.getType(), IgnoredPathFingerprintingStrategy.IGNORED_PATH);
            if (!visitor.visitChange(added)) {
                return false;
            }
        } else {
            previousFilesForContent.remove(0);
        }
    }
    List<Map.Entry<HashCode, FilePathWithType>> unaccountedForPreviousEntries = ImmutableList.sortedCopyOf(ENTRY_COMPARATOR, unaccountedForPreviousFiles.entries());
    for (Map.Entry<HashCode, FilePathWithType> unaccountedForPreviousEntry : unaccountedForPreviousEntries) {
        FilePathWithType removedFile = unaccountedForPreviousEntry.getValue();
        DefaultFileChange removed = DefaultFileChange.removed(removedFile.getAbsolutePath(), propertyTitle, removedFile.getFileType(), IgnoredPathFingerprintingStrategy.IGNORED_PATH);
        if (!visitor.visitChange(removed)) {
            return false;
        }
    }
    return true;
}
Also used : HashCode(org.gradle.internal.hash.HashCode) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) Map(java.util.Map)

Aggregations

FileSystemLocationFingerprint (org.gradle.internal.fingerprint.FileSystemLocationFingerprint)16 ImmutableMap (com.google.common.collect.ImmutableMap)6 DefaultFileSystemLocationFingerprint (org.gradle.internal.fingerprint.impl.DefaultFileSystemLocationFingerprint)6 HashCode (org.gradle.internal.hash.HashCode)6 HashSet (java.util.HashSet)5 FileType (org.gradle.internal.file.FileType)4 IgnoredPathFileSystemLocationFingerprint (org.gradle.internal.fingerprint.impl.IgnoredPathFileSystemLocationFingerprint)3 FileSystemLocationSnapshot (org.gradle.internal.snapshot.FileSystemLocationSnapshot)3 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Nullable (javax.annotation.Nullable)2 ZipInput (org.gradle.api.internal.file.archive.ZipInput)2 FileZipInput (org.gradle.api.internal.file.archive.impl.FileZipInput)2 StreamZipInput (org.gradle.api.internal.file.archive.impl.StreamZipInput)2 RegularFileSnapshotContextHasher (org.gradle.internal.fingerprint.hashing.RegularFileSnapshotContextHasher)2 ResourceHasher (org.gradle.internal.fingerprint.hashing.ResourceHasher)2