Hello...

"When one learns of a hammer...everything looks like a nail"

ANT is a powerful tool and it can be used to easily do many things but some 
times (heaven forbid!!) using ANT is not the most direct route.

Assuming you want to do is extend the example you started earlier...you now 
have a series of properties (that are kept in a file) whose values you wish to 
'convert'

I would extend the JAVA program to take the property file as a parameter, 
rather than iterating over each value in the file and pass them to the program.
Let the JAVA program:
    1) Read the property file (java.util.Properties.load())
    2) Iterate over the keys, converting each value
    3) write out the keys with the new values to a temporary result file
    4) Return the filename of the result file to calling ANT task (via 
System.out)

All the ANT target would do is:
    1) Invoke the <java> program passing the property filename as an argument
    2) Capture the name of result file (via the 'outputproperty' attribute) 
    3) Rename output file (if needed).

Thanks for your kind words...and good luck

Ninju
 


----- Original Message ----
From: broken connection <[EMAIL PROTECTED]>
To: Ant Users List <user@ant.apache.org>
Sent: Thursday, June 28, 2007 1:07:23 AM
Subject: Re: How to make "outputproperty" element work???


Hi again,
I have one small question here,if someone can help please....

Ninju, showed how to pass one parameter and get the value but what if I want
to call the same Java file say 20 times passing different parameter value
each time and getting different encrypted result back each time.

So,is there any way to call the <java> or <exec> task  multiple times
passing different value each time...???

Would appreciate if anyone can help on this one too....if not,no issues...I
am already very grateful to the forum members for showing so much support.

Cheers

On 6/28/07, broken connection <[EMAIL PROTECTED]> wrote:
>
> Hi Ninju,
> I really really want to thank you for that great help. I almost spent 7
> hours and was still trying to figure it out when your reply came.I tried
> everything from <antcontrib> to <replace> to <propertyset> and god knows
> what else....
>
> And you made it sound soo easy...wow..you are genius man.
>
> Thanks again for that great help...really appreciate it!!!!!
>
> On 6/28/07, Ninju Bohra <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> > I made up the following quick test and the 'outputproperty' of the
> > <java> task worked just fine
> >
> > Stupid JAVA class to generate the 'new' password and write the value to
> > System.out (so that it can be captured into the 'outputproperty')
> >
> > public class GeneratePassword {
> >     public static void main(String[] args) {
> >         System.out.println(args[0].toUpperCase());
> >     }
> > }
> >
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > I created the following property file to contain the current password
> > text
> >
> > value.properties:
> >     my_password=Secret
> >
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > Here is the quick build.xml with the target
> >
> > <project name="test" default="convert_password">
> > <property name="prop_file" value="value.properties"/>
> > <target name="convert_password">
> >   <property file="${prop_file}"/>
> >   <echo> Current value of my_password is ${my_password}</echo>
> >   <java classname="GeneratePassword" outputproperty="new_password">
> >    <arg value="${my_password}"/>
> >    <classpath>
> >               <pathelement path="."/>
> >    </classpath>
> >   </java>
> >   <echo>New password is ${new_password}</echo>
> >   <copy file="${prop_file}" tofile="new_${prop_file}"/>
> >   <replace file="new_${prop_file}" token="${my_password}"
> > value="${new_password}"/>
> >   <echo>The new password is stored in the file called
> > new_${prop_file}</echo>
> > </target>
> > </project>
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> >
> > And here is the output:
> >
> > C:\workspace\Test\bin>ant
> > Buildfile: build.xml
> > convert_password:
> >      [echo]  Current value of my_password is Secret
> >      [echo] New password is SECRET
> >      [echo] The new password is stored in the file called
> > new_value.properties
> > BUILD SUCCESSFUL
> > Total time: 0 seconds
> > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> >
> > In my example I wrote the 'updated' password into a copy of the of the
> > original file...if you want to overwrite the original value just skip the
> > <copy> task and adjust the "file" attribute in the <replace> task to match
> > the orginial file name
> >
> > Hope that helps....
> >
> > Ninju
> >
> > ----- Original Message ----
> > From: broken connection <[EMAIL PROTECTED]>
> > To: user@ant.apache.org
> > Sent: Wednesday, June 27, 2007 7:22:59 PM
> > Subject: How to make "outputproperty" element work???
> >
> >
> > Hi Friends,
> > I need some help with "outputproperty" element. I have a properties
> > file, i
> > want to pass in one of the property to a java program and read the
> > response
> > back and store it in the same property using ant for eg:
> >
> > my_property=plain_password
> >
> > //I want to pass this to a java program and the property should be
> > modified
> > as:
> > my_property=encrypted_password
> >
> > I tried to use "JAVA" task but redirection was not working so I used
> > this
> > "exec" task instead:
> >
> > <filter filtersfile="myfile.properties"/>
> >
> > <target name="test">
> > <exec executable="${ext}" resolveexecutable="true" os="Windows XP">
> > <arg value="/c"/>
> > <arg value="call-program.${ext} ${my_property}"/>
> > <redirector output="myfile.properties"
> > outputproperty="my_password" append="true" />
> > </exec>
> > </target>
> >
> > But its not working. I am able to redirect the output to some other file
> > eg,
> > "xyz.txt" but then too the outputproperty element is not working,I want
> > the
> > output as:
> > property=value
> >
> > I have tried a lot, can somebody please give me a clue as to where i am
> > going wrong.I would really appreciate that.
> >
> > Cheers
> >
> >
> >
> >       
> > ____________________________________________________________________________________
> > Shape Yahoo! in your own image.  Join our Network Research Panel
> > today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>


      
____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel 
and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to