Search in sources :

Example 1 with FileSnapshot

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

the class TarTaskOutputPacker method unpack.

private UnpackResult unpack(SortedSet<ResolvedTaskOutputFilePropertySpec> propertySpecs, TarArchiveInputStream tarInput, TaskOutputOriginReader readOriginAction) throws IOException {
    Map<String, ResolvedTaskOutputFilePropertySpec> propertySpecsMap = Maps.uniqueIndex(propertySpecs, new Function<TaskFilePropertySpec, String>() {

        @Override
        public String apply(TaskFilePropertySpec propertySpec) {
            return propertySpec.getPropertyName();
        }
    });
    TarArchiveEntry tarEntry;
    OriginTaskExecutionMetadata originMetadata = null;
    ImmutableListMultimap.Builder<String, FileSnapshot> propertyFileSnapshots = ImmutableListMultimap.builder();
    long entries = 0;
    while ((tarEntry = tarInput.getNextTarEntry()) != null) {
        ++entries;
        String path = tarEntry.getName();
        if (path.equals(METADATA_PATH)) {
            // handle origin metadata
            originMetadata = readOriginAction.execute(new CloseShieldInputStream(tarInput));
        } else {
            // handle output property
            Matcher matcher = PROPERTY_PATH.matcher(path);
            if (!matcher.matches()) {
                throw new IllegalStateException("Cached result format error, invalid contents: " + path);
            }
            String propertyName = unescape(matcher.group(2));
            ResolvedTaskOutputFilePropertySpec propertySpec = propertySpecsMap.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, tarEntry, childPath, outputMissing, propertyFileSnapshots);
        }
    }
    if (originMetadata == null) {
        throw new IllegalStateException("Cached result format error, no origin metadata was found.");
    }
    return new UnpackResult(originMetadata, entries, propertyFileSnapshots.build());
}
Also used : Matcher(java.util.regex.Matcher) TaskFilePropertySpec(org.gradle.api.internal.tasks.TaskFilePropertySpec) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) DirectoryFileSnapshot(org.gradle.api.internal.changedetection.state.DirectoryFileSnapshot) FileSnapshot(org.gradle.api.internal.changedetection.state.FileSnapshot) RegularFileSnapshot(org.gradle.api.internal.changedetection.state.RegularFileSnapshot) OriginTaskExecutionMetadata(org.gradle.api.internal.tasks.OriginTaskExecutionMetadata) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ResolvedTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec) CloseShieldInputStream(org.apache.commons.io.input.CloseShieldInputStream)

Example 2 with FileSnapshot

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

the class DefaultSourceIncludesResolver method searchForDependency.

private void searchForDependency(List<File> searchPath, String include, BuildableResult dependencies) {
    for (File searchDir : searchPath) {
        Map<String, IncludeFileImpl> searchedIncludes = includeRoots.get(searchDir);
        if (searchedIncludes == null) {
            searchedIncludes = new HashMap<String, IncludeFileImpl>();
            includeRoots.put(searchDir, searchedIncludes);
        }
        if (searchedIncludes.containsKey(include)) {
            IncludeFileImpl includeFile = searchedIncludes.get(include);
            if (includeFile.snapshot.getType() == FileType.RegularFile) {
                dependencies.resolved(includeFile);
                return;
            }
            continue;
        }
        File candidate = new File(searchDir, include);
        FileSnapshot fileSnapshot = fileSystemSnapshotter.snapshotSelf(candidate);
        IncludeFileImpl includeFile = fileSnapshot.getType() == FileType.RegularFile ? new IncludeFileImpl(candidate, fileSnapshot) : new IncludeFileImpl(null, fileSnapshot);
        searchedIncludes.put(include, includeFile);
        if (fileSnapshot.getType() == FileType.RegularFile) {
            dependencies.resolved(includeFile);
            return;
        }
    }
}
Also used : FileSnapshot(org.gradle.api.internal.changedetection.state.FileSnapshot) File(java.io.File)

Aggregations

FileSnapshot (org.gradle.api.internal.changedetection.state.FileSnapshot)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 File (java.io.File)1 Matcher (java.util.regex.Matcher)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 CloseShieldInputStream (org.apache.commons.io.input.CloseShieldInputStream)1 DirectoryFileSnapshot (org.gradle.api.internal.changedetection.state.DirectoryFileSnapshot)1 RegularFileSnapshot (org.gradle.api.internal.changedetection.state.RegularFileSnapshot)1 OriginTaskExecutionMetadata (org.gradle.api.internal.tasks.OriginTaskExecutionMetadata)1 ResolvedTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec)1 TaskFilePropertySpec (org.gradle.api.internal.tasks.TaskFilePropertySpec)1