alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (build.xml)

This example Ant source code file (build.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

not, not

The build.xml source code

<?xml version="1.0"?>

<project name="xslt-test" basedir="." default="nothing">

  <property name="out.dir" value="out"/>


  <target name="setup">
  </target>

  <target name="teardown">
      <delete dir="${out.dir}" failonerror="false" />
  </target>
  

  <target name="testStyleIsSet">
      <xslt in="data.xml" out="${out.dir}/out.xml"/>
  </target>

  <target name="testTransferParameterSet">
      <property name="value" value="myvalue"/>
      <xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
          <param name="set" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterEmpty">
      <property name="value" value=""/>
      <xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
          <param name="empty" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterUnset">
      <xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
          <param name="undefined" expression="${value}"/>
      </xslt>
  </target>

  <target name="testTransferParameterUnsetWithIf">
      <xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
          <param name="undefined" expression="${value}" if="value" />
      </xslt>
  </target>

  <target name="testDefaultMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${out.dir}" basedir=".">
      <param name="set" expression="${value}"/>
    </xslt>
  </target>

  <target name="testCustomMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${out.dir}" basedir=".">
      <param name="set" expression="${value}"/>
      <mapper type="glob" from="data.*" to="out.*"/>
    </xslt>
  </target>

  <target name="testTypedMapper">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${out.dir}" basedir=".">
      <param name="set" expression="${value}"/>
      <globmapper from="data.*" to="out.*"/>
    </xslt>
  </target>

  <target name="testExplicitFileset">
    <property name="value" value="myvalue"/>
    <xslt style="printParams.xsl" destDir="${out.dir}"
          useImplicitFileset="false" basedir="..">
      <param name="set" expression="${value}"/>
      <fileset dir="."/>
    </xslt>
  </target>

  <target name="testNewerStylesheet">
      <antcall target="copyXsl">
        <param name="xsl.value" value="old-value"/>
      </antcall>
      <xslt in="data.xml" out="${out.dir}/out.xml" style="tmp.xsl"/>

      <antcall target="copyXsl">
        <param name="xsl.value" value="new-value"/>
      </antcall>
      <xslt in="data.xml" out="${out.dir}/out.xml" style="tmp.xsl"/>
      <delete file="tmp.xsl"/>
  </target>

  <target name="testDirectoryHierarchyWithDirMatching">
    <mkdir dir="${out.dir}/src/level1/"/>
    <copy file="data.xml" todir="${out.dir}/src/level1/"/>
    <xslt basedir="${out.dir}/src" destdir="${out.dir}/dest"
           style="printParams.xsl"/>
  </target>

  <target name="testDirsWithSpaces">
    <mkdir dir="${out.dir}/s rc/"/>
    <copy file="data.xml" todir="${out.dir}/s rc/"/>
    <xslt basedir="${out.dir}/s rc" destdir="${out.dir}/d est"
           style="printParams.xsl"/>
  </target>

  <target name="copyXsl" if="xsl.value">
      <copy file="testNewerStylesheet.xsl" tofile="tmp.xsl" overwrite="true">
          <filterchain>
      </copy>
  </target>

  <target name="testWithStyleAttrAndResource">
      <!-- also testing style as resources, with refid -->
      <file id="xslFile" file="printParams.xsl"/>
      <xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
        <style refid="xslFile" />
      </xslt>
  </target>

  <target name="testWithFileResource">
      <xslt in="data.xml" out="${out.dir}/out.xml">
          <style>
              <file file="printParams.xsl"/>
          </style>
          <param name="set" expression="value"/>
      </xslt>
  </target>

  <target name="testWithUrlResource">
      <makeurl file="printParams.xsl" property="printParams.xsl.url"/>
      <xslt in="data.xml" out="${out.dir}/out.xml">
          <style>
              <url url="${printParams.xsl.url}"/>
          </style>
          <param name="set" expression="value"/>
      </xslt>
  </target>

  <target name="testFilenameAndFiledirAsParam">
      <mkdir dir="${out.dir}/xml/dir"/>
      <mkdir dir="${out.dir}/out"/>
      <copy file="data.xml" tofile="${out.dir}/xml/one.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/two.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/three.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${out.dir}/out"
            basedir="${out.dir}/xml"
            includes="**/*.xml"
            extension=".txt"

            filenameparameter="filename"
            filedirparameter="filedir"
      />
  </target>

  <target name="testFilenameAsParam">
      <mkdir dir="${out.dir}/xml/dir"/>
      <mkdir dir="${out.dir}/out"/>
      <copy file="data.xml" tofile="${out.dir}/xml/one.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/two.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/three.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${out.dir}/out"
            basedir="${out.dir}/xml"
            includes="**/*.xml"
            extension=".txt"

            filenameparameter="filename"
      />
  </target>

  <target name="testFilenameAsParamNoSetting">
      <mkdir dir="${out.dir}/xml/dir"/>
      <mkdir dir="${out.dir}/out"/>
      <copy file="data.xml" tofile="${out.dir}/xml/one.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/two.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/three.xml"/>
      <copy file="data.xml" tofile="${out.dir}/xml/dir/four.xml"/>
      <xslt style="printFilename.xsl"
            destdir="${out.dir}/out"
            basedir="${out.dir}/xml"
            includes="**/*.xml"
            extension=".txt"
      /> <!-- without 'filenameparameter' to check, that the xsl:param is NOT set -->
  </target>

</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.