<?xml version="1.0" encoding="UTF-8"?>
<project name="UserService" default="war" basedir=".">
<description>Builds, tests, and runs the project UserService.</description>
<property file="${basedir}/build.properties" />
<property name="profile" value="dev" />
<property file="build-${profile}.properties" />
<!-- set global properties for this build -->
<property name="project.name" value="UserService" />
<property name="dist.dir" value="dist" />
<property name="src.main.dir" value="src/main" />
<property name="src.test.dir" value="src/test" />
<property name="lib.dir" value="lib" />
<property name="war.dir" value="exploded-archives/${project.name}.war" />
<property name="classes.main.dir" value="${war.dir}/WEB-INF/classes" />
<property name="test.dir" value="test-build" />
<property name="deploy.dir" value="${tomcat.home}/webapps/" />
<property name="war.deploy.dir" value="${deploy.dir}/${project.name}.war" />
<property name="testng.jar" value="${basedir}/lib/testng.jar" />
<property name="javac.debug" value="true" />
<property name="javac.deprecation" value="false" />
<property name="debug" value="false" />
<fileset id="lib" dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<path id="build.classpath">
<fileset refid="lib" />
<pathelement location="${build.java.dir}/main" />
</path>
<target name="init" description="Init the build">
<mkdir dir="${classes.main.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<target name="compilemain" depends="init" description="Compile the Java source code" unless="eclipse.running">
<javac classpathref="build.classpath" destdir="${classes.main.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on">
<src path="${src.main.dir}" />
</javac>
</target>
<target name="copyclasses" depends="init" description="Copy the classes that were compiled by eclipse" if="eclipse.running">
<copy todir="${classes.main.dir}">
<fileset dir="classes/main">
<include name="**/*.class" />
</fileset>
</copy>
</target>
<target name="war" depends="compilemain,copyclasses" description="Build the distribution .war file">
<copy tofile="${war.dir}/WEB-INF/classes/META-INF/persistence.xml" file="${basedir}/resources/META-INF/persistence.xml" overwrite="true" />
<copy todir="${war.dir}">
<fileset dir="${basedir}/view" />
</copy>
<copy todir="${war.dir}/WEB-INF">
<fileset dir="${basedir}/resources/WEB-INF">
<include name="*.*" />
<include name="classes/**/*.*" />
<exclude name="classes/**/*.class" />
<exclude name="classes/**/*.groovy" />
</fileset>
<filterset>
<filter token="debug" value="${debug}" />
</filterset>
</copy>
<copy todir="${war.dir}/WEB-INF/classes">
<fileset dir="${basedir}/resources/">
<include name="applicationContext*.xml" />
<include name="ehcache.xml" />
<include name="log4j.properties" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/classes/hsqldb">
<fileset dir="${basedir}/resources/hsqldb" />
</copy>
<copy todir="${war.dir}/WEB-INF">
<fileset dir="${basedir}/resources/WEB-INF">
<include name="classes/**/*.class" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/lib">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/classes">
<fileset dir="${basedir}/resources">
<include name="messages*.properties" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/flex">
<fileset dir="${basedir}/resources/WEB-INF/flex">
<include name="services-config.xml" />
</fileset>
</copy>
<copy todir="${war.dir}/WEB-INF/granite">
<fileset dir="${basedir}/resources/WEB-INF/granite">
<include name="granite-config.xml" />
</fileset>
</copy>
<copy todir="${war.dir}">
<fileset dir="bin-debug">
<include name="**/*.*" />
</fileset>
</copy>
</target>
<target name="archive" depends="war" description="Package the archives">
<jar jarfile="${dist.dir}/${project.name}.war" basedir="${war.dir}" />
</target>
<target name="clean" description="Cleans up the build directory">
<delete dir="${dist.dir}" />
<delete dir="${war.dir}" />
<delete dir="${basedir}/test-report" />
<delete dir="${basedir}/test-output" />
<delete failonerror="no">
<fileset dir="${test.dir}">
<exclude name="**/*.class" if="eclipse.running" />
</fileset>
</delete>
</target>
<target name="compiletest" unless="eclipse.running" description="Compile the Java source code for the tests">
<delete dir="${test.dir}" />
<delete dir="${class.main.dir}" />
<mkdir dir="${test.dir}" />
<javac classpathref="build.classpath" destdir="${test.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}" nowarn="on">
<src path="${src.main.dir}" />
<src path="${src.test.dir}" />
</javac>
</target>
<target name="copytestclasses" if="eclipse.running" description="Copy classes compiled by eclipse to the test dir">
<mkdir dir="${test.dir}" />
<copy todir="${test.dir}">
<fileset dir="classes/main">
<include name="**/*.class" />
</fileset>
</copy>
<copy todir="${test.dir}">
<fileset dir="classes/test">
<include name="**/*.class" />
</fileset>
</copy>
</target>
<target name="buildtest" depends="compiletest,copytestclasses" description="Build the tests">
<copy todir="${test.dir}">
<fileset dir="${basedir}/resources" />
</copy>
<copy todir="${test.dir}">
<fileset dir="${src.test.dir}">
<exclude name="**/*.class" />
</fileset>
</copy>
<copy todir="${test.dir}">
<fileset dir="${src.main.dir}">
<include name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="test" depends="buildtest" description="Run the tests">
<mkdir dir="test-reports" />
<junit printsummary="yes" showoutput="yes" haltonfailure="yes" failureproperty="unittestFailed">
<formatter type="plain" usefile="true" />
<classpath refid="build.classpath" />
<classpath path="${test.dir}" />
<batchtest todir="${basedir}/test-reports">
<fileset dir="${test.dir}" includes="**/*ManagerTest.class" />
</batchtest>
</junit>
<junitreport todir="${basedir}/test-reports">
<fileset dir="${basedir}/test-reports">
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="${basedir}/test-reports" />
</junitreport>
</target>
<!-- =================================================================================== !-->
<property file="env.properties" />
<property file="project.properties" />
<xmlproperty prefix="eclipse" file=".project" />
<available file="${GRANITEDS_PROJECT_PATH}/build.xml" property="graniteds.path" />
<echo message="Found in env.properties {" />
<echo message=" FLEX_HOME=${FLEX_HOME}" />
<echo message=" FLEX_TASKS_JAR=${FLEX_TASKS_JAR}" />
<echo message=" JBOSS_HOME=${JBOSS_HOME}" />
<echo message=" JBOSS_HOME_DEPLOY=${JBOSS_HOME_DEPLOY}" />
<echo message="}" />
<!--
! Flex 2 SDK tasks (mxmlc, compc, html-wrapper).
!-->
<taskdef resource="flexTasks.tasks" classpath="${FLEX_TASKS_JAR}" />
<!--
! Build swf (if swf is out of date).
!-->
<target name="copy.mxml">
<mkdir dir="build" />
<mkdir dir="build/swf" />
<copy todir="build/swf">
<fileset dir="view/">
<include name="**/*.mxml" />
<include name="**/*.css" />
<include name="**/*.png" />
<include name="**/*.as" />
</fileset>
</copy>
</target>
<target name="check.swf" depends="copy.mxml">
<uptodate property="skip.mxmlc" targetfile="build/swf/Persons.swf">
<srcfiles dir="${FLEX_HOME}/frameworks" includes="**" />
<srcfiles dir="lib" includes="granite.swc" />
<srcfiles dir="lib" includes="granite-hibernate.swc" />
<srcfiles dir="as3" includes="**/*.as" />
<srcfiles dir="build/swf" includes="**/*.mxml" />
<srcfiles dir="build/swf" includes="**/*.as" />
<srcfiles dir="build/swf" includes="**/*.css" />
<srcfiles dir="resources" includes="WEB-INF/flex/services-config.xml" />
</uptodate>
</target>
<target name="build.mxml" depends="check.swf" unless="skip.mxmlc">
<mxmlc file="build/swf/Persons.mxml" output="build/swf/Persons.swf" services="resources/WEB-INF/flex/services-config.xml" context-root="userservice" use-network="false" keep-generated-actionscript="true" incremental="true">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml" />
<source-path path-element="${FLEX_HOME}/frameworks" />
<source-path path-element="as3" />
<source-path path-element="build/swf" />
<compiler.include-libraries dir="lib" append="true">
<include name="granite.swc" />
<include name="granite-hibernate.swc" />
</compiler.include-libraries>
<!--compiler.library-path dir="lib" append="true">
<include name="granite.swc" />
</compiler.library-path-->
</mxmlc>
</target>
<!--
! Clean up and (re)deploy.
!-->
<target name="deploy.clean" depends="clean,deploy" />
<!--
! Clean up and make distrib.
!-->
<target name="distrib" depends="clean,war">
<mkdir dir="build/${eclipse.projectDescription.name}" />
<mkdir dir="build/${eclipse.projectDescription.name}/build" />
<copy todir="build/${eclipse.projectDescription.name}">
<fileset dir=".">
<include name="**" />
<exclude name="*.zip" />
<exclude name="classes/**" />
<exclude name="build/**" />
</fileset>
</copy>
<copy todir="build/${eclipse.projectDescription.name}/build">
<fileset dir="build">
<include name="${APP_NAME}.war" />
<exclude name="swf/**" />
</fileset>
</copy>
<zip destfile="${APP_NAME}-${PROJECT_VERSION}.zip">
<fileset dir="build">
<include name="${eclipse.projectDescription.name}/**" />
</fileset>
</zip>
</target>
<!--
! Build html wrapper for swf (index.html with flash 9 detection/install).
!-->
<!--target name="build.wrapper">
<html-wrapper
title="Granite Data Services (Address Book Demo)"
application="app"
swf="Persons"
height="100%"
width="100%"
version-major="9"
version-minor="0"
version-revision="0"
template="client-side-detection"
output="granite.test.ear/test.war"/>
</target-->
<target name="tomcat.start">
<java classname="org.apache.catalina.startup.Bootstrap" fork="true">
<jvmarg value="-Djava.endorsed.dirs=${tomcat.home}/common/endorsed" />
<jvmarg value="-Dcatalina.base=${tomcat.home}" />
<jvmarg value="-Dcatalina.home=${tomcat.home}" />
<jvmarg value="-Djava.io.tmpdir=${tomcat.home}/temp" />
<arg value="start" />
<classpath>
<pathelement location="${tomcat.home}/bin/bootstrap.jar" />
</classpath>
</java>
</target>
<target name="tomcat.stop">
<echo message="Stopping Tomcat Web Server..." />
<java classname="org.apache.catalina.startup.Bootstrap" fork="true">
<jvmarg value="-Djava.endorsed.dirs=${tomcat.home}/common/endorsed" />
<jvmarg value="-Dcatalina.base=${tomcat.home}" />
<jvmarg value="-Dcatalina.home=${tomcat.home}" />
<jvmarg value="-Djava.io.tmpdir=${tomcat.home}/temp" />
<arg value="stop" />
<classpath>
<pathelement location="${tomcat.home}/bin/bootstrap.jar" />
</classpath>
</java>
</target>
<target name="deploy" depends="archive" description="Deploy to Tomcat">
<fail unless="tomcat.home">Tomcat home not set</fail>
<copy todir="${deploy.dir}" file="${dist.dir}/${project.name}.war" />
</target>
<target name="undeploy" description="Undeploy webapp">
<fail unless="tomcat.home">Tomcat home not set</fail>
<delete dir="${deploy.dir}/${project.name}" />
<delete file="${deploy.dir}/${project.name}.war" />
</target>
<path id="jpatoolslib">
<path location="lib/hibernate-tools.jar" />
<path location="lib/hibernate-all.jar" />
<path location="lib/freemarker.jar" />
<path location="lib/derby.jar" />
<path location="lib/javassist.jar" />
<path location="lib/commons-logging.jar" />
<path location="lib/jboss-common-core.jar" />
<path location="lib/dom4j-1.6.1.jar" />
<path refid="build.classpath" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="jpatoolslib" />
<target name="schema" depends="compilemain">
<hibernatetool destdir="${classes.main.dir}">
<annotationconfiguration configurationfile="resources/hibernate.cfg.xml" />
<classpath>
<path location="${classes.main.dir}" />
</classpath>
<!-- list exporters here -->
<hbm2ddl export="true" update="true" drop="true" create="true" outputfilename="schema.ddl" delimiter=";" format="true" haltonerror="true" />
</hibernatetool>
</target>
<target name="load-data">
<sql driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/userservice?useUnicode=true&characterEncoding=UTF-8"
userid="root" password="mima" >
<classpath>
<pathelement path="lib/mysql-connector-java-5.1.5-bin.jar"/>
</classpath>
<transaction src="resources/load-data.sql"/>
</sql>
</target>
</project>