使用 if with resourcecontains in 并且不返回真值
using if with resourcecontains in and is not returning true value
我正在读取一个包含文件路径列表的文件。
对于每个文件,我想知道它是否包含一个子字符串。
答案总是错误的,尽管它的一部分应该是正确的。
这是我的目标:
<target name="chek-file">
<loadfile property="file" srcfile="c:\tmp\testing.txt"/>
<for param="line" list="${file}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
<loadfile property="inner_file" srcfile="@{line}"/>
<if>
<resourcecontains resource="${inner_file}" substring="parent" />
<then>
<echo message="this is a jpa jar"/>
</then>
<else>
<echo message="this is NOT a jpa jar"/>
</else>
</if>
</sequential>
</for>
</target>
回显正在为所有 jar 输入 "this is NOT a jpa jar"。
'if' 不能与 'resourcecontains' 一起使用吗?
OK,发现两个问题:
1)这里实际上不需要第二个加载文件,因为resourcecontains
需要获取文件名而不是它的值。
2) resourcecontains
继承自<condition>
所以解决方案应该是:
<target name="chek-file">
<loadfile property="file" srcfile="c:\tmp\testing.txt"/>
<for param="line" list="${file}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
<condition property="substring_found">
<resourcecontains resource="@{line}" substring="JPA>true" />
</condition>
<echo message="substring_found value: ${substring_found}"/>
<if>
<equals arg1="${substring_found}" arg2="true" />
<then>
<echo message="this is a jpa jar"/>
<get_jar_name_no_version property.to.process="@{line}" output.property="linetobeadd" />
</then>
<else>
<echo message="this is NOT a jpa jar"/>
</else>
</if>
<var name="substring_found" unset="true"/>
</sequential>
</for>
</target>
我正在读取一个包含文件路径列表的文件。
对于每个文件,我想知道它是否包含一个子字符串。
答案总是错误的,尽管它的一部分应该是正确的。
这是我的目标:
<target name="chek-file">
<loadfile property="file" srcfile="c:\tmp\testing.txt"/>
<for param="line" list="${file}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
<loadfile property="inner_file" srcfile="@{line}"/>
<if>
<resourcecontains resource="${inner_file}" substring="parent" />
<then>
<echo message="this is a jpa jar"/>
</then>
<else>
<echo message="this is NOT a jpa jar"/>
</else>
</if>
</sequential>
</for>
</target>
回显正在为所有 jar 输入 "this is NOT a jpa jar"。
'if' 不能与 'resourcecontains' 一起使用吗?
OK,发现两个问题:
1)这里实际上不需要第二个加载文件,因为resourcecontains
需要获取文件名而不是它的值。
2) resourcecontains
继承自<condition>
所以解决方案应该是:
<target name="chek-file">
<loadfile property="file" srcfile="c:\tmp\testing.txt"/>
<for param="line" list="${file}" delimiter="${line.separator}">
<sequential>
<echo>@{line}</echo>
<condition property="substring_found">
<resourcecontains resource="@{line}" substring="JPA>true" />
</condition>
<echo message="substring_found value: ${substring_found}"/>
<if>
<equals arg1="${substring_found}" arg2="true" />
<then>
<echo message="this is a jpa jar"/>
<get_jar_name_no_version property.to.process="@{line}" output.property="linetobeadd" />
</then>
<else>
<echo message="this is NOT a jpa jar"/>
</else>
</if>
<var name="substring_found" unset="true"/>
</sequential>
</for>
</target>