view build.xml @ 62:c56a0747c256 default tip

Add make plain feature.
author David Barts <n5jrn@me.com>
date Thu, 28 Apr 2022 20:53:39 -0700
parents 066f05ebcc00
children
line wrap: on
line source

<?xml version="1.0" encoding="UTF-8"?>
<project name="ClipMan" default="help" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
  <!-- 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"/>

  <!-- 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"/>

  <!-- define the package-building tasks -->
  <!-- <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
           uri="javafx:com.sun.javafx.tools.ant"
           classpath="${env.JRE_HOME}/lib/ant-javafx.jar"/> -->

  <!-- Define the properties used by the build -->
  <property name="app.name"      value="${ant.project.name}"/>
  <property name="lc.app.name"   value="clipman"/>
  <property name="app.entry"     value="name.blackcap.clipman.MainKt"/>
  <property name="app.domain"    value="name.blackcap.${lc.app.name}"/>
  <property name="app.copyright" value="Copyright © 2020–2022, David W. Barts."/>
  <property name="app.version"   value="1.10"/>
  <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="work.home"      value="${basedir}/work"/>
  <property name="dist.home"     value="${basedir}/dist"/>
  <property name="pf.home"       value="${basedir}/package-files"/>
  <property name="jvm.version"   value="1.8"/>

  <!-- 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>

  <!-- Define the CLASSPATH -->
  <target name="classpath">
    <path id="std.classpath">
      <fileset dir="${lib.home}">
        <include name="*.jar"/>
      </fileset>
    </path>
    <path id="compile.classpath">
      <path refid="std.classpath"/>
      <pathelement location="${src.home}"/>
    </path>
    <path id="test.classpath">
      <path refid="std.classpath"/>
      <pathelement location="${work.home}"/>
    </path>
  </target>

  <!-- make needed directories -->
  <target name="mkdirs">
    <mkdir dir="${dist.home}"/>
  </target>

  <!-- remove old cruft -->
  <target name="clean">
    <delete includeEmptyDirs="true" failonerror="false">
      <fileset dir="${dist.home}" includes="**/*"/>
      <fileset file="${work.jar}"/>
      <fileset file="${jar.name}"/>
    </delete>
  </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="classpath"
          description="Compile Java sources to ${work.home}">
    <kotlinc src="${src.home}" output="${work.jar}"
             noStdlib="false" includeRuntime="true"
             classpathref="compile.classpath">
      <compilerarg line="-jvm-target ${jvm.version}"/>
    </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"/>
    </jar>
  </target>

  <!-- for making bundled apps -->
  <macrodef name="bundle">
    <attribute name="type"/>
    <element name="args" optional="true"/>
    <sequential>
      <fx:deploy nativeBundles="@{type}" outdir="${basedir}" outfile="${app.name}"
        signBundle="false">
        <fx:application mainClass="${app.entry}" name="${app.name}" toolkit="swing"
          version="1.01"/>
        <fx:info description="ClipMan, a clipboard manager." title="${app.name}"
          vendor="David Barts &lt;n5jrn@me.com&gt;"
          copyright="© MMXX, David W. Barts"/>
        <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="mkdirs,jar" description="Create MacOS app bundle.">
    <fail message="Macintosh packages can only be built on a Mac.">
      <condition>
        <not><os family="mac"/></not>
      </condition>
    </fail>
    <sequential>
      <property name="mac.disk.image.filename"
                value="${lc.app.name}_${app.version}.dmg"/>
      <property name="app.bundle" value="${dist.home}/${app.name}.app"/>
      <mkdir dir="${app.bundle}/Contents"/>
      <copy todir="${app.bundle}/Contents" encoding="UTF-8" overwrite="true">
        <fileset file="${pf.home}/osx/Info.plist"/>
        <!-- XXX will break if any tokens contain <, >, or & -->
        <filterset>
          <filter token="app.copyright" value="${app.copyright}"/>
          <filter token="app.domain" value="${app.domain}"/>
          <filter token="app.entry" value="${app.entry}"/>
          <filter token="app.name" value="${app.name}"/>
          <filter token="app.version" value="${app.version}"/>
          <filter token="jar.filename" value="${lc.app.name}.jar"/>
          <filter token="jvm.version" value="${jvm.version}"/>
          <filter token="lc.app.name" value="${lc.app.name}"/>
        </filterset>
      </copy>
      <mkdir dir="${app.bundle}/Contents/MacOS"/>
      <copy todir="${app.bundle}/Contents/MacOS" encoding="UTF-8"
            overwrite="true">
        <fileset file="${pf.home}/osx/JavaApplicationStub"/>
        <filterset>
          <filter token="app.domain" value="${app.domain}"/>
          <filter token="app.name" value="${app.name}"/>
        </filterset>
      </copy>
      <chmod file="${app.bundle}/Contents/MacOS/JavaApplicationStub"
             perm="755"/>
      <mkdir dir="${app.bundle}/Contents/Resources"/>
      <copy file="${basedir}/${app.name}.icns"
            todir="${app.bundle}/Contents/Resources"/>
      <mkdir dir="${app.bundle}/Contents/Java"/>
      <copy file="${jar.name}" todir="${app.bundle}/Contents/Java"/>
      <echo file="${app.bundle}/Contents/PkgInfo" message="APPL????"/>
      <exec executable="hdiutil" failonerror="true">
        <arg value="create"/>
        <arg value="-volname"/>
        <arg value="${app.name}"/>
        <arg value="-srcfolder"/>
        <arg file="${app.bundle}"/>
        <arg file="${dist.home}/orig-${mac.disk.image.filename}"/>
      </exec>
      <exec executable="hdiutil" failonerror="true">
        <arg value="convert"/>
        <arg file="${dist.home}/orig-${mac.disk.image.filename}"/>
        <arg value="-format"/>
        <arg value="UDRW"/>
        <arg value="-o"/>
        <arg file="${dist.home}/udrw-${mac.disk.image.filename}"/>
      </exec>
      <exec executable="hdiutil" failonerror="true">
        <arg value="convert"/>
        <arg file="${dist.home}/udrw-${mac.disk.image.filename}"/>
        <arg value="-format"/>
        <arg value="UDZO"/>
        <arg value="-imagekey"/>
        <arg value="zlib-level=9"/>
        <arg value="-o"/>
        <arg file="${dist.home}/${mac.disk.image.filename}"/>
      </exec>
    </sequential>
  </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="-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>