Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to graal JS engine #461

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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