This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new dc23c4525 CAY-2742 Switch minimum required Java version to 11  - drop 
code that handled incompatibility between Java 8 and 9 in the MacOS version
dc23c4525 is described below

commit dc23c45256fded9a6db038912c27b65ef8a5759d
Author: Nikita Timofeev <stari...@gmail.com>
AuthorDate: Thu Jul 7 17:34:44 2022 +0300

    CAY-2742 Switch minimum required Java version to 11
     - drop code that handled incompatibility between Java 8 and 9 in the MacOS 
version
---
 .../cayenne/modeler/osx/OSXApplicationWrapper.java | 149 ---------------------
 .../modeler/osx/OSXPlatformInitializer.java        |  15 +--
 .../modeler/osx/OSXQuitResponseWrapper.java        |  73 ----------
 3 files changed, 5 insertions(+), 232 deletions(-)

diff --git 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXApplicationWrapper.java
 
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXApplicationWrapper.java
deleted file mode 100644
index 34ad852fa..000000000
--- 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXApplicationWrapper.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    https://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.osx;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.function.Consumer;
-
-import com.apple.eawt.Application;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class wraps apple {@link com.apple.eawt.Application} class and 
dynamically
- * proxying it's lifecycle handlers setup.
- * <p>
- * This code exists to support both Java 8 and 9, as handler interfaces where 
incompatibly moved
- * to other package between these versions.
- * <p>
- * See <a href="https://bugs.openjdk.java.net/browse/JDK-8160437";>JDK-8160437 
issue</a> for details.
- *
- * @see #setAboutHandler(Runnable) run action on "About App" menu item select
- * @see #setPreferencesHandler(Runnable) run action on "Preferences..." menu 
item select
- * @see #setQuitHandler(Consumer) run action on "Quit App" menu item select
- *
- * @see OSXQuitResponseWrapper
- *
- * @since 4.1
- */
-public class OSXApplicationWrapper {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(OSXApplicationWrapper.class);
-
-    // package for handler classes for Java 8 and older
-    private static final String JAVA8_PACKAGE = "com.apple.eawt.";
-
-    // package for handler classes for Java 9 and newer
-    private static final String JAVA9_PACKAGE = "java.awt.desktop.";
-
-    private final Application application;
-
-    private Class<?> aboutHandlerClass;
-    private Method setAboutHandler;
-
-    private Class<?> preferencesHandlerClass;
-    private Method setPreferencesHandler;
-
-    private Class<?> quitHandlerClass;
-    private Method setQuitHandler;
-
-    public OSXApplicationWrapper(Application application) {
-        this.application = application;
-        initMethods();
-    }
-
-    public void setPreferencesHandler(Runnable action) {
-        setHandler(setPreferencesHandler, preferencesHandlerClass, action);
-    }
-
-    public void setAboutHandler(Runnable action) {
-        setHandler(setAboutHandler, aboutHandlerClass, action);
-    }
-
-    public void setQuitHandler(Consumer<OSXQuitResponseWrapper> action) {
-        InvocationHandler handler = (proxy, method, args) -> {
-            // args: 0 - event, 1 - quitResponse
-            action.accept(new OSXQuitResponseWrapper(args[1]));
-            return null;
-        };
-        Object proxy = createProxy(quitHandlerClass, handler);
-        try {
-            setQuitHandler.invoke(application, proxy);
-        } catch (IllegalAccessException | InvocationTargetException ex) {
-            logger.warn("Unable to call " + setQuitHandler.getName(), ex);
-        }
-    }
-
-    /**
-     * Find required handlers' methods and classes
-     */
-    private void initMethods() {
-        aboutHandlerClass = getHandlerClass("AboutHandler");
-        setAboutHandler = getMethod("setAboutHandler", aboutHandlerClass);
-
-        preferencesHandlerClass = getHandlerClass("PreferencesHandler");
-        setPreferencesHandler = getMethod("setPreferencesHandler", 
preferencesHandlerClass);
-
-        quitHandlerClass = getHandlerClass("QuitHandler");
-        setQuitHandler = getMethod("setQuitHandler", quitHandlerClass);
-    }
-
-    private void setHandler(Method setMethod, Class<?> handlerClass, Runnable 
action) {
-        InvocationHandler handler = (proxy, method, args) -> {
-            action.run();
-            return null;
-        };
-        Object proxy = createProxy(handlerClass, handler);
-        try {
-            setMethod.invoke(application, proxy);
-        } catch (IllegalAccessException | InvocationTargetException ex) {
-            logger.warn("Unable to call " + setMethod.getName(), ex);
-        }
-    }
-
-    private Object createProxy(Class<?> handlerClass, InvocationHandler 
handler) {
-        return 
Proxy.newProxyInstance(OSXApplicationWrapper.class.getClassLoader(), new 
Class<?>[]{handlerClass}, handler);
-    }
-
-    private Method getMethod(String name, Class<?> ... parameters) {
-        try {
-            return application.getClass().getMethod(name, parameters);
-        } catch (NoSuchMethodException ex) {
-            logger.warn("Unable to find method " + name, ex);
-            return null;
-        }
-    }
-
-    private Class<?> getHandlerClass(String className) {
-        try {
-            return Class.forName(JAVA8_PACKAGE + className);
-        } catch (ClassNotFoundException ex) {
-            try {
-                return Class.forName(JAVA9_PACKAGE + className);
-            } catch (ClassNotFoundException ex2) {
-                return null;
-            }
-        }
-    }
-
-}
diff --git 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
 
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
index 6651e96d6..0ee1cc110 100644
--- 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
+++ 
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXPlatformInitializer.java
@@ -20,6 +20,7 @@ package org.apache.cayenne.modeler.osx;
 
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.Desktop;
 import java.awt.Graphics;
 import java.util.HashSet;
 import java.util.Set;
@@ -42,8 +43,6 @@ import 
org.apache.cayenne.modeler.action.ConfigurePreferencesAction;
 import org.apache.cayenne.modeler.action.ExitAction;
 import org.apache.cayenne.modeler.init.platform.PlatformInitializer;
 
-import com.apple.eawt.Application;
-
 public class OSXPlatformInitializer implements PlatformInitializer {
 
     @Inject
@@ -54,15 +53,11 @@ public class OSXPlatformInitializer implements 
PlatformInitializer {
         // override some default styles and colors, assuming that Aqua theme 
will be used
         overrideUIDefaults();
 
-        // configure special Mac menu handlers
-        OSXApplicationWrapper wrapper = new 
OSXApplicationWrapper(Application.getApplication());
-        wrapper.setAboutHandler(()
-                -> 
actionManager.getAction(AboutAction.class).showAboutDialog());
-
-        wrapper.setPreferencesHandler(()
-                -> 
actionManager.getAction(ConfigurePreferencesAction.class).showPreferencesDialog());
+        Desktop desktop = Desktop.getDesktop();
 
-        wrapper.setQuitHandler(r -> {
+        desktop.setAboutHandler(e -> 
actionManager.getAction(AboutAction.class).showAboutDialog());
+        desktop.setPreferencesHandler(e -> 
actionManager.getAction(ConfigurePreferencesAction.class).showPreferencesDialog());
+        desktop.setQuitHandler((e, r) -> {
             if(!actionManager.getAction(ExitAction.class).exit()) {
                 r.cancelQuit();
             } else {
diff --git 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXQuitResponseWrapper.java
 
b/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXQuitResponseWrapper.java
deleted file mode 100644
index 815a11c62..000000000
--- 
a/modeler/cayenne-modeler-mac-ext/src/main/java/org/apache/cayenne/modeler/osx/OSXQuitResponseWrapper.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    https://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.osx;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Small wrapper around QuitResponse class that can reside in different 
packages:
- * com.apple.eawt.QuitResponse in JDK 8 and java.awt.desktop.QuitResponse in 
JDK 9.
- * Luckily it has same signature so we can dynamically resolve it's methods.
- *
- * @since 4.1
- */
-public class OSXQuitResponseWrapper {
-
-    private static final Logger logger = 
LoggerFactory.getLogger(OSXQuitResponseWrapper.class);
-
-    private Method performQuit;
-
-    private Method cancelQuit;
-
-    private final Object quitResponse;
-
-    public OSXQuitResponseWrapper(Object quitResponse) {
-        this.quitResponse = quitResponse;
-        try {
-            performQuit = quitResponse.getClass().getMethod("performQuit");
-            cancelQuit = quitResponse.getClass().getMethod("cancelQuit");
-        } catch (NoSuchMethodException ex) {
-            logger.warn("Unable to find methods for quit response", ex);
-        }
-    }
-
-    public void performQuit() {
-        safePerform(performQuit);
-    }
-
-    public void cancelQuit() {
-        safePerform(cancelQuit);
-    }
-
-    private void safePerform(Method method) {
-        if(method == null) {
-            return;
-        }
-        try {
-            method.invoke(quitResponse);
-        } catch (IllegalAccessException | InvocationTargetException ex) {
-            logger.warn("Unable to call " + method.getName(), ex);
-        }
-    }
-}

Reply via email to