The Ant Task

    
  Prev  Next  Contents  Home
 

Page contents

Description

If you need the FMPP Ant task in a project xml (build.xml), use the taskdef core task:

<taskdef name="fmpp" classname="fmpp.tools.AntTask" /> 

Then you can use the <fmpp ...> task further down. You may remember the 4th step of Quick Tour. This is an Ant equivalent:

<project name="FMPP test" default="build">
    <taskdef name="fmpp" classname="fmpp.tools.AntTask" />
    
    <target name="build">
        <fmpp
              sourceRoot="src" outputRoot="out"
              data="tdd(data/style.tdd), birds:csv(data/birds.csv)"
        />
    </target>
</project> 

Almost all parameters of the Ant task correspond to the FMPP settings. If the setting value is of scalar type (as string, boolean, number) then just enter the value simply with Ant-ish syntax, not with TDD syntax. If the setting value is of more tricky type, as hash or sequence, then use TDD syntax for it. For hash settings the value is hash mode TDD, and for sequence setting it is sequence mode TDD, so the brackets should be omitted, as with data above.

The configuration base for the setting values given with Ant parameters is the Ant project base directory. That is, if you enter sourceRoot="src", then src is interpreted relatively to the project base directory.

There is no parameter that directly corresponds to the sources setting. The sources are chosen with nested <fileset>-style parameters and nested elements (as include and exclude). However, if you use the outputFile setting, you can't use <fileset>-style stuff, and sources will be specified with the sourceFile parameter.

Alternatively, the data, localData, borders, modes, turns, xmlRenderings and freemarkerLinks settings can be specified with nested elements instead of parameters. For example, this is equivalent with the above example:

<project name="FMPP test" default="build">
    <taskdef name="fmpp" classname="fmpp.tools.AntTask" />
    
    <target name="build">
        <fmpp sourceRoot="src" outputRoot="out">
            <data>
                 tdd(data/style.tdd)
                 birds: csv(data/birds.csv)
            </data>
        </fmpp>
    </target>
</project> 

This can be useful, if the setting value is long. The content of the element can be a CDATA section, which is useful if the setting value contains HTML or XML fragments. Unlike with attributes, Ant property interpolations (${foo}) in the text are not expanded, unless you force that with the expandProperties attribute of the element (<data expandProperties="yes">...).

About the support and interpretation of FMPP settings:

To access the Ant properties and other Ant specific data in the templates, you can use data loaders such as antProperty(), antProperties(), antProject() and antTask(). Read the chapter about data loaders for more details.

Parameters

The FMPP task accepts the following parameters:

Either the configuration parameter, or sourceRoot+outputRoot parameters, or sourceFile+outputFile parameters are required. All other parameters are optional. When you use configuration, any Ant task parameters can become optional, when the value of the coressponding settings are given in the configuration file.

Nested elements

The FMPP task accepts the following nested elements:

Examples

Run processing session with the settings stored in <projectBaseDir>/config.fmpp (or fmpp.cfg):

<fmpp configuration="." /> 

As the previous, but override outputEncoding:

<fmpp configuration="." outputEncoding="UTF-8" /> 

Processes all files in src/www and stores the output in build/www:

<fmpp sourceRoot="src/www" outputRoot="build/www" /> 

Same as the previous, but processes files with extension ftl only:

<fmpp
    sourceRoot="src/www" outputRoot="build/www"
    includes="**/*.ftl"
/> 

Same as the previous:

<fmpp sourceRoot="src/www" outputRoot="build/www">
    <include name="**/*.ftl" />
</fmpp> 

Run processing session with the settings stored in <projectBaseDir>/src/wwwconfig.fmpp, but process files with extension ftl only:

<fmpp configuration="src/wwwconfig.fmpp" includes="**/*.ftl" /> 

Processes a single file:

<fmpp sourceFile="src/test.txt" outputFile="build/test.txt" /> 

Exposes Ant properties foo, bar and baaz for the templates:

<fmpp sourceRoot="src/www" outputRoot="build/www"
        data="antProperties(foo, bar, baaz)"
/> 

Just to show something more complex...:

<fmpp sourceRoot="src/www" outputRoot="build/www"
        replaceExtension="ftl, html"
        modes="copy(**/*.html, **/*.htm)"
>
    <borders><![CDATA[
        border('<#escape x as x?html>', '</#escape>', **/*.ftl)
    ]]></borders>
    <data>
        bgColor: white
        fgColor: black
        antProps: antProperties()
    </data>
</fmpp> 

Prev  Next  Contents  Home      Report bug   Generated on Dec 16, 2007 10:12 PM GMT
For FMPP version 0.9.13
SourceForge Logo  Powered by FreeMarker