[Change] Core 为 FrameworkManager 添加对 'validatePluginDescriptor' 的具体实现, 以对 FrameworkDescriptor 进行检查;

[Change] FrameworkManager 覆盖 'validatePluginDescriptor' 方法, 补充对 FrameworkDescriptor 的检查;
This commit is contained in:
LamGC 2021-01-01 10:07:32 +08:00
parent a5f85227f2
commit 10b36e5f80
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -17,6 +17,7 @@
package net.lamgc.cgj.bot.framework;
import com.google.common.base.Strings;
import org.pf4j.*;
import java.io.File;
@ -82,4 +83,26 @@ public class FrameworkManager extends JarPluginManager {
protected PluginFactory createPluginFactory() {
return new FrameworkFactory(getPluginsRoot().getParent().resolve("frameworkData").toFile(), parentContext);
}
@Override
protected void validatePluginDescriptor(PluginDescriptor descriptor) {
if (!(descriptor instanceof FrameworkDescriptor)) {
throw new PluginRuntimeException("Unsupported framework description specification");
}
super.validatePluginDescriptor(descriptor);
if (Strings.isNullOrEmpty(descriptor.getPluginClass())) {
throw new PluginRuntimeException("Field 'frameworkClass' cannot be empty");
}
Platform platform = ((FrameworkDescriptor) descriptor).getPlatform();
if (platform == null) {
throw new PluginRuntimeException("Field 'platform' cannot be empty");
} else if (Strings.isNullOrEmpty(platform.getPlatformIdentify())) {
throw new PluginRuntimeException("Field 'platform.platformIdentify' cannot be empty");
} else if (Strings.isNullOrEmpty(platform.getPlatformName())) {
throw new PluginRuntimeException("Field 'platform.platformName' cannot be empty");
}
}
}