<?xml version="1.0" encoding="UTF-8" ?>
<project name="JonDonym for Mac" default="mac-dist" basedir=".">
	<description>Ant Build file containing the targets for building Mac OS X Distributions of JonDo</description>

	<taskdef name="jarbundler" 
	         classname="net.sourceforge.jarbundler.JarBundler"/>
	
	<property file="build_properties/global.properties"/>
	<property file="build_properties/jondo-global.properties"/>	
	<property file="build_properties/global-libs.properties"/>	

	<property name="bundleid" value="de.jondos.${appname}"/>
	<property name="JAP_args" value=""/>
	
	<property name="excludesSrcJap" value="${jondoExcludes}"/>
	
	<property name="jarfile" location="${dist}/${jarfile.name}.jar"/>
	<property name="dist.osx" location="${dist}/MacOsX"/>
	
	<property name="portableFirefoxPath" value="Portable%20Firefox.app/Contents/MacOS/Portable%20Firefox"/>
	
	<target name="getcurrentversion" description="Sets the property 'currentVersion', 'releaseDate' to the value provided in JAPConstants.java">
		<loadfile srcfile="${src}/jap/JAPConstants.java" property="currentVersion">
			<filterchain>
		        <linecontains>
					<contains value="static final String aktVersion"/>
				</linecontains>
				<containsregex pattern="(.*)([0-9][0-9][\.][0-9][0-9][\.][0-9][0-9][0-9])(.*)" replace="\2"/>
				<deletecharacters chars="\r\n" />
			</filterchain>
		</loadfile>
		<echo message="Current Version is: ${currentVersion}"/>
		<loadfile srcfile="${src}/jap/JAPConstants.java" property="releaseDate">
		<filterchain>
			<linecontains>
				<contains value="private static final String RELEASE_DATE"/>
			</linecontains>
			<containsregex pattern="(.*&quot;)(.*)(&quot;.*)" replace="\2"/>
			<deletecharacters chars="\r\n" />
		</filterchain>
		</loadfile>
		<echo message="Release Date is: ${releaseDate}"/>
	</target>
	
	<target name="mac-dist" description="creates a JonDo Mac OS X bundle" depends="getcurrentversion">
  		
		<ant antfile="${buildfile.core}" target="${buildfile.core.target.jar.all}">
			<property name="mainclass" value="${mainclass.osx}"/>
		</ant>
		<!-- First build a jar file with JAPMacintosh as MainClass -->
  		<mkdir dir="${dist.osx}"/>
  		<jarbundler dir="${dist.osx}"
  	            name="${appname}"
  	            mainclass="${mainclass.osx}" 
  	            bundleid="${bundleid}"
  				jar="${jarfile}"
  				icon="images/${appname}.icns"
  				signature="JAPp"
  				version="${currentVersion}"
  				shortname="${appname}"
  				arguments="${JAP_args}">
  				
  				<javaproperty name="apple.awt.brushMetalLook" value="false"/>
  				<javaproperty name="apple.awt.showGrowBox" value="false"/>
				<javaproperty name="com.apple.hwaccel" value="true"/>
				<javaproperty name="com.apple.mrj.application.growbox.intrudes" value="false"/>

		</jarbundler>
	</target>
	
	<!-- this archiving target also creates a pgp signature -->
	<target name="mac-dist-archive" depends="mac-dist" 
			description="creates a compressed dmg image of the JonDo Mac OS X bundle (needs Mac OS X)">
		<exec executable="hdiutil">
			<arg value="create"/>
			<arg value="-srcfolder"/>
			<arg value="${dist.osx}/${appname}.app"/>
			<arg value="${dist.osx}/${appname}.dmg"/>
		</exec>
		<!-- sign the archive -->
		<ant  antfile="${buildfile.signature}" target="${buildfile.signature.target.sign}">
			<property name="artefact" value="${dist.osx}/${appname}.dmg"/>
		</ant>
	</target>
	
	<target name="manioq-for-mac-dist-archive">
		<antcall target="mac-dist-archive">
			<param name="JAP_args" value="--manioq"/>
			<param name="dist.osx" value="${dist.osx}/manioq"/>
		</antcall>
	</target>
	
	<target name="portable-mac-dist-archive">
		<antcall target="mac-dist-archive">
			<param name="JAP_args" value="--portable ${portableFirefoxPath}"/>
			<param name="dist.osx" value="${dist.osx}/portable"/>
		</antcall>
	</target>
	
	
	<target name="clean">
		<ant antfile="${buildfile.core}" target="clean"/>
	</target>	
</project>