feat: 新增热刷新任务处理

Signed-off-by: 502647092 <admin@yumc.pw>
merge/6/HEAD
502647092 2017-07-31 22:04:28 +08:00
parent d6c29e8757
commit 33654666cc
2 changed files with 59 additions and 0 deletions

View 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")));
}
}

View 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);
}