You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Jeremy Hanna <je...@mac.com> on 2008/06/12 03:56:24 UTC

Using the script tag, wanting to return a value

I'm using the script tag to run a ruby script and would like to return  
a value from the script.  Is that possible?  I see that I can use the  
setbeans attribute to have access to the build.xml variables from  
within the ruby script.  I can output them and even change those  
variables within the ruby script, but those changes disappear once the  
script returns.
Is there any way to return the value?
Really I'm trying to get the result of `svn info` which is retrieved  
in my ruby script.  I haven't seen ant libraries out there that do  
that - most don't implement the info function.  I tried using the exec  
task but that seems to need the path information and that gets too  
messy.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Using the script tag, wanting to return a value

Posted by Jeremy Hanna <je...@mac.com>.
Thanks Gilbert and others.  This is exactly what I needed to know -  
works great.  It is, as my 4 year old nephew says, super-awesome.

On Jun 12, 2008, at 2:01 AM, Rebhan, Gilbert wrote:

>
> Hi, Jeremy
>
> -----Original Message-----
> From: Jeremy Hanna [mailto:jeremy_hanna@mac.com]
> Sent: Thursday, June 12, 2008 3:56 AM
> To: user@ant.apache.org
> Subject: Using the script tag, wanting to return a value
>
> /*
> I'm using the script tag to run a ruby script and would like to return
> a value from the script.  Is that possible?  I see that I can use the
> setbeans attribute to have access to the build.xml variables from
> within the ruby script.  I can output them and even change those
> variables within the ruby script, but those changes disappear once the
> script returns.
> Is there any way to return the value?
> Really I'm trying to get the result of `svn info` which is retrieved
> in my ruby script.  I haven't seen ant libraries out there that do
> that - most don't implement the info function.  I tried using the exec
> task but that seems to need the path information and that gets too
> messy.
> */
>
> if you need to return value(s) out of <script> and make them available
> for further processing by ant you need to put them into the project
> scope
> of your running ant script.
>
> therefore you make use of the ant api =
> $project.setProperty "propertyname", value
> $project.setNewProperty "propertyname", value
>
> difference = setProperty allows also overwriting of existing  
> properties.
> Overwriting of properties collides with ant rules - means immutability
> of properties - but sometimes it's a must.
>
> beside using the ant api a 'puts' or 'print'  in your script prints on
> stdout
> and gets logged
>
> and finally your script may write/append to a file for persistance
> f.e. to make values available for other scripts that run isolated
>
> what i'd try with your svn info command, is using
> the backtick operator as i did with nslookup in
> the first example.
>
> two small examples =
>
> 1.getting the servername from nslookup on windows
>
> <scriptdef name="getservername" language="ruby">
> <attribute name="alias"/>
> <attribute name="property"/>
> <![CDATA[
>   getserver=`nslookup "#{$attributes.get('alias')}"`
>   $project.setProperty $attributes.get('property'),
> "//#{getserver.scan(/Name:\s+(\w+)\./)}"
> ]]>
> </scriptdef>
>
> <getservername alias="test1" property="test.deploy"/>
>
> ...
>
> <echo>$${test.deploy} = ${test.deploy}</echo>
>
> 2. sleep random
>
> <script language="ruby">
> <![CDATA[
>  a = ['15','30','60','90','120']
>  $project.setProperty "sleep.time", a[rand(a.size)
> ]]]>
> </script>
>
> <sleep seconds="${sleep.time}"/>
>
>
> Regards, Gilbert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Using the script tag, wanting to return a value

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 
Hi, Jeremy

-----Original Message-----
From: Jeremy Hanna [mailto:jeremy_hanna@mac.com] 
Sent: Thursday, June 12, 2008 3:56 AM
To: user@ant.apache.org
Subject: Using the script tag, wanting to return a value

/*
I'm using the script tag to run a ruby script and would like to return  
a value from the script.  Is that possible?  I see that I can use the  
setbeans attribute to have access to the build.xml variables from  
within the ruby script.  I can output them and even change those  
variables within the ruby script, but those changes disappear once the  
script returns.
Is there any way to return the value?
Really I'm trying to get the result of `svn info` which is retrieved  
in my ruby script.  I haven't seen ant libraries out there that do  
that - most don't implement the info function.  I tried using the exec  
task but that seems to need the path information and that gets too  
messy.
*/

if you need to return value(s) out of <script> and make them available
for further processing by ant you need to put them into the project
scope
of your running ant script.

therefore you make use of the ant api =
$project.setProperty "propertyname", value
$project.setNewProperty "propertyname", value

difference = setProperty allows also overwriting of existing properties.
Overwriting of properties collides with ant rules - means immutability
of properties - but sometimes it's a must.

beside using the ant api a 'puts' or 'print'  in your script prints on
stdout
and gets logged

and finally your script may write/append to a file for persistance
f.e. to make values available for other scripts that run isolated

what i'd try with your svn info command, is using
the backtick operator as i did with nslookup in
the first example.

two small examples =

1.getting the servername from nslookup on windows

<scriptdef name="getservername" language="ruby">
 <attribute name="alias"/>
 <attribute name="property"/>
 <![CDATA[
   getserver=`nslookup "#{$attributes.get('alias')}"`
   $project.setProperty $attributes.get('property'),
"//#{getserver.scan(/Name:\s+(\w+)\./)}"
 ]]>
 </scriptdef>

<getservername alias="test1" property="test.deploy"/>

...

<echo>$${test.deploy} = ${test.deploy}</echo>

2. sleep random

<script language="ruby">
<![CDATA[
  a = ['15','30','60','90','120']    
  $project.setProperty "sleep.time", a[rand(a.size)
]]]>
</script>
    
<sleep seconds="${sleep.time}"/>


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Using the script tag, wanting to return a value

Posted by Dale Anson <da...@grafidog.com>.
javasvn became svnkit a couple of years ago.  I don't recall the story, 
but the name was changed.  So if you're still using javasvn, it's quite 
old.  svnkit is used in the Subclipse and Subversive plugins for Eclipse 
and in the jEdit SVN plugin, and it seems to be quite fast.  svnkit 
comes with a command line interface also, it's as fast as the standard 
svn command line client.  I believe the Subclipse svn ant tasks call the 
svnkit command line client internally, so I would expect the ant tasks 
to be as fast as the command line client itself.

Dale


Shawn Castrianni wrote:
> I am currently using svnant with javasvn and everything works great, it is just very sloooooow.  Much slower than command line svn or SmartSVN.  I was thinking about trying svnkit as a replacement for javasvn.  Would it be any faster?
>
> ---
> Shawn Castrianni
>
> -----Original Message-----
> From: Dale Anson [mailto:danson@grafidog.com]
> Sent: Wednesday, June 11, 2008 10:17 PM
> To: Ant Users List
> Subject: Re: Using the script tag, wanting to return a value
>
> Have you tried the svn ant task from subclipse?
>
> http://subclipse.tigris.org/svnant.html
>
> The documentation appears to be out of date since it doesn't mention
> that the "info" command is supported, yet there is a command in the code
> base for it.  The documentation also doesn't say it can use svnkit, but
> that capability was added over a year ago.
>
> Dale
>
>
> Jeremy Hanna wrote:
>   
>> I'm using the script tag to run a ruby script and would like to return
>> a value from the script.  Is that possible?  I see that I can use the
>> setbeans attribute to have access to the build.xml variables from
>> within the ruby script.  I can output them and even change those
>> variables within the ruby script, but those changes disappear once the
>> script returns.
>> Is there any way to return the value?
>> Really I'm trying to get the result of `svn info` which is retrieved
>> in my ruby script.  I haven't seen ant libraries out there that do
>> that - most don't implement the info function.  I tried using the exec
>> task but that seems to need the path information and that gets too messy.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
> ----------------------------------------------------------------------
> This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Using the script tag, wanting to return a value

Posted by Shawn Castrianni <Sh...@halliburton.com>.
I am currently using svnant with javasvn and everything works great, it is just very sloooooow.  Much slower than command line svn or SmartSVN.  I was thinking about trying svnkit as a replacement for javasvn.  Would it be any faster?

---
Shawn Castrianni

-----Original Message-----
From: Dale Anson [mailto:danson@grafidog.com]
Sent: Wednesday, June 11, 2008 10:17 PM
To: Ant Users List
Subject: Re: Using the script tag, wanting to return a value

Have you tried the svn ant task from subclipse?

http://subclipse.tigris.org/svnant.html

The documentation appears to be out of date since it doesn't mention
that the "info" command is supported, yet there is a command in the code
base for it.  The documentation also doesn't say it can use svnkit, but
that capability was added over a year ago.

Dale


Jeremy Hanna wrote:
> I'm using the script tag to run a ruby script and would like to return
> a value from the script.  Is that possible?  I see that I can use the
> setbeans attribute to have access to the build.xml variables from
> within the ruby script.  I can output them and even change those
> variables within the ruby script, but those changes disappear once the
> script returns.
> Is there any way to return the value?
> Really I'm trying to get the result of `svn info` which is retrieved
> in my ruby script.  I haven't seen ant libraries out there that do
> that - most don't implement the info function.  I tried using the exec
> task but that seems to need the path information and that gets too messy.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Using the script tag, wanting to return a value

Posted by Dale Anson <da...@grafidog.com>.
Have you tried the svn ant task from subclipse? 

http://subclipse.tigris.org/svnant.html

The documentation appears to be out of date since it doesn't mention 
that the "info" command is supported, yet there is a command in the code 
base for it.  The documentation also doesn't say it can use svnkit, but 
that capability was added over a year ago.

Dale


Jeremy Hanna wrote:
> I'm using the script tag to run a ruby script and would like to return 
> a value from the script.  Is that possible?  I see that I can use the 
> setbeans attribute to have access to the build.xml variables from 
> within the ruby script.  I can output them and even change those 
> variables within the ruby script, but those changes disappear once the 
> script returns.
> Is there any way to return the value?
> Really I'm trying to get the result of `svn info` which is retrieved 
> in my ruby script.  I haven't seen ant libraries out there that do 
> that - most don't implement the info function.  I tried using the exec 
> task but that seems to need the path information and that gets too messy.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org