You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Stefan Bodewig <bo...@bost.de> on 2000/09/08 12:42:43 UTC

Proposed way to make ${} happen at runtime

Hi,

the appended patch will move ${} expansion (and the execution of all
tasks, including <property>) to runtime instead of parser time.

As there are so many ways this could be implemented I wanted to make
sure I'm not totally of the hook and have introduced silly design
flaws. Therefore I wanted to get you comments before I commit
anything.

The patched version has been working for me (bootstrapped Ant and
built Tomcat as well as my private projects successfully).

<project name="test" default="echo">
  <target name="echo1">
    <echo message="${echo1}" />
  </target>
  <property name="echo1" value="set globally" />

  <target name="echo2" depends="setup2">
    <echo message="${echo2}" />
  </target>

  <target name="setup2">
    <property name="echo2" value="set after first use" />
  </target>

  <target name="setup3a">
    <property name="echo3" value="set in unused target" />
  </target>

  <target name="setup3">
    <property name="echo3" value="set before first use" />
  </target>

  <target name="echo3" depends="setup3">
    <echo message="${echo3}" />
  </target>

  <target name="echo" depends="echo1,echo2,echo3" />
</project>

will now generate

echo1:
set globally
setup2:
echo2:
set after first use
setup3:
echo3:
set before first use
echo:

instead of

echo1:
${echo1}
setup2:
echo2:
${echo2}
setup3:
echo3:
set in unused target
echo:

Comments please (including how stupid I am if this should be true).

Stefan


Re: Proposed way to make ${} happen at runtime

Posted by Peter Donald <do...@mad.scientist.com>.
At 09:39  11/9/00 +0930, you wrote:
>My only comment is: Is there any coding standard for jakarta projects? 
>I'm just being nit picky on the use of {} for all if/else statements
>even if they are one line bodies.

Most projects are supposed to use Sun standards but can add decorations on
top of that if you want. It is up to the particular participants in the
project.



Cheers,

Pete

*------------------------------------------------------*
| "Nearly all men can stand adversity, but if you want |
| to test a man's character, give him power."          |
|       -Abraham Lincoln                               |
*------------------------------------------------------*

Re: Proposed way to make ${} happen at runtime

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "MS" == Marcel Schutte <ma...@schutte.com> writes:

 MS> This is what I would have expected right from the beginning,

Yes, that should be the result of the change 8^).

 MS> why was the current behavior ever introduced?

It's not that counter-intuitive if you stop thinking of <property> as
a task and start thinking of it as the definition of a property (much
like the definition of an XML entity) and nothing else.

If you are then going to restrict <property> to be a child of
<project> and not of <target>, you are done.

Making Property extend Task (and thus allowing it to be placed inside
<target>) has changed the notion of <property> and led to usage
patterns that had not been intended in the first place (and that this
patch is going to take care of).

I don't know why <property> was changed from some kind of constant
definition to a task, this happened before I turned my attention to
Ant.

Stefan

RE: Proposed way to make ${} happen at runtime

Posted by Marcel Schutte <ma...@schutte.com>.
Hi,

This is what I would have expected right from the beginning, why was the
current behavior ever introduced? I always thought it was non-intuitive that
properties in tasks that are never executed still get set.

Marcel

> -----Original Message-----
> From: Stefan Bodewig [mailto:bodewig@bost.de]
> Sent: vrijdag 8 september 2000 12:43
> To: ant-dev@jakarta.apache.org
> Subject: Proposed way to make ${} happen at runtime
>
>
> Hi,
>
> the appended patch will move ${} expansion (and the execution of all
> tasks, including <property>) to runtime instead of parser time.
>
> As there are so many ways this could be implemented I wanted to make
> sure I'm not totally of the hook and have introduced silly design
> flaws. Therefore I wanted to get you comments before I commit
> anything.
>
> The patched version has been working for me (bootstrapped Ant and
> built Tomcat as well as my private projects successfully).
>
> <project name="test" default="echo">
>   <target name="echo1">
>     <echo message="${echo1}" />
>   </target>
>   <property name="echo1" value="set globally" />
>
>   <target name="echo2" depends="setup2">
>     <echo message="${echo2}" />
>   </target>
>
>   <target name="setup2">
>     <property name="echo2" value="set after first use" />
>   </target>
>
>   <target name="setup3a">
>     <property name="echo3" value="set in unused target" />
>   </target>
>
>   <target name="setup3">
>     <property name="echo3" value="set before first use" />
>   </target>
>
>   <target name="echo3" depends="setup3">
>     <echo message="${echo3}" />
>   </target>
>
>   <target name="echo" depends="echo1,echo2,echo3" />
> </project>
>
> will now generate
>
> echo1:
> set globally
> setup2:
> echo2:
> set after first use
> setup3:
> echo3:
> set before first use
> echo:
>
> instead of
>
> echo1:
> ${echo1}
> setup2:
> echo2:
> ${echo2}
> setup3:
> echo3:
> set in unused target
> echo:
>
> Comments please (including how stupid I am if this should be true).
>
> Stefan
>
>


Re: Proposed way to make ${} happen at runtime

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "BT" == Barrie Treloar <Ba...@camtech.com.au> writes:

 BT> This will break the old way of using the definition order in the
 BT> file.

True - I'd list this in WHATSNEW quite prominently anyway. Do you
think this is a real problem - my guess is one would place all
<property> tags outside of any targets if one was going to rely on the
order of definition.

 BT> When you specify an id that xml structure is available globaly.
 BT> Id must be unique in the build.xml file.

This has been true before.

 BT> I'm just being nit picky on the use of {} for all if/else
 BT> statements even if they are one line bodies.

A matter of taste. I tend to write them that way - at least since
JDE's abbrev mode added the braces automagically 8^).

Stefan

RE: Proposed way to make ${} happen at runtime

Posted by Conor MacNeill <co...@ebinteractive.com.au>.
Barrie,

> From: Barrie Treloar [mailto:Barrie.Treloar@camtech.com.au]
>
> My only comment is: Is there any coding standard for Jakarta projects?
> I'm just being nit picky on the use of {} for all if/else statements
> even if they are one line bodies.
>

The Jakarta projects are supposed to follow the Sun coding standard which
states

Note: if statements always use braces {}. Avoid the following error-prone
form:

if (condition) //AVOID! THIS OMITS THE BRACES {}!
    statement;

Personally, I agree with this convention but not with others in that
document.

Cheers
Conor (hoping to avoid a brace war :-)



Re: Proposed way to make ${} happen at runtime

Posted by Barrie Treloar <Ba...@camtech.com.au>.
On 8 Sep 2000, Stefan Bodewig wrote:

> Comments please (including how stupid I am if this should be true).

To summarize:

All targets are now hierarchical.  If a target does not contain the
property definition ant will traverse the hierarchy and use the first
occurence of the property it finds.

This will break the old way of using the definition order in the
file.  

When you specify an id that xml structure is available globaly.  Id
must be unique in the build.xml file.


My only comment is: Is there any coding standard for jakarta projects? 
I'm just being nit picky on the use of {} for all if/else statements
even if they are one line bodies.

Barrie
--
Barrie Treloar
____________________________________________________________________

  Barrie Treloar                      Phone: +61 8 8303 3300
  Senior Analyst/Programmer           Fax:   +61 8 8303 4403 
  Electronic Commerce Division        Email: barrie@camtech.com.au
  Camtech (SA) Pty Ltd                http://www.camtech.com.au
 --- Level 8, 10 Pulteney Street, Adelaide SA 5000, Australia. ---
____________________________________________________________________



RE: Proposed way to make ${} happen at runtime

Posted by William Ferguson <wi...@mincom.com>.
Is it reasonable, for the build to throw an Exception if some properties
are not expanded?

I'm only asking because I have found a typoed property to be the biggest
timewaster with a build file.


William Ferguson

This transmission is for the intended addressee only and is confidential
information. If you have received this transmission in error, please
delete it and notify the sender. The contents of this E-mail are the
opinion of the writer only and are not endorsed by Mincom Limited unless
expressly stated otherwise.


> -----Original Message-----
> From: Stefan Bodewig [mailto:bodewig@bost.de]
> Sent: Friday, 8 September 2000 20:43
> To: ant-dev@jakarta.apache.org
> Subject: Proposed way to make ${} happen at runtime
>
>
> Hi,
>
> the appended patch will move ${} expansion (and the execution of all
> tasks, including <property>) to runtime instead of parser time.
>
> As there are so many ways this could be implemented I wanted to make
> sure I'm not totally of the hook and have introduced silly design
> flaws. Therefore I wanted to get you comments before I commit
> anything.
>
> The patched version has been working for me (bootstrapped Ant and
> built Tomcat as well as my private projects successfully).
>
> <project name="test" default="echo">
>   <target name="echo1">
>     <echo message="${echo1}" />
>   </target>
>   <property name="echo1" value="set globally" />
>
>   <target name="echo2" depends="setup2">
>     <echo message="${echo2}" />
>   </target>
>
>   <target name="setup2">
>     <property name="echo2" value="set after first use" />
>   </target>
>
>   <target name="setup3a">
>     <property name="echo3" value="set in unused target" />
>   </target>
>
>   <target name="setup3">
>     <property name="echo3" value="set before first use" />
>   </target>
>
>   <target name="echo3" depends="setup3">
>     <echo message="${echo3}" />
>   </target>
>
>   <target name="echo" depends="echo1,echo2,echo3" />
> </project>
>
> will now generate
>
> echo1:
> set globally
> setup2:
> echo2:
> set after first use
> setup3:
> echo3:
> set before first use
> echo:
>
> instead of
>
> echo1:
> ${echo1}
> setup2:
> echo2:
> ${echo2}
> setup3:
> echo3:
> set in unused target
> echo:
>
> Comments please (including how stupid I am if this should be true).
>
> Stefan
>
>