diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 8b84f09000..f18f560a7c 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -1199,9 +1199,22 @@ public final class FilePath implements Serializable { * can be empty but always non-null. */ public FilePath[] list(final String includes) throws IOException, InterruptedException { + return list(includes, null); + } + + /** + * List up files in this directory that matches the given Ant-style filter. + * + * @param includes + * @param excludes + * See {@link FileSet} for the syntax. String like "foo/*.zip" or "foo/**/*.xml" + * @return + * can be empty but always non-null. + */ + public FilePath[] list(final String includes, final String excludes) throws IOException, InterruptedException { return act(new FileCallable() { public FilePath[] invoke(File f, VirtualChannel channel) throws IOException { - String[] files = glob(f,includes); + String[] files = glob(f,includes,excludes); FilePath[] r = new FilePath[files.length]; for( int i=0; i expected = new HashSet(); + expected.add(createFilePath(baseDir, "top", "sub", "app.log")); + expected.add(createFilePath(baseDir, "top", "sub", "trace.log")); + expected.add(createFilePath(baseDir, "top", "db", "db.log")); + expected.add(createFilePath(baseDir, "top", "db", "trace.log")); + final FilePath[] result = new FilePath(baseDir).list("**"); + assertEquals(expected, new HashSet(Arrays.asList(result))); + } finally { + Util.deleteRecursive(baseDir); + } + } + + public void testListWithExcludes() throws Exception { + File baseDir = Util.createTempDir(); + try { + final Set expected = new HashSet(); + expected.add(createFilePath(baseDir, "top", "sub", "app.log")); + createFilePath(baseDir, "top", "sub", "trace.log"); + expected.add(createFilePath(baseDir, "top", "db", "db.log")); + createFilePath(baseDir, "top", "db", "trace.log"); + final FilePath[] result = new FilePath(baseDir).list("**", "**/trace.log"); + assertEquals(expected, new HashSet(Arrays.asList(result))); + } finally { + Util.deleteRecursive(baseDir); + } + } + }