<?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="jme-gde" basedir=".">
    <description>Builds the module suite jme-gde.</description>
    <import file="nbproject/build-impl.xml"/>
    <!--Load ant extensions-->
    <path id="ant-import.classpath">
        <fileset dir="ant-lib/" includes="*.jar"/>
    </path>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="ant-import.classpath"/>
    <taskdef name="deb" classname="com.googlecode.ant_deb_task.Deb" classpathref="ant-import.classpath"/>
    <taskdef name="desktopentry" classname="com.googlecode.ant_deb_task.DesktopEntry" classpathref="ant-import.classpath"/>

    <!--override branding target to include netbeans config file creation, using this target makes sure init was called-->
    <target name="branding" depends="-create-netbeans-config, -set-base-version, -zip-templates, suite.branding">
    </target>

    <!--updates the help sets-->
    <target name="update-help-sets" description="Loads the wiki pages from the web and converts them to JavaHelp html for manual.">
        <ant antfile="build.xml" target="update-help-sets" inheritall="false" inheritrefs="false" dir="jme3-core/"/>
    </target>

    <target name="-create-netbeans-config">
        <!--replaces default values in jmonkeyplatform.conf file with run.args.extra from project.properties-->
        <mkdir dir="build/launcher/etc"/>
        <copy file="${harness.dir}/etc/app.conf" tofile="build/launcher/etc/${app.name}.conf">
            <filterchain>
                <replacestring from="$${branding.token}" to="${branding.token}"/>
                <replacestring from="$${APPNAME}/dev" to="$${APPNAME}/${app.version}"/>
                <replacestring from="-J-Xmx64m" to="${run.args.extra}"/>
            </filterchain>
        </copy>
    </target>

    <!--zips up the templates and adds them to the template project-->
    <target name="-zip-templates" description="Updates the template zip files">
        <zip basedir="BasicGameTemplate/" destfile="jme3-templates/src/com/jme3/gde/templates/BasicGameProject.zip">
            <exclude name="**/build/"/>
            <exclude name="**/dist/"/>
            <exclude name="**/nbproject/private/"/>
        </zip>
        <zip basedir="JME3TestsTemplate/" destfile="jme3-tests-template/src/com/jme3/gde/templates/tests/JmeTestsProject.zip">
            <exclude name="**/build/"/>
            <exclude name="**/dist/"/>
            <exclude name="**/nbproject/private/"/>
        </zip>
    </target>

    <target name="-set-base-version" description ="sets/unsets base version to major version for all plugins, updates branding version">
        <!--sets/unsets base version to major version (e.g. 3.0.1) for all plugins-->
        <foreach target="-do-base-version" list="${modules}" delimiter=":" param="module_dir" inheritall="true"/>
        <!--sets version to application branding files-->
        <replaceregexp file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties"
                        match="currentVersion=(.*)"
                        replace="currentVersion=${app.title} ${app.version}"
                        byline="true"/>
        <replaceregexp file="${basedir}/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties"
                        match="CTL_MainWindow_Title=(.*)"
                        replace="CTL_MainWindow_Title=${app.title} ${app.version}"
                        byline="true"/>
        <replaceregexp file="${basedir}/branding/modules/org-netbeans-core-windows.jar/org/netbeans/core/windows/view/ui/Bundle.properties"
                        match="CTL_MainWindow_Title_No_Project=(.*)"
                        replace="CTL_MainWindow_Title_No_Project=${app.title} ${app.version}"
                        byline="true"/>
        <!--propertyfile
            file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" 
            comment="Updated by build script">
            <entry key="currentVersion" value="${app.title} ${app.version}" />
        </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} ${app.version}" />
            <entry key="CTL_MainWindow_Title_No_Project" value="${app.title} ${app.version}" />
        </propertyfile-->
    </target>

    <target name="-do-base-version">
        <!--propertyfile
            file="${module_dir}/nbproject/project.properties"
            comment="Updated by build script">
            <entry key="spec.version.base" value="${plugins.version}" />
        </propertyfile-->
        <replaceregexp file="${module_dir}/nbproject/project.properties"
                        match="spec.version.base=(.*)"
                        replace="spec.version.base=${plugins.version}"
                        byline="true"/>
    </target>
    
    <!--
       ****************************************************************
       Only Relevant for building nightly on Hudson server from here on
       ****************************************************************
      -->
      
    <!--creates update center version via hudson build server-->
    <target name="hudson-nightly" depends="suite.clean, -revert-svn-changes, update-help-sets, set-impl-version, suite.nbms, unset-impl-version">
    </target>

    <target name="hudson-stable" depends="suite.clean, -revert-svn-changes, set-impl-version, suite.nbms, unset-impl-version">
    </target>
    
    <target name="set-impl-version">
        <property file="nbproject/project.properties"/>
        <antcall target="-create-jme3-svn-properties" inheritall="true">
            <param name="jme3_dir" value="../engine/"/>
        </antcall>
        <foreach target="-do-impl-version" list="${modules}" delimiter=":" param="module_dir" inheritall="true">
            <param name="set_impl_version" value="true"/>
        </foreach>
    </target>

    <target name="unset-impl-version">
        <property file="nbproject/project.properties"/>
        <foreach target="-do-impl-version" list="${modules}" delimiter=":" param="module_dir" inheritall="true">
            <param name="set_impl_version" value="false"/>
        </foreach>
    </target>

    <!--sets/unsets implementation version to svn revision for plugins-->
    <target name="-do-impl-version">
        <!--jme3 libraries-->
        <if>
            <or>
                <equals arg1="${module_dir}" arg2="jme3-core-libraries"/>
                <equals arg1="${module_dir}" arg2="jme3-project-libraries"/>
            </or>
            <then>
                <!--set jme3 libraries svn revision-->
                <property prefix="svn" file="build/jme3-lib-svn.properties"/>
            </then>
            <else>
                <!--jme3 core-->
                <if>
                    <or>
                        <equals arg1="${module_dir}" arg2="jme3-core-baselibs"/>
                        <equals arg1="${module_dir}" arg2="jme3-project-baselibs"/>
                    </or>
                    <then>
                        <!--set jme3 svn revision-->
                        <property prefix="svn" file="build/jme3-svn.properties"/>
                    </then>
                    <else>
                        <!--jme3 test data-->
                        <if>
                            <equals arg1="${module_dir}" arg2="jme3-project-testdata"/>
                            <then>
                                <!--set jme3 testdata svn revision-->
                                <property prefix="svn" file="build/jme3-testdata-svn.properties"/>
                            </then>
                            <else>
                                <!--jme3 tests-->
                                <if>
                                    <equals arg1="${module_dir}" arg2="jme3-tests-template"/>
                                    <then>
                                        <!--set jme3 tests svn revision-->
                                        <property prefix="svn" file="build/jme3-tests-svn.properties"/>
                                    </then>
                                    <!--"normal" module-->
                                    <else>
                                        <!--load svn revision of this modules folder if we are setting the value-->
                                        <if>
                                            <equals arg1="${set_impl_version}" arg2="true"/>
                                            <then>
                                                <exec executable="svn" output="build/${module_dir}-svn.properties" dir="${module_dir}">
                                                    <arg value="info" />
                                                </exec>
                                                <replace file="build/${module_dir}-svn.properties" token=" " value=""/>
                                            </then>
                                        </if>
                                        <!--set svn revision of module-->
                                        <property prefix="svn" file="build/${module_dir}-svn.properties"/>
                                    </else>
                                </if>
                            </else>
                        </if>
                    </else>
                </if>
            </else>
        </if>

        <if>
            <equals arg1="${set_impl_version}" arg2="true"/>
            <then>
                <echo>Setting implementation version for ${module_dir} to revision: ${svn.LastChangedRev}</echo>
                <replace  file="${module_dir}/manifest.mf" token="OpenIDE-Module-Implementation-Version: 0" value="OpenIDE-Module-Implementation-Version: ${svn.LastChangedRev}"/>
            </then>
            <else>
                <echo>Removing implementation version for ${module_dir} from revision: ${svn.LastChangedRev}</echo>
                <replace file="${module_dir}/manifest.mf" token="OpenIDE-Module-Implementation-Version: ${svn.LastChangedRev}" value="OpenIDE-Module-Implementation-Version: 0"/>
            </else>
        </if>

    </target>

    <!--reverts svn changes (in case the revision numbers haven't been reset-->
    <target name="-revert-svn-changes">
        <!--remove changes from jMP (old version numbers)-->
        <exec executable="svn" dir=".">
            <arg value="revert" />
            <arg value="." />
            <arg value="-R" />
        </exec>
        <!--update gde svn revision-->
        <exec executable="svn" dir=".">
            <arg value="update" />
        </exec>
    </target>

    <!--creates properties files containing svn info for the jme3 folders-->
    <target name="-create-jme3-svn-properties">
        <mkdir dir="build"/>
        <!--jme3 svn properties-->
        <exec executable="svn" dir="${jme3_dir}" output="build/jme3-svn.properties">
            <arg value="info" />
        </exec>
        <replace file="build/jme3-svn.properties" token=" " value=""/>
        <!--jme3 test data svn properties-->
        <exec executable="svn" dir="${jme3_dir}/src/test-data/" output="build/jme3-testdata-svn.properties">
            <arg value="info" />
        </exec>
        <replace file="build/jme3-testdata-svn.properties" token=" " value=""/>
        <!--jme3 libraries svn properties-->
        <exec executable="svn" dir="${jme3_dir}/lib/" output="build/jme3-lib-svn.properties">
            <arg value="info" />
        </exec>
        <replace file="build/jme3-lib-svn.properties" token=" " value=""/>
        <!--jme3 tests svn properties-->
        <exec executable="svn" dir="${jme3_dir}/src/test/" output="build/jme3-tests-svn.properties">
            <arg value="info" />
        </exec>
        <replace file="build/jme3-tests-svn.properties" token=" " value=""/>
    </target>

    <!--creates a debian package from the installer-->
    <target name="create-deb-package" depends="suite.build-zip">
        <unzip src="${dist.dir}/${app.name}.zip" dest="${dist.dir}/${app.name}">
            <globmapper from="${app.name}/*" to="*"/>
        </unzip>
        <desktopentry
            toFile="build/jmonkeyplatform.desktop"
            name="jMonkeyEngine3 GDE"
            comment="jMonkeyEngine3 Game Development Environment"
            exec="/usr/local/${app.name}/bin/${app.name}"
            icon="/usr/local/${app.name}/jmonkeyengine.png"
            categories="Development;Java"
        />
        <deb toDir="dist"
            package="jme3-sdk"
            version="${app.version}"
            section="devel"
            depends="sun-java6-jdk"
            maintainer="jMonkeyEngine"
            homepage="http://www.jmonkeyengine.com"
            postrm="debscripts/postrm"
            >
            <tarfileset dir="dist/${app.name}/" prefix="usr/local/${app.name}">
                <exclude name="bin/**"/>
            </tarfileset>
            <tarfileset dir="dist/${app.name}/bin" prefix="usr/local/${app.name}/bin" filemode="755">
                <exclude name="*.exe"/>
            </tarfileset>
            <tarfileset file="build/jmonkeyengine.desktop" prefix="usr/share/applications"/>
            <tarfileset file="jmonkeyengine.png" prefix="usr/local/${app.name}"/>
            <description synopsis="jMonkeyEngine3 Game Development Environment is a complete solution for Java OpenGL game development.">
jMonkeyEngine 3 was rebuilt from the ground up to be a modern 3D game engine,
compatible with OpenGL 2.0 and above.
Its architecture is shader-based, making it fully capable of current and
next generation graphics standards. The jMonkeyPlatform gives you a complete IDE
for coding and for managing and creating game assets.
            </description>
        </deb>
    </target>

</project>
