build.xml

<!--
  JPPF.
   Copyright (C) 2005-2019 JPPF Team. 
  http://www.jppf.org

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project name='AndroidDemo' basedir="." default="dex.jar">

  <!-- ========================================================================= -->
  <!-- Property definitions                                                      -->
  <!-- ========================================================================= -->

  <property name="build.sysclasspath" value="last"/>
  <property name="shared"             value="${basedir}/../shared"/>
  <property name="lib"                value="${shared}/lib"/>
  <property name="config"             value="${basedir}/config"/>
  <property name="classes"            value="${basedir}/classes"/> 
  <property name="src"                value="${basedir}/src"/>
  <property file="${basedir}/build.properties"/>

  <!-- ========================================================================= -->
  <!-- Classpath definitions                                                     -->
  <!-- ========================================================================= -->

  <path id="project.classpath">
    <pathelement location="${classes}"/>
    <fileset dir="${lib}" includes="**/*.jar"/>
  </path>

  <!-- ========================================================================= -->
  <!-- Cleanup and init                                                          -->
  <!-- ========================================================================= -->

  <target name="clean">
    <delete dir="${classes}" quiet="true" includes="**/*.*"/>
  </target>

  <target name="init">
    <mkdir dir="${classes}"/>
  </target>

  <!-- ========================================================================= -->
  <!-- Compile                                                                   -->
  <!-- ========================================================================= -->

  <target name="compile" depends="clean, init">
    <javac srcdir="" destdir="${classes}" debug="on" deprecation="off" optimize="on" includes="**/*.java">
      <classpath refid="project.classpath"/>
      <compilerarg line="-Xlint:unchecked"/>
      <src path="${src}"/>
    </javac>
  </target>

  <!-- ========================================================================= -->
  <!-- Jar                                                                       -->
  <!-- ========================================================================= -->

  <!-- create a jar with only the classes required for the JPPF tasks -->
  <target name="jar" depends="compile" description="build the demo jar">
    <delete file="demo.jar" quiet="true"/>
    <jar jarfile="demo.jar">
      <fileset dir="${classes}" excludes="**/Runner.*"/>
    </jar>
  </target>
  
  <!-- create a jar in dex format from the previously generated Java jar file -->
  <target name="dex.jar" depends="jar" description="generate the demo jar in dex format">
    <delete file="dex-demo.jar" quiet="true"/>
    <dex in="demo.jar" out="dex-demo.jar"/>
    <delete file="demo.jar" quiet="true"/>
    <printmsg message="The file dex-demo.jar is now ready to be deployed"/>
  </target>
  
  <!-- ========================================================================= -->
  <!-- Macrodefs                                                                 -->
  <!-- ========================================================================= -->
  
  <!--
    Convert a list of Java jar files to a jar file in dex format.
    Attributes:
    - "in": the input file(s) to convert
    - "out": path to the output dexed jar file
    - "toolsDir": path to the Android tools folder: ANDROID_SDK_HOME/build-tools/<android_version>
      optional when "android.tools.home" is defined in the build.properties file
  -->

  <macrodef name="dex">
    <attribute name="in"/>
    <attribute name="out"/>
    <attribute name="toolsDir" default="${android.tools.home}"/>
    <sequential>
      <!-- compute the name of the dex command based on the OS -->
      <local name="cmd"/>
      <condition property="cmd" value="dx.bat" else="dx">
        <os family="windows"/>
      </condition>
      <!-- execute the dex command -->
      <exec executable="@{toolsDir}/${cmd}" failonerror="true" searchpath="true">
        <arg value="--dex"/>
        <arg value="--output=@{out}"/>
        <arg value="@{in}"/>
      </exec>
    </sequential>
  </macrodef>

  <!--
    Print a message to the console with a little bit of formatting.
    Attributes:
    - "message": the message to format and print
  -->

  <macrodef name="printmsg">
    <attribute name="message"/>
    <sequential>
      <echo/>
      <echo message="*** @{message} ***"/>
      <echo/>
    </sequential>
  </macrodef>

</project>