Ant loadfile override property

人盡茶涼 提交于 2019-12-01 19:52:44

The Ant plugin Flaka provides a let task, allowing to overwrite existing properties or variables like that =

<project xmlns:fl="antlib:it.haefelinger.flaka">

<property name="my.property" value="value"/>
<fl:let> my.property ::= 'anothervalue'</fl:let>

</project>

So no need to unset first and set afterwards. btw. Flaka has a unset task also ;-)

<loadfile property="foo" srcfile="bar.txt"/>

 ... do some actions, perhaps in a <for> loop ...

<var name="foo" unset="true"/>

You can then use foo again in <loadfile>

Ant contrib also has a var task that unsets.

Lucks: It is convention to accept one of the answers so people know the question is resolved. I recommend you accept Gilbert's since he post a correct answer first.

One of the built-in tasks that are able to override the property value is script.

Below is a script and the output that proves the property value changed.

<project name="test">
  <property name="bshJar" value="C:\lang\java\bsh-1.3.0.jar:C:\lang\java\bsf.jar:C:\lang\java\commons-logging-1.1.1.jar" />
  <property name="a" value="first" />
  <echo>a=${a}</echo>
  <script manager="bsf" language="beanshell" classpath="${bshJar}"><![CDATA[
  project.setProperty("a", "fourth");
  ]]></script>
  <echo>a=${a}</echo>
</project>

Output:

a=first
a=fourth

I just ended up using the <unset> task provided by Antelope http://antelope.tigris.org/

Did you try the script in ANT.

<script language="javascript">
project.setProperty("my.property", "somevalue");
</script>

You could create a new property in your MacroDef for each srcFile:

<loadfile srcFile="@{some.input}" property="@{some.input}_Prop">

<echo message="@{some.input} Contents: ${@{some.input}_Prop}"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!