we have to extend the existing task to create CustomTask and now to support the custom nested element XYZ create a method in your new class
public XYZ createXYZ();
or
public void addXYZ(XYZ obj)
or
public void addXYZ(XYZ obj)
<taskdef name="CustomTask" classname="com.ant.task.Customtask"> <classpath> <path location="lib/"/> </classpath> </taskdef> <typedef name="XYZ" classname="com.ant.type.XYZ" > <classpath> <path location="lib/"/> </classpath> </typedef> <target name="MyTarget" > <CustomTask> <XYZ></XYZ> </CopyEncrypted> </target>
So my files looked like:-
public class CopyEncrypted extends Copy { public EncryptionAwareFilterSet createEncryptionAwareFilterSet() { EncryptionAwareFilterSet eafilterSet = new EncryptionAwareFilterSet(); getFilterSets().addElement( eafilterSet ); return eafilterSet; } } public class EncryptionAwareFilterSet extends FilterSet{ @Override public synchronized void readFiltersFromFile(File file) throws BuildException { log("EncryptionAwareFilterSet::reading filters",0); super.readFiltersFromFile(file); Vector<Filter> filts = getFilters(); for (Iterator iterator = filts.iterator(); iterator.hasNext();) { Filter filter = (Filter) iterator.next(); if ( filter.getToken().equalsIgnoreCase( "PASSWORD" ) ){ filter.setValue( Encryptor.getEncryptedValue ( filter.getValue() ) ); } } } }
build.xml
<target name="encrypted-copy" > <CopyEncrypted todir="dist/xyz/config" overwrite="true"> <fileset dir="config"/> <encryptionAwareFilterSet> <filtersfile file="conf/properties/blah-blah.properties" /> </encryptionAwareFilterSet> </CopyEncrypted> </target>