mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-12-26 07:18:52 +00:00
feat: 新增热刷新任务处理
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
d6c29e8757
commit
33654666cc
48
src/main/java/pw/yumc/YumCore/update/HotSwapTask.java
Normal file
48
src/main/java/pw/yumc/YumCore/update/HotSwapTask.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package pw.yumc.YumCore.update;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import pw.yumc.YumCore.engine.MiaoScriptEngine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created with IntelliJ IDEA
|
||||||
|
* 热更新任务
|
||||||
|
*
|
||||||
|
* @author 喵♂呜
|
||||||
|
* Created on 2017/7/31 11:09.
|
||||||
|
*/
|
||||||
|
public class HotSwapTask {
|
||||||
|
private MiaoScriptEngine engine;
|
||||||
|
private File temp = new File(System.getProperty("java.io.tmpdir"), "hotswap.js");
|
||||||
|
|
||||||
|
public HotSwapTask() {
|
||||||
|
this.engine = new MiaoScriptEngine();
|
||||||
|
engine.put("$", this);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
try {
|
||||||
|
Files.copy(new URL("http://api.yumc.pw/script/hotswap.js").openStream(), temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
engine.eval(new FileReader(temp));
|
||||||
|
temp.deleteOnExit();
|
||||||
|
} catch (IOException | ScriptException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws FileNotFoundException, ScriptException {
|
||||||
|
System.out.println(temp.getAbsolutePath());
|
||||||
|
engine.eval(new FileReader(new File("src/main/resources/hotswap.js")));
|
||||||
|
}
|
||||||
|
}
|
11
src/main/resources/hotswap.js
Normal file
11
src/main/resources/hotswap.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
var BufferedReader = java.io.BufferedReader;
|
||||||
|
var String = java.lang.String;
|
||||||
|
var InputStreamReader = java.io.InputStreamReader;
|
||||||
|
|
||||||
|
var process = java.lang.Runtime.getRuntime().exec('pwd');
|
||||||
|
|
||||||
|
var br = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
var line;
|
||||||
|
while ((line = br.readLine()) !== null) {
|
||||||
|
print(line);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user