<!-- This file has kindly been donated by LinkedIn (http://www.linkedin.com/) -->
<project name="grails-macrodef">
  <!-- Grails-related properties -->
  <property environment="env"/>
  <property name="grails.home" value="${env.GRAILS_HOME}"/>
  <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=""/>
    <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}">
        <env key="GRAILS_HOME" value="${grails.home}"/>
        <jvmarg value="-server"/>
        <jvmarg value="-Djava.awt.headless=true"/>
        <jvmarg line="${debug.line}"/>
        <jvmarg value="-Dcom.sun.management.jmxremote" />
        <jvmarg line="-XX:MaxPermSize=128m -Xmx512m @{jvmargs}"/>

        <sysproperty key="grails.home" value="${grails.home}"/>
        <sysproperty key="groovy.starter.conf" value="${grails.home}/conf/groovy-starter.conf"/>
        <sysproperty key="base.dir" value="@{cwd}" />
        <sysprops/>

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