IncrementalRelativeFileSets { @NonNull public static ImmutableMap<RelativeFile, FileStatus> makeFromBaseFiles( @NonNull Collection<File> baseFiles, @NonNull Map<File, FileStatus> updates, @NonNull FileCacheByPath cache) throws IOException { for (File f : baseFiles) { Preconditions.checkArgument(f.exists(), "!f.exists()"); } Map<RelativeFile, FileStatus> relativeUpdates = Maps.newHashMap(); for (Map.Entry<File, FileStatus> fileUpdate : updates.entrySet()) { File file = fileUpdate.getKey(); FileStatus status = fileUpdate.getValue(); if (baseFiles.contains(file)) { switch (status) { case CHANGED: relativeUpdates.putAll(IncrementalRelativeFileSets.fromZip(file, cache)); break; case NEW: relativeUpdates.putAll( IncrementalRelativeFileSets.fromZip(file, FileStatus.NEW)); break; case REMOVED: relativeUpdates.putAll( IncrementalRelativeFileSets.fromZip(file, FileStatus.REMOVED)); break; } } else { if (file.isDirectory()) { continue; } File possibleBaseDirectory = file.getParentFile(); while (possibleBaseDirectory != null) { if (baseFiles.contains(possibleBaseDirectory)) { relativeUpdates.put(new RelativeFile(possibleBaseDirectory, file), status); break; } possibleBaseDirectory = possibleBaseDirectory.getParentFile(); } } } return ImmutableMap.copyOf(relativeUpdates); } 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 makingFromBaseFilesIgnoresDirectories() 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); FileCacheByPath cache = new FileCacheByPath(mTemporaryFolder.newFolder()); ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.makeFromBaseFiles( Collections.singleton(mTemporaryFolder.getRoot()), ImmutableMap.of( f0, FileStatus.NEW, f1, FileStatus.NEW, bar, FileStatus.NEW), cache); assertEquals(2, set.size()); assertTrue(set.containsKey(expectedF0)); assertTrue(set.containsKey(expectedF1)); assertEquals(FileStatus.NEW, set.get(expectedF0)); assertEquals(FileStatus.NEW, set.get(expectedF1)); }