我试图获得一个ANT-Buildscript来计算存储在ANT属性中的行.从示例中我得到了计算文件中行的方法,如下所示:
<resourcecount count="0" when="eq">
<tokens>
<concat>
<filterchain>
<tokenfilter>
<linetokenizer/>
</tokenfilter>
</filterchain>
<fileset file="${file}" />
</concat>
</tokens>
</resourcecount>
Run Code Online (Sandbox Code Playgroud)
现在我想引用一个ANT属性而不是文件.有没有办法做到这一点?我知道使用<echo file="${temp.file}">${the.property.with.many.lines}</echo>和使用上面的代码将属性的内容写入文件的解决方案.但我想知道是否有一个没有临时文件的解决方案.
甲propertyresource元件可以代替的使用fileset如下:
<property name="lines"
value="line01${line.separator}line02${line.separator}line03"/>
<target name="count-lines">
<resourcecount property="line.count" count="0" when="eq">
<tokens>
<concat>
<filterchain>
<tokenfilter>
<stringtokenizer delims="${line.separator}" />
</tokenfilter>
</filterchain>
<propertyresource name="lines" />
</concat>
</tokens>
</resourcecount>
<echo message="${line.count}" />
</target>
Run Code Online (Sandbox Code Playgroud)
count-lines:[echo] 3
BUILD SUCCESSFUL总时间:0秒