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

Ant example source code file (available.xml)

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

foo, foo, ibm, ibm, jdk, jdk

The available.xml source code

<?xml version="1.0"?>

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

  <target name="tearDown">
    <delete dir="greatgrandparent"/>
  </target>

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

  <target name="test2">
    <available property="test"/>
  </target>

  <target name="test3">
    <available file="test"/>
  </target>

  <target name="test4">
    <available property="test" 
               file="src/etc/testcases/taskdefs/this_file_does_not_exist"/>
  </target>

  <target name="test5">
    <available property="test" 
               file="available.xml"/>
  </target>

  <target name="test6">
    <available property="test" 
               resource="org/apache/tools/ant/taskdefs/this_resource_does_not_exist"/>
  </target>

  <target name="test7">
    <available property="test" 
               resource="org/apache/tools/ant/taskdefs/defaults.properties"/>
  </target>

  <target name="test8">
    <available property="test" 
               classname="org.apache.tools.ant.taskdefs.this_class_does_not_exist"/>
  </target>

  <target name="test9">
    <available property="test" 
               classname="org.apache.tools.ant.taskdefs.Ant"/>
  </target>

  <target name="test10">
    <available property="test" 
               file="available.xml"
               resource="org/apache/tools/ant/taskdefs/defaults.properties"
               classname="org.apache.tools.ant.taskdefs.Ant"/>
  </target>
  
  <target name="test11">
    <available property="test" 
               file="src/etc/testcases/taskdefs/available.xml"
               resource="org/apache/tools/ant/taskdefs/defaults.properties"
               classname="org.apache.tools.ant.taskdefs.this_class_does_not_exist"/>
  </target>  
  
  <target name="test12">
    <available property="" 
               file="available.xml"/>
  </target>

  <target name="test13">
    <available property="test" 
               file="" type="file" />
  </target>

  <target name="test13b">
    <available property="test" 
               file=""/>
  </target>

  <target name="test14">
    <available property="test" 
               resource=""/>
  </target>

  <target name="test15">
    <available property="test" 
               classname="org.apache.tools.ant.taskdefs.this_class_does_not_exist"/>
  </target>

  <target name="test16">
    <available property="test" 
               file="" type="dir"/>
  </target>

  <target name="test17">
    <available property="test" 
               file="../taskdefs" type="dir"/>
  </target>

  <target name="test18">
    <available property="test" 
               file="../this_dir_should_never_exist" type="dir"/>
  </target>

  <target name="test19">
    <available property="test" 
               file="available.xml" type="Foo"/>
  </target>

  <target name="test20">
    <available property="test" ignoresystemclasses="true"
               classname="java.awt.Graphics"/>
  </target>

  <target name="test21">
    <available property="test" ignoresystemclasses="true"
               classname="java.awt.Graphics">
      <classpath>
        <pathelement location="${java.home}/lib/rt.jar" />
        <pathelement location="${java.home}/lib/classes.zip" />
        <pathelement location="${java.home}/lib/graphics.jar" /> 
        <pathelement location="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/classes.jar" />
        <pathelement location="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes/ui.jar" />
      </classpath>
    </available>
  </target>

  <target name="test22">
    <available property="test" ignoresystemclasses="false"
               classname="java.awt.Graphics"/>
  </target>

  <target name="test23">
    <available property="test"
               classname="java.awt.Graphics"/>
  </target>

  <target name="test24">
    <!-- create a dummy file and look for it -->
    <mkdir dir="${user.dir}/test"/>
    <echo message="package test;public class test {}" file="${user.dir}/test/test.java"/>
    <javac srcdir="${user.dir}" includes="test/test.java"/>
    <jar destfile="${user.dir}/test.jar" basedir="${user.dir}" includes="test/test.class"/>
    <available property="test"
               classname="test.test" classpath="${user.dir}/test.jar"/>
    <delete dir="${user.dir}/test"/>
    <delete file="${user.dir}/test.jar"/>
  </target>

  <target name="searchInPathNotThere">
    <available file="not_there" filepath="..:optional"
               property="test" />
  </target>

  <target name="searchInPathIsThere">
    <available file="pvcs.xml" filepath="..:optional"
               property="test" />
  </target>

  <target name="testDoubleBasedir">
    <echo>testing ${basedir}${file.separator}${ant.file}
    <fail>
      <condition>
        <available file="${basedir}${file.separator}${ant.file}" />
      </condition>
    </fail>
  </target>

  <target name="prep.parents">
    <delete quiet="yes" dir="greatgrandparent"/>
    <mkdir  dir="greatgrandparent/grandparent/parent/dir"/>
    <touch  file="greatgrandparent/a.txt"/>
    <touch  file="greatgrandparent/grandparent/b.txt"/>
    <touch  file="greatgrandparent/grandparent/parent/c.txt"/>
    <touch  file="greatgrandparent/grandparent/parent/dir/d.txt"/>
    <property name="available.test.dir"
              value="greatgrandparent/grandparent/parent/dir"/>
  </target>
  <target name="search-parents" depends="prep.parents">
    <echo>testing greatgrandparent - should see

    <fail>
      <condition>
        <not>
          <available file="a.txt" searchparents="yes">
            <filepath path="${available.test.dir}"/>
          </available>
        </not>
      </condition>
    </fail>

    <echo>testing grandparent - should see
    <fail>
      <condition>
        <not>
          <available file="b.txt" searchparents="yes">
            <filepath path="${available.test.dir}"/>
          </available>
        </not>
      </condition>
    </fail>

    <echo>testing parent - should see
    <fail>
      <condition>
        <not>
          <available file="c.txt" searchparents="yes">
            <filepath path="${available.test.dir}"/>
          </available>
        </not>
      </condition>
    </fail>

    <echo>testing dir - should see
    <fail>
      <condition>
        <not>
          <available file="d.txt" searchparents="yes">
            <filepath path="${available.test.dir}"/>
          </available>
        </not>
      </condition>
    </fail>

  </target>

  <target name="search-parents-not" depends="prep.parents">
    <echo>testing grandparent - should not see
    <fail>
      <condition>
        <available file="b.txt">
          <filepath path="${available.test.dir}"/>
        </available>
      </condition>
    </fail>

    <echo>testing parent - should not see
    <fail>
      <condition>
        <available file="c.txt">
          <filepath path="${available.test.dir}"/>
        </available>
      </condition>
    </fail>

    <echo>testing dir - should see
    <fail>
      <condition>
        <not>
          <available file="d.txt">
            <filepath path="${available.test.dir}"/>
          </available>
        </not>
      </condition>
    </fail>

  </target>
</project>

Other Ant examples (source code examples)

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