package com.lidihuo; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.condition.Condition; public class AllUpperCaseCondition implements Condition { private String value; // The setter for the "value" attribute public void setValue(String value) { this.value = value; } // this method evaluates the condition public boolean eval() { if (value == null) { throw new BuildException("value attribute is not set"); } return value.toUpperCase().equals(value); } }
<typedef name="alluppercase" classname="com.lidihuo.AllUpperCaseCondition" classpath="test.com.lidihuo"/>
<project name="java-ant project" default="abc"> <typedef name="alluppercase" classname="com.lidihuo.AllUpperCaseCondition" classpath="test.com.lidihuo"/> <target name="abc" > <condition property="allupper"> <alluppercase value="this IS ALL UPPER CASE"/> </condition> </target> </project>
package com.lidihuo; import java.io.File; import org.apache.tools.ant.types.selectors.FileSelector; public class JavaSelector implements FileSelector { public boolean isSelected(File b, String filename, File f) { return filename.toLowerCase().endsWith(".java"); } }
<typedef name="javaselector" classname="com.lidihuo.JavaSelector" classpath="test"/>
<project name="java-ant project" default="abc"> <target name="abc"> <typedef name="javaselector" classname="com.lidihuo.JavaSelector" classpath="test"/> <copy todir="destdir"> <fileset dir="src"> <javaselector/> </fileset> </copy> </target> </project>