diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 9b14501085..2f21b2cd5d 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -138,6 +138,7 @@ import static hudson.Util.fixEmpty; import static hudson.Util.isSymlink; import java.util.Collections; +import org.apache.tools.ant.BuildException; /** * {@link File} like object with remoting support. @@ -1829,7 +1830,12 @@ public final class FilePath implements Serializable { throw new IOException("Expecting Ant GLOB pattern, but saw '"+includes+"'. See http://ant.apache.org/manual/Types/fileset.html for syntax"); FileSet fs = Util.createFileSet(dir,includes,excludes); fs.setDefaultexcludes(defaultExcludes); - DirectoryScanner ds = fs.getDirectoryScanner(new Project()); + DirectoryScanner ds; + try { + ds = fs.getDirectoryScanner(new Project()); + } catch (BuildException x) { + throw new IOException(x.getMessage()); + } String[] files = ds.getIncludedFiles(); return files; } diff --git a/pom.xml b/pom.xml index 844cbf9243..c5544b74bb 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,7 @@ THE SOFTWARE. 3.0.0 - 3.18 + 3.19-20180319.205443-1 2.60 diff --git a/test/src/test/java/hudson/FilePathTest.java b/test/src/test/java/hudson/FilePathTest.java new file mode 100644 index 0000000000..bc5dfd3f4d --- /dev/null +++ b/test/src/test/java/hudson/FilePathTest.java @@ -0,0 +1,59 @@ +/* + * The MIT License + * + * Copyright 2018 CloudBees, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package hudson; + +import hudson.model.Node; +import org.apache.tools.ant.DirectoryScanner; +import static org.hamcrest.Matchers.*; +import org.junit.Test; +import static org.junit.Assert.*; +import org.junit.Rule; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +public class FilePathTest { + + @Rule + public JenkinsRule r = new JenkinsRule(); + + @Issue("JENKINS-50237") + @Test + public void listGlob() throws Exception { + for (Node n : new Node[] {r.jenkins, r.createOnlineSlave()}) { + FilePath d = n.getRootPath().child("globbing"); + FilePath exists = d.child("dir/exists"); + exists.write("", null); + assertThat(d.list("**/exists"), arrayContainingInAnyOrder(exists)); + assertThat(d.list("**/nonexistent"), emptyArray()); + FilePath nonexistentDir = d.child("nonexistentDir"); + try { + assertThat("if it works at all, should be empty", nonexistentDir.list("**"), emptyArray()); + } catch (Exception x) { + assertThat(x.toString(), containsString(nonexistentDir.getRemote() + DirectoryScanner.DOES_NOT_EXIST_POSTFIX)); + } + } + } + +}