Matt Benson wrote:
this test works on the command line:
<target name="testPath" depends="define">
<book:filesize property="size">
<path path="${java.class.path}"/>
</book:filesize>
<echo> classpath size=${size}</echo>
</target>
but when run from antunit, it fails cos
java.class.path isnt set.
Steve, I was noticing this filesize task you've got in
the "book" ns... I assume this relates to an example
that will go in the forthcoming revision to the
Manning book. How does <book:filesize> differ from
the 1.6.3+ <length> task?
hey, go check out antbook.cvs.sourceforge.net and see for yourself.
For reference, it only does file resources. I iterate and cast
public void execute() throws BuildException {
if (property == null) {
throw new BuildException("No property");
}
long size = 0;
int count = 0;
Iterator element = resources.iterator();
while (element.hasNext()) {
Resource resource = (Resource) element.next();
if (!(resource instanceof FileResource)) {
throw new BuildException("Not a file: " + resource);
}
log(resource.getName(), Project.MSG_VERBOSE);
FileResource fileResource = (FileResource) resource;
File file = fileResource.getFile();
if (!file.exists()) {
throw new BuildException("Not found: " + file);
}
size += file.length();
count++;
}
if (count == 0) {
log("No files sized up", Project.MSG_WARN);
}
getProject().setNewProperty(property, Long.toString(size));
}
It just shows how to go from a file to a fileset to resources.
the other interesting task does classpath setup and delegates to java
/**
* [EMAIL PROTECTED]
* @throws org.apache.tools.ant.BuildException
* if something goes wrong with the build.
*/
public void execute() {
Java java=new Java();
java.bindToOwner(this);
java.init();
java.setClasspath(classpath);
java.setClassname(classname);
java.setFailonerror(true);
java.setFork(true);
Iterator element = resources.iterator();
while (element.hasNext()) {
Resource resource = (Resource) element.next();
java.createArg().setValue(resource.toString());
}
java.execute();
}
Its a resource-enabled equivalent of <apply>, effectively. And you can
see why I like toString() to be meaningful.
-steve
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]