Search in sources :

Example 1 with CacheableTaskOutputFilePropertySpec

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

Matcher (java.util.regex.Matcher)1 CloseShieldInputStream (org.apache.commons.io.input.CloseShieldInputStream)1 TarEntry (org.apache.tools.tar.TarEntry)1 CacheableTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.CacheableTaskOutputFilePropertySpec)1 TaskFilePropertySpec (org.gradle.api.internal.tasks.TaskFilePropertySpec)1 TaskOutputFilePropertySpec (org.gradle.api.internal.tasks.TaskOutputFilePropertySpec)1