Browse Source

Pull request #8160: REPORT-67689 对Install4j方法的调用全部改用反射实现,避免出现引用异常

Merge in DESIGN/design from ~STARRYI/design:release/11.0 to release/11.0

* commit 'fd1e35aaa194d8f471ec66e2295c5e66f59b6afd':
  无JIRA项目 对Install4j方法的调用全部改用反射实现,避免出现引用异常
bugfix/11.0
starryi 3 years ago
parent
commit
70bf342d9e
  1. 42
      designer-base/src/main/java/com/fr/design/startup/Install4jStartupNotificationProvider.java

42
designer-base/src/main/java/com/fr/design/startup/Install4jStartupNotificationProvider.java

@ -1,6 +1,10 @@
package com.fr.design.startup;
import com.install4j.api.launcher.StartupNotification;
import com.fr.invoke.Reflect;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* @author Starryi
@ -18,18 +22,30 @@ public class Install4jStartupNotificationProvider implements FineStartupNotifica
@Override
public void registerStartupListener(Listener listener) {
boolean supported = false;
try {
supported = Class.forName("com.install4j.api.launcher.StartupNotification") != null;
} catch (Throwable ignored) {}
if (supported) {
StartupNotification.registerStartupListener(new StartupNotification.Listener() {
@Override
public void startupPerformed(String parameters) {
listener.startupPerformed(parameters);
}
});
Class<?> StartupNotificationListenerClass = Reflect.on("com.install4j.api.launcher.StartupNotification$Listener").type();
if (StartupNotificationListenerClass == null) {
return;
}
ListenerHandler mHandler = new ListenerHandler(listener);
Object listenerCallbackInstance = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { StartupNotificationListenerClass }, mHandler);
Reflect.on("com.install4j.api.launcher.StartupNotification").call("registerStartupListener", listenerCallbackInstance);
}
private static class ListenerHandler implements InvocationHandler {
private final Listener listener;
public ListenerHandler(Listener listener) {
this.listener = listener;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (args[0] instanceof String) {
String parameters = (String) args[0];
listener.startupPerformed(parameters);
}
return null;
}
}
}

Loading…
Cancel
Save