blob: d96679b84ccb6b3ef1d4b616cacfdba8f5efc9ff [file] [log] [blame]
<project name="grails" default="help">
<property name="servlet.version" value="2.3"/>
<property name="path" value="" />
<target name="help">
<echo>Usage: grails [target]
Targets:
"init" - initialise the current app
"create-app" - Create a new grails app
"create-controller" - Create a new controller
"create-domain-class" - Create a new domain class
"create-test-suite" - Create a new test suite
"test-app" - Run current app's unit tests
"run-app" - Run the application (coming soon)
</echo>
</target>
<target name="create-app">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<input addproperty="project.name" message="Enter application name:" />
<antcall target="init">
<param name="path" value="${project.name}/"/>
</antcall>
<script language="groovy">
def projName = grails.getProperty("project.name")
grails.setProperty("project.class.name", projName.substring(0,1).toUpperCase() + projName.substring(1,projName.length()))
</script>
<copy file="${grails.home}/src/grails/templates/DataSource.groovy"
tofile="${project.name}/grails-app/conf/${project.class.name}DataSource.groovy"/>
<copy file="${grails.home}/src/grails/templates/BootStrap.groovy"
tofile="${project.name}/grails-app/conf/${project.class.name}BootStrap.groovy"/>
<replace file="${project.name}/grails-app/conf/${project.class.name}DataSource.groovy"
token="@data.source.name@"
value="${project.class.name}" />
<replace file="${project.name}/grails-app/conf/${project.class.name}BootStrap.groovy"
token="@bootstrap.class.name@"
value="${project.class.name}" />
</target>
<target name="create-controller">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<input addproperty="controller.name" message="Enter controller name:" />
<script language="groovy">
def ctrlName = grails.getProperty("controller.name")
ctrlName = ctrlName.substring(0,1).toUpperCase() + ctrlName.substring(1,ctrlName.length())
if(ctrlName.endsWith("Controller")) {
def i = ctrlName.lastIndexOf("Controller");
ctrlName = ctrlName.substring(0, i);
}
grails.setProperty("controller.class.name", ctrlName)
</script>
<copy file="${grails.home}/src/grails/templates/Controller.groovy"
tofile="grails-app/controllers/${controller.class.name}Controller.groovy"/>
<replace file="grails-app/controllers/${controller.class.name}Controller.groovy"
token="@controller.name@"
value="${controller.class.name}" />
<echo>Created controller: grails-app/controllers/${controller.class.name}Controller.groovy</echo>
</target>
<target name="create-domain-class">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<input addproperty="domain.class.name" message="Enter domain class name:" />
<script language="groovy">
def className = grails.getProperty("domain.class.name")
className = className.substring(0,1).toUpperCase() + className.substring(1,className.length())
grails.setProperty("domain.class.name", className)
</script>
<copy file="${grails.home}/src/grails/templates/DomainClass.groovy"
tofile="grails-app/domain/${domain.class.name}.groovy"/>
<replace file="grails-app/domain/${domain.class.name}.groovy"
token="@domain.class.name@"
value="${domain.class.name}" />
<echo>Domain class created: grails-app/domain/${domain.class.name}.groovy</echo>
</target>
<target name="create-test-suite">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<input addproperty="test.suite.name" message="Enter test suite name:" />
<script language="groovy">
def suiteName = grails.getProperty("test.suite.name")
suiteName = suiteName.substring(0,1).toUpperCase() + suiteName.substring(1,suiteName.length())
if(suiteName.endsWith("Tests")) {
def i = suiteName.lastIndexOf("Tests");
suiteName = suiteName.substring(0, i);
}
grails.setProperty("test.suite.name", suiteName)
</script>
<copy file="${grails.home}/src/grails/templates/Tests.groovy"
tofile="grails-app/tests/${test.suite.name}Tests.groovy"/>
<replace file="grails-app/tests/${test.suite.name}Tests.groovy"
token="@test.suite.name@"
value="${test.suite.name}" />
<echo>Created test suite: grails-app/tests/${test.suite.name}Tests.groovy</echo>
</target>
<target name="init">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<mkdir dir="${path}src"/>
<mkdir dir="${path}src/java"/>
<mkdir dir="${path}src/groovy"/>
<mkdir dir="${path}grails-app"/>
<mkdir dir="${path}grails-app/controllers"/>
<mkdir dir="${path}grails-app/domain"/>
<mkdir dir="${path}grails-app/views"/>
<mkdir dir="${path}grails-app/layouts"/>
<mkdir dir="${path}grails-app/conf"/>
<mkdir dir="${path}grails-app/tests"/>
<mkdir dir="${path}grails-test"/>
<mkdir dir="${path}jsp"/>
<mkdir dir="${path}lib"/>
<mkdir dir="${path}spring"/>
<mkdir dir="${path}html"/>
<mkdir dir="${path}war"/>
<mkdir dir="${path}war/WEB-INF"/>
<mkdir dir="${path}war/WEB-INF/classes"/>
<mkdir dir="${grails.home}/dist"/>
<copy todir="${path}war/WEB-INF">
<fileset dir="${grails.home}/src/war/WEB-INF">
<include name="applicationContext.xml"/>
</fileset>
</copy>
<copy file="${grails.home}/src/war/WEB-INF/web${servlet.version}.xml" tofile="${path}war/WEB-INF/web.xml"/>
<copy file="${grails.home}/src/war/WEB-INF/sitemesh.xml" tofile="${path}war/WEB-INF/sitemesh.xml"/>
<copy todir="${path}spring">
<fileset dir="${grails.home}/src/war/WEB-INF/spring">
<include name="*.xml"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete file="grails-app.war"/>
<delete dir="tmp"/>
</target>
<target name="build">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<path id="classpath">
<fileset dir="lib"/>
<fileset dir="${grails.home}/lib"/>
<fileset dir="${grails.home}/dist"/>
</path>
<delete>
<fileset dir="war/WEB-INF/classes"/>
</delete>
<javac srcdir="src" destdir="war/WEB-INF/classes" classpathref="classpath" debug="on" deprecation="on" optimize="off"/>
</target>
<target name="test" depends="build">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<delete dir="tmp/reports"/>
<mkdir dir="tmp/reports"/>
<path id="test_classpath">
<fileset dir="lib"/>
<fileset dir="${grails.home}/lib"/>
<fileset dir="${grails.home}/dist"/>
<path location="war/WEB-INF/classes"/>
</path>
<junit>
<classpath refid="test_classpath"/>
<formatter type="plain" usefile="no"/>
<formatter type="xml"/>
<batchtest todir="tmp/reports" fork="yes">
<fileset dir="war/WEB-INF/classes" includes="**/*Tests.class" excludes="**/Abstract*"/>
</batchtest>
</junit>
</target>
<target name="test-app">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<delete dir="tmp/tests/classpath"/>
<mkdir dir="tmp/tests/classpath/spring"/>
<copy todir="tmp/tests/classpath">
<fileset dir="${grails.home}/src/war/WEB-INF">
<include name="log4j.properties"/>
</fileset>
<fileset dir="grails-app"/>
</copy>
<copy todir="tmp/tests/classpath/spring">
<fileset dir="spring" includes="**"/>
</copy>
<path id="test.classpath">
<pathelement location="${basedir}/tmp/tests/classpath"/>
<pathelement location="${grails.home}/src/war/WEB-INF"/>
<pathelement location="${basedir}/grails-app"/>
<pathelement location="${basedir}/grails-app/controllers"/>
<pathelement location="${basedir}/grails-app/domain"/>
<pathelement location="${basedir}/grails-app/conf"/>
<pathelement location="${basedir}/grails-app/tests"/>
<pathelement location="${basedir}/grails-test"/>
<fileset dir="${grails.home}/lib"/>
<fileset dir="${grails.home}/dist"/>
<fileset dir="lib"/>
</path>
<java classpathref="test.classpath" classname="grails.util.RunTests" fork="true">
<!-- <jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=50010,suspend=y,server=y"/> -->
</java>
</target>
<target name="war">
<property environment="env"/>
<fail unless="env.GRAILS_HOME" message="GRAILS_HOME is not set."/>
<property name="grails.home" location="${env.GRAILS_HOME}"/>
<delete file="grails-app.war"/>
<delete dir="tmp"/>
<mkdir dir="tmp/war"/>
<copy todir="tmp/war">
<fileset dir="war">
<include name="WEB-INF/*.xml"/>
</fileset>
</copy>
<mkdir dir="tmp/war/WEB-INF/classes"/>
<touch file="tmp/war/WEB-INF/classes/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/lib"/>
<touch file="tmp/war/WEB-INF/lib/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/jsp"/>
<touch file="tmp/war/WEB-INF/jsp/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/jsp/layouts"/>
<touch file="tmp/war/WEB-INF/jsp/layouts/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/spring"/>
<touch file="tmp/war/WEB-INF/spring/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/grails-app"/>
<touch file="tmp/war/WEB-INF/grails-app/.dummy"/>
<mkdir dir="tmp/war/WEB-INF/tld"/>
<mkdir dir="tmp/war/js"/>
<copy todir="tmp/war">
<fileset dir="html"/>
</copy>
<copy todir="tmp/war/js">
<fileset dir="${grails.home}/src/war/js"/>
</copy>
<copy todir="tmp/war/WEB-INF/tld">
<fileset dir="${grails.home}/src/war/WEB-INF/tld/${servlet.version}"/>
<fileset dir="${grails.home}/src/war/WEB-INF/tld" includes="spring.tld"/>
<fileset dir="${grails.home}/src/war/WEB-INF/tld" includes="gvtags.tld"/>
</copy>
<copy todir="tmp/war/WEB-INF/lib">
<fileset dir="${grails.home}/lib">
<include name="antlr-2.7.5.jar"/>
<include name="asm.jar"/>
<include name="asm-attrs.jar"/>
<include name="cglib-2.1.jar"/>
<include name="dom4j-1.6.jar"/>
<include name="ehcache-1.1.jar"/>
<include name="ejb-3.0-edr2.jar"/>
<include name="hibernate3.jar"/>
<include name="jdbc2_0-stdext.jar"/>
<include name="jta.jar"/>
<include name="junit.jar"/>
<include name="hibernate3.jar"/>
<include name="asm-2.0.jar"/>
<include name="asm-util-2.0.jar"/>
<include name="commons-logging.jar"/>
<include name="sitemesh-2.2.1.jar"/>
<include name="spring-webflow.jar"/>
<include name="spring-binding.jar"/>
<include name="spring.jar"/>
<include name="groovy-all-1.0-jsr-04-SNAPSHOT.jar"/>
<include name="springmodules-sandbox.jar"/>
<include name="standard-${servlet.version}.jar"/>
<include name="jstl-${servlet.version}.jar"/>
<include name="commons-lang-2.0.jar"/>
<include name="log4j-1.2.8.jar"/>
<include name="ognl-2.7.jar"/>
<include name="hsqldb.jar"/>
<include name="gvtags.jar"/>
<include name="commons-collections-3.0.jar"/>
<include name="commons-pool-1.2.jar"/>
<include name="commons-dbcp-1.2.1.jar"/>
<include name="commons-cli-1.0.jar"/>
<include name="commons-validator.jar"/>
<include name="jakarta-oro-2.0.8.jar"/>
</fileset>
<fileset dir="${grails.home}/dist"/>
<fileset dir="lib"/>
</copy>
<copy todir="tmp/war/WEB-INF/classes">
<fileset dir="war/WEB-INF/classes"/>
<fileset dir="grails-app" includes="**">
<exclude name="controllers"/>
<exclude name="domain"/>
<exclude name="conf"/>
<exclude name="tests"/>
<exclude name="views"/>
</fileset>
<fileset dir="grails-app/controllers" includes="**"/>
<fileset dir="grails-app/domain" includes="**"/>
<fileset dir="grails-app/conf" includes="**"/>
<fileset dir="grails-app/tests" includes="**"/>
</copy>
<copy todir="tmp/war/WEB-INF/jsp">
<fileset dir="jsp" includes="**"/>
<fileset dir="grails-app/views" includes="**"/>
</copy>
<copy todir="tmp/war/WEB-INF/jsp/layouts">
<fileset dir="grails-app/layouts" includes="**"/>
</copy>
<copy todir="tmp/war/WEB-INF/spring">
<fileset dir="spring" includes="**"/>
</copy>
<copy todir="tmp/war/WEB-INF">
<fileset dir="${grails.home}/src/war/WEB-INF">
<include name="log4j.properties"/>
</fileset>
</copy>
<basename property="project.dir" file="."/>
<jar destfile="${project.dir}.war" basedir="tmp/war" />
</target>
<target name="run-app" depends="war">
<property location="tmp/war" name="tmp.war.location" />
<basename property="project.dir" file="."/>
<script language="groovy">
import org.mortbay.jetty.*;
import org.mortbay.http.*;
try {
def server = new Server();
def listener = new SocketListener();
listener.setPort(8080);
server.addListener(listener);
server.addWebApplication("/" + grails.getProperty("project.dir"),grails.getProperty("tmp.war.location"));
server.start();
// we put this here because ant drops out of its process when the script tag finishes
// and hence stops the web server
while(true) {
Thread.sleep(Long.MAX_VALUE)
}
}
catch(Error er) {
er.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
</script>
</target>
</project>