ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject Re: using multiple properties in the 'if' and 'unless' conditions
Date Mon, 26 Jun 2006 11:07:26 GMT 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:

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

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

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

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:
For additional commands, e-mail:

View raw message