Methods Summary |
---|
public synchronized void | add(org.apache.tools.ant.types.FileSet fs)Add a FileSet.
add((ResourceCollection) fs);
|
public synchronized void | add(org.apache.tools.ant.types.ResourceCollection c)Add a ResourceCollection.
if (c == null) {
return;
}
resources = (resources == null) ? new Resources() : resources;
resources.add(c);
|
public boolean | eval()Fulfill the condition contract.
validate();
if (length == null) {
throw new BuildException(LENGTH_REQUIRED);
}
Long ell = null;
if (STRING.equals(mode)) {
ell = new Long(getLength(string, getTrim()));
} else {
ConditionHandler h = new ConditionHandler();
handleResources(h);
ell = new Long(h.getLength());
}
return when.evaluate(ell.compareTo(length));
|
public void | execute()Execute the length task.
validate();
PrintStream ps = new PrintStream((property != null)
? (OutputStream) new PropertyOutputStream(getProject(), property)
: (OutputStream) new LogOutputStream(this, Project.MSG_INFO));
if (STRING.equals(mode)) {
ps.print(getLength(string, getTrim()));
ps.close();
} else if (EACH.equals(mode)) {
handleResources(new EachHandler(ps));
} else if (ALL.equals(mode)) {
handleResources(new AllHandler(ps));
}
|
private static long | getLength(java.lang.String s, boolean t)
return (t ? s.trim() : s).length();
|
public boolean | getTrim()Learn whether strings will be trimmed.
return trim != null && trim.booleanValue();
|
private void | handleResources(org.apache.tools.ant.taskdefs.Length$Handler h)
for (Iterator i = resources.iterator(); i.hasNext();) {
Resource r = (Resource) i.next();
if (!r.isExists()) {
log(r + " does not exist", Project.MSG_ERR);
} else if (r.isDirectory()) {
log(r + " is a directory; length unspecified",
Project.MSG_ERR);
} else {
h.handle(r);
}
}
h.complete();
|
public synchronized void | setFile(java.io.File file)Set the single file for this task.
add(new FileResource(file));
|
public synchronized void | setLength(long ell)Set the target count number for use as a Condition.
length = new Long(ell);
|
public synchronized void | setMode(org.apache.tools.ant.taskdefs.Length$FileMode m)Set the execution mode for working with files.
this.mode = m.getValue();
|
public synchronized void | setProperty(java.lang.String property)The property in which the length will be stored.
this.property = property;
|
public synchronized void | setString(java.lang.String string)Set the string whose length to get.
this.string = string;
this.mode = STRING;
|
public synchronized void | setTrim(boolean trim)Set whether to trim in string mode.
this.trim = trim ? Boolean.TRUE : Boolean.FALSE;
|
public synchronized void | setWhen(org.apache.tools.ant.taskdefs.Length$When w)Set the comparison for use as a Condition.
setWhen((Comparison) w);
|
public synchronized void | setWhen(org.apache.tools.ant.types.Comparison c)Set the comparison for use as a Condition.
when = c;
|
private void | validate()
if (string != null) {
if (resources != null) {
throw new BuildException("the string length function"
+ " is incompatible with the file/resource length function");
}
if (!(STRING.equals(mode))) {
throw new BuildException("the mode attribute is for use"
+ " with the file/resource length function");
}
} else if (resources != null) {
if (!(EACH.equals(mode) || ALL.equals(mode))) {
throw new BuildException("invalid mode setting for"
+ " file/resource length function: \"" + mode + "\"");
} else if (trim != null) {
throw new BuildException("the trim attribute is"
+ " for use with the string length function only");
}
} else {
throw new BuildException("you must set either the string attribute"
+ " or specify one or more files using the file attribute or"
+ " nested resource collections");
}
|