feat: add okhttp lib

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-09-23 09:02:34 +08:00
parent 0dfe04040e
commit 8be38800b0
4 changed files with 15 additions and 220 deletions

14
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>MiaoScript</artifactId> <artifactId>MiaoScript</artifactId>
<version>1.3.5</version> <version>0.0.1</version>
<developers> <developers>
<developer> <developer>
<id>502647092</id> <id>502647092</id>
@ -33,6 +33,8 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>org.kamranzafar:jtar</include> <include>org.kamranzafar:jtar</include>
<include>com.squareup.okhttp3:okhttp</include>
<include>com.squareup.okio:okio</include>
</includes> </includes>
</artifactSet> </artifactSet>
</configuration> </configuration>
@ -54,10 +56,11 @@
<properties> <properties>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT> <env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<update.changes> <update.changes>
§619-08-31 §afeat: 新增 tar 类库 支持 tar.gz 解压; §619-09-21 §afeat: 新增 okhttp3 类库;
§619-08-29 §erefactor: 移动插件文件 默认自带MSPM插件 优化bios §619-08-31 §afeat: 新增 tar 类库 支持 tar.gz 解压
</update.changes> </update.changes>
<update.changelog> <update.changelog>
§619-08-29 §erefactor: 移动插件文件 默认自带MSPM插件 优化bios;
§618-5-20 §afeat: 新增MiaoBoard插件; §618-5-20 §afeat: 新增MiaoBoard插件;
§618-5-20 §afeat: 新增MiaoAuth插件; §618-5-20 §afeat: 新增MiaoAuth插件;
§618-5-20 §afeat: 修改初始化函数名称; §618-5-20 §afeat: 修改初始化函数名称;
@ -162,6 +165,11 @@
<artifactId>jtar</artifactId> <artifactId>jtar</artifactId>
<version>2.3</version> <version>2.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.1.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>

View File

@ -2,10 +2,9 @@
var log; var log;
var boot; var boot;
var engineDisable; var engineDisable;
// noinspection ThisExpressionReferencesGlobalObjectJS
var global = this; var global = this;
/** /**
* Init Engine Env * Init MiaoScriptEngine Runtime
*/ */
(function() { (function() {
var loader; var loader;
@ -53,7 +52,7 @@ var global = this;
jarPath = "/" + jarPath; jarPath = "/" + jarPath;
} }
var jar = new java.util.jar.JarFile(jarPath); var jar = new java.util.jar.JarFile(jarPath);
var r = new RegExp(regex);// "[core|modules]/.*" var r = new RegExp(regex);
jar.stream().forEach(function(entry) { jar.stream().forEach(function(entry) {
try { try {
if (!entry.isDirectory()) { if (!entry.isDirectory()) {

View File

@ -11,11 +11,11 @@
// Init console and require // Init console and require
global.console = engineLoad(global.root + '/core/console.js')(logger); global.console = engineLoad(global.root + '/core/console.js')(logger);
global.require = engineLoad(global.root + '/core/require.js')(root); global.require = engineLoad(global.root + '/core/require.js')(root);
// String contains playfill // String contains ployfill
String.prototype.contains = function(searchString, position) { String.prototype.contains = function(searchString, position) {
return String.prototype.indexOf.call(this, searchString, position) > -1; return String.prototype.indexOf.call(this, searchString, position) > -1;
}; };
// ES6 Map Symbol playfill // ES6 Map Symbol ployfill
require('es6-map/implement'); require('es6-map/implement');
require('es6-symbol/implement'); require('es6-symbol/implement');
}); });

View File

@ -1,212 +0,0 @@
'use strict';
/*global Java, base, module, exports, require, __dirname, __filename, ScriptEngineContextHolder*/
var task = require('api/task');
var manager = require('api/plugin');
var command = require('api/command');
var fs = require('fs');
var http = require('http');
var template = require('template');
var pluginCache = [];
var packageCache = [];
var packageNameCache = [];
var description = {
name: 'MiaoScriptPackageManager',
prefix: 'PM',
version: '1.0',
author: 'MiaoWoo',
description: 'MiaoScript包管理工具',
commands: {
'mpm': {
description: 'MiaoScriptPackageManager主命令'
}
},
config: {
center: 'https://ms.yumc.pw/api/package/list',
template: 'http://paste.yumc.pw/pxus6ap6l/g7di8z/raw'
}
};
var help = [
'§6========= §6[§a' + description.name + '§6] 帮助 §aBy §b喵♂呜 §6=========',
'§6/mpm §ainstall §e<插件名称> §6- §3安装插件',
'§6/mpm §alist [install]§6- §3列出仓库插件[已安装的插件]',
'§6/mpm §aupdate §e<插件名称> §6- §3更新插件(无插件名称则更新源)',
'§6/mpm §aupgrade §e<插件名称> §6- §3及时更新插件(update需要重启生效)',
'§6/mpm §areload §e<插件名称> §6- §3重载插件(无插件名称则重载自身)',
'§6/mpm §arun §e<JS代码> §6- §3运行JS代码',
'§6/mpm §acreate §e<插件名称> [作者] [版本] [主命令] §6- §3通过模板创建名称',
'§6/mpm §crestart §6- §4重启MiaoScript脚本引擎'
];
function load() {
task.async(function() {
pluginCache = Object.keys(manager.plugins);
JSON.parse(http.get(self.config.center)).data.forEach(function cachePackageName(pkg) {
packageCache[pkg.name] = pkg;
})
packageNameCache = Object.keys(packageCache);
})
}
function enable() {
command.on(this, 'mpm', {
cmd: function(sender, command, args) {
task.async(function asyncCommand() {
main(sender, command, args);
});
},
tab: function(sender, command, args) {
if (args.length === 1) return ['list', 'install', 'update', 'upgrade', 'reload', 'restart', 'run', 'help', 'create'];
if (args.length > 1) {
switch (args[0]) {
case "install":
return packageNameCache;
case "update":
case "upgrade":
case "reload":
return pluginCache;
}
}
}
})
}
function main(sender, command, args) {
if (!args[0] || args[1] === 'help') {
console.sender(sender, help);
return;
}
switch (args[0]) {
case "list":
if (args[1]) {
console.sender(sender, '§6当前 §bMiaoScript §6已安装下列插件:');
pluginCache.forEach(function listInfo(pluginName) {
var desc = manager.plugins[pluginName].description;
console.sender(sender, '§6插件名称: §b%s §6版本: §a%s §6作者: §3%s'.format(desc.name, desc.version || '1.0', desc.author || '未知'))
})
} else {
console.sender(sender, '§6当前 §bMiaoScriptPackageCenter §6中存在下列插件:');
for (var pkgName in packageCache) {
var pkg = packageCache[pkgName];
console.sender(sender, '§6插件名称: §b%s §6版本: §a%s §6作者: §3%s'.format(pkg.name, pkg.version || '1.0', pkg.author || '未知'))
}
}
break;
case "install":
if (args.length > 1) {
download(sender, args[1]);
} else {
console.sender(sender, '§c请输入插件名称!')
}
break;
case "update":
if (args.length > 1) {
update(sender, args[1]);
} else {
load();
console.sender(sender, "§a仓库缓存刷新成功 共存在 §b" + Object.keys(packageCache).length + " §a个插件!")
}
break;
case "upgrade":
break;
case "delete":
if (args.length > 1) {
del(sender, args[1]);
} else {
console.sender(sender, '§c请输入插件名称!')
}
break;
case "reload":
if (args.length > 1) {
var pname = args[1];
if (pluginCache.indexOf(pname) !== -1) {
manager.reload(pname)
console.sender(sender, '§6插件 §b%s §a重载完成!'.format(pname))
} else {
console.sender(sender, '§c插件 §b%s §c不存在!'.format(pname))
}
} else {
self.reloadConfig();
load();
}
break;
case "restart":
try {
console.sender(sender, '§6Reloading §3MiaoScript Engine...');
ScriptEngineContextHolder.disableEngine();
ScriptEngineContextHolder.enableEngine();
console.sender(sender, '§3MiaoScript Engine §6Reload §aSuccessful...');
} catch (ex) {
console.sender(sender, "§3MiaoScript Engine §6Reload §cError! ERR: " + ex);
console.sender(sender, console.stack(ex));
}
break;
case "run":
args.shift(1);
try {
var script = args.join(' ')
console.sender(sender, '§b运行脚本:§r', script)
console.sender(sender, '§a返回结果:§r', eval(script) || '§4没有返回结果!');
} catch (ex) {
console.sender(sender, console.stack(ex))
}
break;
case "create":
var name = args[1];
if (!name) {
console.sender(sender, '§4参数错误 /mpm create <插件名称> [作者] [版本] [主命令]');
return;
}
var result = template.create(http.get(self.config.template)).render({
name: name,
author: args[2] || 'MiaoWoo',
version: args[3] || '1.0',
command: args[4] || name.toLowerCase(),
});
fs.save(fs.file(__dirname, name + '.js'), result);
console.sender(sender, '§6插件 §a' + name + ' §6已生成到插件目录...');
break;
default:
console.sender(sender, help);
break;
}
}
function del(sender, name) {
if (pluginCache.indexOf(name) !== -1) {
console.sender(sender, '§c插件 %s 不存在!'.format(name));
return;
}
manager.disable(name);
fs.delete(plugin.__FILE__);
console.sender(sender, '§c插件 §b%s §c删除成功!'.format(name));
}
function download(sender, name) {
var plugin = packageCache[name];
if (!plugin) {
console.sender(sender, '§c插件 §b%s §c不存在!'.format(name));
return;
}
var pfile = fs.file(__dirname, name + '.js');
console.sender(sender, '§6开始下载插件: §b%s'.format(plugin.name));
console.sender(sender, '§6插件下载地址: §b%s'.format(plugin.url));
fs.save(pfile, http.get(plugin.url));
console.sender(sender, '§6插件 §b%s §a下载完毕 开始加载 ...'.format(name));
manager.loadPlugin(pfile);
console.sender(sender, '§6插件 §b%s §a安装成功!'.format(name));
}
function disable() {
}
module.exports = {
description: description,
load: load,
enable: enable,
disable: disable
};