public static Filter fromDisplayString(String displayString) { Filter filter = new Filter(); String[] ignoredPatterns = displayString.split(","); for (String ignoredPattern : ignoredPatterns) { filter.add(new IgnoredFiles(ignoredPattern.trim())); } return filter; }
@Test public void shouldIgnoreWhenTextIsADocumentInAnyFolderWhenDirectoryWildcardNotInTheBegining() throws Exception { IgnoredFiles ignore = new IgnoredFiles("foo*/**/*.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "foo-hi/bar/a.doc"), is(true)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "bar/baz/b.doc"), is(false)); }
@Test public void shouldAddErrorToItsErrorCollection() { IgnoredFiles ignore = new IgnoredFiles("helper/*.*"); ignore.addError("pattern", "not allowed"); assertThat(ignore.errors().on("pattern"), is("not allowed")); }
private void appyIgnoreFilter(MaterialConfig materialConfig, ModifiedFile file, Set<ModifiedFile> ignoredFiles) { for (IgnoredFiles ignore : materialConfig.filter()) { if (ignore.shouldIgnore(materialConfig, file.getFileName())) { ignoredFiles.add(file); } } }
private String processedPattern() { if (this.processedPattern == null) { String[] parts = FilenameUtils.separatorsToUnix(pattern).split("/"); StringBuilder sb = new StringBuilder(); for (String part : parts) { part = escape(part); if ("**".equals(part)) { sb.append(part.replace("**", "([^/]*/)*")); } else if (part.contains("*")) { sb.append(part.replace("*", "[^/]*")); sb.append("/"); } else { sb.append(part); sb.append("/"); } } this.processedPattern = StringUtils.removeEnd(sb.toString(), "/"); } return this.processedPattern; }
private Filter toFilter(List<String> filterList) { Filter filter = new Filter(); if (filterList == null) return filter; for (String pattern : filterList) { filter.add(new IgnoredFiles(pattern)); } return filter; }
@Test public void shouldSkipDiot() throws Exception { IgnoredFiles ignore = new IgnoredFiles("helper/*.*"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "helper" + separator + "configuration_reference.html"), is(true)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "helper" + separator + "conf-docs" + separator + "configuration_reference.html"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "helper" + separator + "resources" + separator + "images" + separator + "cruise" + separator + "dependent_build.png"), is(false)); }
public static PluggableSCMMaterialConfig pluggableSCMMaterialConfig() { Filter filter = new Filter(new IgnoredFiles("**/*.html"), new IgnoredFiles("**/foobar/")); return pluggableSCMMaterialConfig("scm-id", "des-folder", filter); }
@Test public void shouldIgnoreWhenTextIsADocumentInAnyFolder() throws Exception { IgnoredFiles ignore = new IgnoredFiles("**/*.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(true)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(true)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "a.doc"), is(true)); }
public static Filter create(String... files) { Filter f = new Filter(); for (String file : files) { f.add(new IgnoredFiles(file)); } return f; }
@Test public void shouldIncludeWhenTheTextDoesnotMatchDocumentUnderRoot() { IgnoredFiles ignore = new IgnoredFiles("a.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "b.doc"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc1"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "B" + separator + "a.doc"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(false)); }
@Test public void shouldInitializeFromDisplayString() { assertThat(Filter.fromDisplayString("/foo/**.*,/another/**.*,bar"), is(new Filter(new IgnoredFiles("/foo/**.*"), new IgnoredFiles("/another/**.*"), new IgnoredFiles("bar")))); assertThat(Filter.fromDisplayString("/foo/**.* , /another/**.*, bar "), is(new Filter(new IgnoredFiles("/foo/**.*"), new IgnoredFiles("/another/**.*"), new IgnoredFiles("bar")))); }
@Test public void shouldIgnoreWhenTheTextDoesMatchDocumentUnderRoot() { IgnoredFiles ignore = new IgnoredFiles("a.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc"), is(true)); }
@Test public void shouldConcatenateIgnoredFilesWithCommaWhenDisplaying() { Filter filter = new Filter(new IgnoredFiles("/foo/**.*"), new IgnoredFiles("/another/**.*"), new IgnoredFiles("bar")); assertThat(filter.getStringForDisplay(), is("/foo/**.*,/another/**.*,bar")); }
@Test public void shouldIncludeWhenTheTextUnderRootIsNotADocument() { IgnoredFiles ignore = new IgnoredFiles("*.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.pdf"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "a.doc.aaa"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "A" + separator + "a.doc"), is(false)); }
@Test public void shouldReturnFilterForDisplay() { material.setFilter(new Filter(new IgnoredFiles("/foo/**.*"), new IgnoredFiles("/another/**.*"), new IgnoredFiles("bar"))); assertThat(material.getFilterAsString(), is("/foo/**.*,/another/**.*,bar")); }
@Test public void shouldIncludeIfTheTextIsNotADocumentInTheSpecifiedFolder() throws Exception { IgnoredFiles ignore = new IgnoredFiles("ROOTFOLDER/*.doc"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "shouldNotBeIgnored.doc"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "ANYFOLDER" + separator + "shouldNotBeIgnored.doc"), is(false)); assertThat(ignore.shouldIgnore(hgMaterialConfig, "ROOTFOLDER" + separator + "" + "ANYFOLDER" + separator + "shouldNotBeIgnored.doc"), is(false)); }
public static Filter fromJSON(JsonReader jsonReader) { Filter filter = new Filter(); filter.clear(); jsonReader.readArrayIfPresent("ignore", ignoredFiles -> { ignoredFiles.forEach(ignoredFile -> { filter.add(new IgnoredFiles(ignoredFile.getAsString())); }); }); return filter; } }
@Test public void shouldIgnoreIfTextIsUnderAFolderMatchingTheGivenFolder() throws Exception { IgnoredFiles ignore = new IgnoredFiles("**/*Test*/*"); assertThat(ignore.shouldIgnore(hgMaterialConfig, "B" + separator + "SomethingTestThis" + separator + "isIgnored"), is(true)); }
public static Filter fromJSON(JsonReader jsonReader) { Filter filter = new Filter(); filter.clear(); jsonReader.readArrayIfPresent("ignore", ignoredFiles -> { ignoredFiles.forEach(ignoredFile -> { filter.add(new IgnoredFiles(ignoredFile.getAsString())); }); }); return filter; } }