|
|
@ -7,15 +7,34 @@ import com.fanruan.carina.annotions.FineComponent; |
|
|
|
import com.fanruan.carina.annotions.Start; |
|
|
|
import com.fanruan.carina.annotions.Start; |
|
|
|
import com.fanruan.carina.annotions.Stop; |
|
|
|
import com.fanruan.carina.annotions.Stop; |
|
|
|
import com.fanruan.carina.annotions.Supplemental; |
|
|
|
import com.fanruan.carina.annotions.Supplemental; |
|
|
|
|
|
|
|
import com.fanruan.plugin.autonomy.AutonomyClassManagerFactory; |
|
|
|
import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup; |
|
|
|
import com.fanruan.plugin.autonomy.AutonomyClassManagerGroup; |
|
|
|
import com.fanruan.plugin.autonomy.AutonomyClassManagerProvider; |
|
|
|
import com.fanruan.plugin.autonomy.AutonomyClassManagerProvider; |
|
|
|
|
|
|
|
import com.fr.config.ConfigContext; |
|
|
|
|
|
|
|
import com.fr.invoke.ClassFactory; |
|
|
|
import com.fr.json.JSONObject; |
|
|
|
import com.fr.json.JSONObject; |
|
|
|
import com.fr.plugin.ExtraClassManager; |
|
|
|
import com.fr.plugin.beforeload.embed.PluginEmbedInfo; |
|
|
|
|
|
|
|
import com.fr.plugin.config.PluginConfigContext; |
|
|
|
|
|
|
|
import com.fr.plugin.injectable.PluginInjectionFilter; |
|
|
|
import com.fr.plugin.manage.PluginManager; |
|
|
|
import com.fr.plugin.manage.PluginManager; |
|
|
|
import com.fr.plugin.manage.PluginSyncModuleType; |
|
|
|
import com.fr.plugin.manage.PluginSyncModuleType; |
|
|
|
|
|
|
|
import com.fr.plugin.observer.PluginEvent; |
|
|
|
|
|
|
|
import com.fr.plugin.observer.PluginEventListener; |
|
|
|
|
|
|
|
import com.fr.plugin.observer.PluginListenerRegistration; |
|
|
|
|
|
|
|
import com.fr.plugin.validate.PluginValidator; |
|
|
|
|
|
|
|
import com.fr.stable.CommonUtils; |
|
|
|
|
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
|
|
|
|
import com.fr.stable.resource.ResourceLoader; |
|
|
|
|
|
|
|
import com.fr.startup.web.annotation.MappingJackson2HttpMessageConverter; |
|
|
|
|
|
|
|
import com.fr.workspace.WorkContext; |
|
|
|
import com.fr.workspace.server.repository.plugin.PluginRepository; |
|
|
|
import com.fr.workspace.server.repository.plugin.PluginRepository; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext; |
|
|
|
import javax.servlet.ServletContext; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.net.MalformedURLException; |
|
|
|
|
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.net.URLClassLoader; |
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.function.Supplier; |
|
|
|
import java.util.function.Supplier; |
|
|
|
|
|
|
|
|
|
|
@ -43,13 +62,35 @@ public class DesignPluginComponent extends PluginComponent { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Start |
|
|
|
@Start |
|
|
|
public void start() { |
|
|
|
public void start() { |
|
|
|
ExtraClassManager.getInstance().registerAutonomyClassManager(Carina.getApplicationContext().group(AutonomyClassManagerGroup.class).getAll().toArray(new AutonomyClassManagerProvider[0])); |
|
|
|
//收集插件对象的过滤器
|
|
|
|
|
|
|
|
Collection<PluginInjectionFilter> filters = Carina.getApplicationContext().group(PluginInjectionFilter.GroupKey.class).getAll(); |
|
|
|
|
|
|
|
for (PluginInjectionFilter filter: filters) { |
|
|
|
|
|
|
|
PluginManager.addInjectionFilter(filter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//装备外部的验证器
|
|
|
|
|
|
|
|
assembleValidator(); |
|
|
|
|
|
|
|
// 注册内置插件信息
|
|
|
|
|
|
|
|
registerEmbedPluginInfo(); |
|
|
|
|
|
|
|
// 注册插件配置类Provider
|
|
|
|
|
|
|
|
registerPluginConfigProvider(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AutonomyClassManagerFactory.getInstance().registerAutonomyClassManager(Carina.getApplicationContext().group(AutonomyClassManagerGroup.class).getAll().toArray(new AutonomyClassManagerProvider[0])); |
|
|
|
|
|
|
|
|
|
|
|
Supplier<List<JSONObject>> supplier = () -> PluginRepository.getInstance().getPluginStatus(); |
|
|
|
Supplier<List<JSONObject>> supplier = () -> PluginRepository.getInstance().getPluginStatus(); |
|
|
|
PluginManager.registerRemotePluginSupplier(supplier); |
|
|
|
PluginManager.registerRemotePluginSupplier(supplier); |
|
|
|
PluginManager.setSyncModuleType(PluginSyncModuleType.DESIGN); |
|
|
|
PluginManager.setSyncModuleType(PluginSyncModuleType.DESIGN); |
|
|
|
|
|
|
|
//PluginManager要在环境切换和模块启动之前初始化
|
|
|
|
|
|
|
|
PluginManager.startEngine(); |
|
|
|
|
|
|
|
|
|
|
|
super.start(); |
|
|
|
PluginListenerRegistration.getInstance().listenRunningChanged(new PluginEventListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void on(PluginEvent event) { |
|
|
|
|
|
|
|
MappingJackson2HttpMessageConverter.KEY.refreshObjectMapper(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
registerPluginClassFinder(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -57,6 +98,45 @@ public class DesignPluginComponent extends PluginComponent { |
|
|
|
// do nothing
|
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void registerEmbedPluginInfo() { |
|
|
|
|
|
|
|
Collection<PluginEmbedInfo> pluginEmbedInfos = Carina.getApplicationContext().group(PluginEmbedInfo.class).getAll(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PluginManager.getPluginEmbedManager().addPluginEmbedInfos(pluginEmbedInfos); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void registerPluginConfigProvider() { |
|
|
|
|
|
|
|
ConfigContext.setPluginConfigContextProvider(new PluginConfigContext()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void assembleValidator() { |
|
|
|
|
|
|
|
PluginManager.getValidatorManager().register(Carina.getApplicationContext().group(PluginValidator.GroupKey.class).getAll()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void registerPluginClassFinder() { |
|
|
|
|
|
|
|
ClassFactory.getInstance().addFinder(className -> { |
|
|
|
|
|
|
|
//再找.
|
|
|
|
|
|
|
|
// alex:currentEnv可能是null
|
|
|
|
|
|
|
|
String envPath = WorkContext.getCurrent().getPath(); |
|
|
|
|
|
|
|
if (envPath == null) { |
|
|
|
|
|
|
|
throw new ClassNotFoundException(className); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
File clssesFile = new File(CommonUtils.pathJoin(envPath, ProjectConstants.CLASSES_NAME)); |
|
|
|
|
|
|
|
ClassLoader urlClassLoader; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
urlClassLoader = new URLClassLoader(new URL[]{clssesFile.toURI().toURL()}, CommonUtils.class.getClassLoader()); |
|
|
|
|
|
|
|
} catch (MalformedURLException malformedURLException) { |
|
|
|
|
|
|
|
urlClassLoader = ClassLoader.getSystemClassLoader(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Class.forName(className, true, urlClassLoader); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//从插件中拿
|
|
|
|
|
|
|
|
ClassFactory.getInstance().addFinder(ResourceLoader::classForName); |
|
|
|
|
|
|
|
//从插件引擎中拿
|
|
|
|
|
|
|
|
ClassFactory.getInstance().addFinder(className -> Class.forName(className, true, PluginManager.getController().getClass().getClassLoader())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* stop |
|
|
|
* stop |
|
|
|
*/ |
|
|
|
*/ |
|
|
|