Search in sources :

Example 1 with FileSystemLocationFingerprint

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

the class ZipHasher method hashZipContents.

@Nullable
private HashCode hashZipContents(RegularFileSnapshot zipFileSnapshot) {
    try {
        List<FileSystemLocationFingerprint> fingerprints = fingerprintZipEntries(zipFileSnapshot.getAbsolutePath());
        if (fingerprints.isEmpty()) {
            return null;
        }
        Hasher hasher = Hashing.newHasher();
        FingerprintHashingStrategy.SORT.appendToHasher(hasher, fingerprints);
        return hasher.hash();
    } catch (Exception e) {
        hashingExceptionReporter.report(zipFileSnapshot, e);
        return zipFileSnapshot.getHash();
    }
}
Also used : ResourceHasher(org.gradle.internal.fingerprint.hashing.ResourceHasher) RegularFileSnapshotContextHasher(org.gradle.internal.fingerprint.hashing.RegularFileSnapshotContextHasher) Hasher(org.gradle.internal.hash.Hasher) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) DefaultFileSystemLocationFingerprint(org.gradle.internal.fingerprint.impl.DefaultFileSystemLocationFingerprint) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 2 with FileSystemLocationFingerprint

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

the class NormalizedPathFingerprintCompareStrategy method visitChangesSince.

/**
 * Determines changes by:
 *
 * <ul>
 *     <li>Determining which {@link FileSystemLocationFingerprint}s are only in the previous or current fingerprint collection.</li>
 *     <li>
 *         For those only in the previous fingerprint collection it checks if some entry with the same normalized path is in the current collection.
 *         If it is, file is reported as modified, if not as removed.
 *     </li>
 * </ul>
 */
private static boolean visitChangesSince(Map<String, FileSystemLocationFingerprint> previousFingerprints, Map<String, FileSystemLocationFingerprint> currentFingerprints, String propertyTitle, ChangeVisitor visitor) {
    ListMultimap<FileSystemLocationFingerprint, FilePathWithType> unaccountedForPreviousFiles = getUnaccountedForPreviousFingerprints(previousFingerprints, currentFingerprints.entrySet());
    ListMultimap<String, FilePathWithType> addedFilesByNormalizedPath = getAddedFilesByNormalizedPath(currentFingerprints, unaccountedForPreviousFiles, previousFingerprints.entrySet());
    Iterator<Entry<FileSystemLocationFingerprint, FilePathWithType>> iterator = unaccountedForPreviousFiles.entries().stream().sorted(comparingByKey()).iterator();
    while (iterator.hasNext()) {
        Entry<FileSystemLocationFingerprint, FilePathWithType> entry = iterator.next();
        FileSystemLocationFingerprint previousFingerprint = entry.getKey();
        FilePathWithType pathWithType = entry.getValue();
        Change change = getChange(propertyTitle, addedFilesByNormalizedPath, previousFingerprint, pathWithType);
        if (!visitor.visitChange(change)) {
            return false;
        }
    }
    for (Entry<String, FilePathWithType> entry : addedFilesByNormalizedPath.entries()) {
        Change added = added(propertyTitle, entry);
        if (!visitor.visitChange(added)) {
            return false;
        }
    }
    return true;
}
Also used : Entry(java.util.Map.Entry) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint)

Example 3 with FileSystemLocationFingerprint

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

the class NormalizedPathFingerprintCompareStrategy method getChange.

private static Change getChange(String propertyTitle, ListMultimap<String, FilePathWithType> addedFilesByNormalizedPath, FileSystemLocationFingerprint previousFingerprint, FilePathWithType pathWithType) {
    String normalizedPath = previousFingerprint.getNormalizedPath();
    FileType previousFingerprintType = previousFingerprint.getType();
    String absolutePath = pathWithType.getAbsolutePath();
    List<FilePathWithType> filePathWithTypes = addedFilesByNormalizedPath.get(normalizedPath);
    Optional<FilePathWithType> match = filePathWithTypes.stream().filter(file -> absolutePath.equals(file.getAbsolutePath())).findFirst();
    return match.map(filePathWithType -> {
        filePathWithTypes.remove(filePathWithType);
        return modified(propertyTitle, previousFingerprintType, normalizedPath, filePathWithType);
    }).orElseGet(() -> removed(propertyTitle, normalizedPath, pathWithType));
}
Also used : List(java.util.List) Iterator(java.util.Iterator) ListMultimap(com.google.common.collect.ListMultimap) MultimapBuilder(com.google.common.collect.MultimapBuilder) Entry.comparingByKey(java.util.Map.Entry.comparingByKey) Map(java.util.Map) Entry(java.util.Map.Entry) Optional(java.util.Optional) Set(java.util.Set) FileType(org.gradle.internal.file.FileType) FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) FileType(org.gradle.internal.file.FileType)

Example 4 with FileSystemLocationFingerprint

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

the class NormalizedPathFingerprintCompareStrategy method getAddedFilesByNormalizedPath.

private static ListMultimap<String, FilePathWithType> getAddedFilesByNormalizedPath(Map<String, FileSystemLocationFingerprint> currentFingerprints, ListMultimap<FileSystemLocationFingerprint, FilePathWithType> unaccountedForPreviousFiles, Set<Entry<String, FileSystemLocationFingerprint>> previousEntries) {
    ListMultimap<String, FilePathWithType> results = MultimapBuilder.linkedHashKeys().arrayListValues(1).build();
    for (Entry<String, FileSystemLocationFingerprint> currentEntry : currentFingerprints.entrySet()) {
        // skip exact matches
        if (previousEntries.contains(currentEntry)) {
            continue;
        }
        String absolutePath = currentEntry.getKey();
        FileSystemLocationFingerprint currentFingerprint = currentEntry.getValue();
        List<FilePathWithType> previousFilesForFingerprint = unaccountedForPreviousFiles.get(currentFingerprint);
        FileType fingerprintType = currentFingerprint.getType();
        if (previousFilesForFingerprint.isEmpty()) {
            results.put(currentFingerprint.getNormalizedPath(), new FilePathWithType(absolutePath, fingerprintType));
        } else {
            previousFilesForFingerprint.remove(0);
        }
    }
    return results;
}
Also used : FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) FileType(org.gradle.internal.file.FileType)

Example 5 with FileSystemLocationFingerprint

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

the class NormalizedPathFingerprintCompareStrategy method getUnaccountedForPreviousFingerprints.

private static ListMultimap<FileSystemLocationFingerprint, FilePathWithType> getUnaccountedForPreviousFingerprints(Map<String, FileSystemLocationFingerprint> previousFingerprints, Set<Entry<String, FileSystemLocationFingerprint>> currentEntries) {
    ListMultimap<FileSystemLocationFingerprint, FilePathWithType> results = MultimapBuilder.hashKeys(previousFingerprints.size()).linkedListValues().build();
    for (Entry<String, FileSystemLocationFingerprint> previousEntry : previousFingerprints.entrySet()) {
        // skip exact matches
        if (currentEntries.contains(previousEntry)) {
            continue;
        }
        String absolutePath = previousEntry.getKey();
        FileSystemLocationFingerprint previousFingerprint = previousEntry.getValue();
        FileType previousFingerprintType = previousFingerprint.getType();
        results.put(previousFingerprint, new FilePathWithType(absolutePath, previousFingerprintType));
    }
    return results;
}
Also used : FileSystemLocationFingerprint(org.gradle.internal.fingerprint.FileSystemLocationFingerprint) FileType(org.gradle.internal.file.FileType)

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