You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Pa...@nokia.com on 2006/06/22 20:58:18 UTC

using multiple properties in the 'if' and 'unless' conditions

Hello,

Has the possibility of adding multiple conditions to the target 'if' and
'unless' attributes ever been considered? Are there any reasons why this
change would be a bad idea?

cheers

paul

Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Paul King <ki...@asert.com.au>.
Paul.Mackay@nokia.com wrote:
> Hello,
> 
> Has the possibility of adding multiple conditions to the target 'if' and
> 'unless' attributes ever been considered? Are there any reasons why this
> change would be a bad idea?

I have found Groovy (and to a lesser degree other scripting
languages) to be very useful for complex builds.
You can use Groovy from normal ant build files using the
<script> or external <groovy> tasks:

  http://groovy.codehaus.org/Groovy+Ant+Task

Or you can start from Groovy and use the ant builder syntax
to have full programming capabilities if you wish:

  http://groovy.codehaus.org/Ant+Scripting

As an example (not optimal) which combines both techniques:

  <groovy>
  def ant = new AntBuilder()
  def scanner = ant.fileScanner {
      fileset(dir:properties['basedir']) {
          include(name:"**/*.xml")
      }
  }
  def nameCheck = scanner.every{ file -> file.name.contains('build') }
  def totalSize = 0
  def fileCount = 0
  def maxSize = 0
  for(file in scanner){
      fileCount++
      if (file.length() > maxSize) maxSize = file.length()
      totalSize += file.length()
  }
  if (nameCheck || totalSize / fileCount > 50 ||
      maxSize > 100 || fileCount > 10) properties.put('shouldCompress', 'true')
  </groovy>

This sets up a property for subsequent use in an if or unless attribute
called 'shouldCompress' which is set based on the properties of xml
files in the directory in which the script is run. The property will
be set if every file in the selected fileset has the characters 'build'
in its name or if there are more than 10 files or if the average file
size is greater than 50 or if the maximum file size is more than 100.

This would be difficult trying to use alternative notations and
probably would be harder to understand. (Not that I am advocating
complex build logic just for the sake of it!)


Cheers, Paul.


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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Paul King <ki...@asert.com.au>.
Paul.Mackay@nokia.com wrote:
> Hello,
> 
> Has the possibility of adding multiple conditions to the target 'if' and
> 'unless' attributes ever been considered? Are there any reasons why this
> change would be a bad idea?

I have found Groovy (and to a lesser degree other scripting
languages) to be very useful for complex builds.
You can use Groovy from normal ant build files using the
<script> or external <groovy> tasks:

  http://groovy.codehaus.org/Groovy+Ant+Task

Or you can start from Groovy and use the ant builder syntax
to have full programming capabilities if you wish:

  http://groovy.codehaus.org/Ant+Scripting

As an example (not optimal) which combines both techniques:

  <groovy>
  def ant = new AntBuilder()
  def scanner = ant.fileScanner {
      fileset(dir:properties['basedir']) {
          include(name:"**/*.xml")
      }
  }
  def nameCheck = scanner.every{ file -> file.name.contains('build') }
  def totalSize = 0
  def fileCount = 0
  def maxSize = 0
  for(file in scanner){
      fileCount++
      if (file.length() > maxSize) maxSize = file.length()
      totalSize += file.length()
  }
  if (nameCheck || totalSize / fileCount > 50 ||
      maxSize > 100 || fileCount > 10) properties.put('shouldCompress', 'true')
  </groovy>

This sets up a property for subsequent use in an if or unless attribute
called 'shouldCompress' which is set based on the properties of xml
files in the directory in which the script is run. The property will
be set if every file in the selected fileset has the characters 'build'
in its name or if there are more than 10 files or if the average file
size is greater than 50 or if the maximum file size is more than 100.

This would be difficult trying to use alternative notations and
probably would be harder to understand. (Not that I am advocating
complex build logic just for the sake of it!)


Cheers, Paul.


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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Dominique Devienne <dd...@gmail.com>.
It's believed that you can easily combine the various conditions in
one <condition>, that sets a single property based on as complex a
logic as <condition>'s nested <or>/<and> allows, so it's not
necessary.

When you remember that targets listed in 'depends' are executed before
'if' / 'unless' are evaluated, you can easily execute the <condition>
before the target and test if/unless on its results.

--DD

On 6/22/06, Paul.Mackay@nokia.com <Pa...@nokia.com> wrote:
> Hello,
>
> Has the possibility of adding multiple conditions to the target 'if' and
> 'unless' attributes ever been considered? Are there any reasons why this
> change would be a bad idea?
>
> cheers
>
> paul
>
>

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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Steve Loughran <st...@apache.org>.
Stefan Bodewig wrote:

> On Thu, 22 Jun 2006, Paul Mackay <Pa...@nokia.com> wrote:
> 
>> Has the possibility of adding multiple conditions to the target 'if'
>> and 'unless' attributes ever been considered?
> 
> Yes, but it hasn't come up often after Ant 1.4 ;-)
> 
>> Are there any reasons why this change would be a bad idea?
> 
> One of the reasons (and my main one) is that you'd soon need an
> expression language since simple listing two properties isn't enough?
> Does if="a,b" mean "either a is set or b" or "a is set and b"?
> 
> And then the example above doesn't work since "," is a legal character
> inside of property names, as is " " or any other character.  There
> could be a property named "a,b".
> 

yeah, you would need a whole new language. And it may need to be 
extensible, which makes things even more complex, as we'd add unary and 
binary functions to ant, plus a whole new syntax and related support calls.

The "obvious" language would be Xpath, but as someone who is behind 
schedule on adding xpath expression eval to something, I must warn that 
it is not easy, even with jaxen.

The <condition> logic is there, it works; new conditions are easy to 
add. its verbose, I agree, but extensible. And someone could add an 
<xpatheval> condition if they wanted. Hey, they could add a <lispeval> 
if they felt like it; with <scriptcondition> we implicitly have 
python/ruby/js conditions in there

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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 26 Jun 2006, Wolfgang Häfelinger <wh...@epo.org> wrote:
>> Which one would you prefer?  Or should we invent a new one?
> 
> Use an existing one of course. There could also be more than one,
> just supported by a "language" attribute.

This is the approach the NAnt folks have chosen, you can do stuff like
${functionn-library::some-method()} and implement your NAnt extensions
in any language that compiles to MSIL.  I can't say I find the typical
NAnt build file easier to read than Ant build files, but that may be a
matter of getting used to it.

I think you can do almost everything you'd like to do with a script
condition - without making the core of Ant more complicated.

>> We do have the "clumsy" XML expression language that we built into
>> the condition task and it follows the rest of Ant's "language".
> 
> I do not see  your point why an embedded expression language would
> not follow Ant's language terms. Perhaps you can elaborate on this
> bit further.

It would add a new one - or even multiple new ones.

Stefan

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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Wolfgang Häfelinger <wh...@epo.org>.
> -What is the existing one you'd recommend? XPath 1.0? Perl? 
> Pascal-style, Ruby-Style?

I implemented the "test" expression logic found in popular shells, left a 
couple of
tests out (like -p, -O etc) and added a couple of usefull tests like
 -P s  => test whether "s" is a reference
 -R s  => test whether "s" is a reference
 -T s  => test whether "s" is a target
 -M s  => test whether "s" is a macro or task
 ...

> what functions to test for. defined/undefied, true/false, equality?

and also numerical comparison, older/newer then, length of a string ..

> How would I be able to declare and add new functions or operators into 
the language?

You would use the same technique as we are currently using in Ant to 
install my
own property or component handler.

-What are we going to use as a parser; the recursive descent thingy 
built in to java, or use ANTLR to generate our own from the BNF nota

I do not have an opinion on this (ANTLR is fine with me, after all I'm one 
of the contributors :-)

-How are we going to test the language?

Unit tests etc, where's the probem?

-How do we roll it out to other conditional types such as fail?

Add a new attribute named "test" (and deprecate "if"). If "if" and "test" 
are present
do something like  eval(test) && eval(if).

Another idea is to stay with "if" (and "unless") and change it's 
evaluation on demand:

<expression-lang  use="test" />

<fail if="-f some-file" ../>

<expression-lang pop="true" />     fall back to whatever was there before 
using "test"

<fail if="some-property" .. />



Btw, we need to have a quota character. For example

<fail  test=" -d 'C:/Program Files'  " message="..." />


Wolfgang.





Steve Loughran <st...@apache.org> 
26-06-2006 13:17
Please respond to
"Ant Developers List" <de...@ant.apache.org>


To
Ant Developers List <de...@ant.apache.org>
cc

Subject
Re: using multiple properties in the 'if' and 'unless' conditions






Wolfgang Häfelinger wrote:
>> Which one would you prefer?  Or should we invent a new one?
> 
> Use an existing one of course. There could also be more than one,
> just supported by a "language" attribute.
> 
>> We do have the "clumsy" XML expression language that we built into the
>> condition task and it follows the rest of Ant's "language".
> 
> I do not see  your point why an embedded expression language would
> not follow Ant's language terms. Perhaps you can elaborate on this
> bit further.
> 
>> And regardless which existing language we'd chose, we'd always find 
>> users who'd find it hard to use - not all Ant users are Java 
>> developers and are able to read "a && b".
> 
> Users who do not understand feature are not obligied to use them and
> I still  believe that users quickly get the idea what "a && b" could
> mean. After all, you also need a lot of imagniation to understand 
> what you can do with Ant, right?
> 
> The  only  problem with "&"  is that it is an "XML" character as 
> well.


so clearly then, java booleans are not the obvious choice.
-What is the existing one you'd recommend? XPath 1.0? Perl? 
Pascal-style, Ruby-Style?
-what functions to test for. defined/undefied, true/false, equality?
-How would I be able to declare and add new functions or operators into 
the language?
-What are we going to use as a parser; the recursive descent thingy 
built in to java, or use ANTLR to generate our own from the BNF notation.
-How are we going to test the language?
-How do we roll it out to other conditional types such as fail?

I can see a conditional target as a more likely option.

<ctarget>
   <condition>
    </condition>
   <sequence>
   </sequence>
</ctarget>


-steve

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




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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Steve Loughran <st...@apache.org>.
Wolfgang Häfelinger wrote:
>> Which one would you prefer?  Or should we invent a new one?
> 
> Use an existing one of course. There could also be more than one,
> just supported by a "language" attribute.
> 
>> We do have the "clumsy" XML expression language that we built into the
>> condition task and it follows the rest of Ant's "language".
> 
> I do not see  your point why an embedded expression language would
> not follow Ant's language terms. Perhaps you can elaborate on this
> bit further.
> 
>> And regardless which existing language we'd chose, we'd always find 
>> users who'd find it hard to use - not all Ant users are Java 
>> developers and are able to read "a && b".
> 
> Users who do not understand feature are not obligied to use them and
> I still  believe that users quickly get the idea what "a && b" could
> mean. After all, you also need a lot of imagniation to understand 
> what you can do with Ant, right?
> 
> The  only  problem with "&"  is that it is an "XML" character as 
> well.


so clearly then, java booleans are not the obvious choice.
-What is the existing one you'd recommend? XPath 1.0? Perl? 
Pascal-style, Ruby-Style?
-what functions to test for. defined/undefied, true/false, equality?
-How would I be able to declare and add new functions or operators into 
the language?
-What are we going to use as a parser; the recursive descent thingy 
built in to java, or use ANTLR to generate our own from the BNF notation.
-How are we going to test the language?
-How do we roll it out to other conditional types such as fail?

I can see a conditional target as a more likely option.

<ctarget>
   <condition>
    </condition>
   <sequence>
   </sequence>
</ctarget>


-steve

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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Wolfgang Häfelinger <wh...@epo.org>.
> Which one would you prefer?  Or should we invent a new one?

Use an existing one of course. There could also be more than one,
just supported by a "language" attribute.

> We do have the "clumsy" XML expression language that we built into the
> condition task and it follows the rest of Ant's "language".

I do not see  your point why an embedded expression language would
not follow Ant's language terms. Perhaps you can elaborate on this
bit further.

> And regardless which existing language we'd chose, we'd always find 
> users who'd find it hard to use - not all Ant users are Java 
> developers and are able to read "a && b".

Users who do not understand feature are not obligied to use them and
I still  believe that users quickly get the idea what "a && b" could
mean. After all, you also need a lot of imagniation to understand 
what you can do with Ant, right?

The  only  problem with "&"  is that it is an "XML" character as 
well.

Wolfgang.





Stefan Bodewig <bo...@apache.org> 
25-06-2006 11:42
Please respond to
"Ant Developers List" <de...@ant.apache.org>


To
dev@ant.apache.org
cc

Subject
Re: using multiple properties in the 'if' and 'unless' conditions






On Fri, 23 Jun 2006, Wolfgang Häfelinger <wh...@epo.org> wrote:

> What would so bad introducing an "expression language"? 

Which one would you prefer?  Or should we invent a new one?

We do have the "clumsy" XML expression language that we built into the
condition task and it follows the rest of Ant's "language".
Introducing a different language would mean implementing a different
interpreter for it, documenting it an all that.  And regardless which
existing language we'd chose, we'd always find users who'd find it
hard to use - not all Ant users are Java developers and are able to
read "a && b".

Stefan

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




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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Stefan Bodewig <bo...@apache.org>.
On Fri, 23 Jun 2006, Wolfgang Häfelinger <wh...@epo.org> wrote:

> What would so bad introducing an "expression language"? 

Which one would you prefer?  Or should we invent a new one?

We do have the "clumsy" XML expression language that we built into the
condition task and it follows the rest of Ant's "language".
Introducing a different language would mean implementing a different
interpreter for it, documenting it an all that.  And regardless which
existing language we'd chose, we'd always find users who'd find it
hard to use - not all Ant users are Java developers and are able to
read "a && b".

Stefan

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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Wolfgang Häfelinger <wh...@epo.org>.
Just out of curiousity:

What would so bad introducing an "expression language"? 

After all, there's no need to express everything in (clumsy) XML just 
because
we are able to do so. I believe that an expression language, escpecially 
for
testing, would simplify Ant scripting considerably.

Wolfgang.




Stefan Bodewig <bo...@apache.org> 
23-06-2006 05:54
Please respond to
"Ant Developers List" <de...@ant.apache.org>


To
dev@ant.apache.org
cc

Subject
Re: using multiple properties in the 'if' and 'unless' conditions






On Thu, 22 Jun 2006, Paul Mackay <Pa...@nokia.com> wrote:

> Has the possibility of adding multiple conditions to the target 'if'
> and 'unless' attributes ever been considered?

Yes, but it hasn't come up often after Ant 1.4 ;-)

> Are there any reasons why this change would be a bad idea?

One of the reasons (and my main one) is that you'd soon need an
expression language since simple listing two properties isn't enough?
Does if="a,b" mean "either a is set or b" or "a is set and b"?

And then the example above doesn't work since "," is a legal character
inside of property names, as is " " or any other character.  There
could be a property named "a,b".

Stefan

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




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


Re: using multiple properties in the 'if' and 'unless' conditions

Posted by Stefan Bodewig <bo...@apache.org>.
On Thu, 22 Jun 2006, Paul Mackay <Pa...@nokia.com> wrote:

> Has the possibility of adding multiple conditions to the target 'if'
> and 'unless' attributes ever been considered?

Yes, but it hasn't come up often after Ant 1.4 ;-)

> Are there any reasons why this change would be a bad idea?

One of the reasons (and my main one) is that you'd soon need an
expression language since simple listing two properties isn't enough?
Does if="a,b" mean "either a is set or b" or "a is set and b"?

And then the example above doesn't work since "," is a legal character
inside of property names, as is " " or any other character.  There
could be a property named "a,b".

Stefan

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