[GitHub] raducotescu commented on a change in pull request #1: SLING-7134 - Script execution order is not deterministic on Java 9

2017-12-04 Thread GitBox
raducotescu commented on a change in pull request #1: SLING-7134 - Script 
execution order is not deterministic on Java 9
URL: 
https://github.com/apache/sling-org-apache-sling-scripting-core/pull/1#discussion_r154671227
 
 

 ##
 File path: 
src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
 ##
 @@ -0,0 +1,320 @@
+/*~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF 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 org.apache.sling.scripting.core.impl.jsr223;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+
+import org.apache.sling.api.scripting.SlingScriptConstants;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+service = {ScriptEngineManager.class, SlingScriptEngineManager.class},
+reference = @Reference(
+name = "ScriptEngineFactory",
+bind = "bindScriptEngineFactory",
+unbind = "unbindScriptEngineFactory",
+service = ScriptEngineFactory.class,
+cardinality = ReferenceCardinality.MULTIPLE,
+policy = ReferencePolicy.DYNAMIC
+)
+)
+public class SlingScriptEngineManager extends ScriptEngineManager implements 
BundleListener {
+
+public static final String EVENT_TOPIC_SCRIPT_MANAGER_UPDATED =
+
"org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager/UPDATED";
+public static final String ENGINE_FACTORY_SERVICE = "META-INF/services/" + 
ScriptEngineFactory.class.getName();
+
+private static final Logger LOG = 
LoggerFactory.getLogger(SlingScriptEngineManager.class);
+
+private final Set engineSpiBundles = new HashSet<>();
+private final ReentrantReadWriteLock readWriteLock = new 
ReentrantReadWriteLock();
+private final Map> 
factoriesProperties = new HashMap<>();
+private final Set> serviceReferences 
= new HashSet<>();
+
+private ScriptEngineManager internalManager = new 
ScriptEngineManager(SlingScriptEngineManager.class.getClassLoader());
 
 Review comment:
   Nashorn is not there on Java 8, but it is present on Java 9. Even if I 
change the constructor to remove the current passed classloader, using the 
default `Thread.currentThread().getContextClassLoader()` doesn't change things.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] raducotescu commented on a change in pull request #1: SLING-7134 - Script execution order is not deterministic on Java 9

2017-12-04 Thread GitBox
raducotescu commented on a change in pull request #1: SLING-7134 - Script 
execution order is not deterministic on Java 9
URL: 
https://github.com/apache/sling-org-apache-sling-scripting-core/pull/1#discussion_r154671227
 
 

 ##
 File path: 
src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
 ##
 @@ -0,0 +1,320 @@
+/*~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF 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 org.apache.sling.scripting.core.impl.jsr223;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+
+import org.apache.sling.api.scripting.SlingScriptConstants;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+service = {ScriptEngineManager.class, SlingScriptEngineManager.class},
+reference = @Reference(
+name = "ScriptEngineFactory",
+bind = "bindScriptEngineFactory",
+unbind = "unbindScriptEngineFactory",
+service = ScriptEngineFactory.class,
+cardinality = ReferenceCardinality.MULTIPLE,
+policy = ReferencePolicy.DYNAMIC
+)
+)
+public class SlingScriptEngineManager extends ScriptEngineManager implements 
BundleListener {
+
+public static final String EVENT_TOPIC_SCRIPT_MANAGER_UPDATED =
+
"org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager/UPDATED";
+public static final String ENGINE_FACTORY_SERVICE = "META-INF/services/" + 
ScriptEngineFactory.class.getName();
+
+private static final Logger LOG = 
LoggerFactory.getLogger(SlingScriptEngineManager.class);
+
+private final Set engineSpiBundles = new HashSet<>();
+private final ReentrantReadWriteLock readWriteLock = new 
ReentrantReadWriteLock();
+private final Map> 
factoriesProperties = new HashMap<>();
+private final Set> serviceReferences 
= new HashSet<>();
+
+private ScriptEngineManager internalManager = new 
ScriptEngineManager(SlingScriptEngineManager.class.getClassLoader());
 
 Review comment:
   Nashorn is not there on Java 8, but it is present on Java 9.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] raducotescu commented on a change in pull request #1: SLING-7134 - Script execution order is not deterministic on Java 9

2017-12-03 Thread GitBox
raducotescu commented on a change in pull request #1: SLING-7134 - Script 
execution order is not deterministic on Java 9
URL: 
https://github.com/apache/sling-org-apache-sling-scripting-core/pull/1#discussion_r154532142
 
 

 ##
 File path: 
src/main/java/org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager.java
 ##
 @@ -0,0 +1,320 @@
+/*~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF 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 org.apache.sling.scripting.core.impl.jsr223;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptEngineManager;
+
+import org.apache.sling.api.scripting.SlingScriptConstants;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.osgi.service.component.annotations.ReferencePolicyOption;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+service = {ScriptEngineManager.class, SlingScriptEngineManager.class},
+reference = @Reference(
+name = "ScriptEngineFactory",
+bind = "bindScriptEngineFactory",
+unbind = "unbindScriptEngineFactory",
+service = ScriptEngineFactory.class,
+cardinality = ReferenceCardinality.MULTIPLE,
+policy = ReferencePolicy.DYNAMIC
+)
+)
+public class SlingScriptEngineManager extends ScriptEngineManager implements 
BundleListener {
+
+public static final String EVENT_TOPIC_SCRIPT_MANAGER_UPDATED =
+
"org/apache/sling/scripting/core/impl/jsr223/SlingScriptEngineManager/UPDATED";
+public static final String ENGINE_FACTORY_SERVICE = "META-INF/services/" + 
ScriptEngineFactory.class.getName();
+
+private static final Logger LOG = 
LoggerFactory.getLogger(SlingScriptEngineManager.class);
+
+private final Set engineSpiBundles = new HashSet<>();
+private final ReentrantReadWriteLock readWriteLock = new 
ReentrantReadWriteLock();
+private final Map> 
factoriesProperties = new HashMap<>();
+private final Set> serviceReferences 
= new HashSet<>();
+
+private ScriptEngineManager internalManager = new 
ScriptEngineManager(SlingScriptEngineManager.class.getClassLoader());
+private SortedSet factories = new TreeSet<>();
+private ComponentContext componentContext;
+
+@Reference(policy = ReferencePolicy.DYNAMIC,
+   policyOption = ReferencePolicyOption.GREEDY,
+   cardinality = ReferenceCardinality.OPTIONAL)
+private volatile EventAdmin eventAdmin;
+
+@Override
+public ScriptEngine getEngineByName(String shortName) {
+readWriteLock.readLock().lock();
+try {
+return internalManager.getEngineByName(shortName);
+} finally {
+readWriteLock.readLock().unlock();
+}
+}
+
+@Override
+public ScriptEngine getEngineByExtension(String extension) {
+