Skip to content

Commit

Permalink
chore(script-engine): remove nashorn
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleycaselli committed Apr 11, 2022
1 parent 69fd535 commit 302fddd
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 338 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.graalvm.polyglot.Value;
import org.topbraid.shacl.js.model.TermFactory;

public class GraalScriptEngine extends JSScriptEngineImpl {
/**
* @author Ashley Caselli
*/
public class GraalJSScriptEngine extends JSScriptEngineImpl {

private Context context;

public GraalScriptEngine() {
public GraalJSScriptEngine() {
initEngine();
context.getBindings("js").putMember("TermFactory", new TermFactory());
context.eval("js", ARGS_FUNCTION);
Expand All @@ -21,7 +24,6 @@ public void initEngine() {
//.allowHostClassLookup(s -> true)
.allowHostAccess(HostAccess.ALL)
.allowExperimentalOptions(true)

//.allowNativeAccess(true)
//.allowCreateThread(true)
//.allowIO(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ public static void set(JSScriptEngineFactory value) {
}

public JSScriptEngine createScriptEngine(final String engineName) {
if (engineName.equals("Nashorn")) {
return new NashornScriptEngine();
}
if (engineName.equals("Graal")) {
return new GraalScriptEngine();
return new GraalJSScriptEngine();
}
// TODO integrate another Script engines
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/topbraid/shacl/js/JSScriptEngineImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public void executeScriptFromURL(String url) throws Exception {

protected Reader createScriptReader(String url) throws Exception {
if (DASH_JS.equals(url)) {
return new InputStreamReader(GraalScriptEngine.class.getResourceAsStream("/js/dash.js"));
return new InputStreamReader(GraalJSScriptEngine.class.getResourceAsStream("/js/dash.js"));
} else if (RDFQUERY_JS.equals(url)) {
return new InputStreamReader(GraalScriptEngine.class.getResourceAsStream("/js/rdfquery.js"));
return new InputStreamReader(GraalJSScriptEngine.class.getResourceAsStream("/js/rdfquery.js"));
} else {
return new InputStreamReader(new URL(url).openStream());
}
Expand Down
82 changes: 0 additions & 82 deletions src/main/java/org/topbraid/shacl/js/NashornScriptEngine.java

This file was deleted.

50 changes: 0 additions & 50 deletions src/main/java/org/topbraid/shacl/js/NashornUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static JSScriptEngine getCurrentEngine() {
JSScriptEngine engine = engines.get();
if(engine == null) {
// TODO decide how to manage the Engine creation
engine = JSScriptEngineFactory.get().createScriptEngine("Nashorn");
engine = JSScriptEngineFactory.get().createScriptEngine("Graal");
engines.set(engine);
}
return engine;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/topbraid/shacl/js/ScriptEngineUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.topbraid.shacl.js;

import jdk.nashorn.api.scripting.ScriptObjectMirror;
import org.graalvm.polyglot.Value;

import java.util.List;
Expand All @@ -10,8 +9,6 @@ public class ScriptEngineUtil {
public static List<Object> asArray(Object obj) throws Exception {
if (obj instanceof Value) {
return GraalUtil.asArray(obj);
} else if (obj instanceof ScriptObjectMirror) {
return NashornUtil.asArray(obj);
} else {
throw new Exception("Object not supported");
}
Expand All @@ -23,8 +20,6 @@ public static boolean isArray(Object obj) throws Exception {
}
if (obj instanceof Value) {
return GraalUtil.isArray(obj);
} else if (obj instanceof ScriptObjectMirror) {
return NashornUtil.isArray(obj);
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/topbraid/shacl/js/model/TermFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* A partial implementation of DataFactory from
* https://github.com/rdfjs/representation-task-force/blob/master/interface-spec.md
* to be used by JavaScript via Nashorn.
* to be used by JavaScript.
*
* @author Holger Knublauch
*/
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/topbraid/shacl/TestDASHTestCases.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.topbraid.jenax.util.JenaUtil;
import org.topbraid.shacl.js.GraalJSScriptEngine;
import org.topbraid.shacl.js.JSScriptEngine;
import org.topbraid.shacl.js.JSScriptEngineFactory;
import org.topbraid.shacl.js.NashornScriptEngine;
import org.topbraid.shacl.testcases.TestCase;
import org.topbraid.shacl.testcases.TestCaseType;
import org.topbraid.shacl.testcases.TestCaseTypes;
Expand All @@ -53,16 +53,16 @@ public class TestDASHTestCases {
JSScriptEngineFactory.set(new JSScriptEngineFactory() {
@Override
public JSScriptEngine createScriptEngine(final String engineName) {
return new NashornScriptEngine() {
return new GraalJSScriptEngine() {
@Override
protected Reader createScriptReader(String url) throws Exception {
if (DASH_JS.equals(url)) {
return new InputStreamReader(NashornScriptEngine.class.getResourceAsStream("/js/dash.js"));
return new InputStreamReader(GraalJSScriptEngine.class.getResourceAsStream("/js/dash.js"));
} else if (RDFQUERY_JS.equals(url)) {
//return new InputStreamReader(new FileInputStream("/Users/ashleycaselli/git/shacl/src/main/ts/rdfquery.js"));
return new InputStreamReader(NashornScriptEngine.class.getResourceAsStream("/js/rdfquery.js"));
return new InputStreamReader(GraalJSScriptEngine.class.getResourceAsStream("/js/rdfquery.js"));
} else if (url.startsWith("http://datashapes.org/js/")) {
return new InputStreamReader(NashornScriptEngine.class.getResourceAsStream(url.substring(21)));
return new InputStreamReader(GraalJSScriptEngine.class.getResourceAsStream(url.substring(21)));
} else {
return new InputStreamReader(new URL(url).openStream());
}
Expand Down
133 changes: 0 additions & 133 deletions src/test/java/org/topbraid/shacl/TestDASHTestCasesGraal.java

This file was deleted.

Loading

0 comments on commit 302fddd

Please sign in to comment.