 <!-- This file has kindly been donated by LinkedIn (http://www.linkedin.com/) -->
<project name="grails-macrodef">
  <!-- Grails-related properties -->
  <property name="grails.bin" value="${grails.home}/bin"/>

  <!--
  Example of sys properties that you can add:

    <grails ...>
      <sysprops>
        <sysproperty key="grails.project.class.dir" value="${build.dir.classes}"/>
        <sysproperty key="grails.project.test.class.dir" value="${build.dir.classes}"/>
        <sysproperty key="jetty.home" value="/${top.dist.dir}/cap" />
        <sysproperty key="disable.auto.recompile" value="false"/>
        <sysproperty key="server.port" value="7070"/>
        <sysproperty key="server.port.https" value="7443" />
        <sysproperty key="enable.jndi" value="true"/>
        <sysproperty key="dist.dir" value="${top.dist.dir}" />
        <sysproperty key="test.report.dir" value="${test.report.dir}/bl"/>
      </sysprops>
    </grails>

  Example of extending the classpath:

    <grails ...>
      <extend-classpath>
        <pathelement location="${lib.dir}/postgresql-8.3.4-jdbc.jar"/>
      </extend-classpath>
    </grails>
  -->

  <!-- Wrapper around GRAILS command: used for development and build only -->
  <macrodef name="grails">
    <attribute name="grailsStarter" default="org.codehaus.groovy.grails.cli.support.GrailsStarter"/>
    <attribute name="command" default="help"/>
    <attribute name="cwd" default="${basedir}"/>
    <attribute name="debug" default="false" />
    <attribute name="jvmargs" default=""/>
    <attribute name="args" default=""/>
    <attribute name="returncode" default="grails.macro.exit.code"/>
    <element name="sysprops" optional="true"/>
    <element name="extend-classpath" optional="true"/>
    <sequential>
      <!-- Enable debugging if the 'debug' attribute is set to true -->
      <condition property="debug.line" value="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005">
        <equals arg1="@{debug}" arg2="true" />
      </condition>

      <!-- If debug mode has not been requested, the 'debug.line' property will -->
      <!-- not be set at this point. So, we set it now. Note that this does not -->
      <!-- override any existing value.                                         -->
      <property name="debug.line" value=""/>

      <!-- Execute Grails -->
      <java fork="true" classname="@{grailsStarter}" dir="@{cwd}" failonerror="false" resultproperty="@{returncode}">
        <env key="GRAILS_HOME" value="${grails.home}"/>
        <jvmarg value="-server"/>
        <jvmarg value="-Djava.awt.headless=true"/>
        <!-- NOTE: A blank value here causes linux builds to fail, revisit this when debugging is needed
        <jvmarg value="${debug.line}"/>
        -->
        <jvmarg value="-Dcom.sun.management.jmxremote" />
        <jvmarg line="-XX:MaxPermSize=128m -Xmx512m @{jvmargs}"/>

        <sysproperty key="grails.home" value="${grails.home}"/>
        <sysproperty key="user.home" value="${grails.work.dir}" />
        <sysproperty key="groovy.starter.conf" value="${grails.home}/conf/groovy-starter.conf"/>
        <sysproperty key="base.dir" value="@{cwd}" />
        <sysproperty key="tools.jar" value="${java.home}/../lib/tools.jar"/>
        <sysprops/>

        <classpath>
          <pathelement location="@{cwd}"/>
          <pathelement location="${grails.home}/lib/groovy-all-1.5.6.jar"/>
          <pathelement location="${grails.home}/dist/grails-cli-1.0.3.jar"/>
          <extend-classpath/>
        </classpath>
        <arg line="--main org.codehaus.groovy.grails.cli.GrailsScriptRunner"/>
        <arg line="@{command}"/>
        <arg line="@{args}"/>
      </java>
    </sequential>
  </macrodef>
</project>
