Skip to content

Commit

Permalink
Merge pull request #54 from ctran/master
Browse files Browse the repository at this point in the history
Add "excludes" option to skip over large directories
  • Loading branch information
rsandell authored Feb 1, 2019
2 parents 113be3b + 97e8358 commit 1a926d2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
*/
public class FindFilesStep extends Step {
private String glob;
private String excludes;

@DataBoundConstructor
public FindFilesStep() {
Expand Down Expand Up @@ -80,6 +81,21 @@ public void setGlob(String glob) {
this.glob = glob;
}

/**
* Pattern of files to excludes in the list. This is useful for large
* directory structure (i.e npm-modules)
*
* @return the excludes pattern
*/
public String getExcludes() {
return excludes;
}

@DataBoundSetter
public void setExcludes(String excludes) {
this.excludes = excludes;
}

@Extension
public static class DescriptorImpl extends StepDescriptor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected FileWrapper[] run() throws Exception {
if (StringUtils.isBlank(step.getGlob())) {
list = ws.list();
} else {
list = Arrays.asList(ws.list(step.getGlob()));
list = Arrays.asList(ws.list(step.getGlob(), step.getExcludes()));
}
FileWrapper[] res = new FileWrapper[list.size()];
for(int i = 0; i < list.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ def f = namespace(lib.FormTagLib) as lib.FormTagLib

f.entry(field: 'glob', title: _('Glob')) {
f.textbox()
}

f.entry(field: 'exclusions', title: _('Exclusions')) {
f.textbox()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2016 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.
-->

<p>
<a href="https://ant.apache.org/manual/dirtasks.html#patterns" target="_blank">Ant style pattern</a>
of file paths that should be excluded.
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,31 @@ public void listSome() throws Exception {
j.assertLogNotContains("F: b/11.txt", run);
j.assertLogNotContains("F: b/12.txt", run);
}

@Test
public void listSomeWithExclusions() throws Exception {
String flow = CODE.replace("%TESTCODE%",
"def files = findFiles(glob: '**/*.txt', excludes: 'b/*.txt,**/aba/*.txt')\n" +
"echo \"${files.length} files\"\n" +
"for(int i = 0; i < files.length; i++) {\n" +
" echo \"F: ${files[i].path.replace('\\\\', '/')}\"\n" +
"}"
);
p.setDefinition(new CpsFlowDefinition(flow, true));
WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));

j.assertLogContains("8 files", run);
j.assertLogContains("F: 1.txt", run);
j.assertLogContains("F: 2.txt", run);
j.assertLogContains("F: a/3.txt", run);
j.assertLogContains("F: a/4.txt", run);
j.assertLogContains("F: a/aa/5.txt", run);
j.assertLogContains("F: a/aa/6.txt", run);
j.assertLogContains("F: a/ab/7.txt", run);
j.assertLogContains("F: a/ab/8.txt", run);
j.assertLogNotContains("F: a/ab/aba/9.txt", run);
j.assertLogNotContains("F: a/ab/aba/10.txt", run);
j.assertLogNotContains("F: b/11.txt", run);
j.assertLogNotContains("F: b/12.txt", run);
}
}

0 comments on commit 1a926d2

Please sign in to comment.