From 3dd945fac0da966eb7e7bc576bf5793d6086c25a Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Sun, 6 Jan 2019 18:48:24 -0800 Subject: [PATCH 01/94] Making the ThinkDifferent classes be JVM version-independent. JDK 1.9 and later have a new java.awt.desktop package that replaces the custom handlers in the com.apple.eawt package. This commit uses java.lang.reflect.Proxy to generate handlers of the correct type. --- .../app/platform/ThinkDifferent.java | 111 ++++++++++++------ core/src/processing/core/ThinkDifferent.java | 68 ++++++++--- 2 files changed, 129 insertions(+), 50 deletions(-) diff --git a/app/src/processing/app/platform/ThinkDifferent.java b/app/src/processing/app/platform/ThinkDifferent.java index dc905c62a3..01c9823bc3 100644 --- a/app/src/processing/app/platform/ThinkDifferent.java +++ b/app/src/processing/app/platform/ThinkDifferent.java @@ -24,11 +24,15 @@ import java.awt.event.*; import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; import javax.swing.*; -import com.apple.eawt.*; -import com.apple.eawt.AppEvent.*; +import com.apple.eawt.Application; import processing.app.*; import processing.app.ui.About; @@ -65,44 +69,40 @@ static protected void init(final Base base) { if (adapter == null) { adapter = new ThinkDifferent(); //base); } - - application.setAboutHandler(new AboutHandler() { - public void handleAbout(AboutEvent ae) { - new About(null); - } + + setHandler(application, "setAboutHandler", (proxy, method, args) -> { + new About(null); + return null; }); - - application.setPreferencesHandler(new PreferencesHandler() { - public void handlePreferences(PreferencesEvent arg0) { - base.handlePrefs(); - } + + setHandler(application, "setPreferencesHandler", (proxy, method, args) -> { + base.handlePrefs(); + return null; }); - application.setOpenFileHandler(new OpenFilesHandler() { - public void openFiles(OpenFilesEvent event) { - for (File file : event.getFiles()) { - base.handleOpen(file.getAbsolutePath()); - } + setHandler(application, "setOpenFileHandler", (proxy, method, args) -> { + Method m = args[0].getClass().getMethod("getFiles"); + for (File file : (List) m.invoke(args[0])) { + base.handleOpen(file.getAbsolutePath()); } + return null; }); - - application.setPrintFileHandler(new PrintFilesHandler() { - public void printFiles(PrintFilesEvent event) { - // TODO not yet implemented - } + + setHandler(application, "setPrintFileHandler", (proxy, method, args) -> { + // TODO not yet implemented + return null; }); - - application.setQuitHandler(new QuitHandler() { - public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { - if (base.handleQuit()) { - response.performQuit(); - } else { - response.cancelQuit(); - } + + setHandler(application, "setQuitHandler", (proxy, method, args) -> { + if (base.handleQuit()) { + args[1].getClass().getMethod("performQuit").invoke(args[1]); + } else { + args[1].getClass().getMethod("cancelQuit").invoke(args[1]); } + return null; }); - // Set the menubar to be used when nothing else is open. + // Set the menubar to be used when nothing else is open. JMenuBar defaultMenuBar = new JMenuBar(); JMenu fileMenu = buildFileMenu(base); defaultMenuBar.add(fileMenu); @@ -117,12 +117,12 @@ public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { e.printStackTrace(); // oh well, never mind } // } else { -// // The douchebags at Oracle didn't feel that a working f*king menubar -// // on OS X was important enough to make it into the 7u40 release. +// // The douchebags at Oracle didn't feel that a working f*king menubar +// // on OS X was important enough to make it into the 7u40 release. // //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8007267 // // It languished in the JDK 8 source and has been backported for 7u60: // //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8022667 -// +// // JFrame offscreen = new JFrame(); // offscreen.setUndecorated(true); // offscreen.setJMenuBar(defaultMenuBar); @@ -131,12 +131,51 @@ public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { // offscreen.setVisible(true); // } } - + // public ThinkDifferent(Base base) { // this.base = base; // } + /** + * Sets a handler on an instance of {@link Application}, taking into account JVM version + * differences. + * + * @param app an instance of {@link Application} + * @param name the "set handler" method name + * @param handler the handler + */ + private static void setHandler(Application app, String name, InvocationHandler handler) { + // Determine which version of com.apple.eawt.Application to use and pass it a handler of the + // appropriate type + Method[] methods = app.getClass().getMethods(); + for (Method m : methods) { + if (!name.equals(m.getName())) { + continue; + } + if (m.getParameterCount() != 1) { + continue; + } + Class paramType = m.getParameterTypes()[0]; + try { + // Allow a null handler + Object proxy = null; + if (handler != null) { + proxy = Proxy.newProxyInstance( + paramType.getClassLoader(), new Class[] { paramType }, handler); + } + m.invoke(app, proxy); + } catch (IllegalArgumentException ex) { + // TODO: Print error?: method doesn't take an interface, etc. + } catch (IllegalAccessException ex) { + // TODO: Print error?: Other method invocation problem + } catch (InvocationTargetException ex) { + ex.getCause().printStackTrace(); + // TODO: Print ex.getCause() a different way? + } + break; + } + } /** * Gimpy file menu to be used on OS X when no sketches are open. @@ -162,7 +201,7 @@ public void actionPerformed(ActionEvent e) { fileMenu.add(item); item = Toolkit.newJMenuItemShift(Language.text("menu.file.sketchbook"), 'K'); - item.addActionListener(new ActionListener() { + item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { base.getNextMode().showSketchbookFrame(); diff --git a/core/src/processing/core/ThinkDifferent.java b/core/src/processing/core/ThinkDifferent.java index 8596696198..af40d8a544 100644 --- a/core/src/processing/core/ThinkDifferent.java +++ b/core/src/processing/core/ThinkDifferent.java @@ -23,11 +23,12 @@ package processing.core; import java.awt.Image; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; -import com.apple.eawt.AppEvent.QuitEvent; import com.apple.eawt.Application; -import com.apple.eawt.QuitHandler; -import com.apple.eawt.QuitResponse; /** @@ -57,25 +58,64 @@ static public void init(final PApplet sketch) { application = Application.getApplication(); } - application.setQuitHandler(new QuitHandler() { - public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { - sketch.exit(); - if (PApplet.uncaughtThrowable == null && // no known crash - !attemptedQuit) { // haven't tried yet - response.cancelQuit(); // tell OS X we'll handle this - attemptedQuit = true; - } else { - response.performQuit(); // just force it this time - } + setHandler(application, "setQuitHandler", (proxy, method, args) -> { + sketch.exit(); + if (PApplet.uncaughtThrowable == null && // no known crash + !attemptedQuit) { // haven't tried yet + args[1].getClass().getMethod("cancelQuit").invoke(args[1]); // tell OS X we'll handle this + attemptedQuit = true; + } else { + args[1].getClass().getMethod("performQuit").invoke(args[1]); // just force it this time } + return null; }); } + /** + * Sets a handler on an instance of {@link Application}, taking into account JVM version + * differences. + * + * @param app an instance of {@link Application} + * @param name the "set handler" method name + * @param handler the handler + */ + private static void setHandler(Application app, String name, InvocationHandler handler) { + // Determine which version of com.apple.eawt.Application to use and pass it a handler of the + // appropriate type + Method[] methods = app.getClass().getMethods(); + for (Method m : methods) { + if (!name.equals(m.getName())) { + continue; + } + if (m.getParameterCount() != 1) { + continue; + } + Class paramType = m.getParameterTypes()[0]; + try { + // Allow a null handler + Object proxy = null; + if (handler != null) { + proxy = Proxy.newProxyInstance( + paramType.getClassLoader(), new Class[] { paramType }, handler); + } + m.invoke(app, proxy); + } catch (IllegalArgumentException ex) { + // TODO: Print error?: method doesn't take an interface, etc. + } catch (IllegalAccessException ex) { + // TODO: Print error?: Other method invocation problem + } catch (InvocationTargetException ex) { + ex.getCause().printStackTrace(); + // TODO: Print ex.getCause() a different way? + } + break; + } + } + static public void cleanup() { if (application == null) { application = Application.getApplication(); } - application.setQuitHandler(null); + setHandler(application, "setQuitHandler", null); } // Called via reflection from PSurfaceAWT and others From 3cc210fba67b689d424baae54305b9b04165df3c Mon Sep 17 00:00:00 2001 From: sampottinger Date: Sat, 12 Jan 2019 10:47:05 -0800 Subject: [PATCH 02/94] Initial migration to Java 11 on Mac as POC. Focusing first on getting "hello world" applications running under Java 11, this initial migration works for Mac OS X (10.14.1). There are a number of issues and warnings still to address so the overall PR remains WIP. Specific modifications to address #5750: - Modification in build system to address a unified JDK / JRE. - Modification in build system and application code to deal with version naming convention migration. - Modification of OS X specific system paths changed by Java 11. - Migration to OpenJDK (#4415) via AdoptOpenJDK (selected due to long term build support and some vendor independence). - Migration to OpenJFX (#5286). - Removal of deprecated `java.ext.dirs` (replacement funcationality is still being explored). - Update to the appbundler fork. - Update to the JDT jars. Documentation is still incomplete as is reaching feature parity on mac as well as testing on other OS'. Please don't merge yet. --- app/build.xml | 25 +- app/src/processing/app/Platform.java | 4 +- build/build.xml | 31 +- build/jre/build.xml | 30 +- build/macosx/appbundler.jar | Bin 143975 -> 157624 bytes build/macosx/appbundler/build.xml | 8 +- build/macosx/appbundler/doc/appbundler.html | 365 +++++ build/macosx/appbundler/native/main.m | 881 ++++++++++-- .../res/de.lproj/Localizable.strings | 7 + .../res/en.lproj/Localizable.strings | 4 + .../res/fr.lproj/Localizable.strings | 7 + .../com/oracle/appbundler/AppBundlerTask.java | 1206 ++++++++++------- .../com/oracle/appbundler/BundleDocument.java | 220 +-- .../com/oracle/appbundler/Environment.java | 30 + .../com/oracle/appbundler/IconContainer.java | 32 + .../src/com/oracle/appbundler/Option.java | 34 +- .../src/com/oracle/appbundler/PlistEntry.java | 46 + .../src/com/oracle/appbundler/Runtime.java | 123 ++ .../oracle/appbundler/TypeDeclaration.java | 141 ++ build/shared/tools/MovieMaker/build.xml | 15 +- core/.classpath | 7 +- core/build.xml | 41 +- core/library/javafx-swt.jar | Bin 0 -> 36804 bytes core/library/javafx.base.jar | Bin 0 -> 749889 bytes core/library/javafx.controls.jar | Bin 0 -> 2511080 bytes core/library/javafx.fxml.jar | Bin 0 -> 127394 bytes core/library/javafx.graphics.jar | Bin 0 -> 4414818 bytes core/library/javafx.media.jar | Bin 0 -> 276103 bytes core/library/javafx.properties | 3 + core/library/javafx.swing.jar | Bin 0 -> 119848 bytes core/library/javafx.web.jar | Bin 0 -> 712659 bytes core/src/processing/javafx/PSurfaceFX.java | 12 +- java/build.xml | 65 +- java/libraries/dxf/build.xml | 15 +- java/libraries/net/build.xml | 11 +- java/libraries/pdf/build.xml | 15 +- java/libraries/serial/build.xml | 11 +- java/libraries/svg/build.xml | 15 +- java/mode/.api_description | 265 ++++ java/mode/.options | 133 ++ java/mode/about.html | 42 + java/mode/jdtCompilerAdapter.jar | Bin 14260 -> 14370 bytes java/mode/org.eclipse.jdt.compiler.apt.jar | Bin 0 -> 217506 bytes java/mode/org.eclipse.jdt.core.jar | Bin 5640136 -> 6882842 bytes java/mode/plugin.properties | 34 + java/mode/plugin.xml | 313 +++++ java/src/processing/mode/java/JavaBuild.java | 4 +- .../mode/java/pdex/PreprocessingService.java | 4 +- .../processing/mode/java/runner/Runner.java | 5 +- 49 files changed, 3345 insertions(+), 859 deletions(-) create mode 100644 build/macosx/appbundler/res/de.lproj/Localizable.strings create mode 100644 build/macosx/appbundler/res/fr.lproj/Localizable.strings create mode 100644 build/macosx/appbundler/src/com/oracle/appbundler/Environment.java create mode 100644 build/macosx/appbundler/src/com/oracle/appbundler/IconContainer.java create mode 100644 build/macosx/appbundler/src/com/oracle/appbundler/PlistEntry.java create mode 100644 build/macosx/appbundler/src/com/oracle/appbundler/Runtime.java create mode 100644 build/macosx/appbundler/src/com/oracle/appbundler/TypeDeclaration.java create mode 100644 core/library/javafx-swt.jar create mode 100644 core/library/javafx.base.jar create mode 100644 core/library/javafx.controls.jar create mode 100644 core/library/javafx.fxml.jar create mode 100644 core/library/javafx.graphics.jar create mode 100644 core/library/javafx.media.jar create mode 100644 core/library/javafx.properties create mode 100644 core/library/javafx.swing.jar create mode 100644 core/library/javafx.web.jar create mode 100644 java/mode/.api_description create mode 100644 java/mode/.options create mode 100644 java/mode/about.html create mode 100644 java/mode/org.eclipse.jdt.compiler.apt.jar create mode 100644 java/mode/plugin.properties create mode 100644 java/mode/plugin.xml diff --git a/app/build.xml b/app/build.xml index b6d97218ab..bef3f06b70 100644 --- a/app/build.xml +++ b/app/build.xml @@ -13,14 +13,14 @@ - + - + @@ -30,22 +30,19 @@ + nowarn="true"> - diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 16a31bf80e..df2a30db37 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -342,7 +342,7 @@ public boolean accept(File dir, String name) { name.endsWith(".jdk") && !name.startsWith("."); } }); - return new File(plugins[0], "Contents/Home/jre"); + return new File(plugins[0], "Contents/Home"); } // On all other platforms, it's the 'java' folder adjacent to Processing return getContentFile("java"); @@ -412,4 +412,4 @@ static public int unsetenv(String variable) { static public int getSystemDPI() { return inst.getSystemDPI(); } -} \ No newline at end of file +} diff --git a/build/build.xml b/build/build.xml index a23317c813..6727836fd7 100644 --- a/build/build.xml +++ b/build/build.xml @@ -54,11 +54,11 @@ - + - + @@ -70,15 +70,20 @@ - - + + + - + + + + + + value="/Library/Java/JavaVirtualMachines/${jdk.prefix}${jdk.separator}${jdk.esoteric}.jdk" /> @@ -532,11 +537,8 @@ signature="Pde3" icon="macosx/processing.icns" copyright="© The Processing Foundation" - getInfo="${version}, Copyright © The Processing Foundation" shortVersion="${version}" version="${revision}" - javafx="true" - minimumSystem="10.8.5" mainClassName="processing.app.BaseSplash"> -