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

Ant example source code file (echo.xml)

This example Ant source code file (echo.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

appended, appended, did, echo, of, output, simple, simple, this, utf-16, utf16, utf16, utf8, utf8

The echo.xml source code

<?xml version="1.0"?>

<project name="echo-test" basedir="." default="test1">

  <property name="dest.dir" location="echo.dest"/>

  <target name="init">
    <mkdir dir="${dest.dir}" />
  </target>

  <target name="clean">
    <delete dir="${dest.dir}"/>
  </target>

  <target name="test1">
    <echo/>
  </target>

  <target name="test2">
    <echo message="OUTPUT OF ECHO"/>
  </target>

  <target name="test3">
    <echo>
    This 
    is
    a 
    multiline
    message
    </echo>
  </target>

  <macrodef name="assertContains">
    <attribute name="expected" />
    <attribute name="actual" />
    <sequential>
      <fail>
        <condition>
          <not>
            <contains string="@{actual}" substring="@{expected}">
          </not>
        </condition>
        Did not find @{expected} in @{actual}
      </fail>
    </sequential>
  </macrodef>

  <target name="testFile" depends="init">
    <echo file="${dest.dir}/echo.txt">Simple text
    <loadfile srcfile="${dest.dir}/echo.txt" property="echo" />
    <assertContains actual="${echo}" expected="Simple text" />
  </target>


  <target name="testAppend" depends="init">
    <echo file="${dest.dir}/echo.txt">Simple text
    <echo file="${dest.dir}/echo.txt" append="true">Appended
    <loadfile srcfile="${dest.dir}/echo.txt" property="echo"/>
    <assertContains actual="${echo}" expected="Simple text"/>
    <assertContains actual="${echo}" expected="Appended"/>
  </target>

  <target name="testEmptyEncoding" depends="init">
    <echo file="${dest.dir}/echo.txt" encoding="">Simple text
    <loadfile srcfile="${dest.dir}/echo.txt" property="echo"/>
    <assertContains actual="${echo}" expected="Simple text"/>
  </target>

  <target name="testUTF16Encoding" depends="init">
    <property name="char" value="©" />
    <echo file="${dest.dir}/echo16.txt" encoding="UTF-16">${char}
    <loadfile srcfile="${dest.dir}/echo16.txt" property="echo16" encoding="UTF16"/>
    <assertContains actual="${echo16}" expected="${char}"/>
  </target>
  
  <target name="testUTF8Encoding" depends="init">
    <property name="char" value="©" />
    <echo file="${dest.dir}/echo8.txt" encoding="UTF8">${char}
    <loadfile srcfile="${dest.dir}/echo8.txt" property="echo" encoding="UTF8"/>
    <assertContains actual="${echo}" expected="${char}"/>
  </target>


</project>

Other Ant examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.