<project name="evo-app-build-5" > 
	
	<import file="common/evo-app-load-properties.xml" />
	<import file="common/evo-app-deploy-common.xml" />
	
	<!--  CLASSPATH -->
	<path id="app.jar.classpath">
		<fileset dir="${app.lib.dir}" />
	</path>

	<path id="app.build.classpath">
		<path refid="app.jar.classpath" />
		<pathelement location="${app.build.dir}" />
	</path>
	
	<path id="svn.classpath">
		<fileset dir="${evolute.lib.tools.dir}" />
	</path>
	
	<path id="jsch.classpath">
		<fileset dir="${evolute.lib.tools.dir}" />
	</path>
	
	<path id="lib.tools.classpath">
		<fileset dir="${lib.tools.dir}" />
	</path>
	
	<!-- BUILD -->
	<target name="app-prepare" depends="load-properties">
		<echo message="Copying non-java files to build directory" />
		<copy todir="${app.build.dir}">
			<fileset dir="${app.src.dir}">
				<exclude name="**/*.java" />
				<exclude name="*.java" />
			</fileset>
			<fileset dir="${properties.dir}">
				<include name="*" />
				<include name="**/*" />
			</fileset>
		</copy>
	</target>

	<target name="app-build" description="Compiles all application classes" depends="app-prepare">
		<mkdir dir="${app.build.dir}" />
		<depend srcdir="${app.src.dir}" destdir="${app.build.dir}" cache="${app.dependencies.chache.dir}">
			<include name="**/*.java" />
		</depend>
		<javac srcdir="${app.src.dir}" destdir="${app.build.dir}" classpathref="app.build.classpath" debug="on" deprecation="on" fork="true" memoryMaximumSize="512M" source="1.5" target="1.5" />
		<antcall target="app-datanucleus"/>
	</target>
	
	<target name="app-datanucleus">
		<path id="jpox.enhancer.classpath">
			<fileset dir="${lib.tools.dir}" />
			<path refid="app.build.classpath" />
		</path>
		<taskdef name="jpoxEnhancer" description="JPOX Enhancer" classpathref="jpox.enhancer.classpath" classname="org.datanucleus.enhancer.tools.EnhancerTask" />
		<jpoxEnhancer maxmemory="256M" classpathref="jpox.enhancer.classpath" dir="${app.build.dir}" verbose="true"/>
	</target>

	<target name="app-clean" description="Removes all generated files">
		<delete failonerror="false">
			<fileset dir="${app.build.dir}">
				<include name="**/*" />
			</fileset>
		</delete>
		<delete dir="${app.build.dir}" failonerror="false" />
		<delete dir="${app.dist.dir}" failonerror="false" />
		<delete dir="${app.deploy.dist.dir}" failonerror="false" />
	</target>

	<target name="app-run" description="Runs the application" depends="app-build">
		<java classname="${app.main}" classpathref="app.build.classpath" fork="true" dir="${app.build.dir}" />
	</target>
		
	<!-- JAR -->
	<target name="app-deploy-create-jar" depends="app-clean, app-build" >
		<mkdir dir="${app.deploy.dist.dir}" />
		<jar destfile="${app.deploy.dist.dir}/${app.jar.name}" >
			<fileset dir="${app.build.dir}">
				<include name="**/*" />
			</fileset>
		</jar>
		<copy todir="${app.deploy.dist.lib.dir}">
			<fileset dir="${app.lib.dir}">
				<include name="**/*" />
			</fileset>
		</copy>
	</target>
	
	<target name="app-create-jar" description="Make application Jar" depends="app-clean, app-build"  >
		<pathconvert property="jar.classpath.converted" refid="app.jar.classpath" pathsep=" ">
			<map from="${app.dir}/" to="" />
			<map from="${basedir}/" to="" />
		</pathconvert>
		<mkdir dir="${app.dist.dir}" />
		<jar destfile="${app.dist.dir}/${app.jar.name}">
			<fileset dir="${app.build.dir}">
				<include name="**/*" />
			</fileset>
			<manifest>
				<attribute name="Main-Class" value="${app.main}" />
				<attribute name="Class-Path" value="${jar.classpath.converted}" />
			</manifest>
		</jar>
		<copy todir="${app.dist.lib.dir}">
			<fileset dir="${app.lib.dir}">
				<include name="**/*" />
			</fileset>
		</copy>
	</target>
	
</project>