From a366d9787c36dd9d847f443b04c4a896eaa5dd7a Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 19 Jun 2022 13:15:34 -0400 Subject: [PATCH] rewrite Info.plist.tmpl subst, also specify JVM version --- java/application/Info.plist.tmpl | 3 ++ java/src/processing/mode/java/JavaBuild.java | 57 +++++++++----------- todo.txt | 19 ++++++- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/java/application/Info.plist.tmpl b/java/application/Info.plist.tmpl index f63884a9e..e7a3a74c2 100644 --- a/java/application/Info.plist.tmpl +++ b/java/application/Info.plist.tmpl @@ -37,6 +37,9 @@ JVMMainClassName @@sketch@@ + JVMVersion + @@jdk_version@@ + LSMinimumSystemVersion 10.14.6 diff --git a/java/src/processing/mode/java/JavaBuild.java b/java/src/processing/mode/java/JavaBuild.java index cd506fcc7..777d46e2c 100644 --- a/java/src/processing/mode/java/JavaBuild.java +++ b/java/src/processing/mode/java/JavaBuild.java @@ -882,46 +882,28 @@ public class JavaBuild { runOptionsXML.append('\n'); } - + // read the template, first checking whether the sketch has its own copy String PLIST_TEMPLATE = "Info.plist.tmpl"; File plistTemplate = new File(sketch.getFolder(), PLIST_TEMPLATE); if (!plistTemplate.exists()) { plistTemplate = mode.getContentFile("application/" + PLIST_TEMPLATE); } + + // substitute variables from the template with their values + StringBuilder sb = new StringBuilder(Util.loadFile(plistTemplate)); + replaceTags(sb, "jvm_runtime", jvmRuntime); + replaceTags(sb, "jvm_version", MIN_JAVA_VERSION); + replaceTags(sb, "jvm_options_list", runOptionsXML.toString()); + replaceTags(sb, "sketch", sketch.getMainName()); + replaceTags(sb, "lsuipresentationmode", + Preferences.getBoolean("export.application.present") ? "4" : "0"); + replaceTags(sb, "lsarchitecturepriority", + exportVariant.substring("macos-".length())); + + // write the plist file File plistFile = new File(dotAppFolder, "Contents/Info.plist"); PrintWriter pw = PApplet.createWriter(plistFile); - - String[] lines = PApplet.loadStrings(plistTemplate); - for (int i = 0; i < lines.length; i++) { - if (lines[i].contains("@@")) { - StringBuilder sb = new StringBuilder(lines[i]); - int index = 0; - while ((index = sb.indexOf("@@jvm_runtime@@")) != -1) { - sb.replace(index, index + "@@jvm_runtime@@".length(), - jvmRuntime); - } - while ((index = sb.indexOf("@@jvm_options_list@@")) != -1) { - sb.replace(index, index + "@@jvm_options_list@@".length(), - runOptionsXML.toString()); - } - while ((index = sb.indexOf("@@sketch@@")) != -1) { - sb.replace(index, index + "@@sketch@@".length(), - sketch.getMainName()); - } - while ((index = sb.indexOf("@@lsuipresentationmode@@")) != -1) { - sb.replace(index, index + "@@lsuipresentationmode@@".length(), - Preferences.getBoolean("export.application.present") ? "4" : "0"); - } - while ((index = sb.indexOf("@@lsarchitecturepriority@@")) != -1) { - sb.replace(index, index + "@@lsarchitecturepriority@@".length(), - exportVariant.substring("macos-".length())); - } - - lines[i] = sb.toString(); - } - // explicit newlines to avoid Windows CRLF - pw.print(lines[i] + "\n"); - } + pw.print(sb); pw.flush(); pw.close(); @@ -1055,6 +1037,15 @@ public class JavaBuild { } + private void replaceTags(StringBuilder sb, String replacing, String replacement) { + int index = 0; + String tag = "@@" + replacing + "@@"; + while ((index = sb.indexOf(tag)) != -1) { + sb.replace(index, index + tag.length(), replacement); + } + } + + // This is a workaround until a more complete solution is found. public Library findJavaFX() { for (Library library : getImportedLibraries()) { diff --git a/todo.txt b/todo.txt index e904574ee..bd0adbfd5 100755 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,24 @@ 1284 (4.0b9) X bump to Java 17.0.3+7 +X specify Java version with appbundler in main app + +export application X fix Export to Application on macOS with Apple Silicon -X gets rid of "Unable to start Java Runtime" +X gets rid of "Unable to load Java Runtime Environment" +X update appbundler main.m through https://github.com/TheInfiniteKind/appbundler/commit/5946207c9e29ab85887e94d5651b329e4669e2d6 +X rewrite variable substitution for Info.plist.tmpl +X cleans up readability +X would have broken w/ anything on the same line +X specify JVM version in exported applications + + JVMVersion + 17 + +_ appbundler seems to prefer Java 1.8 if installed +_ Export Application gives java.lang.ClassNotFoundException: --full-screen error +_ https://github.com/processing/processing4/issues/488 +_ --full-screen not being added with Export to Application? + contrib X add flatlaf.jar to the Windows config.xml