Skip to content

Commit

Permalink
[Fixed JENKINS-11928] Added posibility to specify also exclude filter
Browse files Browse the repository at this point in the history
  • Loading branch information
vjuranek committed Dec 6, 2011
1 parent ae33d1e commit 42a6a9b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/main/java/hudson/plugins/ws_cleanup/Cleanup.java
Expand Up @@ -2,10 +2,13 @@

import hudson.FilePath.FileCallable;
import hudson.Util;
import hudson.plugins.ws_cleanup.Pattern.PatternType;
import hudson.remoting.VirtualChannel;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.apache.tools.ant.DirectoryScanner;
Expand All @@ -28,12 +31,23 @@ public boolean getDeleteDirs(){
public Object invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(f);
String[] includes = new String[patterns.size()];
int i = 0;
ArrayList<String> includes = new ArrayList<String>();
ArrayList<String> excludes = new ArrayList<String>();
for (Pattern pattern : patterns) {
includes[i++] = pattern.getPattern();
}
ds.setIncludes(includes);
if(pattern.getType() == PatternType.INCLUDE)
includes.add(pattern.getPattern());
else
excludes.add(pattern.getPattern());
}
//if there is no include pattern, set up ** (all) as include
if(includes.size() == 0)
includes.add("**/*");
String[] includesArray = new String[(includes.size())];
String[] excludesArray = new String[excludes.size()];
includes.toArray(includesArray);
excludes.toArray(excludesArray);
ds.setIncludes(includesArray);
ds.setExcludes(excludesArray);
ds.scan();
int length = ds.getIncludedFilesCount();
if(deleteDirs)
Expand Down
48 changes: 46 additions & 2 deletions src/main/java/hudson/plugins/ws_cleanup/Pattern.java
@@ -1,23 +1,67 @@
package hudson.plugins.ws_cleanup;

import hudson.Extension;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.util.ListBoxModel;

import java.io.Serializable;

import org.kohsuke.stapler.DataBoundConstructor;

/**
* @author <a href="mailto:nicolas.deloof@cloudbees.com">Nicolas De loof</a>
*/
public class Pattern implements Serializable{
public class Pattern implements Serializable, Describable<Pattern>{

private final String pattern;
private PatternType type;

@DataBoundConstructor
public Pattern(String pattern) {
public Pattern(String pattern, PatternType type) {
this.pattern = pattern;
this.type = type;
}

public Object readResolve(){
if(type == null)
type = PatternType.INCLUDE;
return this;
}

public String getPattern() {
return pattern;
}

public PatternType getType(){
return type;
}

public Descriptor<Pattern> getDescriptor() {
return Hudson.getInstance().getDescriptor(getClass());
}

@Extension
public static final class DescriptorImpl extends Descriptor<Pattern>{

public String getDisplayName(){
return "Directory scanner pattern";
}

public ListBoxModel doFillTypeItems(){
ListBoxModel model = new ListBoxModel(2);
model.add("Include",PatternType.INCLUDE.toString());
model.add("Exclude",PatternType.EXCLUDE.toString());
return model;
}

}

public enum PatternType{
INCLUDE,
EXCLUDE;
}

private static final long serialVerisonUID = 1L;
}
@@ -1,3 +1,8 @@
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:textbox field="pattern"/>
<table>
<tr>
<td width="15%"><f:select field="type" /></td>
<td width="85%"><f:textbox field="pattern"/></td>
</tr>
</table>
</j:jelly>

0 comments on commit 42a6a9b

Please sign in to comment.