[java-idp-plugin-scripting] 01/15: Inital commit of a Nashorn Plugin

Ian Young ian at iay.org.uk
Mon Jun 22 13:03:37 UTC 2020


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch master
in repository java-idp-plugin-scripting.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=commit;h=2eed87ec5a196010948a6ebdb3668fe8484b579f

commit 2eed87ec5a196010948a6ebdb3668fe8484b579f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed May 6 15:19:59 2020 +0100

    Inital commit of a Nashorn Plugin
---
 .gitignore                                         |   6 +
 nashorn-dist/pom.xml                               |  54 +++++++++
 .../src/main/assembly/nashorn-assembly.xml         |  32 ++++++
 nashorn-impl/pom.xml                               |  75 ++++++++++++
 .../plugins/scripting/AbstractScriptEngine.java    | 111 ++++++++++++++++++
 .../scripting/RuntimeScriptingException.java       |  37 ++++++
 .../plugins/scripting/nashorn/GraalEngine.java     | 126 +++++++++++++++++++++
 .../plugins/scripting/nashorn/GraalFactory.java    |  98 ++++++++++++++++
 .../plugins/scripting/nashorn/package-info.java    |  20 ++++
 .../services/javax.script.ScriptEngineFactory      |   1 +
 .../plugins/scripting/nashorn/EngineTests.java     |  75 ++++++++++++
 pom.xml                                            |  45 ++++++++
 12 files changed, 680 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b742e95
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*/target
+*/test-output
+*~
+*/.classpath
+*/.project
+*/.settings
diff --git a/nashorn-dist/pom.xml b/nashorn-dist/pom.xml
new file mode 100644
index 0000000..5dfa743
--- /dev/null
+++ b/nashorn-dist/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+	<groupId>net.shibboleth.plugin</groupId>
+	<artifactId>scripting</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <groupId>net.shibboleth.plugin</groupId>
+    <artifactId>nashorn-dist</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>Shibboleth Project Nashorn plugin package</name>
+    <description>
+        A project to build a Nashorn plugin package
+    </description>
+
+    <properties>
+	<nashorn.finalName>shibboleth-idp-plugins-scripting-nashorn-${project.version}</nashorn.finalName>
+    </properties>
+
+    <build>
+        <plugins>
+	     <!-- Assemble -->
+             <plugin>
+		 <artifactId>maven-assembly-plugin</artifactId>
+		 <executions>
+                     <execution>
+			 <id>make-assembly</id>
+			 <phase>package</phase>
+			 <goals>
+                             <goal>single</goal>
+			 </goals>
+                     </execution>
+		 </executions>
+		 <configuration>
+                     <appendAssemblyId>false</appendAssemblyId>
+                     <descriptors>
+			 <descriptor>src/main/assembly/nashorn-assembly.xml</descriptor>
+                     </descriptors>
+                     <finalName>${nashorn.finalName}</finalName>
+                     <tarLongFileMode>gnu</tarLongFileMode>
+		 </configuration>
+             </plugin>
+        </plugins>
+
+    </build>
+
+</project>
diff --git a/nashorn-dist/src/main/assembly/nashorn-assembly.xml b/nashorn-dist/src/main/assembly/nashorn-assembly.xml
new file mode 100644
index 0000000..7105894
--- /dev/null
+++ b/nashorn-dist/src/main/assembly/nashorn-assembly.xml
@@ -0,0 +1,32 @@
+<assembly>
+    <id>assembly</id>
+    <formats>
+        <format>tar.gz</format>
+        <format>zip</format>
+    </formats>
+    <fileSets>
+        <fileSet>
+            <directory>../nashorn-impl/target/dependency</directory>
+            <outputDirectory>webapp/WEB-INF/lib</outputDirectory>
+            <includes>
+                <include>graal-sdk-*.jar</include>
+                <include>js-*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*test*.jar</exclude>
+            </excludes>
+        </fileSet>
+        <fileSet>
+            <directory>../nashorn-impl/target</directory>
+            <outputDirectory>edit-webapp/WEB-INF/lib</outputDirectory>
+            <includes>
+                <include>idp-oidc-extension-impl-*.jar</include>
+            </includes>
+            <excludes>
+                <exclude>*test*.jar</exclude>
+                <exclude>*javadoc.jar</exclude>
+                <exclude>*sources.jar</exclude>
+            </excludes>
+        </fileSet>
+    </fileSets>
+</assembly>
diff --git a/nashorn-impl/pom.xml b/nashorn-impl/pom.xml
new file mode 100644
index 0000000..ce92f76
--- /dev/null
+++ b/nashorn-impl/pom.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+	<groupId>net.shibboleth.plugin</groupId>
+	<artifactId>scripting</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>net.shibboleth.plugin</groupId>
+    <artifactId>nashorn-impl</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>Shibboleth Project Nashorn plugin</name>
+    <description>
+        A project to build a Nashorn plugin jar.
+    </description>
+
+    <dependencies>
+	<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>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+	    <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+			    <!-- <excludeTransitive>true</excludeTransitive> -->
+                            <outputDirectory>target/dependency</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId> 
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifestEntries>
+                            <Automatic-Module-Name>${automatic.module.name}</Automatic-Module-Name>
+                        </manifestEntries>
+                    </archive>
+                </configuration>
+             </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/AbstractScriptEngine.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/AbstractScriptEngine.java
new file mode 100644
index 0000000..330810b
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/AbstractScriptEngine.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting;
+
+import java.io.Reader;
+
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+
+/**
+ * Enough boiler plate to allow us to implement a {@link ScriptEngine} sufficient for our own use.
+ */
+public abstract class AbstractScriptEngine implements ScriptEngine, Compilable {
+
+    /** {@inheritDoc} */
+    public Object eval(final String script, final ScriptContext context) throws ScriptException {
+        final Bindings globals = context.getBindings(ScriptContext.GLOBAL_SCOPE); 
+        if (globals != null && !globals.isEmpty()) {
+            throw new ScriptException("Non empty GLOBAL_SCOPE");
+        }
+        return eval(script, context.getBindings(ScriptContext.ENGINE_SCOPE));
+    }
+
+    /** {@inheritDoc} */
+    public Object eval(final Reader reader, final ScriptContext context) throws ScriptException {
+        throw new ScriptException("Unsupported method eval(Reader, ScriptContext)");
+    }
+
+    /** {@inheritDoc} */
+    public Object eval(final String script) throws ScriptException {
+        throw new ScriptException("Unsupported method eval(String)");
+    }
+
+    /** {@inheritDoc} */
+    public Object eval(final Reader reader) throws ScriptException {
+        throw new ScriptException("Unsupported method eval(Reader, ScriptContext)");
+    }
+
+    /** {@inheritDoc} */
+    public Object eval(final Reader reader, final Bindings n) throws ScriptException {
+        throw new ScriptException("Unsupported method eval(Reader, Bindings)");
+    }
+
+    /** {@inheritDoc} */
+    public void put(final String key, final Object value) {
+        throw new RuntimeScriptingException("Unsupported method put(String, Object)");
+    }
+
+    /** {@inheritDoc} */
+    public Object get(final String key) {
+        throw new RuntimeScriptingException("Unsupported method get(String)");
+    }
+
+    /** {@inheritDoc} */
+    public Bindings getBindings(final int scope) {
+        throw new RuntimeScriptingException("Unsupported method getBindings(String)");
+    }
+
+    /** {@inheritDoc} */
+    public void setBindings(final Bindings bindings, final int scope) {
+        if (!bindings.isEmpty()) {
+            throw new RuntimeScriptingException("non empty bindings set");            
+        }
+    }
+
+    /** {@inheritDoc} */
+    public Bindings createBindings() {
+        throw new RuntimeScriptingException("Unsupported method createBindings");
+    }
+
+    /** {@inheritDoc} */
+    public ScriptContext getContext() {
+        throw new RuntimeScriptingException("Unsupported method getContext");
+    }
+
+    /** {@inheritDoc} */
+    public void setContext(final ScriptContext context) {
+        throw new RuntimeScriptingException("Unsupported method setContext");
+    }
+
+    /** {@inheritDoc} */
+    public ScriptEngineFactory getFactory() {
+        throw new RuntimeScriptingException("Unsupported method getFactory");
+    }
+
+    /** {@inheritDoc} */
+    public CompiledScript compile(final Reader script) throws ScriptException {
+       throw new ScriptException("Cannot compile from a reader");
+    }
+
+}
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/RuntimeScriptingException.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/RuntimeScriptingException.java
new file mode 100644
index 0000000..1715870
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/RuntimeScriptingException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting;
+
+/**
+ * A run time exception to handle ligatured off methods in our JRS-223 support.
+ */
+public class RuntimeScriptingException extends RuntimeException {
+ 
+    /** serialVersionUID. */
+    private static final long serialVersionUID = -2539172571249068564L;
+
+
+    /**
+     * Constructor.
+     *
+     * @param message the message.
+     */
+    public RuntimeScriptingException(final String message) {
+        super(message);
+    }
+}
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalEngine.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalEngine.java
new file mode 100644
index 0000000..f328d22
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalEngine.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting.nashorn;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+
+import org.graalvm.polyglot.Context;
+import org.graalvm.polyglot.Source;
+import org.graalvm.polyglot.Value;
+
+import net.shibboleth.plugins.scripting.AbstractScriptEngine;
+import net.shibboleth.utilities.java.support.scripting.EvaluableScript;
+
+/**
+ * A subset of {@link ScriptEngine} implemented with GraaVm with enough function that 
+ * {@link EvaluableScript} can work with it. 
+ * 
+ * NOTE that this does not (currently) implement {@link javax.script.Compilable}.
+ */
+public class GraalEngine extends AbstractScriptEngine implements ScriptEngine, Compilable {
+
+    /** {@inheritDoc} */
+    public Object eval(final String script, final Bindings scriptBindings) throws ScriptException {
+        try (final Context context = Context.newBuilder().allowExperimentalOptions(true).
+                option("js.nashorn-compat", "true").
+                allowAllAccess(true).
+                build()) {
+            
+            final Value bindings  = context.getBindings("js");
+            for (final String name: scriptBindings.keySet()) {
+                bindings.putMember(name, scriptBindings.get(name));
+            }
+            final Source s = Source.newBuilder("js", script, "embedded").buildLiteral();
+            final Value v = context.eval(s);
+            return processValue(v);
+        }  catch (final RuntimeException e) {
+            throw new ScriptException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public CompiledScript compile(final String script) throws ScriptException {
+
+        return new GraalVMCompiledScript(script);
+    }
+
+    /** Convert the output from {@link Context#eval(String, CharSequence)} or
+     * {@link Context#eval(String, CharSequence)} into a java {@link Object}.
+     * @param value what to consider
+     * @return The output
+     */
+    @Nullable protected static Object processValue(@Nonnull final Value value) {
+        if (value.isNull()) {
+            return null;
+        } else if (value.isHostObject()) {
+            return value.asHostObject();
+        } else if (value.isProxyObject()) {
+            return value.asProxyObject();
+        } else {
+            return  value.as(Object.class);
+        }
+    }
+
+    /** GraalVM {@link CompiledScript} implementation. */
+    private class GraalVMCompiledScript extends CompiledScript {
+        
+        /** The compiled source. */
+        private final Source source;
+
+        /**
+         * Constructor.
+         *
+         * @param script the script (as text)
+         */
+        protected GraalVMCompiledScript(final String script) {
+            source = Source.newBuilder("js", script, "embedded").buildLiteral();
+        }
+
+        /** {@inheritDoc} */
+        public ScriptEngine getEngine() {
+            return GraalEngine.this;
+        }
+
+        /** {@inheritDoc} */
+        public Object eval(final ScriptContext scriptContext) throws ScriptException {
+
+            try (final Context context = Context.newBuilder().allowExperimentalOptions(true).
+                    option("js.nashorn-compat", "true").
+                    allowAllAccess(true).
+                    build()) {
+
+                final Bindings scriptBindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+                final Value bindings  = context.getBindings("js");
+                for (final String name: scriptBindings.keySet()) {
+                    bindings.putMember(name, scriptBindings.get(name));
+                }
+                final Value v = context.eval(source);
+                return processValue(v);
+            }  catch (final RuntimeException e) {
+                throw new ScriptException(e);
+            }
+        }
+    }
+}
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalFactory.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalFactory.java
new file mode 100644
index 0000000..e6027ea
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/GraalFactory.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting.nashorn;
+
+import java.util.Collections;
+import java.util.List;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+import net.shibboleth.plugins.scripting.RuntimeScriptingException;
+
+/**
+ * A JSR-223 factory for {@link GraalEngine}.
+ */
+public class GraalFactory implements ScriptEngineFactory {
+    
+    /** {@inheritDoc} */
+    public String getEngineName() {
+        
+        return this.getClass().getCanonicalName();
+    }
+
+    /** {@inheritDoc} */
+    public String getEngineVersion() {
+        return "1";
+    }
+
+    /** {@inheritDoc} */
+    public List<String> getExtensions() {
+        
+        return List.of("js","nashorn-js");
+    }
+
+    /** {@inheritDoc} */
+    public List<String> getMimeTypes() {
+        return Collections.emptyList();
+    }
+
+    /** {@inheritDoc} */
+    public List<String> getNames() {
+        return List.of("shibboleth-nashorn", "shibboleth-Nashorn", 
+                "shibboleth-js", "shibboleth-JS", "shibboleth-JavaScript", "shibboleth-javascript", 
+                "shibboleth-ECMAScript", "shibboleth-ecmascript");
+    }
+
+    /** {@inheritDoc} */
+    public String getLanguageName() {
+        return "ECMAScript";
+    }
+
+    /** {@inheritDoc} */
+    public String getLanguageVersion() {
+        throw new RuntimeScriptingException("Unsupported method getMethodCallSyntax");
+    }
+
+    /** {@inheritDoc} */
+    public Object getParameter(final String key) {
+        throw new RuntimeScriptingException("Unsupported method getMethodCallSyntax");
+    }
+
+    /** {@inheritDoc} */
+    public String getMethodCallSyntax(final String obj, final String m, final String... args) {
+        throw new RuntimeScriptingException("Unsupported method getMethodCallSyntax");
+    }
+
+    /** {@inheritDoc} */
+    public String getOutputStatement(final String toDisplay) {
+        throw new RuntimeScriptingException("Unsupported method getMethodCallSyntax");
+    }
+
+    /** {@inheritDoc} */
+    public String getProgram(final String... statements) {
+        throw new RuntimeScriptingException("Unsupported method getMethodCallSyntax");
+    }
+
+    /** {@inheritDoc} */
+    public ScriptEngine getScriptEngine() {
+       
+        return new GraalEngine();
+    }
+
+}
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/package-info.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/package-info.java
new file mode 100644
index 0000000..0a4c7e2
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Classes for working with JSR-223 scripting environments. */
+
+package net.shibboleth.plugins.scripting.nashorn;
\ No newline at end of file
diff --git a/nashorn-impl/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory b/nashorn-impl/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
new file mode 100644
index 0000000..0148718
--- /dev/null
+++ b/nashorn-impl/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
@@ -0,0 +1 @@
+net.shibboleth.plugins.scripting.nashorn.GraalFactory
diff --git a/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/EngineTests.java b/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/EngineTests.java
new file mode 100644
index 0000000..e71fd65
--- /dev/null
+++ b/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/EngineTests.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting.nashorn;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.script.SimpleScriptContext;
+
+import org.testng.annotations.Test;
+
+/** Minimal tests for our two JSR-223 engine plug ins. */
+ at SuppressWarnings({"javadoc", "rawtypes", })
+public class EngineTests {
+    
+    @Test public void testGraal() throws ScriptException {
+        final ScriptEngineManager engineManager = new ScriptEngineManager();
+        final ScriptEngine scriptEngine = engineManager.getEngineByName("shibboleth-nashorn");
+        final ScriptContext ctx = new SimpleScriptContext();
+        final String script = "var map = Java.type('java.util.HashMap');"
+                + "var s = new map(2); s.put('a',b); s";
+
+        ctx.setAttribute("b", this, ScriptContext.ENGINE_SCOPE);
+        
+        final Object o = scriptEngine.eval(script, ctx);
+
+        assertTrue(o instanceof Map);
+        final Map map = (Map) o;
+        assertEquals(map.size(), 1);
+        assertEquals(map.get("a"), this);
+    }
+
+    @Test public void testGraalCompiled() throws ScriptException {
+        final ScriptEngineManager engineManager = new ScriptEngineManager();
+        final ScriptEngine scriptEngine = engineManager.getEngineByName("shibboleth-nashorn");
+        final Compilable compiler = (Compilable) scriptEngine;
+
+        final ScriptContext ctx = new SimpleScriptContext();
+        ctx.setAttribute("b", this, ScriptContext.ENGINE_SCOPE);
+
+        final String script = "var map = Java.type('java.util.HashMap');"
+                + "var s = new map(2); s.put('a',b); s";
+
+        final CompiledScript compiled = compiler.compile(script);
+        final Object o = compiled.eval(ctx);
+
+        assertTrue(o instanceof Map);
+        final Map map = (Map) o;
+        assertEquals(map.size(), 1);
+        assertEquals(map.get("a"), this);
+    }
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..8a5eef1
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>net.shibboleth</groupId>
+        <artifactId>parent</artifactId>
+        <version>11.0.1-SNAPSHOT</version>
+    </parent>
+
+    
+    <groupId>net.shibboleth.plugin</groupId>
+    <artifactId>scripting</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <name>Shibboleth Project Scripting plugin</name>
+    <description>
+        Parent project for scirpting plugins
+    </description>
+
+    <properties>
+	<java-support-version>8.1.0-SNAPSHOT</java-support-version>
+	<graalvm.version>20.0.0</graalvm.version>
+        <automatic.module.name>net.shibboleth.plugins.scripting.nashorn</automatic.module.name>
+    </properties>
+
+    <dependencies>
+        <!-- provided dependency -->
+        <dependency>
+            <groupId>net.shibboleth.utilities</groupId>
+            <artifactId>java-support</artifactId>
+            <version>${java-support-version}</version>
+	    <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <modules>
+	<module>nashorn-impl</module>
+	<module>nashorn-dist</module>
+    </modules>
+
+</project>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list