<project name="my_cool_proggy" default="dist" basedir=".">

	<property name="src" location="d:\myproggy\src" />
	<property name="lib" location="lib" />
	<property name="images" location="images" />
	<property name="nsis" location="nsis" />
	<property name="dist" location="dist" />
	<property name="html" location="html" />
	<property name="build" location="build" />
	<property name="launch4j.dir" location="../.." />
	<property name="original.dir" location="d:\myproggy" />

	<path id="dist.classpath">
		<pathelement path="${build}" />
		<fileset dir="${lib}">
			<include name="**/*.jar" />
		</fileset>
	</path>

	<target name="init" depends="clean">
		<tstamp />
		<mkdir dir="${build}" />
		<mkdir dir="${html}" />
		<mkdir dir="${images}" />
		<mkdir dir="${lib}" />
		<mkdir dir="${dist}" />
		
		<copy todir="${html}">
			<fileset dir="${original.dir}/html/"/>
		</copy>
		
		<copy todir="${images}">
			<fileset dir="${original.dir}/images/"/>
		</copy>		

		<copy todir="${lib}">
			<fileset dir="${original.dir}/lib"/>
		</copy>		
		
		
	</target>
	

	<target name="compile" depends="init" description="compile the source">
		<javac srcdir="${src}" destdir="${build}" classpathref="dist.classpath" source="1.5" debug="on" />
		
		  <copy todir="${build}">
		    <fileset dir="${src}">
		      <include name="*.vm"/>
			  <include name="*.properties"/>
		    </fileset>
		  </copy>		
		  
		  
	</target>

	<target name="jar" depends="compile" description="create the jar">
	
		<fileset dir="${lib}" id="lib.dist.fileset">
			<include name="**/*.jar" />
		</fileset>
		
		<pathconvert pathsep=" " property="dist.classpath" refid="lib.dist.fileset">
			<map from="${lib}" to=".\lib" />
		</pathconvert>
		
		<!-- Put everything in ${build} into a jar file -->
		<jar jarfile="${ant.project.name}.jar">
			<fileset dir="${build}" includes="**/*" />
			<manifest>
				<!-- SET YOUR MAIN CLASS HERE -->
				<attribute name="Main-Class" value="com.javazing.MyProggyLauncher" />
				<attribute name="Class-Path" value=". ${dist.classpath}" />
			</manifest>
		</jar>
		
		<!-- obfuscate and optimize by ProGuard -->
		<taskdef resource="proguard/ant/task.properties" classpath="${launch4j.dir}/lib/proguard.jar" />
		<proguard>
		
			-libraryjars jre/lib/rt.jar 
			-libraryjars lib/commons-collections-3.1.jar
			-libraryjars lib/commons-io-1.2.jar
			-libraryjars lib/commons-lang-2.1.jar
			-libraryjars lib/commons-logging.jar
			-libraryjars lib/hsqldb.jar
			-libraryjars lib/jdom-1.0.jar
			-libraryjars lib/log4j.jar
			-libraryjars lib/lucene-core-1.9.1.jar
			-libraryjars lib/org.eclipse.core.commands_3.2.0.I20060511-0800a.jar
			-libraryjars lib/org.eclipse.equinox.common_3.2.0.v20060512.jar
			-libraryjars lib/org.eclipse.jface.text_3.2.0.v20060518-0800.jar
			-libraryjars lib/org.eclipse.jface_3.2.0.I20060511-0800a.jar
			-libraryjars lib/org.eclipse.osgi_3.2.0.v20060510.jar
			-libraryjars lib/org.eclipse.swt.win32.win32.x86_3.2.0.v3224.jar
			-libraryjars lib/org.eclipse.text_3.2.0.v20060518-0800.jar
			-libraryjars lib/rome-0.8.jar
			-libraryjars lib/velocity-1.4.jar			
			
			-injars      ${ant.project.name}.jar
			-outjars     obfuscated_${ant.project.name}.jar

			-keepclasseswithmembers public class * {
			public static void main(java.lang.String[]);
			}

			-dontskipnonpubliclibraryclasses

			-keep public class com.javazing.MyProggyLauncher
			
			-keep class * implements java.sql.Driver
			
			
		</proguard>
		
	</target>

	<target name="exe" depends="jar">
		<taskdef name="launch4j" classname="net.sf.launch4j.ant.Launch4jTask" classpath="${launch4j.dir}/launch4j.jar
		    :${launch4j.dir}/lib/xstream.jar" />
		<launch4j configFile="./l4j/proggy.xml" />
		
	</target>

	<target name="clean" description="clean up">
		<delete dir="${build}"/>
		<delete dir="${html}"/>
		<delete dir="${images}"/>
		<delete dir="${lib}"/>
		<delete dir="${dist}"/>
		<!--
		<delete file="${ant.project.name}.jar"/>
		<delete file="${ant.project.name}.exe"/>
		-->
	</target>
	
	<target name="dist"  depends="exe" description="make installation package for distribution">
	
		<taskdef name="nsis" classname="net.sf.nsisant.Task">
			<classpath location="nsisant-1.2.jar"/>
		</taskdef>
		
	    <nsis script="nsis/my_proggy.nsi" verbosity="4" out="nsis_build.log" noconfig="yes">
	        <define name="VERSION" value="1.0"/>
			<define name="PRODUCT_NAME" value="My Proggy"/>
			<define name="EXE_NAME" value="${ant.project.name}.exe"/>
			<define name="SHORT_NAME" value="MyCoolProggy"/>
			<define name="FOLDER" value="D:\launch4j\MyProggy"/>
	    </nsis>
		
		<copy file="${nsis}/${ant.project.name}.exe" tofile="${dist}/${ant.project.name}.exe"/>
		
		<delete file="${nsis}/${ant.project.name}.exe"/>
		
		<delete dir="${build}"/>
		<delete dir="${html}"/>
		<delete dir="${images}"/>
		<delete dir="${lib}"/>
		
		<delete file="${ant.project.name}.jar"/>
		<delete file="${ant.project.name}.exe"/>
		<delete file="obfuscated_${ant.project.name}.jar" />
		
		
	</target>
</project>
