From 10b36e5f806d941dc33d3e51a0297741ad6a553a Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 1 Jan 2021 10:07:32 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20Core=20=E4=B8=BA=20FrameworkManager?= =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20'validatePluginDescriptor'=20?= =?UTF-8?q?=E7=9A=84=E5=85=B7=E4=BD=93=E5=AE=9E=E7=8E=B0,=20=E4=BB=A5?= =?UTF-8?q?=E5=AF=B9=20FrameworkDescriptor=20=E8=BF=9B=E8=A1=8C=E6=A3=80?= =?UTF-8?q?=E6=9F=A5;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [Change] FrameworkManager 覆盖 'validatePluginDescriptor' 方法, 补充对 FrameworkDescriptor 的检查; --- .../cgj/bot/framework/FrameworkManager.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java index df2914c..6e5ec3a 100644 --- a/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java +++ b/ContentGrabbingJi-core/src/main/java/net/lamgc/cgj/bot/framework/FrameworkManager.java @@ -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"); + } + + } }