在这里,target.location是用户作为属性文件输入传递的目录。现在,我需要编写一个验证,以确保目录位置始终以/properties开头。用户可以传递">
我刚开始使用Ant脚本,我的版本是1.6.5,在SUSe Linux11上,请您帮助实现下面的内容。
<fileset dir="${target.location}" includes = "${file.list}"/>
在这里,target.location是用户作为属性文件输入传递的目录。现在,我需要编写一个验证,以确保目录位置始终以/properties开头。
用户可以传递/properties//之类的任何内容,但是起始字符串应该始终是"/properties“,否则就会将错误抛给用户并退出,我不能使用ant-cont肋骨,因为要向现有的ant添加任何库都需要经过大量的审批过程。
发布于 2014-03-10 14:57:28
您可以使用javascript实现自定义脚本条件检查。对Javascript的支持来自JVM,因此不需要额外的jars:
<project name="demo" default="check">
<property name="target.location" value="/properties/some/path"/>
<condition property="found.prefix">
<scriptcondition language="javascript">
self.setValue(String(project.getProperty("target.location")).indexOf("/properties")==0)
</scriptcondition>
</condition>
<target name="check">
<fail message="target.location must be prefixed with '/properties'" unless="found.prefix"/>
</target>
</project>
https://stackoverflow.com/questions/22311996
复制相似问题