<?xml version="1.0" encoding="UTF-8" ?>
<project name="AN.ON" default="dist" basedir=".">
  <description>Ant Build file for the various compontens of the AN.ON project</description>
  <!-- set global properties for this build -->
  <property name="javac1.3.exe" value="/opt/java/jdk1.3/bin/javac" />
  <property name="src" location="src"/>
  <property name="certificates" location="certificates"/>
  
  <property name="excludesSrcJap" value="jpi/** infoservice/** misc/** platform/signal/** jondonym/** captcha/** anon/crypto/tinytls/test/**"/>
  <property name="infoservice-excludes" value="jpi/** infoservice/performance/** misc/**"/>
  <property name="build" location="build"/>
  <property name="build.libs" location="build/libs"/>
  <property name="build.gcj" location="build/gcj"/>
  <property name="build.gcj.build" location="build/gcj/build"/>
  <property name="build.gcj.libs" location="build/gcj/libs"/>
	<property name="build.gcj.src" location="build/gcj/src"/>
	<property name="dist" location="dist"/>
  <property name="japrelease.jnlp" location="/home/infoservice/japRelease.jnlp"/>
  <property name="japtomcat" location="/home/tomcat/webapps/jap/"/>
  <property name="japweb" location="/var/www/JapWeb/"/>
  <property name="japkeystore" location="/home/compile/.keystore"/>
  
  
  <property name="classpath_httplib_file_name" location="${build.libs}/HTTPClient.jar"/>
  <property name="classpath_xmllib_file_name" location="${build.libs}/xml-1.1.jar"/>
  <property name="classpath_ftplib_file_name" location="${build.libs}/ApacheFTPClient.jar"/>
  <property name="classpath_log4j_file_name" location="${build.libs}/log4j.jar"/>
  <property name="classpath_bouncy_file_name" location="${build.libs}/BouncyCastleLightForJAP.jar"/>
  <property name="classpath_xmlrpc_file_name" location="${build.libs}/apache-xml-rpc-1.1.jar"/>
  <property name="classpath_jaf_file_name" location="${build.libs}/activation.jar"/>
  <property name="classpath_skype_file_name" location="${build.libs}/skype.jar"/>
	
  <path id="classpath_httplib" location="${classpath_httplib_file_name}"/>
  <path id="classpath_ftplib" location="${classpath_ftplib_file_name}"/>
  <path id="classpath_xml-rpc" location="${classpath_xmlrpc_file_name}"/>
  <path id="classpath_xml" location="${classpath_xmllib_file_name}"/>
  <path id="classpath_java_mail" location="${build.libs}/mail.jar"/>
  <path id="classpath_mrj" location="${build.libs}/MRJClasses.zip"/>
  <path id="classpath_aje" location="${build.libs}/AppleJavaExtensions.jar"/>
  <path id="classpath_jama" location="${build.libs}/jama.jar"/>
  <path id="classpath_swing" location="${build.libs}/swingall.jar"/>
  <path id="classpath_log4j" location="${classpath_log4j_file_name}"/>
  <path id="classpath_bouncycastle_jap" location="${classpath_bouncy_file_name}"/>
  <path id="classpath_jaf" location="${classpath_jaf_file_name}"/>
  <path id="classpath_skype" location="${classpath_skype_file_name}"/>
	
  <path id="classpath_all">
    <path refid="classpath_swing"/>
    <path refid="classpath_httplib"/>
    <path refid="classpath_ftplib"/>
    <path refid="classpath_xml-rpc"/>
    <path refid="classpath_xml"/> 
    <path refid="classpath_jama"/> 
    <path refid="classpath_log4j"/>
    <path refid="classpath_mrj"/>
    <path refid="classpath_aje"/>
    <path refid="classpath_bouncycastle_jap"/>
    <path refid="classpath_skype"/>
  </path>
  <path id="java_1_1_boot_classes" location="${build.libs}/java_1_1_classes.zip"/>
  <target name="init-dirs">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
    <mkdir dir="${build.libs}"/>
  </target>
  <target name="init-libs" depends="init-dirs">
    <get src="http://anon.inf.tu-dresden.de/develop/java_1_1_classes.zip" verbose="true" dest="${build.libs}/java_1_1_classes.zip">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/swingall.jar" verbose="true" dest="${build.libs}/swingall.jar">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/http.jar" verbose="true" dest="${classpath_httplib_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/xml-1.1.jar" verbose="true" dest="${classpath_xmllib_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/BouncyCastleLightForJAP.jar" verbose="true" dest="${classpath_bouncy_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/ApacheFTPClient.jar" verbose="true" dest="${classpath_ftplib_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/apache-xmlrpc-1.1.jar" verbose="true" dest="${classpath_xmlrpc_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/mail.jar" verbose="true" dest="${build.libs}/mail.jar">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/Jama.jar" verbose="true" dest="${build.libs}/jama.jar">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/log4j.jar" verbose="true" dest="${classpath_log4j_file_name}">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/MRJClasses.zip" verbose="true" dest="${build.libs}/MRJClasses.zip">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/AppleJavaExtensions.jar" verbose="true" dest="${build.libs}/AppleJavaExtensions.jar">    </get>
    <get src="http://anon.inf.tu-dresden.de/develop/japdll.dll" verbose="true" dest="${build.libs}/japdll.dll"> </get>
    <get src="http://anon.inf.tu-dresden.de/develop/activation.jar" verbose="true" dest="${build.libs}/activation.jar"> </get>
    <get src="http://anon.inf.tu-dresden.de/develop/skype.jar" verbose="true" dest="${build.libs}/skype.jar"> </get>
   
    <get src="http://anon.inf.tu-dresden.de/develop/japdllversion.txt" verbose="true" dest="${build.libs}/japdllversion.txt">
    </get>
  </target>
  <target name="init" depends="init-libs"/>
<target name="dist-pre-compile">
  <!-- Use javac from Java1.3, because this compiler (at the moment) is the only one know
      to produce byte codes which could be processed by all java 1.1 compatible implementation
      Note: Java 1.4 and 1.5 are know to prodcue "bad" bytecode even if target="1.1" is specified!
      -->
   <property name="mycompilerversion" value="javac1.3">
   </property>
   <property name="mycompilerexecutable" value="${javac1.3.exe}">
   </property>
</target>
  <target name="release-pre-compile" depends="init,dist-pre-compile" description="set things so that we can compile a release version of JAP">
    <!-- Check whether the release flag was set to true ==> if this is not the case set it to relase and
    increment the version nubmer by one and set the date to the current date
    -->
    <loadfile srcfile="${src}/jap/JAPConstants.java" property="bIsReleaseVersion">
      <filterchain>
        <linecontains>
          <contains value="m_bReleasedVersion"/>
        </linecontains>
        <containsregex pattern="(.*)m_bReleasedVersion( )*=( )*([falsetru]*)(.*)" replace="\4"/>
        <deletecharacters chars="\r\n" />
      </filterchain>
    </loadfile>
    <echo message="Is Current Version as Release version: ${bIsReleaseVersion}"/>
    <loadfile srcfile="${src}/jap/JAPConstants.java" property="tmpCurrentVersion_LastValue">
      <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>
    <loadfile srcfile="${src}/jap/JAPConstants.java" property="tmpCurrentVersion_FirstPart">
      <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>
    <!-- Calculate current Date and new Version number with the help of a property file -->
    <delete file="${src}/build.number">
    </delete>
    <propertyfile file="${src}/build.number">
    <entry key="currentVersion_LastPart" value="1" operation="+" type="int" pattern="000" default="${tmpCurrentVersion_LastValue}"/>
    <entry key="releaseDate" default="now" type="date" pattern="yyyy/MM/dd HH:mm:ss">
    </entry>
    </propertyfile>
    <loadproperties srcfile="${src}/build.number">
    </loadproperties>
    <property name="currentVersion" value="${tmpCurrentVersion_FirstPart}${currentVersion_LastPart}">
    </property>
    <echo message="Current Version is: ${currentVersion}"/>
    <echo message="Current ReleaseDate is: ${releaseDate}"/>
    <!-- Replace the values in JAPConstant.java -->
    <replaceregexp file="${src}/jap/JAPConstants.java" byline="true" match="m_bReleasedVersion( )*=( )*false" replace="m_bReleasedVersion = true"></replaceregexp>
    <replaceregexp file="${src}/jap/JAPConstants.java" byline="true" match="static final String aktVersion( )*=( )*&quot;[0-9][0-9][\.][0-9][0-9][\.][0-9][0-9][0-9]&quot;" replace="static final String aktVersion = &quot;${currentVersion}&quot;"/>
    <replaceregexp file="${src}/jap/JAPConstants.java" byline="true" match="private static final String RELEASE_DATE = &quot;.*&quot;" replace="private static final String RELEASE_DATE = &quot;${releaseDate}&quot;"></replaceregexp>
    <touch file="${src}/jap/JAPConstants.java">    </touch>
  </target>
  <target name="compile" depends="init" description="compile the source ">
    <!-- Compile the java code from ${src} into ${build} -->
    <javac sourcepath=""  srcdir="${src}" excludes="${excludesSrcJap}"
    destdir="${build}"  classpathref="classpath_all" target="1.1" source="1.2" fork="yes" bootclasspathref="java_1_1_boot_classes" verbose="no" compiler="${mycompilerversion}" executable="${mycompilerexecutable}">
    <include name="**/*.java"/>
    </javac>

  </target>
  <target name="dist" depends="dist-pre-compile,compile,make-only-jap-jar" description="generate the distribution">  </target>
  <target name="make-only-jap-jar" depends="getcurrentjapdllversion">
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}"/>
    <jar jarfile="${dist}/JAP.jar" manifest="MANIFEST.MF" index="true" duplicate="preserve">
      <fileset dir="${build}" includes="**/*.class">
        <exclude name="jpi/**/*"/>
        <exclude name="infoservice/**/*"/>
        <exclude name="misc/**/*"/>
        <exclude name="captcha/**/*"/>
        <exclude name="jondonym/**/*"/>
       </fileset>
      <zipfileset dir="src" includes="JAPM*.properties"/>
      <zipfileset dir="src" includes="jap/*.html"/>
      <zipfileset dir="." includes="help/**/*"/>
      <zipfileset dir="." includes="images/**/*"/>
      <zipfileset dir="." includes="certificates/**/*"/>
      <zipfileset src="${classpath_httplib_file_name}"/>
      <zipfileset src="${classpath_xmllib_file_name}"/>
      <zipfileset src="${classpath_ftplib_file_name}"/>
      <zipfileset src="${classpath_log4j_file_name}"/>
      <zipfileset src="${classpath_bouncy_file_name}"/>
      <zipfileset src="${classpath_xmlrpc_file_name}"/>
      <zipfileset file="${build.libs}/japdll.dll" fullpath="japdll.dll.${currentJAPDllVersion}"/>
    </jar>
  </target>
  <target name="signJAP.jar" description="sings JAP.jar">
  <input message="Enter passwd for JAP signing key:" addproperty="japkeypass">
  </input>
  <signjar jar="${dist}/JAP.jar" verbose="true" alias="jap" storepass="useruser" keypass="useruser"
 sigfile="JAP-TEAM" keystore="/home/compile/.keystore">
  </signjar>
  </target>
  <target name="dist-release" depends="clean,release-pre-compile,dist,signJAP.jar" description="Generates a release version of JAP.jar(this mainly means that the JAP internal release flag is set to 'release'">  </target>
  <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="getcurrentjapdllversion" description="Sets the property 'currentJAPDllVersion' to the value provided on the Web">

    <loadfile srcfile="${build.libs}/japdllversion.txt" property="currentJAPDllVersion">
      <filterchain>
        <deletecharacters chars="\r\n" />
      </filterchain>
    </loadfile>
    <echo message="Current JAPDLL Version is: ${currentJAPDllVersion}"/>
  </target>
  <target name="sign-setup-files" description="Signes the setup files on the Web">
    <input message="Enter passwd for JAP setup files signing key:" addproperty="japsetupfileskeypass">
  </input>
  <exec executable="/home/www/make_sig.bat">
  <arg value="${japsetupfileskeypass}">
  </arg>
  </exec>
  </target>
  <target name="copy-jap-release-files-to-web">
    <!-- Copies the newly created JAP.jar to the Web-Server -->
    <copy file="${dist}/JAP.jar" todir="${japweb}/jap/">    </copy>
    <!-- Sets the new release version number according to JAPConstants.java -->
    <echo message="${currentVersion}" file="${japweb}/japversionstable.txt"/>
    <!-- Copy JAP.jar to the Tomcat directory for JAP Update functionality -->
    <copy file="${dist}/JAP.jar" tofile="${japtomcat}/signedJAP__V${currentVersion}.jar">
    </copy>
    <!-- Touch version.xml to make tomcat reread the JAP web-app -->
    <touch file="${japtomcat}/version.xml">
    </touch>
    <!-- Sets the new version number in the JavaWebStart/JAP Update japRelease.jnlp -->
    <replaceregexp file="${japrelease.jnlp}"
    match="version=&quot;([0-9][0-9][\.][0-9][0-9][\.][0-9][0-9][0-9])&quot;"
    replace="version=&quot;${currentVersion}&quot;" byline="true">
    </replaceregexp>
    <!-- Sets the new release date in the JavaWebStart/JAP Update japRelease.jnlp -->
    <replaceregexp file="${japrelease.jnlp}"
    match="releaseDate=&quot;([^&quot;]*)&quot;"
    replace="releaseDate=&quot;${releaseDate}&quot;" byline="true">
    </replaceregexp>

  </target>
  <target name="make-relase-jap-dmg">
    <exec executable="/home/compile/generation/test.japmac.dofinal"/>
  </target>
  <target name="new-jap-release-anon" depends="clean,dist-release,getcurrentversion,copy-jap-release-files-to-web,make-relase-jap-dmg,sign-setup-files" description="Makes a new release of JAP. Note: This target needs to be started on anon.inf.tu-dresden.de as root...">
  </target>
  <target name="clean" description="clean up">
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
    <!-- Delte unwante certifcates from source... -->
    <delete>
    <fileset dir="${certificates}" includes="**/*.cer.dev"/>
    </delete>    
    <!-- Delete unwanted source files (aka tests etc.) -->
    <delete dir="${src}/anon/tor/test"/>
    <delete dir="${src}/anon/crypto/tinytls/test"/>
    <delete dir="${src}/misc"/>
    
  </target>
	
	
	<target name="infoservice-init" depends="clean" 
			description="initializes folder structure for infoservice distribution">
		<mkdir dir="${build}" />
		<mkdir dir="${build}/infoservice" />
		<mkdir dir="${dist}" />
		<mkdir dir="${dist}/infoservice" />
	</target>
	
	<target name="infoservice-compile" depends="infoservice-init, init-libs"
			description="compiles infoservices sources">
		
		<javac 	srcdir="${src}" 
				destdir="${build}" 
				excludes="${infoservice-excludes}" 
				classpathref="classpath_all">
			
			<include name="**/*.java"/>
		</javac>
	</target>
	
	<target name="infoservice-dist" depends="infoservice-compile"
				description="creates infoservice binary distribution">
			
			<jar jarfile="${dist}/InfoService.jar" manifest="manifest_info.mf">
				<fileset dir="${build}" includes="**/*.class">
				        
				</fileset>
				<zipfileset src="${classpath_httplib_file_name}"/>
				<zipfileset src="${classpath_xmllib_file_name}"/>
				<zipfileset src="${classpath_ftplib_file_name}"/>
				<zipfileset src="${classpath_log4j_file_name}"/>
				<zipfileset src="${classpath_bouncy_file_name}"/>
				<zipfileset src="${classpath_xmlrpc_file_name}"/>
			
			</jar>
	</target>
	
	<target name="jap-gcj-clean">
	   <delete dir="${build.gcj}"/>
	</target>
	
	<target name="jap-gcj-init">
	<!-- Delet unecessary source files -->
	<delete dir="${src}/misc" />
	<delete dir="${src}/infoservice" />
	<delete dir="${src}/captcha" />
	<delete dir="${src}/platform/signal" />
	<delete dir="${src}/anon/tor/test"/>
	<delete dir="${src}/anon/crypto/tinytls/test"/>
	<delete file="${src}/JAPMacintosh.java" />
		<!-- Create the build directory structure used by compile -->
	  <mkdir dir="${build}"/>
	  <mkdir dir="${build.gcj}"/>
    <mkdir dir="${build.gcj.build}"/>
    <mkdir dir="${build.gcj.libs}"/>
    <!-- Copy JAP sources -->
		<copydir dest="${build.gcj.src}" src="${src}"></copydir>
		<!-- Get sources of libraries -->
	  <get src="http://anon.inf.tu-dresden.de/develop/ApacheFTPClient-1.3_for_JDK1.1.src.zip" verbose="true" dest="${build.gcj.libs}/ApacheFTPClient-1.3_for_JDK1.1.src.zip"></get>
	  <unzip src="${build.gcj.libs}/ApacheFTPClient-1.3_for_JDK1.1.src.zip" dest="${build.gcj.src}">
	   <patternset>
	   	 <include name="src/java/org/**/*.*" />
	   </patternset>
	   <mapper type="glob" from="src/java/org/*" to="org/*"/>
	  </unzip>
	  <get src="http://anon.inf.tu-dresden.de/develop/HTTPClient_src.zip" verbose="true" dest="${build.gcj.libs}/HTTPClient_src.zip"></get>
	  <unzip src="${build.gcj.libs}/HTTPClient_src.zip" dest="${build.gcj}">
	   <patternset>
	   	 <include name="src/**/*.*" />	   
	   	 <exclude name="src/HTTPClient/doc/**/*.*" />
	   </patternset>
	  </unzip>
	  <get src="http://anon.inf.tu-dresden.de/develop/BouncyCastleLightForJAP_src.zip" verbose="true" dest="${build.gcj.libs}/BouncyCastleLightForJAP_src.zip"></get>
	  <unzip src="${build.gcj.libs}/BouncyCastleLightForJAP_src.zip" dest="${build.gcj.src}">
	   <patternset>
	   	 <include name="org/**/*.*" />	   
	   </patternset>
	  </unzip>
	  <get src="http://anon.inf.tu-dresden.de/develop/log4j_src.zip" verbose="true" dest="${build.gcj.libs}/log4j_src.zip"></get>
	  <unzip src="${build.gcj.libs}/log4j_src.zip" dest="${build.gcj.src}">
	   <patternset>
	   	 <include name="java/org/**/*.*" />	   
	   </patternset>
	   <mapper type="glob" from="java/org/*" to="org/*"/>
	  </unzip>
	  <get src="http://anon.inf.tu-dresden.de/develop/ApacheXMLRPC_src.zip" verbose="true" dest="${build.gcj.libs}/ApacheXMLRPC_src.zip"></get>
	  <unzip src="${build.gcj.libs}/ApacheXMLRPC_src.zip" dest="${build.gcj}">
	   <patternset>
	   	 <include name="java/**/*.*" />	   
	   </patternset>
	   <mapper type="glob" from="java/*" to="src/*"/>
	  </unzip>

	</target>
	<target name="jap-gcj-compile" depends="jap-gcj-init">
	 <javac verbose="false" nowarn="true" debug="true" debuglevel="lines,vars,source" srcdir="${build.gcj.src}" destdir="${build.gcj.build}" compiler="gcj">
	 <compilerarg line="-combine -o JAP -fjni --main=JAP -Wno-deprecated -Wno-unused -g3"/>
	 </javac>
	</target>
	<target name="jap-gcj" depends="jap-gcj-clean,jap-gcj-compile">
	</target>
</project>
