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

Ant example source code file (delete.xml)

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

bugzilla, bugzilla, cvs, cvs, cvs/lala, cvs/lala

The delete.xml source code

<?xml version="1.0"?>

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

  <property name="dirname" value="taskdefs.tmp" />
  <property name="dir" location="${dirname}" />

  <macrodef name="expectabsent">
    <attribute name="target" default="${dir}"/>
    <sequential>
      <fail>
        <condition>
          <available file="@{target}" />
        </condition>
    </fail>
    </sequential>
  </macrodef>

  <macrodef name="expectdirsonly">
    <sequential>
      <fail>
        <condition>
          <or>
            <resourcecount when="greater" count="0">
              <fileset dir="${dir}" />
            </resourcecount>
            <not>
              <resourcecount count="${srcdirs}">
                <dirset dir="${dir}" />
              </resourcecount>
            </not>
          </or>
        </condition>
      </fail>
    </sequential>
  </macrodef>

  <target name="init">
    <resourcecount property="srcdirs">
      <dirset dir="${basedir}" />
    </resourcecount>

    <resourcecount property="srcsize">
      <files includes="${basedir}/" />
    </resourcecount>

    <mkdir dir="${dir}" />

    <copy todir="${dir}">
      <fileset dir="${basedir}" excludes="${dirname},${dirname}/**" />
    </copy>
  </target>

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

  <target name="test2" depends="init">
    <delete file="${dir}" />
    <fail>
      <condition>
        <not>
          <resourcecount count="${srcsize}">
            <files includes="${dir}/" />
          </resourcecount>
        </not>
      </condition>
    </fail>
  </target>

  <target name="test4" depends="init">
    <delete dir="${dir}" />
    <expectabsent />
  </target>

  <target name="test5" depends="init">
    <delete dir="${dir}" includes="**" />
    <expectdirsonly />
  </target>

  <target name="test6" depends="init">
    <delete dir="${dir}" includes="**" includeemptydirs="true" />
    <expectabsent />
  </target>

  <target name="test7" depends="init">
    <delete>
      <fileset id="fs" dir="${dir}" />
    </delete>
    <expectdirsonly />
  </target>

  <target name="test8" depends="init">
    <delete includeemptydirs="true">
      <fileset dir="${dir}" />
    </delete>
    <expectabsent />
  </target>

  <target name="test9" depends="init">
    <delete>
      <files includes="${dir}/**" />
    </delete>
    <expectabsent />
  </target>

  <target name="test10">
    <delete>
      <filelist dir="${dir}" files="test10absentfile" />
    </delete>
  </target>

  <target name="test11">
    <delete failonerror="false">
      <fileset dir="thisdenotesadirectorythatwillneverexistblah" />
    </delete>
  </target>

  <target name="test12">
    <delete failonerror="false" includeemptydirs="true">
      <fileset dir="thisdenotesadirectorythatwillneverexistblah" />
    </delete>
  </target>

  <target name="test13" depends="init">
    <delete includeemptydirs="true">
      <fileset dir="${dir}" />
      <fileset dir="${dir}" />
    </delete>
    <expectabsent />
  </target>

  <target name="test14" depends="init">
	<delete quiet="false">
		<fileset dir="${dir}" />
		<fileset dir="${dir}" />
	</delete>
  </target>

  <target name="test15" depends="init">
	<delete quiet="true">
		<fileset dir="${dir}" />
		<fileset dir="${dir}" />
	</delete>
  </target>
  <!-- Bugzilla 40313 -->
  <target name="test16.init">
    <mkdir dir="${dir}/CVS"/>
    <touch file="${dir}/CVS/lala"/>
    <mkdir dir="${dir}/subdir"/>
  </target>

  <target name="test16" depends="test16.init">
    <delete defaultexcludes="false" dir="${dir}" includeemptydirs="true"/>
    <expectabsent/>
  </target>

  <target name="test17" depends="test16.init">
    <delete dir="${dir}" defaultexcludes="true" includeemptydirs="true"/>
    <fail message="file in CVS dir deleted">
      <condition>
        <not>
          <available file="${dir}/CVS/lala"/>
        </not>
      </condition>
    </fail>
    <expectabsent target="${dir}/subdir"/>
  </target>


  <target name="cleanup" depends="test4" />

</project>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant delete.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.