Java/Ant/Condition — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 06:36, 1 июня 2010

Condition for file change

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="compile" basedir=".">
  <fileset dir="." id="uptodate.id">
    <include name="src/jstl/One.java"/>
  </fileset>
  <property name="jstl.src" value="jstl"/>
  <property name="jstl.jar" value="jstl.jar"/>  
  
  <condition property="jstl.src.exists">
    <available file="${jstl.src}" filepath="./src"/>
  </condition>
  <condition property="jstl.jar.exists">
    <available file="${jstl.jar}" filepath="./lib"/>
  </condition>
  <condition property="uptodate">
    <uptodate>
      <srcfiles refid="uptodate.id"/>
      <mapper type="merge" to="./One.java"/>
    </uptodate>
  </condition>
  <target name="checkout-jstl" unless="jstl.src.exists">
    <echo message="Checking out ${jstl.jar}"/>
  </target>
  <target name="build-jstl" depends="checkout-jstl" unless="jstl.jar.exists">
    <echo message="Building ${jstl.jar}"/>
  </target>
  <target name="compile" if="uptodate">
    <echo message="File changed: ${uptodate}"/>
  </target>
 
  <condition property="is.fileset">
    <isreference refid="uptodate.id" type="fileset"/>
  </condition>
  <target name="fileset-prepare">
    <echo message="Value of is.fileset = ${is.fileset}"/>
  </target>


</project>





Specify condition

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="do-windows" basedir=".">
  <condition property="is.windows">
    <os family="windows"/>
  </condition>
  <condition property="is.unix">
    <os family="unix"/>
  </condition>
  <target name="do-windows" if="is.windows">
    <echo message="This is Windows"/>
  </target>
  <target name="do-unix" if="is.unix">
    <echo message="This is Unix"/>
  </target>

</project>





Target based on condition

<?xml version="1.0"?>
<project name="Apache Ant Properties Project" default="do-windows" basedir=".">
  <condition property="is.windows">
    <os family="windows"/>
  </condition>
  <condition property="is.unix">
    <os family="unix"/>
  </condition>
  <target name="do-windows" if="is.windows">
    <echo message="This is Windows"/>
  </target>
  <target name="do-unix" if="is.unix">
    <echo message="This is Unix"/>
  </target>

</project>