本文介绍了如何为蚂蚁任务创建嵌套元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为任何蚂蚁任务创建嵌套元素.例如
Is it possible to create the nested element for any ant task. For e.g.
<copy todir="../backup/dir">
<fileset dir="src_dir"/>
<filterset>
<filter token="TITLE" value="Foo Bar"/>
</filterset>
</copy>
对于任务复制,我们将嵌套元素作为过滤器集.现在,我想为任务 copy 创建自己的嵌套元素 encryptfilterset.
Here for the task copy we are having nested element as filterset. Now, i would like to create my own nested element encryptfilterset for the task copy.
<copy todir="../backup/dir">
<fileset dir="src_dir"/>
<encryptfilterset>
<filter token="TITLE" value="Foo Bar"/>
</encryptfilterset>
</copy>
我们该怎么做?
推荐答案
我们必须扩展现有任务以创建 CustomTask
并且现在支持自定义嵌套元素 XYZ 在您的新类中创建一个方法
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();
或public void addXYZ(XYZ obj)
或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
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>
这篇关于如何为蚂蚁任务创建嵌套元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!