Search in sources :

Example 1 with DirectorySnapshotBuilder

use of org.gradle.internal.snapshot.DirectorySnapshotBuilder in project gradle by gradle.

the class FileSystemSnapshotBuilder method build.

public FileSystemSnapshot build() {
    if (rootFileSnapshot != null) {
        return rootFileSnapshot;
    }
    if (rootDirectoryBuilder == null) {
        return FileSystemSnapshot.EMPTY;
    }
    DirectorySnapshotBuilder builder = MerkleDirectorySnapshotBuilder.sortingRequired();
    rootDirectoryBuilder.accept(rootPath, rootName, builder);
    return Preconditions.checkNotNull(builder.getResult());
}
Also used : DirectorySnapshotBuilder(org.gradle.internal.snapshot.DirectorySnapshotBuilder) MerkleDirectorySnapshotBuilder(org.gradle.internal.snapshot.MerkleDirectorySnapshotBuilder)

Example 2 with DirectorySnapshotBuilder

use of org.gradle.internal.snapshot.DirectorySnapshotBuilder in project gradle by gradle.

the class FileSystemSnapshotFilter method filterSnapshot.

public static FileSystemSnapshot filterSnapshot(SnapshottingFilter.FileSystemSnapshotPredicate predicate, FileSystemSnapshot unfiltered) {
    DirectorySnapshotBuilder builder = MerkleDirectorySnapshotBuilder.noSortingRequired();
    AtomicBoolean hasBeenFiltered = new AtomicBoolean(false);
    unfiltered.accept(new RelativePathTracker(), new FilteringVisitor(predicate, builder, hasBeenFiltered));
    if (builder.getResult() == null) {
        return FileSystemSnapshot.EMPTY;
    }
    return hasBeenFiltered.get() ? builder.getResult() : unfiltered;
}
Also used : DirectorySnapshotBuilder(org.gradle.internal.snapshot.DirectorySnapshotBuilder) MerkleDirectorySnapshotBuilder(org.gradle.internal.snapshot.MerkleDirectorySnapshotBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RelativePathTracker(org.gradle.internal.snapshot.RelativePathTracker)

Example 3 with DirectorySnapshotBuilder

use of org.gradle.internal.snapshot.DirectorySnapshotBuilder in project gradle by gradle.

the class TarBuildCacheEntryPacker method unpackDirectoryTree.

@Nullable
private TarArchiveEntry unpackDirectoryTree(TarArchiveInputStream input, TarArchiveEntry rootEntry, Map<String, FileSystemLocationSnapshot> snapshots, AtomicLong entries, File treeRoot, String treeName) throws IOException {
    RelativePathParser parser = new RelativePathParser(rootEntry.getName());
    DirectorySnapshotBuilder builder = MerkleDirectorySnapshotBuilder.noSortingRequired();
    builder.enterDirectory(DIRECT, stringInterner.intern(treeRoot.getAbsolutePath()), stringInterner.intern(treeRoot.getName()), INCLUDE_EMPTY_DIRS);
    TarArchiveEntry entry;
    while ((entry = input.getNextTarEntry()) != null) {
        boolean isDir = entry.isDirectory();
        boolean outsideOfRoot = parser.nextPath(entry.getName(), isDir, builder::leaveDirectory);
        if (outsideOfRoot) {
            break;
        }
        entries.incrementAndGet();
        File file = new File(treeRoot, parser.getRelativePath());
        if (isDir) {
            FileUtils.forceMkdir(file);
            chmodUnpackedFile(entry, file);
            String internedAbsolutePath = stringInterner.intern(file.getAbsolutePath());
            String internedName = stringInterner.intern(parser.getName());
            builder.enterDirectory(DIRECT, internedAbsolutePath, internedName, INCLUDE_EMPTY_DIRS);
        } else {
            RegularFileSnapshot fileSnapshot = unpackFile(input, entry, file, parser.getName());
            builder.visitLeafElement(fileSnapshot);
        }
    }
    parser.exitToRoot(builder::leaveDirectory);
    builder.leaveDirectory();
    snapshots.put(treeName, builder.getResult());
    return entry;
}
Also used : DirectorySnapshotBuilder(org.gradle.internal.snapshot.DirectorySnapshotBuilder) MerkleDirectorySnapshotBuilder(org.gradle.internal.snapshot.MerkleDirectorySnapshotBuilder) RegularFileSnapshot(org.gradle.internal.snapshot.RegularFileSnapshot) File(java.io.File) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) Nullable(javax.annotation.Nullable)

Aggregations

DirectorySnapshotBuilder (org.gradle.internal.snapshot.DirectorySnapshotBuilder)3 MerkleDirectorySnapshotBuilder (org.gradle.internal.snapshot.MerkleDirectorySnapshotBuilder)3 File (java.io.File)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Nullable (javax.annotation.Nullable)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 RegularFileSnapshot (org.gradle.internal.snapshot.RegularFileSnapshot)1 RelativePathTracker (org.gradle.internal.snapshot.RelativePathTracker)1