<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See harness/README in the NetBeans platform -->
<!-- for some information on what you could do (e.g. targets to override). -->
<!-- If you delete this file and reopen the project it will be recreated. -->
<project name="alkitab" basedir=".">
    <description>Builds the module suite alkitab.</description>
    <import file="nbproject/build-impl.xml"/>
    
    <!-- override build to add custom.branding -->
    <target name="build" depends="build-brand,suite.build"/>
    
    <target name="build-brand" depends="-init">
        <!-- for automated build number, 
            do not forget the remove the app.buildnumber from project.properties
        <tstamp>
            <format property="app.buildnumber" pattern="yyyyMMddHHmm"/>
        </tstamp>
        <echo message="app.buildnumber: ${app.buildnumber}" />
        -->
        
        <propertyfile
            file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" 
            comment="Updated by build script">
            <entry key="currentVersion" value="${app.title.full} ${app.version} (Build ${app.buildnumber})" />
        </propertyfile>
        
        <propertyfile
            file="${basedir}/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties"
            comment="Updated by build script">
            <entry key="CTL_MainWindow_Title" value="${app.title.full}" />
            <entry key="CTL_MainWindow_Title_No_Project" value="${app.title.full}" />
        </propertyfile>
        
        <!-- Why i comment this, is it not needed anymore ???
        <propertyfile
            file="${basedir}/branding/modules/org-netbeans-core.jar/org/netbeans/core/ui/Bundle.properties" 
            comment="Updated by build script">
            <entry key="LBL_ProductInformation" value="${app.title.full}" />
        </propertyfile>
        -->
        
        <propertyfile
            file="${basedir}/../alkitab-core/src/kiyut/alkitab/Application.properties" 
            comment="Updated by build script">
            <entry key="title" value="${app.title}" />
            <entry key="title.full" value="${app.title.full}" />
            <entry key="buildnumber" value="${app.buildnumber}" />
            <entry key="version" value="${app.version}" />
            <entry key="debug" value="${app.debug}" />
        </propertyfile>
        
        <copy todir="${basedir}/branding/core/core.jar/org/netbeans/core/startup/" overwrite="true">
            <fileset dir="${basedir}">
                <include name="frame.gif"/>
                <include name="frame32.gif"/>
                <include name="frame48.gif"/>
            </fileset>
        </copy>
        
    </target>
    
    <target name="build-installer" description="Create Installer" depends="clean,build-zip">
        <echo message="Setting property and task for installer creation" />
        <property name="redist-books" value="redist-books"/>
        <property name="nbdist.dir" value="dist"/>
        <property name="nbdist-app.dir" value="${nbdist.dir}/${app.name}"/>
        <property name="nbdist-app-installer" value="${app.name}-${app.version.dash}.zip"/> 
        <property name="nbdist-izpack.dir" value="${nbdist.dir}/izpack"/>
        <property name="nbdist-izpack-packs.dir" value="packs"/>
        <property name="nbdist-izpack-app-core.pack" value="${app.title}-${app.version.dash}"/>
        <property name="izpack-installer" value="setup.jar"/>
        <property name="izpack.dir" value="/home/tonny/opt/IzPack"/>
        <taskdef name="izpack" classpath="${izpack.dir}/lib/standalone-compiler.jar" 
            classname="com.izforge.izpack.ant.IzPackTask"/>
        
        <echo message="=================" />
        <echo message="STEP 1" />
        <echo message="=================" />

        <unzip src="${nbdist.dir}/${app.name}.zip" dest="${nbdist.dir}"/>

        <copy todir="${nbdist-app.dir}/legal">
            <fileset dir="legal"/>
        </copy>

        <copy todir="${nbdist-app.dir}/${app.name}">
            <fileset dir="installer/icons"/>
        </copy>
        
        <copy file="installer/readme.html" todir="${nbdist-app.dir}"/>
        <replace file="${nbdist-app.dir}/readme.html">
            <replacefilter token="$${app.version}" value="${app.version}" />
        </replace>
        
        <replace file="${nbdist-app.dir}/etc/${app.name}.conf">
            <!-- new since Nb 6.7 -->
            <replacefilter token="$${APPNAME}" value="${app.name}" />
            
            <replacefilter token="/dev" value="/${app.version}" />
            <replacefilter token="-J-Xms24m -J-Xmx64m" value="${run.args.extra}" />
        </replace>
        
        <delete file="${nbdist-app.dir}/DISTRIBUTION.txt"/>
        <delete file="${nbdist-app.dir}/LICENSE.txt"/>
        
        <echo message="=================" />
        <echo message="STEP 2" />
        <echo message="=================" />
        
        <mkdir dir="${nbdist-izpack.dir}/packs" />
        
        <echo message="Create core app pack" />
        
        <!-- XXX Izpack Bug when loose=true and unpack=true
        <zip destfile="${nbdist-izpack.dir}/packs/${nbdist-izpack-app-core.pack}" basedir="${nbdist-app.dir}" />
        <copy todir="${nbdist-izpack.dir}/packs">
            <fileset dir="${basedir}/../../redist-books"/>
        </copy>
        -->
        <copy todir="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/${nbdist-izpack-app-core.pack}">
            <fileset dir="${nbdist-app.dir}" />
        </copy>
        
        <copy todir="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/${nbdist-izpack-app-core.pack}/Uninstaller">
            <fileset dir="installer/izpack" >
                <include name="uninstaller"/>
                <include name="uninstaller.exe"/>
            </fileset>
        </copy>
        
        <echo message="Copying books to be included with installer" />
        <unzip src="${basedir}/../../redist-books/KJV.zip" dest="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/KJV"/>
        <unzip src="${basedir}/../../redist-books/StrongsGreek.zip" dest="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/StrongsGreek"/>
        <unzip src="${basedir}/../../redist-books/StrongsHebrew.zip" dest="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/StrongsHebrew"/>
        <unzip src="${basedir}/../../redist-books/Robinson.zip" dest="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/Robinson"/>
        <unzip src="${basedir}/../../redist-books/Institutes.zip" dest="${nbdist-izpack.dir}/${nbdist-izpack-packs.dir}/Institutes"/>

        <copy todir="${nbdist-izpack.dir}">
            <fileset dir="installer/izpack" />
        </copy>
        
        <replace file="${nbdist-izpack.dir}/izpack-install-script.xml">
            <replacefilter token="$${app.title.full}" value="${app.title.full}" />
            <replacefilter token="$${app.title}" value="${app.title}" />
            <replacefilter token="$${app.version}" value="${app.version}" />
            <replacefilter token="$${app.path}" value="Kiyut/Alkitab-${app.version.dash}" />
            <replacefilter token="$${app-core.pack}" value="${nbdist-izpack-app-core.pack}" />
            <replacefilter token="$${packs.dir}" value="${nbdist-izpack-packs.dir}" />
        </replace>
        <replace file="${nbdist-izpack.dir}/shortcutSpecWindows.xml">
            <replacefilter token="$${app.name}" value="${app.name}" />
            <replacefilter token="$${app.title.full}" value="${app.title.full}" />
            <replacefilter token="$${app.version}" value="${app.version}" />
        </replace>
        <replace file="${nbdist-izpack.dir}/shortcutSpecUnix.xml">
            <replacefilter token="$${app.name}" value="${app.name}" />
            <replacefilter token="$${app.title.full}" value="${app.title.full}" />
            <replacefilter token="$${app.version}" value="${app.version}" />
        </replace>
        
        <echo message="=================" />
        <echo message="STEP 3" />
        <echo message="=================" />
        
        <copy file="${nbdist-app.dir}/readme.html" todir="${nbdist-izpack.dir}"/>
        <copy file="${nbdist-app.dir}/legal/LICENSE-alkitab.txt" todir="${nbdist-izpack.dir}"/>
        
        <echo message="Makes the installer using IzPack to ${izpack-installer}"/>
            <izpack input="${basedir}/${nbdist-izpack.dir}/izpack-install-script.xml"
                output="${basedir}/${nbdist-izpack.dir}/${izpack-installer}"  
                installerType="standard"              
                basedir="${basedir}/${nbdist-izpack.dir}"
                izPackDir="${izpack.dir}/"/>
        
        <zip destfile="${nbdist.dir}/${nbdist-app-installer}">
            <zipfileset dir="${nbdist-izpack.dir}">
                <include name="readme.html"/>
                <include name="setup.exe"/>
                <include name="${izpack-installer}"/>
                <include name="packs/**"/>
            </zipfileset>
            <zipfileset dir="${nbdist-izpack.dir}" filemode="755">
                <include name="setup"/>
            </zipfileset>
        </zip>

        <echo message="" />
        <echo message="app.buildnumber: ${app.buildnumber}" />
        <echo message="Release: ${nbdist-app-installer}" />
        
        <echo message="=================" />
        <echo message="FINISH" />
        <echo message="=================" />
        
    </target>
    
    <!-- override to add add legal, icons, and some stuffs -->
    <target name="build-mac" description="Create Mac OSX Installer" depends="suite.build-mac">
        <property name="nbdist.dir" value="dist"/>
        <property name="nbdist-contents.dir" value="${nbdist.dir}/${app.name}.app/Contents"/>
        <property name="nbdist-resources.dir" value="${nbdist-contents.dir}/Resources"/>
        <property name="nbdist-app.dir" value="${nbdist-resources.dir}/${app.name}"/>
        <property name="nbdist-app-installer" value="${app.name}-${app.version.dash}-mac.zip"/>
        
        <delete file="${nbdist-app.dir}/DISTRIBUTION.txt"/>
        <delete file="${nbdist-app.dir}/LICENSE.txt"/>
        
        <copy todir="${nbdist-app.dir}/legal">
            <fileset dir="legal"/>
        </copy>

        <delete file="${nbdist-resources.dir}/${app.name}.icns"/>
        <copy tofile="${nbdist-resources.dir}/${app.name}.icns" file="installer/icons/${app.name}.icns" />
        
        <replace file="${nbdist-app.dir}/etc/${app.name}.conf">
            <replacefilter token="/dev" value="/${app.version}" />
            <replacefilter token="-J-Xms24m -J-Xmx64m" value="${run.args.extra}" />
        </replace>
        
        <!-- rename alkitab.app to Alkitab.app, use unix mv command to keep symbolic link -->
        <!-- <move file="${nbdist.dir}/${app.name}.app" tofile="${nbdist.dir}/${app.title}.app"/> -->
        <delete dir="${nbdist.dir}/${app.title.full}.app"/>
        <exec dir="${nbdist.dir}" executable="mv">
            <arg line="${app.name}.app &quot;${app.title.full}.app&quot;"/>
        </exec>
        
        <!-- <delete file="${nbdist.dir}/${nbdist-app-installer}"/> -->
        <exec dir="${nbdist.dir}" executable="zip">
            <arg line="-yr ${nbdist-app-installer} &quot;${app.title.full}.app&quot;"/>
        </exec>
        
    </target>
    
</project>
