diff build.xml @ 23:92afaa27f40a

Mac app support.
author David Barts <n5jrn@me.com>
date Tue, 24 Nov 2020 16:45:37 -0800
parents 5234e4500d45
children 9bf3d8de6904
line wrap: on
line diff
--- a/build.xml	Mon Nov 23 15:45:04 2020 -0800
+++ b/build.xml	Tue Nov 24 16:45:37 2020 -0800
@@ -41,6 +41,7 @@
   <property name="lib.home"      value="${basedir}/lib"/>
   <property name="src.home"      value="${basedir}/src"/>
   <property name="dist.home"     value="${basedir}/dist"/>
+  <property name="pf.home"       value="${basedir}/package-files"/>
   <property name="jvm.version"   value="1.8"/>
 
   <!-- define the kotlin task -->
@@ -119,4 +120,75 @@
     </jar>
   </target>
 
+  <target name="macapp" depends="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>
+
 </project>