view build.xml @ 56:22725d4d7849

An attempt to get it to troff-ize styled text.
author David Barts <n5jrn@me.com>
date Sat, 19 Mar 2022 23:04:40 -0700
parents b1198e4bec25
children c6cccbe2f393
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"/>

  <!-- 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.entry"     value="name.blackcap.clipman.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="work.home"      value="${basedir}/work"/>

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

  <!-- 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}"
             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"/>
    </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="jar" description="Create MacOS app bundle.">
    <bundle type="image">
      <args>
        <fx:bundleArgument arg="jvmOptions" value="-Xdock:name=${app.name}"/>
      </args>
    </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="-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>