DataSet implements SourceSet, DataMap<I> { public static boolean isIgnored(@NonNull File file) { String path = file.getPath(); int nameIndex = path.lastIndexOf(File.separatorChar) + 1; if (path.equals(".") || path.equals("..")) { return true; } boolean ignore = false; boolean isDirectory = file.isDirectory(); int nameLength = path.length() - nameIndex; for (String token : sIgnoredPatterns) { if (token.isEmpty()) { continue; } int tokenIndex = 0; if (token.charAt(tokenIndex) == '!') { tokenIndex++; } if (token.regionMatches(tokenIndex, "<dir>", 0, 5)) { if (!isDirectory) { continue; } tokenIndex += 5; } if (token.regionMatches(tokenIndex, "<file>", 0, 6)) { if (isDirectory) { continue; } tokenIndex += 6; } int n = token.length() - tokenIndex; if (token.charAt(tokenIndex) == '*') { tokenIndex++; n--; if (n <= nameLength) { ignore = token.regionMatches(true, tokenIndex, path, nameIndex + nameLength - n, n); } } else if (n > 1 && token.charAt(token.length() - 1) == '*') { ignore = token.regionMatches(true, tokenIndex, path, nameIndex, n - 1); } else { ignore = (token.length() - tokenIndex) == (path.length() - nameIndex) && token.regionMatches(true, tokenIndex, path, nameIndex, path.length() - nameIndex); } if (ignore) { break; } } return ignore; } DataSet(String configName, boolean validateEnabled); void addSources(Collection<File> files); void addSource(File file); @NonNull @Override List<File> getSourceFiles(); String getConfigName(); @Override File findMatchingSourceFile(File file); @Override int size(); boolean isEmpty(); @NonNull @Override ListMultimap<String, I> getDataMap(); void loadFromFiles(ILogger logger); @Nullable F loadFile(@NonNull File sourceFolder, @NonNull File dataFile, @NonNull ILogger logger); boolean updateWith(File sourceFolder, File changedFile, FileStatus fileStatus,
                              ILogger logger); @Override String toString(); static boolean isIgnored(@NonNull File file);  }
@Test public void testIsIgnored() throws Exception { assertNull("Environment variable $ANDROID_AAPT_IGNORE should not be set while " + "running test; can interfere with results", System.getenv("ANDROID_AAPT_IGNORE")); assertFalse(isIgnored(new File("a."))); assertFalse(isIgnored(new File("foo"))); assertFalse(isIgnored(new File("foo" + separator + "bar"))); assertFalse(isIgnored(new File("foo"))); assertFalse(isIgnored(new File("foo" + separator + "bar"))); assertFalse(isIgnored(new File("layout" + separator + "main.xml"))); assertFalse(isIgnored(new File("res" + separator + "drawable" + separator + "foo.png"))); assertFalse(isIgnored(new File(""))); assertTrue(isIgnored(new File("."))); assertTrue(isIgnored(new File(".."))); assertTrue(isIgnored(new File(".git"))); assertTrue(isIgnored(new File("foo" + separator + ".git"))); assertTrue(isIgnored(new File(".svn"))); assertTrue(isIgnored(new File("thumbs.db"))); assertTrue(isIgnored(new File("Thumbs.db"))); assertTrue(isIgnored(new File("foo" + separator + "Thumbs.db"))); assertTrue(isIgnored(new File("foo~"))); assertTrue(isIgnored(new File("foo.scc"))); assertTrue(isIgnored(new File("foo" + separator + "foo.scc"))); assertTrue(isIgnored(new File(".test"))); assertTrue(isIgnored(new File("foo" + separator + ".test"))); assertFalse(isIgnored(new File("_test"))); File dir = new File(TestUtils.createTempDirDeletedOnExit(), "_test"); assertTrue(dir.mkdirs()); assertTrue(isIgnored(dir)); }