views:

45

answers:

3

Hi,

I need to keep a control value (possibly inside a file), in order to decide whether to execute a task or not.

I'm coming from here: http://stackoverflow.com/questions/2239236/ant-how-can-i-subtract-two-properties-containing-timestamps

What I want to do, is to check if the control value is equal to a period (mmYY). If it is equal, nothing will be done, but if they are not, the control value should be updated.

For example:

<task dosomethingifcontrolvaluediffers>
control value is 0000
(calculated) property is: 0110
Then, control value should now be 0110.

</task>

I was thinking of keeping the value in a separate file, and if rewriting is neccessary, then truncate the file and updating, but

1) Cant find a way to do this

2) Dont know how.

3) scripting ? Would be my favorite choice, but dont know howto in js.

Any thoughts?

Thanks in advance.

+1  A: 

Should be done outside of Ant. Write a script in whatever language you know (bash, Python, JavaScript, etc.) that does the calculation, does the check, and calls Ant using that value as a parameter if needed.

Ant's not intended to be a scripting language. People get into trouble when they try to make it so.

duffymo
Sh*t. I was hoping the "ant is no scripting language" wouldnt come up.The thing is that ant is the only "scripting" possibility I have in this project.
Tom
What operating system are you using? You can't use a batch or command file on Windows, or a cshell in *nix? You always have a choice.
duffymo
A: 

I haven't tried it but, you may be able to do this:

use the condition task like so

<condition property="exectask">
   <equals arg1="${prop1}" arg2="${prop2}" trim="true"/>
</condition>

And then call a target based on the property value

<target name="dosomethingifcontrolvaluediffers" unless="${exectask}">
</target>

Hope it helps.

Alonso
I see what you mean, but heres the thing. prop1 can be calculated, but my question is "how do i get prop2". Plus, how can I update it inside the target.Thanks.
Tom
Sorry, I don't get it :S Maybe prop2 is the control value?
Alonso
A: 

As mentioned by duffymo, ant is not a scripting language. Though, you can use a scripting language like javascript inside of ant, see the ant scriptdef task for details. You can define your own tasks like this:

<scriptdef name="nameOfTheTask" language="javascript">
    <![CDATA[
        (your script goes here)
    ]]>
</scriptdef>

You can use the new task like this:

 <nameOfTheTask/>

You also mentioned that you like to store a value in a file. This can be done with the ant echo task:

    <echo file="yourFile">aProperty=${aProperty}{line.separator}</echo>

This writes the value to the file yourFile. The output is for example:

aProperty=some value

You can read the value again in a script with the loadproperties task:

<loadproperties srcFile="yourFile" />

I hope this helps.

akr