<!--
  This file contains useful Ant definitions for users of App Engine.
  To use these macrodefs and taskdefs, import the file into your own build.xml:

  <property name="appengine.sdk.dir" location="/some_dir/appengine-java-sdk-trunk"/>
  <import file="${appengine.sdk.dir}/config/user/ant-macros.xml"/>

  For example uses of the macros, see the template project's build.xml.
 -->
<project name="appengine-ant-macros">

  <property name="appengine.sdk.home" location="${ant.file.appengine-ant-macros}../../../.."/>
  <property name="appengine.tools.classpath" 
            location="${appengine.sdk.home}/lib/appengine-tools-api.jar"/>

  <!-- 
    A macrodef for dev_appserver. Use like:
    
    <dev_appserver war="${war}"/>
  -->
  <macrodef name="dev_appserver" description="Runs the App Engine Development App Server">
    <attribute name="war" description="The exploded war directory containing the application"/>
    <attribute name="port" default="8080" description="The port the server starts on"/>
    <attribute name="address" default="localhost" description="The interface the server binds to"/>
    <element name="options" optional="true" description="Additional options for dev_appserver"/>
    <element name="args" optional="true" description="Additional arguments for the java task"/>

    <sequential>
      <java classname="com.google.appengine.tools.KickStart"
            classpath="${appengine.tools.classpath}"
            fork="true" failonerror="true">
        <arg value="com.google.appengine.tools.development.DevAppServerMain"/>
        <arg value="--port=@{port}"/>
        <arg value="--address=@{address}"/>
        <options/>
        <arg value="@{war}"/>
        <args/>
      </java>
    </sequential>
  </macrodef>

  <!-- 
    A macrodef for appcfg. Use like:
    
    <appcfg action="update" war="${war}"/>

  -->
  <macrodef name="appcfg" description="Manages an application">
    <attribute name="war" description="The exploded war directory containing the application"/>
    <attribute name="action" description="One of (update, rollback, update_indexes, request_logs)"/>
    <element name="options" optional="true" description="Options for appcfg (such as --server, --num_days, etc...)"/>
    <element name="args" optional="true" description="Additional arguments for the java task"/>

    <sequential>
      <java classname="com.google.appengine.tools.admin.AppCfg"
            classpath="${appengine.tools.classpath}"
            fork="true" failonerror="true">
        <arg value="--disable_prompt"/>
        <options/>
        <arg value="@{action}"/>
        <arg value="@{war}"/>
        <args/>
      </java>
    </sequential>
  </macrodef>

  <!-- 
    A taskdef for ORM enhancement. Use like:
    
    <enhance failonerror="true">
      <classpath>
        <pathelement path="${appengine.tools.classpath}"/>
        <pathelement path="@{war}/WEB-INF/classes"/>
        <fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
      </classpath>
      <fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
    </enhance>
        
    Alternatively, use the <enhance_war/> macrodef below.
  -->
  <taskdef name="enhance"
           classpath="${appengine.tools.classpath}"
           classname="com.google.appengine.tools.enhancer.EnhancerTask"/>

  <!-- 
    A macrodef for ORM enhancement for a war. Use like:
     
    <enhance_war war="${war}"/>  
  -->
  <macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
    <attribute name="war" description="The exploded war directory containing the application"/>
    <attribute name="api" description="persistence api, JDO or JPA" default="JDO"/>
    <element name="args" optional="true" description="Additional arguments to the enhancer"/>
    <sequential>
      <enhance failonerror="true" api="@{api}">
        <args/>
        <classpath>
          <pathelement path="${appengine.tools.classpath}"/>
          <pathelement path="@{war}/WEB-INF/classes"/>
          <fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
        </classpath>
        <fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
      </enhance>
    </sequential>
  </macrodef>

</project>
