<project name="MyHealth Web Application" default="all" basedir=".">

	<description>MyHealth</description>

	<!-- definition of global property -->
	<property environment="env" />
	<property name="jboss.home" value="${env.JBOSS_HOME}" />
	<property name="source" value="." />
	<property name="sourcesrc" value="${source}/src" />
	<property name="build" value="${source}/build" />
	<property name="buildjar" value="${build}/jar" />
	<property name="buildwar" value="${build}/war" />
	<property name="dist" value="${source}/dist" />
	<property name="jboss-config" value="default" />
	<property name="deploy" value="${jboss.home}\standalone\deployments" />
	<property name="jboss.module.dir" value="${jboss.home}/modules" />

	<path id="jboss.classpath">
		<fileset dir="${jboss.module.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<target name="all" depends="clean, init, ear" />

	<target name="init" description="inicialitzacions is relevant: the structure created
		copy files and directories there. xml ">
		<!-- Crea el time-stamp -->
		<tstamp />
		<!-- It creates the directory structure -->
		<mkdir dir="${build}" />
		<mkdir dir="${buildjar}" />
		<mkdir dir="${buildwar}" />
		<mkdir dir="${buildjar}/META-INF" />
		<mkdir dir="${buildwar}/WEB-INF" />
		<mkdir dir="${buildwar}/WEB-INF/classes" />
		<mkdir dir="${dist}" />
	</target>

	<!--Compiling the EJB classes and makes the build directory -->
	<target name="compileEjb" depends="init">
		<copy file="${sourcesrc}/META-INF/persistence.xml" todir="${buildjar}/META-INF" />
		<copy file="${sourcesrc}/log4j.properties" todir="${buildjar}" />
		<javac srcdir="${sourcesrc}" destdir="${buildjar}" includes="ejb/**/*.java, jpa/**/*.java, TO/**/*.java" classpathref="jboss.classpath" includeantruntime="true" />
	</target>

	<!-- Update the EJB jar file and create if not exist -->
	<target name="jarEjb" depends="compileEjb">
		<jar jarfile="${dist}/MyHealth.jar" basedir="${buildjar}" update="yes" />
	</target>

	<!-- Compile the client application, creating the structure buildwar -->
	<target name="compileWar" depends="init">
		<copy todir="${buildwar}">
			<fileset dir="${source}/docroot" />
		</copy>
		<javac srcdir="${sourcesrc}" destdir="${buildwar}/WEB-INF/classes" includes="managedbean/*.java" classpathref="jboss.classpath" includeantruntime="true" />
		<delete verbose="true" dir="${buildwar}/WEB-INF/classes/ejb" />
		<delete verbose="true" dir="${buildwar}/WEB-INF/classes/jpa" />
		<delete verbose="true" dir="${buildwar}/WEB-INF/classes/TO" />
	</target>

	<!-- Update the WAR file and create if not exist -->
	<target name="deployWar" depends="compileWar">
		<jar jarfile="${dist}/MyHealth.war" basedir="${buildwar}" excludes="/WEB-INF/classes/ejb/*.*, /WEB-INF/classes/jpa/*.*, /WEB-INF/classes/TO/*.*" update="yes" />
	</target>

	<!-- Update the application ear file and created if not exist -->
	<target name="ear" depends="jarEjb, deployWar">
		<copy file="${sourcesrc}/META-INF/application.xml" todir="${dist}/META-INF" />
		<jar jarfile="${dist}/MyHealth.ear" basedir="${dist}" update="yes" />
	</target>

	<!-- Deploy the ear. Copy the ear of the JBoss deployment directory -->
	<target name="deployear" depends="ear">
		<copy file="${dist}/MyHealth.ear" todir="${deploy}" />
	</target>

	<!-- Clean the build directory -->
	<target name="clean">
		<antcall target="init" />
		<delete verbose="true" includeemptydirs="true">
			<fileset dir="${dist}" includes="**/*" />
			<fileset dir="${build}" includes="**/*" />
			<fileset dir="${buildjar}" includes="**/*" />
			<fileset dir="${buildwar}" includes="**/*" />
			<fileset dir="${buildjar}/META-INF" includes="**/*" />
			<fileset dir="${buildwar}/WEB-INF" includes="**/*" />
			<fileset dir="${buildwar}/WEB-INF/classes" includes="**/*" />
		</delete>
	</target>
</project>
