Search in sources :

Example 1 with FileCollectionSnapshot

use of org.gradle.api.internal.changedetection.state.FileCollectionSnapshot in project gradle by gradle.

the class AbstractNamedFileSnapshotTaskStateChanges method buildSnapshots.

protected static ImmutableSortedMap<String, FileCollectionSnapshot> buildSnapshots(String taskName, FileCollectionSnapshotterRegistry snapshotterRegistry, String title, SortedSet<? extends TaskFilePropertySpec> fileProperties) {
    ImmutableSortedMap.Builder<String, FileCollectionSnapshot> builder = ImmutableSortedMap.naturalOrder();
    for (TaskFilePropertySpec propertySpec : fileProperties) {
        FileCollectionSnapshot result;
        try {
            FileCollectionSnapshotter snapshotter = snapshotterRegistry.getSnapshotter(propertySpec.getSnapshotter());
            result = snapshotter.snapshot(propertySpec.getPropertyFiles(), propertySpec.getCompareStrategy(), propertySpec.getSnapshotNormalizationStrategy());
        } catch (UncheckedIOException e) {
            throw new UncheckedIOException(String.format("Failed to capture snapshot of %s files for task '%s' property '%s' during up-to-date check.", title.toLowerCase(), taskName, propertySpec.getPropertyName()), e);
        }
        builder.put(propertySpec.getPropertyName(), result);
    }
    return builder.build();
}
Also used : FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) TaskFilePropertySpec(org.gradle.api.internal.tasks.TaskFilePropertySpec) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) UncheckedIOException(org.gradle.api.UncheckedIOException) FileCollectionSnapshotter(org.gradle.api.internal.changedetection.state.FileCollectionSnapshotter)

Example 2 with FileCollectionSnapshot

use of org.gradle.api.internal.changedetection.state.FileCollectionSnapshot in project gradle by gradle.

the class DefaultClasspathHasher method hash.

@Override
public HashCode hash(ClassPath classpath) {
    FileCollectionSnapshot snapshot = snapshotter.snapshot(new SimpleFileCollection(classpath.getAsFiles()), TaskFilePropertyCompareStrategy.ORDERED, ClasspathSnapshotNormalizationStrategy.INSTANCE);
    BuildCacheHasher hasher = new DefaultBuildCacheHasher();
    snapshot.appendToHasher(hasher);
    return hasher.hash();
}
Also used : SimpleFileCollection(org.gradle.api.internal.file.collections.SimpleFileCollection) FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) DefaultBuildCacheHasher(org.gradle.caching.internal.DefaultBuildCacheHasher) BuildCacheHasher(org.gradle.caching.internal.BuildCacheHasher) DefaultBuildCacheHasher(org.gradle.caching.internal.DefaultBuildCacheHasher)

Example 3 with FileCollectionSnapshot

use of org.gradle.api.internal.changedetection.state.FileCollectionSnapshot in project gradle by gradle.

the class DiscoveredInputsTaskStateChanges method snapshotAfterTask.

@Override
public void snapshotAfterTask() {
    FileCollectionSnapshot discoveredFilesSnapshot = createSnapshot(snapshotter, fileCollectionFactory.fixed("Discovered input files", discoveredFiles));
    current.setDiscoveredInputFilesSnapshot(discoveredFilesSnapshot);
}
Also used : FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot)

Example 4 with FileCollectionSnapshot

use of org.gradle.api.internal.changedetection.state.FileCollectionSnapshot in project gradle by gradle.

the class OutputFilesTaskStateChanges method saveCurrent.

@Override
public void saveCurrent() {
    final ImmutableSortedMap<String, FileCollectionSnapshot> outputFilesAfter = buildSnapshots(getTaskName(), getSnapshotterRegistry(), getTitle(), getFileProperties());
    ImmutableSortedMap<String, FileCollectionSnapshot> results = ImmutableSortedMap.copyOfSorted(Maps.transformEntries(getCurrent(), new Maps.EntryTransformer<String, FileCollectionSnapshot, FileCollectionSnapshot>() {

        @Override
        public FileCollectionSnapshot transformEntry(String propertyName, FileCollectionSnapshot beforeExecution) {
            FileCollectionSnapshot afterExecution = outputFilesAfter.get(propertyName);
            FileCollectionSnapshot afterPreviousExecution = getSnapshotAfterPreviousExecution(propertyName);
            return outputSnapshotter.createOutputSnapshot(afterPreviousExecution, beforeExecution, afterExecution);
        }
    }));
    current.setOutputFilesSnapshot(results);
}
Also used : FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot)

Example 5 with FileCollectionSnapshot

use of org.gradle.api.internal.changedetection.state.FileCollectionSnapshot in project gradle by gradle.

the class TaskCacheKeyCalculator method calculate.

public TaskOutputCachingBuildCacheKey calculate(TaskExecution execution) {
    DefaultTaskOutputCachingBuildCacheKeyBuilder builder = new DefaultTaskOutputCachingBuildCacheKeyBuilder();
    HashCode taskClassLoaderHash = execution.getTaskClassLoaderHash();
    List<HashCode> taskActionsClassLoaderHashes = execution.getTaskActionsClassLoaderHashes();
    builder.appendTaskClass(execution.getTaskClass());
    builder.appendClassloaderHash(taskClassLoaderHash);
    builder.appendActionsClassloaderHashes(taskActionsClassLoaderHashes);
    SortedMap<String, ValueSnapshot> inputProperties = execution.getInputProperties();
    for (Map.Entry<String, ValueSnapshot> entry : inputProperties.entrySet()) {
        DefaultBuildCacheHasher newHasher = new DefaultBuildCacheHasher();
        entry.getValue().appendToHasher(newHasher);
        HashCode hash = newHasher.hash();
        builder.appendInputPropertyHash(entry.getKey(), hash);
    }
    SortedMap<String, FileCollectionSnapshot> inputFilesSnapshots = execution.getInputFilesSnapshot();
    for (Map.Entry<String, FileCollectionSnapshot> entry : inputFilesSnapshots.entrySet()) {
        FileCollectionSnapshot snapshot = entry.getValue();
        DefaultBuildCacheHasher newHasher = new DefaultBuildCacheHasher();
        snapshot.appendToHasher(newHasher);
        HashCode hash = newHasher.hash();
        builder.appendInputPropertyHash(entry.getKey(), hash);
    }
    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(com.google.common.hash.HashCode) FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

FileCollectionSnapshot (org.gradle.api.internal.changedetection.state.FileCollectionSnapshot)6 DefaultBuildCacheHasher (org.gradle.caching.internal.DefaultBuildCacheHasher)3 HashCode (com.google.common.hash.HashCode)2 SimpleFileCollection (org.gradle.api.internal.file.collections.SimpleFileCollection)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 File (java.io.File)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ArtifactTransformException (org.gradle.api.artifacts.transform.ArtifactTransformException)1 VariantTransformConfigurationException (org.gradle.api.artifacts.transform.VariantTransformConfigurationException)1 FileCollectionSnapshotter (org.gradle.api.internal.changedetection.state.FileCollectionSnapshotter)1 ValueSnapshot (org.gradle.api.internal.changedetection.state.ValueSnapshot)1 TaskFilePropertySpec (org.gradle.api.internal.tasks.TaskFilePropertySpec)1 BuildCacheHasher (org.gradle.caching.internal.BuildCacheHasher)1