Skip to content

Commit

Permalink
removing graalvm from dependency and modifying Jsr223ScriptEvaluator …
Browse files Browse the repository at this point in the history
…to write a log with error but mP run futher
  • Loading branch information
skublik committed Jun 11, 2021
1 parent 40470dd commit 33b54b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
15 changes: 0 additions & 15 deletions model/model-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Testing dependencies -->
<dependency>
<groupId>org.testng</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.util.exception.*;

import org.graalvm.polyglot.Context;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;

/**
* Expression evaluator that is using javax.script (JSR-223) engine.
Expand All @@ -29,42 +30,25 @@
*/
public class Jsr223ScriptEvaluator extends AbstractCachingScriptEvaluator<ScriptEngine, CompiledScript> {

private static final Trace LOGGER = TraceManager.getTrace(Jsr223ScriptEvaluator.class);

private final ScriptEngine scriptEngine;

public Jsr223ScriptEvaluator(String engineName, PrismContext prismContext,
Protector protector, LocalizationService localizationService) {
super(prismContext, protector, localizationService);

System.setProperty("polyglot.js.nashorn-compat", "true");
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
scriptEngine = scriptEngineManager.getEngineByName(engineName);
if (scriptEngine == null) {
throw new SystemException("The JSR-223 scripting engine for '" + engineName + "' was not found");
SystemException e = new SystemException("The JSR-223 scripting engine for '" + engineName + "' was not found");
LOGGER.error(e.getMessage(), e);
}
}

@Override
protected CompiledScript compileScript(String codeString, ScriptExpressionEvaluationContext evaluationContext) throws Exception {
return new CompiledScript() {
@Override
public Object eval(ScriptContext Scriptcontext) throws ScriptException {
Context context = Context.newBuilder()
.allowExperimentalOptions(true)
.option("js.nashorn-compat", "true")
.allowAllAccess(true)
.build();
Bindings bindings = Scriptcontext.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.entrySet().forEach(entry -> {
context.getBindings("js").putMember(entry.getKey(), entry.getValue());
});
return context.eval("js", codeString).as(Object.class);
}

@Override
public ScriptEngine getEngine() {
return scriptEngine;
}
};
return ((Compilable) scriptEngine).compile(codeString);
}

@Override
Expand All @@ -85,7 +69,10 @@ private Bindings convertToBindings(ScriptExpressionEvaluationContext context)
*/
@Override
public String getLanguageName() {
return scriptEngine.getFactory().getLanguageName();
if (scriptEngine != null) {
return scriptEngine.getFactory().getLanguageName();
}
return null;
}

/* (non-Javadoc)
Expand Down
22 changes: 2 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<!-- Build system options -->
<!-- Encoding for both sources and resources -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.source.version>11</project.source.version>
<project.source.version>16</project.source.version>
<project.build.locale>en_US</project.build.locale>
<ansi.color>true</ansi.color>
<verbose.jaxb2>false</verbose.jaxb2>
Expand Down Expand Up @@ -220,7 +220,6 @@
<j2html.version>1.4.0</j2html.version>
<bouncycastle.version>1.69</bouncycastle.version>
<protobuf.version>3.17.3</protobuf.version>
<graalvm.version>21.1.0</graalvm.version>
<javax.persistence.version>2.2</javax.persistence.version>

<asciidoclet.version>1.5.6</asciidoclet.version>
Expand Down Expand Up @@ -352,7 +351,7 @@
<dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<version>2.7.2</version>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand Down Expand Up @@ -1566,23 +1565,6 @@
<version>2.1.8</version>
</dependency>

<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>${graalvm.version}</version>
</dependency>

<!-- Test support dependencies -->
<dependency>
<groupId>org.testng</groupId>
Expand Down

0 comments on commit 33b54b9

Please sign in to comment.