fix: files.cwd()
This commit is contained in:
@@ -25,6 +25,7 @@ import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -32,13 +33,13 @@ import java.util.Locale;
|
||||
* Created by Stardust on 2017/4/2.
|
||||
*/
|
||||
|
||||
public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
|
||||
private static final String LOG_TAG = "RhinoJavaScriptEngine";
|
||||
|
||||
private static int contextCount = 0;
|
||||
private static StringScriptSource sInitScript;
|
||||
private String[] mRequirePath = new String[0];
|
||||
private List<String> mRequirePath = Collections.emptyList();
|
||||
|
||||
private Context mContext;
|
||||
private Scriptable mScriptable;
|
||||
@@ -93,11 +94,12 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
return mThread;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void init() {
|
||||
mThread = Thread.currentThread();
|
||||
ScriptableObject.putProperty(mScriptable, "__engine__", this);
|
||||
mRequirePath = (String[]) getTag(TAG_PATH);
|
||||
mRequirePath = (List<String>) getTag(TAG_ENV_PATH);
|
||||
initRequireBuilder(mContext, mScriptable);
|
||||
mContext.evaluateString(mScriptable, getInitScript().getScript(), "<init>", 1, null);
|
||||
}
|
||||
@@ -118,8 +120,10 @@ public class RhinoJavaScriptEngine extends JavaScriptEngine {
|
||||
|
||||
void initRequireBuilder(Context context, Scriptable scope) {
|
||||
List<URI> list = new ArrayList<>();
|
||||
for (String path : mRequirePath) {
|
||||
list.add(new File(path).toURI());
|
||||
if (mRequirePath != null) {
|
||||
for (String path : mRequirePath) {
|
||||
list.add(new File(path).toURI());
|
||||
}
|
||||
}
|
||||
AssetAndUrlModuleSourceProvider provider = new AssetAndUrlModuleSourceProvider(mAndroidContext, list);
|
||||
new RequireBuilder()
|
||||
|
||||
@@ -23,8 +23,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public interface ScriptEngine<S extends ScriptSource> {
|
||||
|
||||
|
||||
String TAG_PATH = "execute_path";
|
||||
String TAG_ENV_PATH = "env_path";
|
||||
String TAG_SOURCE = "source";
|
||||
String TAG_EXECUTE_PATH = "execute_path";
|
||||
|
||||
void put(String name, Object value);
|
||||
|
||||
@@ -87,7 +88,7 @@ public interface ScriptEngine<S extends ScriptSource> {
|
||||
}
|
||||
|
||||
public String cwd() {
|
||||
return (String) getTag(TAG_PATH);
|
||||
return (String) getTag(TAG_EXECUTE_PATH);
|
||||
}
|
||||
|
||||
public void setOnDestroyListener(OnDestroyListener onDestroyListener) {
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.stardust.autojs.execution;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/1.
|
||||
*/
|
||||
public class ExecutionConfig implements Serializable {
|
||||
|
||||
private String[] mRequirePath = new String[0];
|
||||
private List<String> mRequirePath = Collections.emptyList();
|
||||
private String mExecutePath;
|
||||
private static final ExecutionConfig DEFAULT = new ExecutionConfig();
|
||||
public long delay = 0;
|
||||
public long interval = 0;
|
||||
@@ -24,15 +29,27 @@ public class ExecutionConfig implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExecutionConfig path(String... requirePath) {
|
||||
mRequirePath = requirePath;
|
||||
public ExecutionConfig requirePath(String... requirePath) {
|
||||
mRequirePath = new ArrayList<>(Arrays.asList(requirePath));
|
||||
if (mExecutePath != null) {
|
||||
mRequirePath.add(mExecutePath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getPath() {
|
||||
public ExecutionConfig executePath(String executePath) {
|
||||
mExecutePath = executePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getRequirePath() {
|
||||
return mRequirePath;
|
||||
}
|
||||
|
||||
public String getExecutePath() {
|
||||
return mExecutePath;
|
||||
}
|
||||
|
||||
public ExecutionConfig loop(long delay, int loopTimes, long interval) {
|
||||
this.delay = delay;
|
||||
this.loopTimes = loopTimes;
|
||||
|
||||
@@ -49,7 +49,8 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
}
|
||||
|
||||
private void prepare(ScriptEngine engine) {
|
||||
engine.setTag(ScriptEngine.TAG_PATH, getConfig().getPath());
|
||||
engine.setTag(ScriptEngine.TAG_EXECUTE_PATH, getConfig().getExecutePath());
|
||||
engine.setTag(ScriptEngine.TAG_ENV_PATH, getConfig().getRequirePath());
|
||||
engine.init();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,8 @@ public class ScriptExecuteActivity extends AppCompatActivity implements Thread.U
|
||||
|
||||
private void prepare() {
|
||||
mScriptEngine.put("activity", this);
|
||||
mScriptEngine.setTag(ScriptEngine.TAG_PATH, mScriptExecution.getConfig().getPath());
|
||||
mScriptEngine.setTag(ScriptEngine.TAG_ENV_PATH, mScriptExecution.getConfig().getRequirePath());
|
||||
mScriptEngine.setTag(ScriptEngine.TAG_EXECUTE_PATH, mScriptExecution.getConfig().getExecutePath());
|
||||
mScriptEngine.init();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user