feat: 添加类加载器异常检查 核心类去除patch的方法
This commit is contained in:
@ -1,49 +1,62 @@
|
||||
'use strict';
|
||||
var log;
|
||||
var boot;
|
||||
var loader;
|
||||
var disable;
|
||||
/**
|
||||
* 初始化框架引擎
|
||||
*/
|
||||
(function () {
|
||||
boot = function (root, logger) {
|
||||
log = logger;
|
||||
// 开发环境下初始化
|
||||
root = root || "src/main/resources";
|
||||
var debug = false;
|
||||
if (__FILE__ !== "<eval>") {
|
||||
logger.info('载入自定义 BIOS 文件 ' + __FILE__);
|
||||
debug = true;
|
||||
}
|
||||
// 检查类加载器 防止找不到核心文件
|
||||
loader = checkClassLoader();
|
||||
// 解压文件到根目录 非调试模式直接从jar解压覆盖
|
||||
release(root, "[api|core|internal|modules]/.*", !debug);
|
||||
release(root, "plugins/.*");
|
||||
load(root + '/core/init.js');
|
||||
// 初始化必须在load之后 不然global找不到
|
||||
global.debug = debug;
|
||||
try {
|
||||
log = logger;
|
||||
// 开发环境下初始化
|
||||
root = root || "src/main/resources";
|
||||
// 解压文件到根目录
|
||||
release(root, "[api|core|internal|modules]/.*", true);
|
||||
release(root, "plugins/.*");
|
||||
load(root + '/core/init.js');
|
||||
if (__FILE__ !== "<eval>") {
|
||||
logger.info('载入自定义 BIOS 文件 ' + __FILE__);
|
||||
global.debug = true;
|
||||
}
|
||||
init(root);
|
||||
} catch (ex) {
|
||||
if (console && console.ex) {
|
||||
console.ex(ex);
|
||||
} else {
|
||||
ex.printStackTrace();
|
||||
throw ex;
|
||||
}
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
disable = disablePlugins;
|
||||
disable = function () {
|
||||
if (disablePlugins && typeof(disablePlugins) === "function") {
|
||||
disablePlugins();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var pluginYml;
|
||||
|
||||
function checkClassLoader(){
|
||||
var classLoader = java.lang.Thread.currentThread().getContextClassLoader();
|
||||
pluginYml = classLoader.getResource("plugin.yml");
|
||||
if (pluginYml === null) {
|
||||
log.info("==================== ERROR ====================");
|
||||
log.info("异常的类加载器: " + classLoader.class.name);
|
||||
log.info("==================== ERROR ====================");
|
||||
throw Error('MiaoScript核心类库初始化失败 异常的类加载器!');
|
||||
}
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
function release(root, regex, replace) {
|
||||
var Files = Java.type("java.nio.file.Files");
|
||||
var Paths = Java.type("java.nio.file.Paths");
|
||||
var StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||
|
||||
var classLoader = java.lang.Thread.currentThread().getContextClassLoader();
|
||||
var url = classLoader.getResource("plugin.yml");
|
||||
if (url === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var upath = url.getFile().substring(url.getFile().indexOf("/") + 1);
|
||||
var upath = pluginYml.getFile().substring(pluginYml.getFile().indexOf("/") + 1);
|
||||
var jarPath = java.net.URLDecoder.decode(upath.substring(0, upath.indexOf('!')));
|
||||
if (!Files.exists(Paths.get(jarPath))) {
|
||||
jarPath = "/" + jarPath;
|
||||
@ -65,7 +78,6 @@ var disable;
|
||||
}
|
||||
})
|
||||
} catch (ex) {
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user