tags:

views:

211

answers:

1

When you define an extension-point in an Ant build file you can have it conditional by using the if or unless attribute. On a target the if/unless prevent it's tasks from being run. But an extension-point doesn't have any tasks to conditionally run, so what does the condition do? My thought (which proved to be incorrect in Ant 1.8.0) is it would prevent any tasks that extend the extension-point from being run. Here is an example build script showing the problem:

<project name = "ext-test"
    default   = "main">

  <property name = "do.it" value = "false" />

  <extension-point name = "init"/>
  <extension-point name = "doit" depends = "init" if = "${do.it}" />

  <target name = "extend-init" extensionOf = "init">
    <echo message = "Doing extend-init." />
  </target>

  <target name = "extend-doit" extensionOf = "doit">
    <echo message = "Do It! (${do.it})" />
  </target>

  <target name = "main" depends = "doit">
    <echo message = "Doing main." />
  </target>

</project>

Using the command:

ant -v

Relults in:

Apache Ant version 1.8.0 compiled on February 1 2010
Trying the default build file: build.xml
Buildfile: /Users/bob/build.xml
Detected Java version: 1.6 in: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
Detected OS: Mac OS X
parsing buildfile /Users/bob/build.xml with URI = file:/Users/bob/build.xml
Project base dir set to: /Users/bob
parsing buildfile jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/Users/bob/Documents/Development/3P-Tools/apache-ant-1.8.0/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `main' is [extend-init, init, extend-doit, doit, main]
Complete build sequence is [extend-init, init, extend-doit, doit, main, ]

extend-init:
     [echo] Doing extend-init.

init:

extend-doit:
     [echo] Do It! (false)

doit:
Skipped because property 'false' not set.

main:
     [echo] Doing main.

BUILD SUCCESSFUL
Total time: 0 seconds

You will notice the target extend-doit is executed but the extention-point itself is skipped. Since an extention-point doesn't have any tasks exactly what has been skipped? Any targets that depend on the extention-point still get executed since a skipped target is a successful target. What is the value of the if/unless attributes on an extention-point?

A: 

I'm guessing there is no actual use for them, they probably appear as attributes because extension-point extends task (the associated java classes do).

Simon Groenewolt