<?xml version="1.0"?>

<project name="proguard-example">
    <target name="postcompile">
<!-- This ant target can be used to provide an extension to the standard build chain
     in build_common.xml. This target named "postcompile" will override a target in
     build_common that's basically empty and will allow you to specify actions here
     for optimizers, obfuscators, etc.

     When this target is called, compiled class files will be found in the ${WORKING_CLASSES_ROOT}
     directory. This target can do any processing necessary as long as it's output files ultimately
     wind up back in ${WORKING_CLASSES_ROOT}. When this target exits, the remaining tool chain will
     take the files in ${WORKING_CLASSES_ROOT} and process them into bundles or pdm jars or whatever.


     **** Information on ProGuard ****

     ProGuard is a free, open source Java optimizer/obfuscator. In some testing, we've found that
     ProGuard can have a positive impact on an application's bundle size by shortening long class
     and method names, removing unused code, and other optimizations.

     ProGuard is available from http://proguard.sourceforge.net. This postcompile example 
     was tested using the 3.5 release of ProGuard (current at the time of this release).

     You can install ProGuard in any directory you like, but your build.xml file must
     define a PROGUARD_PATH variable to point to the proguard.jar file:

     <property name="PROGUARD_PATH" value="/home/fred/proguard/proguard.jar"/>

     By default this module looks for proguard.jar in ${DANGER_HOME}/tools/proguard3.5/lib/proguard.jar
     This path can be established simply by unzipping the proguard3.5.zip file directly
     into the hiptop-sdk/tools directory. By locating the proguard installation here, you do
     not need to define PROGUARD_PATH.

     To enable this module in your project, simply import this file into your project's build.xml:

     <import file="${DANGER_HOME}/tools/proguard.xml"/>

     Please add this <import> tag before the default import of build_common.xml at the bottom
     of the build.xml file.

     By default, the ProGuard setup below will not obfuscate the main classname of the
     application. You can optionally define another classname with PROGUARD_KEEP_LIST
     to keep an additional classname from being obfuscated. Generally, you shouldn't
     need to define this variable unless you have a specific need to un-obfuscate an 
     additional classname (such as a library entry point or something such).

-->

        <property name="WORKING_TEMP_ROOT" value="${WORKING_ROOT}/temp" />

		<condition property="PROGUARD_PATH" value="${DANGER_HOME}/tools/proguard3.5/lib/proguard.jar">
		    <not>
                <isset property="PROGUARD_PATH"/>
            </not>
        </condition>
	    <taskdef resource="proguard/ant/task.properties"
                 classpath="${PROGUARD_PATH}"/>

        <condition property="PROGUARD_JAVA_RUNTIME" value="${java.home}/../Classes/classes.jar">
            <os family="mac"/>
        </condition>
        <!-- the following only gets set if the above doesn't set the property -->
        <property name="PROGUARD_JAVA_RUNTIME" value="${env.JAVA_HOME}/jre/lib/rt.jar"/>

        <condition property="PROGUARD_KEEP_EXTRA_CLASSES" value="${PROGUARD_KEEP_LIST}">
            <isset property="PROGUARD_KEEP_LIST"/>
        </condition>
        <property name="PROGUARD_KEEP_EXTRA_CLASSES" value="none"/>

        <mkdir dir="${WORKING_TEMP_ROOT}"/>

        <!-- some debugging stuff, for debugging -->
        <echo>
ProGuard execution parameters:
    -injars ${WORKING_CLASSES_ROOT}
    -outjars ${WORKING_TEMP_ROOT}/proguard_temp.jar
    -keep public class ${APP_PACKAGE_NAME}.${APP_CLASS_NAME}
    -keep public class ${PROGUARD_KEEP_EXTRA_CLASSES}
    -allowaccessmodification
    -dontusemixedcaseclassnames
	-dontskipnonpubliclibraryclasses
    -libraryjars ${TARGET_LIB_ROOT}/library.jar
    -libraryjars ${PROGUARD_JAVA_RUNTIME}
    -printmapping ${WORKING_ROOT}/${APP_PROJECT_NAME}_${SCREEN}_${TARGET_LIB_BUILD}.pro.lst
    -verbose
</echo>
        <proguard>
            -injars ${WORKING_CLASSES_ROOT}
            -outjars ${WORKING_TEMP_ROOT}/proguard_temp.jar
            -keep public class ${APP_PACKAGE_NAME}.${APP_CLASS_NAME}
            -keep public class ${PROGUARD_KEEP_EXTRA_CLASSES}
            -allowaccessmodification
            -dontusemixedcaseclassnames
            -dontskipnonpubliclibraryclasses
            -libraryjars ${TARGET_LIB_ROOT}/library.jar
            -libraryjars ${PROGUARD_JAVA_RUNTIME}
            -printmapping ${WORKING_ROOT}/${APP_PROJECT_NAME}_${SCREEN}_${TARGET_LIB_BUILD}.pro.lst
            -verbose
        </proguard>

        <delete dir="${WORKING_CLASSES_ROOT}" failonerror="false" quiet="true" />

        <mkdir dir="${WORKING_CLASSES_ROOT}"/>
        <unjar src="${WORKING_TEMP_ROOT}/proguard_temp.jar" dest="${WORKING_CLASSES_ROOT}">
            <patternset includes="**/*.class" />
        </unjar>

        <delete file="${WORKING_TEMP_ROOT}/proguard_temp.jar" failonerror="false" quiet="true" />
    </target>

</project>
