Browse Source

无JIRA项目 对Install4j方法的调用全部改用反射实现,避免出现引用异常

【问题原因】
考核同学使用starter项目,无法进行正常编译,出现类和方法调用异常。
一方面是starter项目没有配置对intall4j的编译依赖导致,另一方面是主jar中
对install4j API的使用没有反射导致
【改动思路】
改用反射方式调用Install4J相关API
【review建议】
bugfix/11.0
Starryi 2 years ago
parent
commit
fd1e35aaa1
  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