Skip to content

Commit

Permalink
switch to graal JS engine (#461)
Browse files Browse the repository at this point in the history
Nashorn has been removed in jdk15. Move to Graal to make
it compile and run on newer JDKs.
  • Loading branch information
brharrington authored Aug 28, 2020
1 parent e1449ae commit 14c347c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ lazy val `iep-config` = project
.settings(libraryDependencies ++= Seq(
Dependencies.archaiusBridge,
Dependencies.archaiusCore,
Dependencies.graalJs,
Dependencies.graalJsEngine,
Dependencies.guiceCore,
Dependencies.jodaTime,
Dependencies.equalsVerifier % "test"
Expand Down
24 changes: 7 additions & 17 deletions iep-config/src/main/java/com/netflix/iep/config/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
*/
package com.netflix.iep.config;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
Expand All @@ -30,10 +33,6 @@
import java.util.Set;
import java.util.TreeSet;
import java.util.Comparator;
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.SimpleBindings;
import javax.script.ScriptException;

/**
* Helpers for loading configuration properties with scoped blocks.
Expand All @@ -55,21 +54,12 @@
public class ConfigFile {

public static boolean checkScope(Map<String,String> vars, String str) {
ScriptEngineManager mgr = new ScriptEngineManager(null);
ScriptEngine engine = mgr.getEngineByName("javascript");

if (engine == null) throw new IllegalStateException("no javascipt engine found");

SimpleBindings bindings = new SimpleBindings();
Context context = Context.create();
Value bindings = context.getBindings("js");
for (Map.Entry<String,String> t : vars.entrySet()) {
bindings.put(t.getKey(), t.getValue());
}
try {
return (Boolean) engine.eval(str, bindings);
}
catch (ScriptException e) {
throw new RuntimeException(e);
bindings.putMember(t.getKey(), t.getValue());
}
return context.eval("js", str).asBoolean();
}

/** Load the configuration file using the system environment variables as the `vars`. */
Expand Down
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object Dependencies {
val aws = "1.11.847"
val aws2 = "2.14.4"
val eureka = "1.9.25"
val graal = "20.0.0"
val guice = "4.1.0"
val jackson = "2.11.2"
val rxnetty = "0.4.20"
Expand Down Expand Up @@ -47,6 +48,8 @@ object Dependencies {
val caffeine = "com.github.ben-manes.caffeine" % "caffeine" % "2.8.5"
val equalsVerifier = "nl.jqno.equalsverifier" % "equalsverifier" % "3.4.2"
val eurekaClient = "com.netflix.eureka" % "eureka-client" % eureka
val graalJs = "org.graalvm.js" % "js" % graal
val graalJsEngine = "org.graalvm.js" % "js-scriptengine" % graal
val guiceCore = "com.google.inject" % "guice" % guice
val guiceMulti = "com.google.inject.extensions" % "guice-multibindings" % guice
val inject = "javax.inject" % "javax.inject" % "1"
Expand Down

0 comments on commit 14c347c

Please sign in to comment.