Methods Summary |
---|
public boolean | isSelected(java.io.File basedir, java.lang.String filename, java.io.File file)The heart of the matter. This is where the selector gets to decide
on the inclusion of a file in a particular fileset. Most of the work
for this selector is offloaded into SelectorUtils, a static class
that provides the same services for both FilenameSelector and
DirectoryScanner.
// throw BuildException on error
validate();
int depth = -1;
// If you felt daring, you could cache the basedir absolute path
String absBase = basedir.getAbsolutePath();
String absFile = file.getAbsolutePath();
StringTokenizer tokBase = new StringTokenizer(absBase,
File.separator);
StringTokenizer tokFile = new StringTokenizer(absFile,
File.separator);
while (tokFile.hasMoreTokens()) {
String filetoken = tokFile.nextToken();
if (tokBase.hasMoreTokens()) {
String basetoken = tokBase.nextToken();
// Sanity check. Ditch it if you want faster performance
if (!basetoken.equals(filetoken)) {
throw new BuildException("File " + filename
+ " does not appear within " + absBase
+ "directory");
}
} else {
depth += 1;
if (max > -1 && depth > max) {
return false;
}
}
}
if (tokBase.hasMoreTokens()) {
throw new BuildException("File " + filename
+ " is outside of " + absBase + "directory tree");
}
if (min > -1 && depth < min) {
return false;
}
return true;
|
public void | setMax(int max)The minimum depth below the basedir before a file is selected.
this.max = max;
|
public void | setMin(int min)The minimum depth below the basedir before a file is selected.
this.min = min;
|
public void | setParameters(org.apache.tools.ant.types.Parameter[] parameters)When using this as a custom selector, this method will be called.
It translates each parameter into the appropriate setXXX() call.
super.setParameters(parameters);
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
String paramname = parameters[i].getName();
if (MIN_KEY.equalsIgnoreCase(paramname)) {
try {
setMin(Integer.parseInt(parameters[i].getValue()));
} catch (NumberFormatException nfe1) {
setError("Invalid minimum value "
+ parameters[i].getValue());
}
} else if (MAX_KEY.equalsIgnoreCase(paramname)) {
try {
setMax(Integer.parseInt(parameters[i].getValue()));
} catch (NumberFormatException nfe1) {
setError("Invalid maximum value "
+ parameters[i].getValue());
}
} else {
setError("Invalid parameter " + paramname);
}
}
}
|
public java.lang.String | toString()
StringBuffer buf = new StringBuffer("{depthselector min: ");
buf.append(min);
buf.append(" max: ");
buf.append(max);
buf.append("}");
return buf.toString();
|
public void | verifySettings()Checks to make sure all settings are kosher. In this case, it
means that the max depth is not lower than the min depth.
if (min < 0 && max < 0) {
setError("You must set at least one of the min or the "
+ "max levels.");
}
if (max < min && max > -1) {
setError("The maximum depth is lower than the minimum.");
}
|