2021-03-26 07:54:26 +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 () {
|
2020-09-21 08:06:37 +00:00
|
|
|
global.engineDisable = function () {
|
|
|
|
global.engineDisableImpl && global.engineDisableImpl()
|
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "old_node_modules"))) {
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Found old_node_modules folder delete...')
|
2020-09-21 08:06:37 +00:00
|
|
|
base.delete(java.nio.file.Paths.get(root, "old_node_modules"))
|
|
|
|
}
|
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "upgrade"))) {
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Found upgrade file delete node_modules...')
|
2020-09-21 08:06:37 +00:00
|
|
|
base.delete(java.nio.file.Paths.get(root, "node_modules"))
|
|
|
|
base.delete(java.nio.file.Paths.get(root, "upgrade"))
|
|
|
|
}
|
2021-03-26 07:54:26 +00:00
|
|
|
}
|
2020-05-02 16:31:59 +00:00
|
|
|
global.boot = function (root, logger) {
|
2021-03-26 07:54:26 +00:00
|
|
|
global.scope = java.lang.System.getenv("MS_NODE_CORE_SCOPE") || "@ccms"
|
|
|
|
global.log = logger
|
2019-08-29 02:08:29 +00:00
|
|
|
// Development Env Detect
|
2021-03-26 07:54:26 +00:00
|
|
|
global.root = root || "src/main/resources"
|
2020-04-22 01:23:21 +00:00
|
|
|
if (__FILE__.indexOf('!') === -1) {
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Loading custom BIOS file ' + __FILE__)
|
|
|
|
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"))) {
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Running in debug mode...')
|
|
|
|
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"))
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Set system level to [' + global.level + ']...')
|
2017-11-30 05:27:20 +00:00
|
|
|
}
|
2020-08-27 09:30:59 +00:00
|
|
|
if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "upgrade"))) {
|
2021-03-26 07:54:26 +00:00
|
|
|
logger.info('Found upgrade file starting upgrade...')
|
2020-09-21 08:06:37 +00:00
|
|
|
base.move(java.nio.file.Paths.get(root, "node_modules"), java.nio.file.Paths.get(root, "old_node_modules"))
|
2020-08-27 09:30:59 +00:00
|
|
|
base.delete(java.nio.file.Paths.get(root, "upgrade"))
|
|
|
|
}
|
2020-09-21 08:06:37 +00:00
|
|
|
new java.lang.Thread(function () {
|
|
|
|
try {
|
|
|
|
base.delete(java.nio.file.Paths.get(root, "old_node_modules"))
|
|
|
|
} catch (ex) {
|
|
|
|
}
|
|
|
|
}, "MiaoScript node_modules clean thread").start()
|
2020-04-22 01:23:21 +00:00
|
|
|
// Check Class Loader, Sometimes Server will can't found plugin.yml file
|
2021-03-26 07:54:26 +00:00
|
|
|
var loader = checkClassLoader()
|
|
|
|
var future = new java.util.concurrent.FutureTask(function () {
|
|
|
|
java.lang.Thread.currentThread().contextClassLoader = loader
|
|
|
|
load(java.lang.System.getenv("MS_NODE_CORE_POLYFILL") || 'classpath:core/polyfill.js')(root, logger)
|
|
|
|
})
|
2020-02-29 09:32:53 +00:00
|
|
|
// Async Loading MiaoScript Engine
|
2021-03-26 07:54:26 +00:00
|
|
|
new java.lang.Thread(future, "MiaoScript thread").start()
|
|
|
|
return future
|
|
|
|
}
|
|
|
|
|
|
|
|
global.start = function (future) {
|
|
|
|
if (!future.isDone()) {
|
2021-03-26 10:40:57 +00:00
|
|
|
log.info("Waiting MiaoScript booted...")
|
2021-03-26 07:54:26 +00:00
|
|
|
future.get()
|
|
|
|
}
|
2021-03-26 10:40:57 +00:00
|
|
|
log.info("MiaoScript booted starting...")
|
2021-03-26 07:54:26 +00:00
|
|
|
global.engineDisableImpl = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || (global.scope + '/core')).default || function () {
|
2021-03-26 10:40:57 +00:00
|
|
|
log.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...')
|
2021-03-26 07:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-26 13:01:24 +00:00
|
|
|
|
2017-11-15 13:00:07 +00:00
|
|
|
function checkClassLoader() {
|
2021-03-26 07:54:26 +00:00
|
|
|
var classLoader = java.lang.Thread.currentThread().contextClassLoader
|
2020-05-28 09:05:47 +00:00
|
|
|
if (classLoader.getResource("bios.js") === null) {
|
2021-03-26 07:54:26 +00:00
|
|
|
throw Error("Error class loader: " + classLoader.class.name + " Please contact the author MiaoWoo!")
|
2019-02-23 16:00:03 +00:00
|
|
|
} else {
|
2021-03-26 07:54:26 +00:00
|
|
|
log.info("Class loader compatible: " + classLoader.class.name)
|
2019-03-25 09:13:54 +00:00
|
|
|
if (classLoader.parent) {
|
2021-03-26 07:54:26 +00:00
|
|
|
log.info("Parent class loader: " + classLoader.parent.class.name)
|
2019-03-25 09:13:54 +00:00
|
|
|
}
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
2021-03-26 07:54:26 +00:00
|
|
|
return classLoader
|
2017-11-15 10:40:17 +00:00
|
|
|
}
|
2021-03-26 07:54:26 +00:00
|
|
|
})()
|