You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mp...@ThoughtWorks.com on 2000/07/22 01:53:38 UTC

XSLT (was Re: Immutable Properties in 1.1?)

I still think that using XSLT as a sort of "preprocessor" is the best way
to handle these kind of situations. You could define the structure of your
project in an XML file, using as simple a syntax as possible, then use XSL
to generate your Ant file. This keeps the Ant syntax small and clean, while
leveraging an already defined standard to automate the repetitive stuff...

Matt Foemmel
ThoughtWorks, Inc.


                                                                                                                                                 
                    Jesse Glick                                                                                                                  
                    <Jesse.Glick@net        To:     ant-dev@jakarta.apache.org                                                                   
                    beans.com>              cc:                                                                                                  
                    Sent by:                Subject:     Re: Immutable Properties in 1.1?                                                        
                    Jesse.Glick@netb                                                                                                             
                    eans.com                                                                                                                     
                                                                                                                                                 
                                                                                                                                                 
                    07/20/2000 03:49                                                                                                             
                    PM                                                                                                                           
                    Please respond                                                                                                               
                    to ant-dev                                                                                                                   
                                                                                                                                                 
                                                                                                                                                 




Ken Liu wrote:
> BTW, the problem I see with using templated targets ala Jesse's patch is

"patch" -> "proposed patch" :-)

> that it would be difficult to define different "depends" for each
different
> target, no?

Well, I was assuming that you would be able to parametrize depends lists
as well:

<target pattern="prepare-dir-(.*)">
  <somehowCleanIt path="sources/$[1]"/>
</target>
<target pattern="build-dir-(.*)-with-libs-from-(.*)"
        depends="prepare-dir-$[1]">
  <compileIt path="sources/$[1]"
             pullInJars="$[2]/*.jar"/>
</target>

Something like that. Now run targets like
"build-dir-foo/bar-with-libs-from-miscutils". If you have different
*kinds* of dependencies for the different targets, you would need one
template per kind of dependency, I guess.

-Jesse

--
Jesse Glick   <ma...@netbeans.com>
NetBeans, Open APIs  <http://www.netbeans.org/>
tel (+4202) 3300-9161 Sun Micro x49161 Praha CR




Re: XSLT (was Re: Immutable Properties in 1.1?)

Posted by Roger Vaughn <rv...@seaconinc.com>.
mpfoemme@ThoughtWorks.com wrote:

> I still think that using XSLT as a sort of "preprocessor" is the best way
> to handle these kind of situations. You could define the structure of your
> project in an XML file, using as simple a syntax as possible, then use XSL
> to generate your Ant file. This keeps the Ant syntax small and clean, while
> leveraging an already defined standard to automate the repetitive stuff...
>
> Matt Foemmel
> ThoughtWorks, Inc.

Just as an experiment, I did this.  While it does require a two-pass build (Imake-like), it
worked out pretty well.  The trick is to define your XSLT templates at the task level, thus
preserving the full Ant experience.  This way, your "original" build file (which I called
"ibuild.xml" out of sheer bloody-mindedness) looks like normal Ant with a few new taskdefs
added.  What you end up with is effectively new taskdefs which resolve to multi-task
sequences.  Also, since XSLT gives you an include mechanism, this gives you a way to write
your "common" tasks (like clean) once, and include them from a common file.

To go back to my original example, this:

<target name="jar1">
  <property name="jarfile" value="jar1.jar"/>
  <property name="includes" value="**/somefiles"/>
  <!-- some code that uses ${jarfile} and ${includes} -->
</target>

<target name="jar2">
  <property name="jarfile" value="jar2.jar"/>
  <property name="includes" value="**/someotherfiles"/>
  <!-- some code that uses ${jarfile} and ${includes} -->
</target>

now becomes:

<xsl:template match="myjar">
  <!-- some code that uses "{@jarfile}" and <xsl:apply-templates select="include|exclude"/>
-->
</xsl:template>

<target name="jar1">
  <myjar jarfile="jar1.jar">
    <include name="**/somefiles"/>
  </myjar>
</target>

<target name="jar2">
  <myjar jarfile="jar2.jar">
    <include name="**/someotherfiles"/>
  </myjar>
</target>

Thus this preserves the syntactic purity of Ant.  Note, however, that it's just as much work
for simple examples - it's only effective for complex code blocks or simple ones that change
frequently in many places.

Only one caveat I have discovered so far - if your templates contain Ant property expansions
(i.e. ${prop}), you have to write them like this: ${{prop}}, since the brace is a reserved
syntactic construct in XSLT.  I would consider property expansions in templates to be bad
form and easy to break - prefer attributes in the original file instead.

roger