view build.xml @ 33:3d86f0391168

Work on improving the build system.
author David Barts <davidb@stashtea.com>
date Fri, 24 Apr 2020 19:45:57 -0700
parents 985d5b82a882
children d175593317a8
line wrap: on
line source

<?xml version="1.0" encoding="UTF-8"?>
<project name="JpegWasher" default="help" basedir="."
  xmlns:contrib="antlib:net.sf.antcontrib"
  xmlns:jarbundler="antlib:com.ultramixer.jarbundler"
  xmlns:launch4j="antlib:net.sf.launch4j.ant"
  xmlns:mod="antlib:de.masters_of_disaster.ant.tasks">
  <!-- import all environment variables as env.* -->
  <property environment="env"/>

  <!-- ensure required environment variables are set -->
  <macrodef name="env-require">
    <attribute name="name"/>
    <sequential>
      <fail message="Environment variable @{name} not set!">
        <condition>
          <not><isset property="env.@{name}"/></not>
        </condition>
      </fail>
    </sequential>
  </macrodef>
  <env-require name="JRE_HOME"/>
  <env-require name="KOTLIN_HOME"/>

  <!-- load launch4j (Windows app builder) -->
  <!-- load m-o-d (Linux Gnome app builder) -->

  <!-- cribbed from https://stackoverflow.com/questions/7129672/uppercase-lowercase-capitalize-an-ant-property -->
  <scriptdef language="javascript" name="toLowerCase">
    <attribute name="value" />
    <attribute name="target" />
    <![CDATA[
      project.setProperty( attributes.get( "target" ),
                           attributes.get( "value" ).toLowerCase() );
    ]]>
  </scriptdef>

  <!-- Define the properties used by the build -->
  <property name="app.name"      value="${ant.project.name}"/>
  <property name="app.version"   value="1.03"/>
  <property name="app.entry"     value="name.blackcap.exifwasher.MainKt"/>
  <toLowerCase target="lc.app.name" value="${app.name}"/>
  <property name="jar.name"      value="${basedir}/${lc.app.name}.jar"/>
  <property name="work.jar"      value="${basedir}/work.jar"/>
  <property name="lib.home"      value="${basedir}/lib"/>
  <property name="src.home"      value="${basedir}/src"/>
  <property name="nat.dir"       value="${src.home}/name/blackcap/exifwasher/exiv2"/>
  <property name="bin.dir"       value="${src.home}/name/blackcap/exifwasher/binaries"/>

  <!-- load the ant-contrib tasks -->
  <taskdef resource="net/sf/antcontrib/antlib.xml"
           uri="antlib:net.sf.antcontrib">
    <classpath>
      <fileset dir="${lib.home}/ant-contrib" includes="*.jar"/>
    </classpath>
  </taskdef>

  <!-- load jarbundler (Mac app bundler) tasks -->
  <contrib:if>
    <os family="mac"/>
    <contrib:then>
      <taskdef name="create"
               classname="com.ultramixer.jarbundler.JarBundler"
               classpath="${lib.home}/jarbundler-core-3.3.0.jar"
               uri="antlib:com.ultramixer.jarbundler">
      </taskdef>
    </contrib:then>
  </contrib:if>

  <!-- load launch4j (Windows app bundler) tasks -->
  <contrib:if>
    <os family="windows"/>
    <contrib:then>
      <taskdef name="create"
               classname="net.sf.launch4j.ant.Launch4jTask"
               uri="antlib:net.sf.launch4j.ant">
        <classpath>
          <fileset dir="${lib.dir}/launch4j" includes="*.jar"/>
        </classpath>
      </taskdef>
    </contrib:then>
  </contrib:if>

  <!-- load mod (Gnome app bundler) tasks -->
  <contrib:if>
    <os family="unix"/>
    <contrib:then>
      <taskdef name="calculatesize"
               classname="de.masters_of_disaster.ant.tasks.calculatesize.CalculateSize"
               uri="antlib:de.masters_of_disaster.ant.tasks">
        <classpath>
          <fileset dir="${lib.dir}/mod" includes="*.jar"/>
        </classpath>
      </taskdef>
      <taskdef name="deb"
               classname="de.masters_of_disaster.ant.tasks.deb.Deb"
               uri="antlib:de.masters_of_disaster.ant.tasks"/>
        <classpath>
          <fileset dir="${lib.dir}/mod" includes="*.jar"/>
        </classpath>
      </taskdef>
    </contrib:then>
  </contrib:if>

  <!-- define the kotlin task -->
  <property name="kotlin.lib" value="${env.KOTLIN_HOME}/lib"/>
  <typedef resource="org/jetbrains/kotlin/ant/antlib.xml"
           classpath="${kotlin.lib}/kotlin-ant.jar"/>

  <!-- help message -->
  <target name="help">
    <echo>You can use the following targets:</echo>
    <echo> </echo>
    <echo>  help    : (default) Prints this message </echo>
    <echo>  all     : Cleans, compiles, and stages application</echo>
    <echo>  clean   : Deletes work directories</echo>
    <echo>  compile : Compiles servlets into class files</echo>
    <echo>  jar     : Make JAR file.</echo>
    <echo> </echo>
    <echo>For example, to clean, compile, and package all at once, run:</echo>
    <echo>prompt> ant all </echo>
  </target>

  <!-- Determine OS type -->
  <condition property="os.type" value="mac">
    <os family="mac"/>
  </condition>
  <condition property="os.type" value="windows">
    <os family="windows"/>
  </condition>
  <condition property="os.type" value="linux">
    <!-- notes: 1) XXX not all non-mac UNIX systems are Linux, but this assumes
         so; 2) this clause MUST appear AFTER the "mac" one -->
    <os family="unix"/>
  </condition>
  <property name="os.type" value="unknown"/>

  <!-- Define the CLASSPATH -->
  <target name="classpath">
    <path id="compile.classpath">
      <pathelement location="${src.home}"/>
    </path>
  </target>

  <!-- make needed directories -->
  <target name="mkdirs">
    <mkdir dir="${lib.home}"/>
    <mkdir dir="${src.home}/name/blackcap/exifwasher/binaries/${os.type}"/>
  </target>

  <!-- rename files containing OS-dependant code -->
  <target name="osdep">
    <exec executable="${env.JRE_HOME}/bin/java">
      <arg value="-jar"/>
      <arg value="../Osdep/osdep.jar"/>
      <arg value="${src.home}"/>
    </exec>
  </target>

  <!-- do everything but install -->
  <target name="all" depends="jar"
          description="Clean work dirs, compile, make JAR."/>

  <!-- compile *.kt to *.class -->
  <target name="compile" depends="mkdirs,osdep,classpath"
          description="Compile Java sources to ${work.home}">
    <kotlinc src="${src.home}" output="${work.jar}"
             classpathref="compile.classpath">
      <compilerarg line="-jvm-target 1.8"/>
    </kotlinc>
  </target>

  <!-- make .jar file -->
  <target name="jar" depends="compile" description="Create JAR file.">
    <jar destfile="${jar.name}">
      <manifest>
        <attribute name="Main-Class" value="${app.entry}"/>
      </manifest>
      <zipgroupfileset dir="${lib.home}" includes="*.jar"/>
      <zipfileset src="${work.jar}"/>
      <zipfileset dir="${src.home}" includes="**/*.properties,**/*.dll,**/*.so,**/*.dylib"/>
    </jar>
  </target>

  <!-- for making bundled apps -->
  <macrodef name="bundle">
    <attribute name="type"/>
    <element name="args"/>
    <element name="icons"/>
    <sequential>
      <fx:deploy nativeBundles="@{type}" outdir="${basedir}" outfile="${app.name}"
        signBundle="false">
        <fx:application mainClass="${app.entry}" name="${app.name}" toolkit="swing"
          version="${app.version}"/>
        <fx:info description="${app.name}" title="${app.name}"
          vendor="David Barts &lt;n5jrn@me.com&gt;"
          copyright="© MMXX, David W. Barts">
          <icons/>
        </fx:info>
        <fx:resources>
          <fx:fileset dir="${basedir}" includes="${lc.app.name}.jar"/>
        </fx:resources>
        <fx:bundleArgument arg="runtime" value="${env.JRE_HOME}"/>
        <args/>
      </fx:deploy>
      </sequential>
  </macrodef>

  <target name="macapp" depends="jar" description="Create MacOS app bundle.">
    <bundle type="image">
      <args>
        <fx:bundleArgument arg="jvmOptions" value="-Xdock:name=${app.name}"/>
      </args>
      <icons>
        <fx:icon href="${basedir}/${app.name}.icns"/>
      </icons>
    </bundle>
  </target>

  <target name="dummywork" description="dummy dir to make javapackager happy">
    <mkdir dir="${work.home}"/>
    <copy file="${jar.name}" tofile="${work.home}/${app.name}.jar"/>
  </target>

  <!-- fx:deploy is broken on Windoze, must run javapackager command -->
  <target name="winapp" depends="jar,dummywork" description="Create app bundle.">
    <exec executable="${env.JRE_HOME}/bin/javapackager">
      <arg value="-deploy"/>
      <arg value="-Bicon=${app.name}.ico"/>
      <arg value="-BappVersion=${app.version}"/>
      <arg value="-title"/> <arg value="${app.name}"/>
      <arg value="-appclass"/> <arg value="${app.entry}"/>
      <arg value="-native"/> <arg value="image"/>
      <arg value="-name"/> <arg value="${app.name}"/>
      <arg value="-outdir"/> <arg value="."/>
      <arg value="-outfile"/> <arg value="${app.name}"/>
      <arg value="-srcdir"/> <arg value="${work.home}"/>
    </exec>
  </target>

  <target name="rpm" depends="jar" description="Create RPM package.">
    <bundle type="rpm"/>
  </target>

  <target name="deb" depends="jar" description="Create Debian package.">
    <bundle type="deb"/>
  </target>

</project>