2017-09-23 09:42:16 +00:00
|
|
|
'use strict';
|
2017-11-16 12:28:18 +00:00
|
|
|
var global = this;
|
2017-09-14 12:41:34 +00:00
|
|
|
/**
|
2019-09-23 01:02:34 +00:00
|
|
|
* Init MiaoScriptEngine Runtime
|
2017-09-14 12:41:34 +00:00
|
|
|
*/
|
2020-05-02 16:31:59 +00:00
|
|
|
(function () {
|
2017-11-16 12:28:18 +00:00
|
|
|
var loader;
|
2020-05-02 16:31:59 +00:00
|
|
|
global.boot = function (root, logger) {
|
2020-06-23 05:39:00 +00:00
|
|
|
global.scope = java.lang.System.getenv("MS_NODE_CORE_SCOPE") || "@ccms";
|
2020-05-02 16:31:59 +00:00
|
|
|
global.log = logger;
|
2019-08-29 02:08:29 +00:00
|
|
|
// Development Env Detect
|
2020-05-02 16:31:59 +00:00
|
|
|
global.root = root || "src/main/resources";
|
2020-04-22 01:23:21 +00:00
|
|
|
if (__FILE__.indexOf('!') === -1) {
|
2019-02-23 16:00:03 +00:00
|
|
|
logger.info('Loading custom BIOS file ' + __FILE__);
|
2017-11-16 12:28:18 +00:00
|
|
|
global.debug = true;
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
2017-12-28 08:29:10 +00:00
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "debug"))) {
|
2020-01-31 18:41:00 +00:00
|
|
|
logger.info('Running in debug mode...');
|
2017-11-30 05:27:20 +00:00
|
|
|
global.debug = true;
|
2020-01-31 18:41:00 +00:00
|
|
|
}
|
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "level"))) {
|
|
|
|
global.level = base.read(java.nio.file.Paths.get(root, "level"))
|
|
|
|
logger.info('Set system level to [' + global.level + ']...');
|
2017-11-30 05:27:20 +00:00
|
|
|
}
|
2020-04-22 01:23:21 +00:00
|
|
|
// Check Class Loader, Sometimes Server will can't found plugin.yml file
|
2017-11-15 10:40:17 +00:00
|
|
|
loader = checkClassLoader();
|
2020-02-29 09:32:53 +00:00
|
|
|
// Async Loading MiaoScript Engine
|
2020-05-02 16:31:59 +00:00
|
|
|
new java.lang.Thread(function () {
|
2020-04-22 01:23:21 +00:00
|
|
|
java.lang.Thread.currentThread().contextClassLoader = loader;
|
2020-06-23 05:39:00 +00:00
|
|
|
load(java.lang.System.getenv("MS_NODE_CORE_PLOYFILL") || 'classpath:core/ployfill.js')(root, logger);
|
|
|
|
global.engineDisable = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || global.scope + '/core').default || function () {
|
|
|
|
logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...')
|
|
|
|
};
|
2020-02-29 09:32:53 +00:00
|
|
|
}, "MiaoScript thread").start()
|
2017-09-23 09:42:16 +00:00
|
|
|
};
|
2017-10-26 13:01:24 +00:00
|
|
|
|
2017-11-15 13:00:07 +00:00
|
|
|
function checkClassLoader() {
|
2018-03-18 12:06:52 +00:00
|
|
|
var classLoader = java.lang.Thread.currentThread().contextClassLoader;
|
2020-05-28 09:05:47 +00:00
|
|
|
if (classLoader.getResource("bios.js") === null) {
|
2019-02-23 16:00:03 +00:00
|
|
|
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!");
|
|
|
|
} else {
|
|
|
|
log.info("Class loader compatible: " + classLoader.class.name);
|
2019-03-25 09:13:54 +00:00
|
|
|
if (classLoader.parent) {
|
|
|
|
log.info("Parent class loader: " + classLoader.parent.class.name);
|
|
|
|
}
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
|
|
|
return classLoader;
|
|
|
|
}
|
2019-08-29 02:08:29 +00:00
|
|
|
})();
|