changeset 29:e90d290a9a8d

Remove dependence on Nashorn.
author David Barts <n5jrn@me.com>
date Mon, 13 Jun 2022 09:21:24 -0700
parents c310ec097194
children 098c4f5507c7
files antlib/Du.kt antlib/ToLowerCase.kt antlib/antlib.jar antlib/build.xml build.xml setup.sh
diffstat 6 files changed, 109 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/antlib/Du.kt	Mon Jun 13 09:21:24 2022 -0700
@@ -0,0 +1,19 @@
+import java.io.File
+import java.io.IOException
+
+class Du : org.apache.tools.ant.Task() {
+    var path: String? = null
+    var output: String? = null
+
+    override fun execute(): Unit {
+        project.setProperty(output, du(path!!).toString())
+    }
+
+    private fun du(path: String): Long {
+        try {
+            return File(path).walk().map { if (it.isFile()) { it.length() } else { 0L } }.sum()
+        } catch (e: IOException) {
+            return 0L
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/antlib/ToLowerCase.kt	Mon Jun 13 09:21:24 2022 -0700
@@ -0,0 +1,8 @@
+class ToLowerCase : org.apache.tools.ant.Task() {
+    var value: String? = null
+    var output: String? = null
+
+    override fun execute(): Unit {
+        project.setNewProperty(output, value!!.lowercase())
+    }
+}
Binary file antlib/antlib.jar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/antlib/build.xml	Mon Jun 13 09:21:24 2022 -0700
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="ImagePrep" default="help" basedir=".">
+  <!-- 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="ANT_HOME"/>
+  <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"/>
+
+  <!-- help message -->
+  <target name="help">
+    <echo>You can use the following targets:</echo>
+    <echo> </echo>
+    <echo>  help    : (default) Prints this message </echo>
+    <echo>  jar     : Make JAR file.</echo>
+    <echo> </echo>
+  </target>
+
+  <!-- compile *.kt to *.class -->
+  <property name="jar.name"      value="antlib.jar"/>
+  <target name="jar"
+          description="Compile sources to ${jar.name}.">
+    <kotlinc src="." output="${jar.name}"
+             noStdlib="false" includeRuntime="true">
+      <compilerarg line="-jvm-target 1.8"/>
+      <classpath>
+        <fileset dir="${env.ANT_HOME}/lib">
+          <include name="*.jar"/>
+        </fileset>
+      </classpath>
+    </kotlinc>
+  </target>
+
+
+</project>
--- a/build.xml	Fri Dec 25 19:07:47 2020 -0800
+++ b/build.xml	Mon Jun 13 09:21:24 2022 -0700
@@ -18,49 +18,30 @@
   <env-require name="KOTLIN_HOME"/>
   <env-require name="OSDEP_HOME"/>
 
-  <!-- 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[
-      "use strict";
-      project.setProperty( attributes.get( "target" ),
-                           attributes.get( "value" ).toLowerCase() );
-    ]]>
-  </scriptdef>
+  <!-- du and toLowerCase need this -->
+  <property name="antlib.jar"    value="${basedir}/antlib/antlib.jar"/>
 
-  <!-- estimate disk usage -->
-  <scriptdef language="javascript" name="du">
-    <attribute name="path" />
-    <attribute name="target" />
-    <![CDATA[
-      "use strict";
-      var File = Java.type('java.io.File');
-      function du(fp) {
-        if (fp.isDirectory()) {
-          var files = fp.listFiles();
-          if (!files) return 0;
-          var total = 0;
-          for (var i=0; i<files.length; i++)
-            total += du(files[i]);
-          return total;
-        } else {
-          return fp.length();
-        }
-      }
-      var path = new File(attributes.get("path"));
-      project.setProperty(attributes.get("target"),
-        Math.round(du(path) / 1024) + "");
-    ]]>
-  </scriptdef>
+  <!-- turn a string to lower case -->
+  <taskdef name="toLowerCase" classname="ToLowerCase">
+    <classpath>
+      <pathelement location="${antlib.jar}"/>
+    </classpath>
+  </taskdef>
+
+  <!-- calculate disk usage in kbytes -->
+  <taskdef name="du" classname="Du">
+    <classpath>
+      <pathelement location="${antlib.jar}"/>
+    </classpath>
+  </taskdef>
 
   <!-- Define the properties used by the build -->
   <property name="app.name"      value="${ant.project.name}"/>
-  <toLowerCase target="lc.app.name" value="${app.name}"/>
-  <property name="app.version"   value="1.01"/>
+  <toLowerCase output="lc.app.name" value="${app.name}"/>
+  <property name="app.version"   value="1.02"/>
   <property name="app.domain"    value="name.blackcap.${lc.app.name}"/>
   <property name="app.entry"     value="${app.domain}.MainKt"/>
-  <property name="app.copyright" value="Copyright © 2020, David W. Barts."/>
+  <property name="app.copyright" value="Copyright © 2020–2022, David W. Barts."/>
   <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"/>
@@ -74,9 +55,14 @@
   <typedef resource="org/jetbrains/kotlin/ant/antlib.xml"
            classpath="${kotlin.lib}/kotlin-ant.jar"/>
 
+  <target name="testIt">
+    <jshellTest message="This is a test." />
+  </target>
+
   <!-- help message -->
   <target name="help">
     <echo>You can use the following targets:</echo>
+    <echo>lc.app.name is ${lc.app.name}</echo>
     <echo> </echo>
     <echo>  help    : (default) Prints this message </echo>
     <echo>  all     : Cleans, compiles, and stages application</echo>
@@ -107,6 +93,8 @@
   <target name="clean">
     <delete includeEmptyDirs="true" failonerror="false">
       <fileset dir="${dist.home}" includes="**/*"/>
+      <fileset file="${work.jar}"/>
+      <fileset file="${jar.name}"/>
     </delete>
   </target>
 
@@ -127,6 +115,7 @@
   <target name="compile" depends="mkdirs,osdep,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>
@@ -254,7 +243,7 @@
         </filterset>
       </copy>
       <chmod file="${dist.home}/data/usr/bin/imageprep" perm="755"/>
-      <du path="${dist.home}/data" target="deb.installed.size"/>
+      <du path="${dist.home}/data" output="deb.installed.size"/>
       <mkdir dir="${dist.home}/control"/>
       <copy todir="${dist.home}/control" encoding="UTF-8" overwrite="true">
         <fileset file="${pf.home}/linux/deb/control"/>
--- a/setup.sh	Fri Dec 25 19:07:47 2020 -0800
+++ b/setup.sh	Mon Jun 13 09:21:24 2022 -0700
@@ -1,11 +1,12 @@
 #!/bin/bash
 
-export JRE_HOME="$(/usr/libexec/java_home)"
-export KOTLIN_HOME="$HOME/kotlin/1.3.72"
+export JRE_HOME="/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home"
+export JAVA_HOME="$JRE_HOME"
+export KOTLIN_HOME="$HOME/kotlin/1.6.10/kotlinc"
 export EXIV2_HOME="$HOME/temp/exiv2/exiv2-0.27.2-Source"
 export OSDEP_HOME="../Osdep"
 
-export ANT_HOME="$HOME/java/apache-ant-1.10.1"
+export ANT_HOME="$HOME/java/apache-ant-1.10.8"
 if [[ "$PATH" != *$ANT_HOME/bin* ]]
 then
     export PATH="$ANT_HOME/bin:$PATH"