<?xml version="1.0" encoding="ISO-8859-1"?>

<project basedir=".." default="all" name="All">


  <target name="init" description="inits the build">

    <property environment="env" />

    <property name="build.dir" value="build" />

    <!-- read build number -->
    <buildnumber file="${build.dir}/BUILD" />
    <xmlproperty file="plugin.xml" collapseattributes="true" />

    <!-- create scm tag -->
    <propertyfile file="${build.dir}/TAG">
      <entry key="mytag" value="${system.version}" />
    </propertyfile>
    <replaceregexp flags="g" file="${build.dir}/TAG" match="\." replace="_" />
    <loadproperties srcFile="${build.dir}/TAG" />
    <delete file="${build.dir}/TAG" />
    <property name="tag" value="V_${mytag}_BUILD_${build.number}" />

    <loadproperties srcFile="${build.dir}/build.properties" />

    <available file="${signjar.keystore}" type="file" property="havekeystore" />

    <echo message="VERSION: ${system.version}" />
    <echo message="Tag    : ${tag}" />
    <echo message="BUILD  : ${build.number}" />
    <echo message="JAVA   : ${java.version}" />

    <path id="compilepath">
      <fileset dir="lib">
        <include name="**/*.jar" />
      </fileset>
    </path>
  </target>

  <target depends="init" name="update" description="performs scm update">
    <exec executable="git" failonerror="true" dir="${basedir}">
      <arg line="pull" />
    </exec>
  </target>



  <target depends="init" name="compile" description="compiles everything">

    <mkdir dir="${class.dir}" />

    <javac debug="true" includeantruntime="false" debuglevel="lines,vars,source" source="${define.java.version}" target="${define.java.version}" encoding="${define.encoding}" deprecation="true" destdir="${class.dir}" srcdir="${src.dir}">
      <classpath refid="compilepath" />
    </javac>

    <copy todir="${class.dir}/img">
      <fileset dir="${icon.dir}" />
    </copy>
    <copy todir="${class.dir}/lang">
      <fileset dir="${lang.dir}" />
    </copy>
    <copy todir="${class.dir}/help">
      <fileset dir="${help.dir}" />
    </copy>
  </target>



  <target depends="compile" name="tag" description="tags the source in the scm">

    <exec executable="git" failonerror="true" dir="${basedir}">
      <arg line="tag -m ${tag} ${tag}" />
    </exec>

    <exec executable="git" failonerror="true" dir="${basedir}">
      <arg line="push origin ${tag}" />
    </exec>

  </target>


  <target depends="compile" name="jar" description="generates the jar files">

    <mkdir dir="${project.release}" />
    <mkdir dir="${project.zipdir}" />

    <!-- Erzeugt ${DSTAMP} -->
    <tstamp />

    <!-- Die plattformneutrale JAR-Datei mit allen Klassen -->
    <jar destfile="${project.zipdir}/${define.jarfilename}">
      <manifest>
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Built-Date" value="${DSTAMP}" />
        <attribute name="Implementation-Title" value="${define.projectname}" />
        <attribute name="Implementation-Version" value="${system.version}" />
        <attribute name="Implementation-Buildnumber" value="${build.number}" />
      </manifest>
      <fileset dir="${class.dir}" />
    </jar>
    <antcall target="sub_jar_sign">
      <param name="param.filename" value="${define.jarfilename}" />
    </antcall>


    <!-- Die plattformspezifischen JAR-Dateien mit dem Classpath des OS -->
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.linux}" />
      <param name="param.classpath" value="${classpath.linux}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.linux64}" />
      <param name="param.classpath" value="${classpath.linux64}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.linuxarm64}" />
      <param name="param.classpath" value="${classpath.linuxarm64}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.win32}" />
      <param name="param.classpath" value="${classpath.win32}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.win64}" />
      <param name="param.classpath" value="${classpath.win64}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.macos64}" />
      <param name="param.classpath" value="${classpath.macos64}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.macosaarch64}" />
      <param name="param.classpath" value="${classpath.macosaarch64}" />
    </antcall>
    <antcall target="sub_jar_create">
      <param name="param.filename" value="${define.jarfilename.openbsd}" />
      <param name="param.classpath" value="${classpath.openbsd}" />
    </antcall>
  </target>

  <target depends="jar" name="zip" description="generates the zip files">

    <mkdir dir="${project.zipdir}/lib" />
    <mkdir dir="${project.zipdir}/plugins" />

    <copy todir="${project.zipdir}/lib">
      <fileset dir="lib" />
    </copy>

    <copy todir="${project.zipdir}">
      <fileset dir="${build.dir}">
        <include name="*.sh" />
        <include name="*.exe" />
        <include name=".jameica" />
        <include name="rcjameica*" />
        <include name="jameica.service" />
        <include name="jameica-icon.png" />
        <include name="jameica-icon.icns" />
        <include name="README" />
        <include name="Info*.plist" />
      </fileset>
      <fileset dir="${basedir}">
        <include name="LICENSE" />
        <include name="COPYING" />
      </fileset>
    </copy>
    <copy file="plugin.xml" todir="${project.zipdir}" />
    
    <!-- Embedded JREs -->
    <antcall target="sub_addjre_zip">
      <param name="param.target" value="${project.zipdir}/jre-win64" />
      <param name="param.source" value="${define.jre.win64}" />
    </antcall>
    <antcall target="sub_addjre_zip">
      <param name="param.target" value="${project.zipdir}/jre-win32" />
      <param name="param.source" value="${define.jre.win32}" />
    </antcall>
    <antcall target="sub_addjre_tar">
      <param name="param.target" value="${project.zipdir}/jre-macos64" />
      <param name="param.source" value="${define.jre.macos64}" />
    </antcall>
    <antcall target="sub_addjre_tar">
      <param name="param.target" value="${project.zipdir}/jre-macosaarch64" />
      <param name="param.source" value="${define.jre.macosaarch64}" />
    </antcall>

    <!-- ZIP-File fuer Linux -->
    <zip destfile="${project.release}/${project.zipfilename.linux}" duplicate="fail">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.linux}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/.jameica" />
        <include name="${define.projectname}/jameica-icon.png" />
        <include name="${define.projectname}/jameica.service" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />

        <exclude name="${define.projectname}/lib/swt/win*/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/lib/swt/linux64/**" />
        <exclude name="${define.projectname}/lib/swt/linux-arm64/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
      <zipfileset dir="${project.release}" filemode="755">
        <include name="${define.projectname}/jameica.sh" />
        <include name="${define.projectname}/jameicaserver.sh" />
        <include name="${define.projectname}/rcjameica*" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer Linux64 -->
    <zip destfile="${project.release}/${project.zipfilename.linux64}" duplicate="fail">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.linux64}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/.jameica" />
        <include name="${define.projectname}/jameica-icon.png" />
        <include name="${define.projectname}/jameica.service" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />

        <exclude name="${define.projectname}/lib/swt/win*/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/lib/swt/linux/**" />
        <exclude name="${define.projectname}/lib/swt/linux-arm64/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
      <zipfileset dir="${project.release}" filemode="755">
        <include name="${define.projectname}/jameica.sh" />
        <include name="${define.projectname}/jameicaserver.sh" />
        <include name="${define.projectname}/rcjameica*" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer Linux-ARM64 -->
    <zip destfile="${project.release}/${project.zipfilename.linuxarm64}" duplicate="fail">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.linuxarm64}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/.jameica" />
        <include name="${define.projectname}/jameica-icon.png" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />

        <exclude name="${define.projectname}/lib/swt/win*/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/lib/swt/linux/**" />
        <exclude name="${define.projectname}/lib/swt/linux64/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
      <zipfileset dir="${project.release}" filemode="755">
        <include name="${define.projectname}/jameica.sh" />
        <include name="${define.projectname}/jameicaserver.sh" />
        <include name="${define.projectname}/rcjameica*" />
      </zipfileset>
    </zip>

    <zip destfile="${project.release}/${project.zipfilename.win32}">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.win32}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/jameica-win32.exe" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />
        <include name="${define.projectname}/jre-win32/**" />

        <exclude name="${define.projectname}/lib/swt/win64/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/lib/swt/linux*/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer Win64 -->
    <zip destfile="${project.release}/${project.zipfilename.win64}">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.win64}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/jameica-win64.exe" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />
        <include name="${define.projectname}/jre-win64/**" />

        <exclude name="${define.projectname}/lib/swt/win32/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/lib/swt/linux*/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer MacOS64 -->
    <delete dir="${project.tmp}/${define.projectname}.app" />
    <mkdir dir="${project.tmp}/${define.projectname}.app" />
    <copy todir="${project.tmp}/${define.projectname}.app">
      <fileset dir="${project.release}/${define.projectname}">
        <include name="plugin.xml" />
        <include name="${define.jarfilename}" />
        <include name="${define.jarfilename.macos64}" />
        <include name="LICENSE" />
        <include name="COPYING" />
        <include name="README" />
        <include name="Info.plist" />
        <include name="jameica-macos64.sh" />
        <include name="jameica-icon.icns" />
        <include name="plugins" />
        <include name="jre-macos64/**" />
        <include name="lib/**" />
        <exclude name="Info-aarch64.plist" />
        <exclude name="lib/swt/win*/**" />
        <exclude name="lib/swt/linux*/**" />
        <exclude name="lib/swt/macos-aarch64/**" />
      </fileset>
    </copy>
    <zip destfile="${project.release}/${project.zipfilename.macos64}">
      <zipfileset dir="${project.tmp}" filemode="755">
        <include name="${define.projectname}.app/**" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer MacOSAArch64 -->
    <delete dir="${project.tmp}/${define.projectname}.app" />
    <mkdir dir="${project.tmp}/${define.projectname}.app" />
    <copy todir="${project.tmp}/${define.projectname}.app">
      <fileset dir="${project.release}/${define.projectname}">
        <include name="plugin.xml" />
        <include name="${define.jarfilename}" />
        <include name="${define.jarfilename.macosaarch64}" />
        <include name="LICENSE" />
        <include name="COPYING" />
        <include name="README" />
        <include name="Info-aarch64.plist" />
        <include name="jameica-macos-aarch64.sh" />
        <include name="jameica-icon.icns" />
        <include name="plugins" />
        <include name="jre-macosaarch64/**" />
        <include name="lib/**" />
        <exclude name="Info.plist" />
        <exclude name="lib/swt/win*/**" />
        <exclude name="lib/swt/linux*/**" />
        <exclude name="lib/swt/macos64/**" />
      </fileset>
    </copy>
    <move file="${project.tmp}/${define.projectname}.app/Info-aarch64.plist" tofile="${project.tmp}/${define.projectname}.app/Info.plist" />
    <zip destfile="${project.release}/${project.zipfilename.macosaarch64}">
      <zipfileset dir="${project.tmp}" filemode="755">
        <include name="${define.projectname}.app/**" />
      </zipfileset>
    </zip>

    <!-- ZIP-File fuer OpenBSD -->
    <zip destfile="${project.release}/${project.zipfilename.openbsd}" duplicate="fail">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/plugin.xml" />
        <include name="${define.projectname}/${define.jarfilename}" />
        <include name="${define.projectname}/${define.jarfilename.openbsd}" />
        <include name="${define.projectname}/LICENSE" />
        <include name="${define.projectname}/COPYING" />
        <include name="${define.projectname}/README" />
        <include name="${define.projectname}/jameica-icon.png" />
        <include name="${define.projectname}/plugins" />
        <include name="${define.projectname}/lib/**" />

        <exclude name="${define.projectname}/lib/swt/win*/**" />
        <exclude name="${define.projectname}/lib/swt/linux*/**" />
        <exclude name="${define.projectname}/lib/swt/macos*/**" />
        <exclude name="${define.projectname}/*.icns" />
        <exclude name="${define.projectname}/*.plist" />
      </zipfileset>
      <zipfileset dir="${project.release}" filemode="755">
        <include name="${define.projectname}/jameica-openbsd.sh" />
      </zipfileset>
    </zip>

    <!-- ZIP-File mit allen Betriebssystemen -->
    <zip destfile="${project.release}/${project.zipfilename}" duplicate="fail">
      <zipfileset dir="${project.release}">
        <include name="${define.projectname}" />
        <include name="${define.projectname}/**" />
        <exclude name="${define.projectname}/*.sh" />
        <exclude name="${define.projectname}/rcjameica*" />
      </zipfileset>
      <zipfileset dir="${project.release}" filemode="755">
        <include name="${define.projectname}/*.sh" />
        <include name="${define.projectname}/rcjameica*" />
      </zipfileset>
    </zip>


  </target>


  <target depends="compile" name="src" description="build source package, depends compile target to make sure, the code has no errors">
    <mkdir dir="${project.release}" />
    <mkdir dir="${project.tmp}/${define.projectname}" />
    <copy todir="${project.tmp}/${define.projectname}">
      <fileset dir="${basedir}">
        <include name=".project" />
        <include name=".classpath" />
        <include name="plugin.xml" />
        <include name="LICENSE" />
        <include name="COPYING" />
        <include name="lib/**" />
        <include name="test/**" />
        <include name="${src.dir}/**" />
        <include name="${build.dir}/**" />
        <exclude name="${build.dir}/BUILD" />
      </fileset>
    </copy>
    <zip casesensitive="true" zipfile="${project.release}/${define.srcfilename}">
      <fileset dir="${project.tmp}">
        <include name="${define.projectname}/**" />
      </fileset>
    </zip>
  </target>

  <target depends="compile" name="javadoc" description="creates the api doc">

    <mkdir dir="${project.javadoc}" />

    <javadoc charset="${define.encoding}" docencoding="${define.encoding}" encoding="${define.encoding}" destdir="${project.javadoc}" packagenames="${define.package}.*" source="${define.java.version}">
      <classpath refid="compilepath" />
      <sourcepath>
        <pathelement location="${src.dir}" />
      </sourcepath>
    </javadoc>

    <zip casesensitive="true" zipfile="${project.release}/${define.javadocfilename}">
      <fileset dir="${project.javadoc}">
        <include name="**" />
      </fileset>
    </zip>

  </target>


  <target name="clean" description="cleanup">
    <delete dir="${project.tmp}" />
    <delete dir="${project.zipdir}" />
    <delete dir="${project.javadoc}" />
  </target>


  <target name="sign" description="signs the jar/zip file">
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${define.srcfilename}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.win32}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.win64}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.linux}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.linux64}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.linuxarm64}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.macos64}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.macosaarch64}" />
    <checksum format="MD5SUM" algorithm="SHA" file="${project.release}/${project.zipfilename.openbsd}" />

    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${define.srcfilename}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.win32}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.win64}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.linux}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.linux64}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.linuxarm64}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.macos64}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.macosaarch64}" />
    <checksum format="MD5SUM" algorithm="SHA-256" file="${project.release}/${project.zipfilename.openbsd}" />

    <echo message="Creating PGP signatures" />

    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${define.srcfilename}" />
    </exec>

    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.win32}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.win64}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.linux}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.linux64}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.linuxarm64}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.macos64}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.macosaarch64}" />
    </exec>
    <exec executable="gpg" failonerror="true" timeout="60000">
      <arg line="-asb --use-agent ${project.release}/${project.zipfilename.openbsd}" />
    </exec>
  </target>


  <target depends="init,compile,tag,jar,zip,javadoc,src,sign,lib,clean" description="build an official release" name="all" />

  <target depends="init,compile,jar,zip,src,lib,clean" description="build inofficial release" name="fast" />

  <target depends="init,compile,jar,zip,javadoc,src" description="build nightly build" name="nightly">
    <mkdir dir="${project.nightly}" />

    <copy file="${project.release}/${project.zipfilename}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.linux}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.linux64}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.linuxarm64}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.macos64}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.macosaarch64}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.win32}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.win64}" todir="${project.nightly}" />
    <copy file="${project.release}/${project.zipfilename.openbsd}" todir="${project.nightly}" />


    <copy file="${project.release}/${define.srcfilename}" todir="${project.nightly}" />
    <antcall target="lib"/>

    <delete dir="${project.release}" />
  </target>
  
  <target name="lib">
    <!-- Die Datei brauchen die anderen Plugins zum Kompilieren //-->
    <copy file="${project.zipdir}/${define.jarfilename}" tofile="releases/jameica-lib.jar" />
  </target>




  <!-- Sub-Routinen -->

  <!--
    Fuegt das Embedded JRE aus einem ZIP hinzu
    @param.target: Zielordner fuer das JRE
    @param.source: Quelldatei mit dem ZIP des JRE
  //-->
  <target name="sub_addjre_zip" if="jre.embedd">
    <echo message="embedding JRE ${param.source} to ${param.target}"></echo>
    <mkdir dir="${param.target}" />
    <unzip dest="${param.target}" src="${param.source}">
      <cutdirsmapper dirs="1" />
    </unzip>
  </target>

  <!--
    Fuegt das Embedded JRE aus einem TAR.GZ hinzu
    @param.target: Zielordner fuer das JRE
    @param.source: Quelldatei mit dem TAR.GZ des JRE
  //-->
  <target name="sub_addjre_tar" if="jre.embedd">
    <echo message="embedding JRE ${param.source} to ${param.target}"></echo>
    <mkdir dir="${param.target}" />
    <untar compression="gzip" dest="${param.target}" src="${param.source}">
      <cutdirsmapper dirs="1" />
    </untar>
  </target>

  <!--
    Erzeugt die plattform-spezifische JAR-Datei
    @param param.filename Dateiname der zu erzeugenden JAR-Datei
    @param param.classpath Classpath, der im Manifest angegeben werden soll
  //-->
  <target name="sub_jar_create">
    <jar destfile="${project.zipdir}/${param.filename}">
      <manifest>
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Built-Date" value="${DSTAMP}" />
        <attribute name="Implementation-Title" value="${define.projectname}" />
        <attribute name="Implementation-Version" value="${system.version}" />
        <attribute name="Implementation-Buildnumber" value="${build.number}" />
        <attribute name="Main-Class" value="de.willuhn.jameica.Main" />
        <attribute name="Class-Path" value="${param.classpath}" />
      </manifest>
      <fileset dir="${class.dir}" includes="**/Main.class" />
    </jar>

    <!-- Signieren der JAR-Datei - aber nur, wenn der Keystore existiert -->
    <antcall target="sub_jar_sign">
      <param name="param.filename" value="${param.filename}" />
    </antcall>
  </target>

  <!--
    Signiert die JAR-Datei.
    @param param.filename Dateiname der zu signierenden JAR-Datei
  //-->
  <target name="sub_jar_sign" if="havekeystore">
    <loadfile property="storepass" srcFile="${signjar.storepass}" />
    <exec executable="jarsigner" failonerror="true" timeout="60000">
      <arg line="-verbose -keystore ${signjar.keystore} -storepass ${storepass} ${project.zipdir}/${param.filename} &quot;${signjar.alias}&quot;" />
    </exec>
  </target>
</project>
