ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Pawson <>
Subject Re: ant 1.7. Finding undefined variables
Date Thu, 21 May 2009 15:58:10 GMT
2009/5/21 Dominique Devienne <>:

>> An example please Dominique?
> XML elements reading properties without the ${name} notation
> <target if/unless>
> <fail if/unless>
> <condition><isset property></condition>
> ...
> XML elements writing properties affecting the rest of the build:
> <condition property>
> <exec (output|error)property>
> <manifestclasspath property>

I've not seen any of those.
Perhaps you could provide me with an example build file I can experiment with?

Below, the xslt script I'm using if you want to play

java -cp saxon9.jar:/myjava:/myjava/xercesImpl.jar
net.sf.saxon.Transform  -x:org.apache.xerces.parsers.SAXParser -o $3
$1 $2  $4 $5 $6


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl=""

  exclude-result-prefixes=" xs"
  <xsl:strip-space elements="*"/>
  <d:doc xmlns:d="">
        <d:para>This stylesheet works with an ant build file file to produce a
         ant script which tests all variables within the build file</d:para>

  <xsl:output method="xml" indent="yes" encoding="utf-8"/>

  <xsl:template match="/">
    <project name="testvars.2" >
      <xsl:apply-templates select="//pathelement"/>

      <xsl:apply-templates select="//exec"/>

      <xsl:apply-templates select="//arg"/>

      <xsl:apply-templates select="//java"/>

      <xsl:apply-templates select="//fileset"/>

      <xsl:apply-templates select="//jvmarg"/>


<xsl:template match="pathelement[contains(@path,'$')]">
   <xsl:copy-of select="dp:property(@path,'')"/>

 <xsl:template match="exec[contains(@executable,'$')]">
   <xsl:copy-of select="dp:property(@executable,'')"/>

 <xsl:template match="arg[contains(@value,'$')]">
   <xsl:copy-of select="dp:property(@value,'')"/>

 <xsl:template match="arg[contains(@line,'$')]">
   <xsl:copy-of select="dp:property(@line,'')"/>

<xsl:template match="java">
  <xsl:if test="contains(@classname,'$')">
    <xsl:copy-of select="dp:property(@classname,'')"/>
  <xsl:if test="contains(@dir,'$')">
    <xsl:copy-of select="dp:property(@dir,'')"/>

 <xsl:template match="fileset[contains(@dir,'$')]">
   <xsl:copy-of select="dp:property(@dir,'')"/>

<xsl:template match="jvmarg[contains(@value,'$')]">
   <xsl:copy-of select="dp:property(@value,'')"/>

  <xsl:template match="*"/>

<!--  -->
<!-- Function to output all properties for checking  -->
<!--  -->
<xsl:function name="dp:property">
  <xsl:param name="str" as="xs:string"/>
  <xsl:param name='res' as="item()*"/>
  <xsl:analyze-string select="$str" regex="\$\{{([^}}]+)\}}">
      <xsl:variable name='part'>
 <property name="{{prop.msg}}" value="Must be defined, preferably in
  <fail message="{regex-group(1)} ${{prop.msg}}" unless="{regex-group(1)}"/>
  <xsl:when test="contains(regex-group(2), '$')">
     <xsl:copy-of select="dp:property(regex-group(2), $part)"/>
     <xsl:copy-of select="$part"/>
      <!--      <xsl:message>
        oops <xsl:value-of select="$str"/>
    <xsl:value-of select="$res"/>



> ...
> In macros with params having default params (or lack thereof, what you
> try to catch), it uses @{name} to differentiate it from property using
> the ${name}. Of course the two can be combined ${foo@{bar}} so
> figuring out what property could be missing would replicate the
> running behavior.
> These are various reasons looking for ${name} may be insufficient for
> some builds. Nonetheless I agree than looking for ${name} covers a lot
> of ground.
> You need to watch out for property helpers though, as
> ${toString:some-ref-id} is a fake property name converting the Java
> object (Ant datatype typically like a path) with reference id
> "some-ref-id" to a string on the fly. (undocumented feature, but
> there's an official API to add custom property helpers for
> ${helper:rest} notation.
>> But yes, for clarity, I am assuming ${name} form. ?Best practice?
> Using ${name} is how you deref properties in the XML. All I'm saying
> is that property derefs happen in the code as well, and that even
> ${name} can have a different meaning with macros and property helpers
> (the latter is not very common, but the former more so).
> But as I said, ${name} covers 90% of the ground, if not more. I just
> wanted to make you aware of the 10% or 5% or 1% you could be missing.
> 90+ % is a good hit rate ;-) --DD
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Dave Pawson
Docbook FAQ.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message