2020-05-02 16:14:47 +00:00
|
|
|
import i18n from '@ccms/i18n'
|
|
|
|
import { plugin, server, command, event } from '@ccms/api'
|
|
|
|
import { inject, provideSingleton, Container, ContainerInstance } from '@ccms/container'
|
|
|
|
import * as fs from '@ccms/common/dist/fs'
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2020-05-07 09:12:15 +00:00
|
|
|
import { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata, getPlugin, getPluginTabCompleterMetadata, getPluginConfigMetadata, getPluginStageMetadata, getPluginSources } from './utils'
|
2019-11-05 09:03:49 +00:00
|
|
|
import { interfaces } from './interfaces'
|
2020-02-24 08:24:36 +00:00
|
|
|
import { getConfigLoader } from './config'
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2020-04-24 07:38:00 +00:00
|
|
|
const Thread = Java.type('java.lang.Thread')
|
|
|
|
|
2020-02-26 02:15:33 +00:00
|
|
|
@provideSingleton(plugin.PluginManager)
|
2019-09-07 04:23:15 +00:00
|
|
|
export class PluginManagerImpl implements plugin.PluginManager {
|
2020-01-17 03:11:20 +00:00
|
|
|
@inject(ContainerInstance)
|
|
|
|
private container: Container
|
2019-09-07 04:23:15 +00:00
|
|
|
@inject(plugin.PluginInstance)
|
2019-11-05 09:03:49 +00:00
|
|
|
private pluginInstance: any
|
2020-02-24 08:24:36 +00:00
|
|
|
@inject(plugin.PluginFolder)
|
2020-05-15 06:28:40 +00:00
|
|
|
private pluginFolder: string
|
2019-09-07 04:23:15 +00:00
|
|
|
@inject(server.ServerType)
|
2019-11-05 09:03:49 +00:00
|
|
|
private serverType: string
|
2019-09-19 10:59:32 +00:00
|
|
|
@inject(command.Command)
|
2019-11-05 09:03:49 +00:00
|
|
|
private CommandManager: command.Command
|
2019-09-19 10:59:32 +00:00
|
|
|
@inject(event.Event)
|
2019-11-05 09:03:49 +00:00
|
|
|
private EventManager: event.Event
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2020-04-24 07:38:00 +00:00
|
|
|
private initialized: boolean = false
|
2020-05-08 10:41:56 +00:00
|
|
|
private pluginRequireMap: Map<string, any>
|
|
|
|
private pluginInstanceMap: Map<string, interfaces.Plugin>
|
|
|
|
private pluginMetadataMap: Map<string, interfaces.PluginMetadata>
|
2019-09-07 04:23:15 +00:00
|
|
|
|
2020-01-31 18:46:55 +00:00
|
|
|
initialize() {
|
2020-04-24 07:38:00 +00:00
|
|
|
if (this.pluginInstance !== null && this.initialized !== true) {
|
2019-09-07 04:23:15 +00:00
|
|
|
// 如果plugin不等于null 则代表是正式环境
|
2020-04-24 07:38:00 +00:00
|
|
|
console.i18n('ms.plugin.initialize', { plugin: this.pluginInstance, loader: Thread.currentThread().contextClassLoader })
|
2020-05-15 06:28:40 +00:00
|
|
|
console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType })
|
2020-05-08 10:41:56 +00:00
|
|
|
this.pluginRequireMap = new Map()
|
|
|
|
this.pluginInstanceMap = new Map()
|
2020-05-15 06:28:40 +00:00
|
|
|
this.pluginMetadataMap = getPluginSources()
|
|
|
|
this.initialized = true
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scan(folder: string): void {
|
2020-04-24 07:38:00 +00:00
|
|
|
this.initialize()
|
2019-11-05 09:03:49 +00:00
|
|
|
var plugin = fs.file(root, folder)
|
2020-04-24 07:38:00 +00:00
|
|
|
var files = this.scanFolder(plugin)
|
2019-11-05 09:03:49 +00:00
|
|
|
this.loadPlugins(files)
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 03:11:20 +00:00
|
|
|
build(): void {
|
|
|
|
this.buildPlugins()
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-31 18:46:55 +00:00
|
|
|
private logStage(plugin: interfaces.Plugin, stage: string) {
|
2020-02-27 04:11:18 +00:00
|
|
|
console.i18n("ms.plugin.manager.stage", { stage, plugin: plugin.description.name, version: plugin.description.version, author: plugin.description.author })
|
2020-01-31 18:46:55 +00:00
|
|
|
}
|
|
|
|
|
2020-04-26 02:19:44 +00:00
|
|
|
private runPluginStage(plugin: interfaces.Plugin, stage: string, ext: Function) {
|
|
|
|
this.logStage(plugin, i18n.translate(`ms.plugin.manager.stage.${stage}`))
|
2020-05-02 16:14:47 +00:00
|
|
|
ext()
|
2020-04-26 02:19:44 +00:00
|
|
|
this.runCatch(plugin, stage)
|
|
|
|
this.runCatch(plugin, `${this.serverType}${stage}`)
|
|
|
|
this.execPluginStage(plugin, stage)
|
|
|
|
}
|
|
|
|
|
2020-05-07 10:33:10 +00:00
|
|
|
/**
|
|
|
|
* 从文件加载插件
|
|
|
|
* @param file java.io.File
|
|
|
|
*/
|
2020-05-07 09:12:15 +00:00
|
|
|
loadFromFile(file: string): interfaces.Plugin {
|
2020-05-15 06:28:40 +00:00
|
|
|
let metadata = this.loadPlugin(file)
|
2020-05-08 10:41:56 +00:00
|
|
|
let plugin = this.buildPlugin(metadata && metadata.description ? metadata.description : this.pluginMetadataMap.get(file.toString()))
|
2020-05-07 09:12:15 +00:00
|
|
|
this.load(plugin)
|
|
|
|
this.enable(plugin)
|
2020-05-15 06:28:40 +00:00
|
|
|
return plugin
|
2020-05-07 09:12:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
load(...args: any[]): void {
|
2020-01-31 18:46:55 +00:00
|
|
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
2020-04-26 02:19:44 +00:00
|
|
|
this.runPluginStage(plugin, 'load', () => {
|
|
|
|
this.loadConfig(plugin)
|
|
|
|
})
|
2019-11-05 09:03:49 +00:00
|
|
|
})
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
enable(...args: any[]): void {
|
2020-01-31 18:46:55 +00:00
|
|
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
2020-04-26 02:19:44 +00:00
|
|
|
this.runPluginStage(plugin, 'enable', () => {
|
|
|
|
this.registryCommand(plugin)
|
|
|
|
this.registryListener(plugin)
|
|
|
|
})
|
2019-11-05 09:03:49 +00:00
|
|
|
})
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
disable(...args: any[]): void {
|
2020-01-31 18:46:55 +00:00
|
|
|
this.checkAndGet(args[0]).forEach((plugin: interfaces.Plugin) => {
|
2020-04-26 02:19:44 +00:00
|
|
|
this.runPluginStage(plugin, 'disable', () => {
|
2020-05-15 06:28:40 +00:00
|
|
|
this.saveConfig(plugin)
|
2020-04-26 02:19:44 +00:00
|
|
|
this.unregistryCommand(plugin)
|
|
|
|
this.unregistryListener(plugin)
|
|
|
|
})
|
2019-11-05 09:03:49 +00:00
|
|
|
})
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reload(...args: any[]): void {
|
2019-09-21 07:05:37 +00:00
|
|
|
this.checkAndGet(args[0]).forEach((pl: interfaces.Plugin) => {
|
2019-11-05 09:03:49 +00:00
|
|
|
this.disable(pl)
|
2020-05-07 09:12:15 +00:00
|
|
|
this.loadFromFile(pl.description.source)
|
2019-09-19 10:59:32 +00:00
|
|
|
})
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2019-09-22 10:00:18 +00:00
|
|
|
getPlugins() {
|
2020-05-08 10:41:56 +00:00
|
|
|
return this.pluginInstanceMap
|
2019-09-22 10:00:18 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 04:23:15 +00:00
|
|
|
private runCatch(pl: any, func: string) {
|
|
|
|
try {
|
2019-11-05 09:03:49 +00:00
|
|
|
if (pl[func]) pl[func].call(pl)
|
2019-09-07 04:23:15 +00:00
|
|
|
} catch (ex) {
|
2020-04-26 02:19:44 +00:00
|
|
|
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pl.description.name, executor: func, error: ex })
|
2019-11-05 09:03:49 +00:00
|
|
|
console.ex(ex)
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 09:20:50 +00:00
|
|
|
private checkAndGet(name: string | interfaces.Plugin | undefined | any): Map<string, interfaces.Plugin> | interfaces.Plugin[] {
|
2020-05-12 06:22:31 +00:00
|
|
|
if (name == this.pluginInstanceMap) { return this.pluginInstanceMap }
|
2020-05-08 10:41:56 +00:00
|
|
|
if (typeof name == 'string' && this.pluginInstanceMap.has(name)) { return [this.pluginInstanceMap.get(name)] }
|
2019-11-05 09:03:49 +00:00
|
|
|
if (name instanceof interfaces.Plugin) { return [name as interfaces.Plugin] }
|
2020-05-11 09:20:50 +00:00
|
|
|
if (name.description || name.description.name) { return [name as interfaces.Plugin] }
|
2019-11-05 09:03:49 +00:00
|
|
|
throw new Error(`Plugin ${JSON.stringify(name)} not exist!`)
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 17:58:23 +00:00
|
|
|
private scanFolder(folder: any): string[] {
|
2019-11-05 09:03:49 +00:00
|
|
|
var files = []
|
2020-02-26 17:58:23 +00:00
|
|
|
console.i18n('ms.plugin.manager.scan', { folder })
|
|
|
|
this.checkUpdateFolder(folder)
|
2020-02-23 16:12:32 +00:00
|
|
|
// must check file is exist maybe is a illegal symbolic link file
|
2020-02-26 17:58:23 +00:00
|
|
|
fs.list(folder).forEach((file: any) => file.toFile().exists() ? files.push(file.toFile()) : void 0)
|
2019-11-05 09:03:49 +00:00
|
|
|
return files
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新插件
|
|
|
|
* @param path
|
|
|
|
*/
|
2020-01-15 08:48:18 +00:00
|
|
|
private checkUpdateFolder(path: any) {
|
2019-11-05 09:03:49 +00:00
|
|
|
var update = fs.file(path, "update")
|
2019-09-07 04:23:15 +00:00
|
|
|
if (!update.exists()) {
|
2019-11-05 09:03:49 +00:00
|
|
|
update.mkdirs()
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private loadPlugins(files: any[]): void {
|
2019-11-05 09:03:49 +00:00
|
|
|
this.loadJsPlugins(files)
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JS类型插件预加载
|
|
|
|
*/
|
|
|
|
private loadJsPlugins(files: any[]) {
|
2020-05-11 09:20:50 +00:00
|
|
|
files.filter(file => file.name.endsWith(".js")).forEach(file => {
|
|
|
|
try {
|
|
|
|
this.loadPlugin(file)
|
|
|
|
} catch (ex) {
|
|
|
|
console.i18n("ms.plugin.manager.initialize.error", { name: file.name, ex })
|
|
|
|
console.ex(ex)
|
|
|
|
}
|
|
|
|
})
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private loadPlugin(file: any) {
|
2020-05-11 09:20:50 +00:00
|
|
|
this.updatePlugin(file)
|
|
|
|
return this.createPlugin(file.toString())
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private updatePlugin(file: any) {
|
2019-11-05 09:03:49 +00:00
|
|
|
var update = fs.file(fs.file(file.parentFile, 'update'), file.name)
|
2019-09-07 04:23:15 +00:00
|
|
|
if (update.exists()) {
|
2020-02-27 04:11:18 +00:00
|
|
|
console.i18n("ms.plugin.manager.build.update", { name: file.name })
|
2019-11-05 09:03:49 +00:00
|
|
|
fs.move(update, file, true)
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 09:57:29 +00:00
|
|
|
private allowProcess(servers: string[]) {
|
2020-05-07 09:12:15 +00:00
|
|
|
// Not set servers -> allow
|
2020-04-24 07:38:00 +00:00
|
|
|
if (!servers || !servers.length) return true
|
2020-05-07 09:12:15 +00:00
|
|
|
// include !type -> deny
|
2020-02-27 09:57:29 +00:00
|
|
|
let denyServers = servers.filter(svr => svr.startsWith("!"))
|
|
|
|
if (denyServers.length !== 0) {
|
|
|
|
return !denyServers.includes(`!${this.serverType}`)
|
|
|
|
} else {
|
2020-05-07 09:12:15 +00:00
|
|
|
// only include -> allow
|
2020-02-27 09:57:29 +00:00
|
|
|
return servers.includes(this.serverType)
|
|
|
|
}
|
2020-01-17 09:45:13 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 03:11:20 +00:00
|
|
|
private createPlugin(file: string) {
|
2019-09-07 04:23:15 +00:00
|
|
|
//@ts-ignore
|
2020-05-08 10:41:56 +00:00
|
|
|
let instance = require(file, { cache: false })
|
2020-05-15 06:28:40 +00:00
|
|
|
this.pluginRequireMap.set(file, instance)
|
|
|
|
return instance
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 03:11:20 +00:00
|
|
|
private buildPlugins() {
|
2020-05-15 06:28:40 +00:00
|
|
|
let metadatas = []
|
2019-11-05 09:03:49 +00:00
|
|
|
let pluginMetadatas = getPluginMetadatas()
|
2020-05-15 06:28:40 +00:00
|
|
|
for (const [_, metadata] of pluginMetadatas) { metadatas.push(metadata) }
|
2020-05-08 10:41:56 +00:00
|
|
|
for (const [_, instance] of this.pluginRequireMap) { if (instance.description) { this.buildPlugin(instance.description) } }
|
|
|
|
for (const metadata of metadatas) {
|
2020-02-27 09:57:29 +00:00
|
|
|
if (!this.allowProcess(metadata.servers)) { continue }
|
2019-11-05 09:03:49 +00:00
|
|
|
this.buildPlugin(metadata)
|
2020-01-17 09:45:13 +00:00
|
|
|
}
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private buildPlugin(metadata: interfaces.PluginMetadata) {
|
2020-05-15 06:28:40 +00:00
|
|
|
let pluginInstance: interfaces.Plugin
|
2020-05-08 10:41:56 +00:00
|
|
|
switch (metadata.type) {
|
|
|
|
case "ioc":
|
|
|
|
try {
|
|
|
|
this.bindPlugin(metadata)
|
2020-05-11 09:20:50 +00:00
|
|
|
pluginInstance = this.container.getNamed<interfaces.Plugin>(plugin.Plugin, metadata.name)
|
2020-05-08 10:41:56 +00:00
|
|
|
if (!(pluginInstance instanceof interfaces.Plugin)) {
|
|
|
|
console.i18n('ms.plugin.manager.build.not.extends', { source: metadata.source })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
console.i18n("ms.plugin.manager.initialize.error", { name: metadata.name, ex })
|
|
|
|
console.ex(ex)
|
|
|
|
}
|
2020-05-15 06:28:40 +00:00
|
|
|
break
|
2020-05-08 10:41:56 +00:00
|
|
|
case "basic":
|
2020-05-11 09:20:50 +00:00
|
|
|
pluginInstance = this.pluginRequireMap.get(metadata.source.toString())
|
2020-05-15 06:28:40 +00:00
|
|
|
break
|
2020-05-08 10:41:56 +00:00
|
|
|
default:
|
|
|
|
throw new Error('§4不支持的插件类型 请检查加载器是否正常启用!')
|
2019-11-05 09:03:49 +00:00
|
|
|
}
|
2020-05-11 09:20:50 +00:00
|
|
|
this.pluginInstanceMap.set(metadata.name, pluginInstance)
|
2020-05-15 06:28:40 +00:00
|
|
|
return pluginInstance
|
2019-11-05 09:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private bindPlugin(metadata: interfaces.PluginMetadata) {
|
2019-09-19 10:59:32 +00:00
|
|
|
try {
|
2020-01-17 03:11:20 +00:00
|
|
|
let pluginInstance = this.container.getNamed<interfaces.Plugin>(plugin.Plugin, metadata.name)
|
2019-09-19 10:59:32 +00:00
|
|
|
if (pluginInstance.description.source + '' !== metadata.source + '') {
|
2020-02-27 04:11:18 +00:00
|
|
|
console.i18n('ms.plugin.manager.build.duplicate', { exists: pluginInstance.description.source, source: metadata.source })
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
2020-01-17 03:11:20 +00:00
|
|
|
this.container.rebind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
2019-09-19 10:59:32 +00:00
|
|
|
} catch{
|
2020-01-17 03:11:20 +00:00
|
|
|
this.container.bind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name)
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-24 08:24:36 +00:00
|
|
|
private loadConfig(plugin: interfaces.Plugin) {
|
2020-05-15 06:28:40 +00:00
|
|
|
let configs = getPluginConfigMetadata(plugin)
|
2020-02-24 08:24:36 +00:00
|
|
|
for (let [_, config] of configs) {
|
2020-05-15 06:28:40 +00:00
|
|
|
try {
|
|
|
|
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
|
|
|
|
let configFactory = getConfigLoader(config.format)
|
|
|
|
if (!fs.exists(configFile)) {
|
|
|
|
base.save(configFile, configFactory.dump(plugin[config.variable]))
|
|
|
|
console.i18n("ms.plugin.manager.config.save.default", { plugin: plugin.description.name, name: config.name, format: config.format })
|
|
|
|
} else {
|
|
|
|
plugin[config.variable] = configFactory.load(base.read(configFile))
|
|
|
|
plugin[config.variable].save = () => base.save(configFile, configFactory.dump(plugin[config.variable]))
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.i18n("ms.plugin.manager.config.load.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
|
|
|
|
console.ex(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private saveConfig(plugin: interfaces.Plugin) {
|
|
|
|
let configs = getPluginConfigMetadata(plugin)
|
|
|
|
for (let [_, config] of configs) {
|
|
|
|
try {
|
|
|
|
let configFile = fs.concat(root, this.pluginFolder, plugin.description.name, config.name + '.' + config.format)
|
|
|
|
let configFactory = getConfigLoader(config.format)
|
|
|
|
if (!config.readonly) { base.save(configFile, configFactory.dump(plugin[config.variable])) }
|
|
|
|
} catch (error) {
|
|
|
|
console.i18n("ms.plugin.manager.config.save.error", { plugin: plugin.description.name, name: config.name, format: config.format, error })
|
|
|
|
console.ex(error)
|
2020-02-24 08:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-23 16:12:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 10:59:32 +00:00
|
|
|
private registryCommand(pluginInstance: interfaces.Plugin) {
|
2019-11-05 09:03:49 +00:00
|
|
|
let cmds = getPluginCommandMetadata(pluginInstance)
|
|
|
|
let tabs = getPluginTabCompleterMetadata(pluginInstance)
|
2020-01-17 03:11:20 +00:00
|
|
|
for (const [_, cmd] of cmds) {
|
2019-11-05 09:03:49 +00:00
|
|
|
let tab = tabs.get(cmd.name)
|
2020-02-27 09:57:29 +00:00
|
|
|
if (!this.allowProcess(cmd.servers)) { continue }
|
2019-09-19 10:59:32 +00:00
|
|
|
this.CommandManager.on(pluginInstance, cmd.name, {
|
|
|
|
cmd: pluginInstance[cmd.executor].bind(pluginInstance),
|
|
|
|
tab: tab ? pluginInstance[tab.executor].bind(pluginInstance) : undefined
|
2019-11-05 09:03:49 +00:00
|
|
|
})
|
2020-01-17 03:11:20 +00:00
|
|
|
}
|
2019-09-19 10:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private registryListener(pluginInstance: interfaces.Plugin) {
|
|
|
|
let events = getPluginListenerMetadata(pluginInstance)
|
|
|
|
for (const event of events) {
|
2019-09-21 07:05:37 +00:00
|
|
|
// ignore space listener
|
2020-02-27 09:57:29 +00:00
|
|
|
if (!this.allowProcess(event.servers)) { continue }
|
2019-09-19 10:59:32 +00:00
|
|
|
// here must bind this to pluginInstance
|
2019-11-05 09:03:49 +00:00
|
|
|
this.EventManager.listen(pluginInstance, event.name, pluginInstance[event.executor].bind(pluginInstance))
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-22 10:00:18 +00:00
|
|
|
|
|
|
|
private unregistryCommand(pluginInstance: interfaces.Plugin) {
|
2019-11-05 09:03:49 +00:00
|
|
|
let cmds = getPluginCommandMetadata(pluginInstance)
|
2019-09-22 10:00:18 +00:00
|
|
|
cmds.forEach(cmd => {
|
2019-11-05 09:03:49 +00:00
|
|
|
this.CommandManager.off(pluginInstance, cmd.name)
|
2019-09-22 10:00:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private unregistryListener(pluginInstance: interfaces.Plugin) {
|
2019-11-05 09:03:49 +00:00
|
|
|
this.EventManager.disable(pluginInstance)
|
2019-09-22 10:00:18 +00:00
|
|
|
}
|
2020-04-24 07:38:00 +00:00
|
|
|
|
|
|
|
private execPluginStage(pluginInstance: interfaces.Plugin, stageName: string) {
|
2020-05-15 06:28:40 +00:00
|
|
|
let stages = getPluginStageMetadata(pluginInstance, stageName)
|
2020-04-24 07:38:00 +00:00
|
|
|
for (const stage of stages) {
|
|
|
|
if (!this.allowProcess(stage.servers)) { continue }
|
|
|
|
console.i18n("ms.plugin.manager.stage.exec", { plugin: pluginInstance.description.name, name: stage.executor, stage: stageName, servers: stage.servers })
|
2020-04-26 02:19:44 +00:00
|
|
|
try {
|
|
|
|
pluginInstance[stage.executor].apply(pluginInstance)
|
|
|
|
} catch (error) {
|
|
|
|
console.i18n("ms.plugin.manager.stage.exec.error", { plugin: pluginInstance.description.name, executor: stage.executor, error })
|
|
|
|
console.ex(error)
|
|
|
|
}
|
2020-04-24 07:38:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-07 04:23:15 +00:00
|
|
|
}
|