diff --git a/build.sbt b/build.sbt index f6631421..8bfe317e 100644 --- a/build.sbt +++ b/build.sbt @@ -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" diff --git a/iep-config/src/main/java/com/netflix/iep/config/ConfigFile.java b/iep-config/src/main/java/com/netflix/iep/config/ConfigFile.java index 9e60e250..d73a51e4 100644 --- a/iep-config/src/main/java/com/netflix/iep/config/ConfigFile.java +++ b/iep-config/src/main/java/com/netflix/iep/config/ConfigFile.java @@ -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; @@ -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. @@ -55,21 +54,12 @@ public class ConfigFile { public static boolean checkScope(Map 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 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`. */ diff --git a/project/Dependencies.scala b/project/Dependencies.scala index ef5946c4..35573998 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -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" @@ -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"