<?xml version="1.0"?>
<project name="BaseletGWT" basedir="." default="gwt-compile-and-zip">

	<property name="build.properties" value="src/com/baselet/gwt/client/version/build.properties" />
	<loadproperties srcFile="${build.properties}"/>
	
	<property name="src.dir" location="src" />
	<property name="build.dir" location="compile_out" />
	<property name="zip.name" location="umletino" />
	<property name="lib.dir" location="war/WEB-INF/lib" />
	<property name="gwt.module.name" value="com.baselet.gwt.BaseletGWT" />
	<property name="gwt.sdk.location" value="C:/Program Files/Eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.7.0/gwt-2.7.0" />
	<property name="elements.src.dir" location="../BaseletElements/src" />

	<path id="project.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<pathelement location="${gwt.sdk.location}/gwt-user.jar" />
		<pathelement location="${gwt.sdk.location}/gwt-dev.jar" />
		<pathelement location="${elements.src.dir}" />
	</path>

	<target name="gwt-compile-helper">
		<delete dir="${build.dir}" />
		<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
			<classpath>
				<!-- src dir is added to ensure the module.xml file(s) are on the classpath -->
				<pathelement location="${src.dir}" />
				<path refid="project.classpath" />
			</classpath>
			<jvmarg value="-Xmx256M" />
			<arg line="${args}" />
			<arg line="-war"/>
			<arg value="${build.dir}" />
			<arg value="${gwt.module.name}" />
		</java>
		<delete dir="${build.dir}/WEB-INF" />
		<copy file="war/favicon.ico" tofile="${build.dir}/favicon.ico"/>
		<copy file="war/umletino.css" tofile="${build.dir}/umletino.css"/>
		<copy file="war/index.html" tofile="${build.dir}/index.html"/>
		<copy file="war/umletino.html" tofile="${build.dir}/umletino.html"/>
		<copy file="war/UMLetino_logo_small.png" tofile="${build.dir}/UMLetino_logo_small.png"/>
		<!-- replace version with current date (to force browsers to update javascript) -->
	    <tstamp>
	      <format property="timestamp" pattern="yyyyMMdd_HHmmsssss"/>
	    </tstamp>
		<replace file="${build.dir}/umletino.html">
			<replacefilter token=".nocache.js?umletino_version" value=".nocache.js?${timestamp}" />
		</replace>
	</target>
	
	<target name="gwt-compile-draft-with-detailed-names" description="compile in draft mode">
	  <antcall target="gwt-compile-helper">
	    <param name="args" value="-draftCompile -style PRETTY"/> <!-- set to DETAILED to see even more details like class names-->
	  </antcall>
	</target>
	
	<target name="gwt-compile-and-zip" description="compile in normal mode" depends="buildinfo">
	  <antcall target="gwt-compile-helper">
	    <param name="args" value="-optimize 9"/>
	  </antcall>
		<zip destfile="${zip.name}_${versionNew}.zip" basedir="${build.dir}" />
		<delete dir="${build.dir}" failonerror="false" />
	</target>
	
	<target name="buildinfo">
	    <input message="Please enter version:" addproperty="versionNew" defaultvalue="${version}" />
	    <tstamp>
	        <format property="buildtimeNew" pattern="yyyy-MM-dd HH:mm" timezone="Europe/Vienna"/>
	    </tstamp>

	    <propertyfile file="${build.properties}"
	        comment="This file is automatically generated - DO NOT EDIT">        
	        <entry key="buildtime" value="${buildtimeNew}"/>
	        <entry key="version" value="${versionNew}"/>
	    </propertyfile>
	</target>
</project>