Search in sources :

Example 1 with TaskFilePropertySpec

use of org.gradle.api.internal.tasks.TaskFilePropertySpec 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 TaskFilePropertySpec

use of org.gradle.api.internal.tasks.TaskFilePropertySpec in project gradle by gradle.

the class TarTaskOutputPacker method unpack.

private void unpack(TaskOutputsInternal taskOutputs, TarInputStream tarInput, TaskOutputOriginReader readOriginAction) throws IOException {
    Map<String, TaskOutputFilePropertySpec> propertySpecs = Maps.uniqueIndex(taskOutputs.getFileProperties(), new Function<TaskFilePropertySpec, String>() {

        @Override
        public String apply(TaskFilePropertySpec propertySpec) {
            return propertySpec.getPropertyName();
        }
    });
    boolean originSeen = false;
    TarEntry entry;
    while ((entry = tarInput.getNextEntry()) != null) {
        String name = entry.getName();
        if (name.equals(METADATA_PATH)) {
            // handle origin metadata
            originSeen = true;
            readOriginAction.execute(new CloseShieldInputStream(tarInput));
        } else {
            // handle output property
            Matcher matcher = PROPERTY_PATH.matcher(name);
            if (!matcher.matches()) {
                throw new IllegalStateException("Cached result format error, invalid contents: " + name);
            }
            String propertyName = matcher.group(2);
            CacheableTaskOutputFilePropertySpec propertySpec = (CacheableTaskOutputFilePropertySpec) propertySpecs.get(propertyName);
            if (propertySpec == null) {
                throw new IllegalStateException(String.format("No output property '%s' registered", propertyName));
            }
            boolean outputMissing = matcher.group(1) != null;
            String childPath = matcher.group(3);
            unpackPropertyEntry(propertySpec, tarInput, entry, childPath, outputMissing);
        }
    }
    if (!originSeen) {
        throw new IllegalStateException("Cached result format error, no origin metadata was found.");
    }
}
Also used : CacheableTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec) TaskOutputFilePropertySpec(org.gradle.api.internal.tasks.TaskOutputFilePropertySpec) Matcher(java.util.regex.Matcher) TaskFilePropertySpec(org.gradle.api.internal.tasks.TaskFilePropertySpec) TarEntry(org.apache.tools.tar.TarEntry) CacheableTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream)

Aggregations

TaskFilePropertySpec (org.gradle.api.internal.tasks.TaskFilePropertySpec)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Matcher (java.util.regex.Matcher)1 CloseShieldInputStream (org.apache.commons.io.input.CloseShieldInputStream)1 TarEntry (org.apache.tools.tar.TarEntry)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 FileCollectionSnapshot (org.gradle.api.internal.changedetection.state.FileCollectionSnapshot)1 FileCollectionSnapshotter (org.gradle.api.internal.changedetection.state.FileCollectionSnapshotter)1 CacheableTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec)1 TaskOutputFilePropertySpec (org.gradle.api.internal.tasks.TaskOutputFilePropertySpec)1