sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] npeltier closed pull request #1: SLING-7241 Fix SciptEngineManager
Date Thu, 01 Jan 1970 00:00:00 GMT
npeltier closed pull request #1: SLING-7241 Fix SciptEngineManager
URL: https://github.com/apache/sling-org-apache-sling-pipes/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/pipes/PipeBindings.java b/src/main/java/org/apache/sling/pipes/PipeBindings.java
index b50ab57..923302d 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBindings.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBindings.java
@@ -74,8 +74,16 @@
      * public constructor, built from pipe's resource
      * @param resource pipe's configuration resource
      */
-    public PipeBindings(Resource resource){
-        engine.setContext(scriptContext);
+    public PipeBindings(Resource resource) throws Exception {
+    	//In some contexts the nashorn engine cannot be obtained. Do fallback to system classloader.
+    	if(engine == null){
+    		engine = new ScriptEngineManager(null).getEngineByName("nashorn");
+    		//Check if nashorn can still not be instantiated
+    		if(engine == null){
+    			throw new Exception("Can not instantiate nashorn scriptengine. Check JVM version &
capabilities.");
+    		}
+    	}
+    	engine.setContext(scriptContext);
         //add path bindings where path.MyPipe will give MyPipe current resource path
         getBindings().put(PATH_BINDING, pathBindings);
 
diff --git a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
index aff153b..864812c 100644
--- a/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
+++ b/src/test/java/org/apache/sling/pipes/PipeBindingsTest.java
@@ -45,13 +45,13 @@ public void setup() throws PersistenceException {
         context.load().json("/container.json", PATH_PIPE);
     }
 
-    private PipeBindings getDummyTreeBinding(){
+    private PipeBindings getDummyTreeBinding() throws Exception{
         Resource resource = context.resourceResolver().getResource(PATH_PIPE + "/" + ContainerPipeTest.NN_DUMMYTREE);
         return new PipeBindings(resource);
     }
 
     @Test
-    public void testEvaluateSimpleString() throws ScriptException {
+    public void testEvaluateSimpleString() throws Exception {
         PipeBindings bindings = getDummyTreeBinding();
         String simple = "simple string";
         String evaluated = (String)bindings.evaluate(simple);
@@ -59,7 +59,7 @@ public void testEvaluateSimpleString() throws ScriptException {
     }
 
     @Test
-    public void computeEcma5Expression() {
+    public void computeEcma5Expression() throws Exception {
         PipeBindings bindings = getDummyTreeBinding();
         Map<String,String> expressions = new HashMap<>();
         expressions.put("blah ${blah} blah", "'blah ' + blah + ' blah'");


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message