IncrementalRelativeFileSets { @NonNull public static ImmutableMap<RelativeFile, FileStatus> fromDirectory(@NonNull File directory) { Preconditions.checkArgument(directory.isDirectory(), "!directory.isDirectory()"); Set<RelativeFile> files = RelativeFiles.fromDirectory(directory); files = Sets.filter(files, Predicates.compose(Files.isFile(), RelativeFile.EXTRACT_FILE)); Map<RelativeFile, FileStatus> map = Maps.asMap(files, Functions.constant(FileStatus.NEW)); return ImmutableMap.copyOf(map); } private  IncrementalRelativeFileSets(); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromDirectory(@NonNull File directory); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip,
            FileStatus status); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip,
            @NonNull FileCacheByPath cache); @NonNull static ImmutableMap<RelativeFile, FileStatus> union(
            @NonNull Iterable<ImmutableMap<RelativeFile, FileStatus>> sets); static int getBaseDirectoryCount(@NonNull ImmutableMap<RelativeFile, FileStatus> set); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZipsAndDirectories(
            @NonNull Iterable<File> files); @NonNull static ImmutableMap<RelativeFile, FileStatus> makeFromBaseFiles(
            @NonNull Collection<File> baseFiles,
            @NonNull Map<File, FileStatus> updates,
            @NonNull FileCacheByPath cache);  }
@Test public void readEmptyDirectory() { ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.fromDirectory( mTemporaryFolder.getRoot()); assertEquals(0, set.size()); }
@Test public void readDirectory() throws Exception { File a = mTemporaryFolder.newFolder("a"); File ab = new File(a, "ab"); @SuppressWarnings("unused") boolean ignored1 = ab.createNewFile(); File ac = new File(a, "ac"); @SuppressWarnings("unused") boolean ignored2 = ac.createNewFile(); File d = mTemporaryFolder.newFile("d"); RelativeFile expectedB = new RelativeFile(mTemporaryFolder.getRoot(), ab); RelativeFile expectedC = new RelativeFile(mTemporaryFolder.getRoot(), ac); RelativeFile expectedD = new RelativeFile(mTemporaryFolder.getRoot(), d); ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.fromDirectory( mTemporaryFolder.getRoot()); assertEquals(3, set.size()); assertTrue(set.containsKey(expectedB)); assertTrue(set.containsKey(expectedC)); assertTrue(set.containsKey(expectedD)); assertEquals(FileStatus.NEW, set.get(expectedB)); assertEquals(FileStatus.NEW, set.get(expectedC)); assertEquals(FileStatus.NEW, set.get(expectedD)); }
@Test public void makeFromDirectoryIgnoresDirectories() throws Exception { File foo = mTemporaryFolder.newFolder("foo"); File f0 = new File(foo, "f0"); assertTrue(f0.createNewFile()); File bar = new File(foo, "bar"); bar.mkdir(); File f1 = new File(bar, "f1"); assertTrue(f1.createNewFile()); RelativeFile expectedF0 = new RelativeFile(mTemporaryFolder.getRoot(), f0); RelativeFile expectedF1 = new RelativeFile(mTemporaryFolder.getRoot(), f1); ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.fromDirectory(mTemporaryFolder.getRoot()); assertEquals(2, set.size()); assertTrue(set.containsKey(expectedF0)); assertTrue(set.containsKey(expectedF1)); assertEquals(FileStatus.NEW, set.get(expectedF0)); assertEquals(FileStatus.NEW, set.get(expectedF1)); }