[jrubyscripting] Reverses order of class imports and ScriptEngine puts calls to fix incompatability introduced after M5 (#13904)
Signed-off-by: Brian OConnell <broconne@gmail.com>
This commit is contained in:
parent
015cc847bb
commit
48b471a313
|
@ -61,7 +61,8 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory {
|
||||||
|
|
||||||
private JRubyDependencyTracker jrubyDependencyTracker;
|
private JRubyDependencyTracker jrubyDependencyTracker;
|
||||||
|
|
||||||
// Adds $ in front of a set of variables so that Ruby recognizes them as global variables
|
// Adds $ in front of a set of variables so that Ruby recognizes them as global
|
||||||
|
// variables
|
||||||
private static Map.Entry<String, Object> mapGlobalPresets(Map.Entry<String, Object> entry) {
|
private static Map.Entry<String, Object> mapGlobalPresets(Map.Entry<String, Object> entry) {
|
||||||
if (Character.isLowerCase(entry.getKey().charAt(0)) && !(entry.getValue() instanceof Class)
|
if (Character.isLowerCase(entry.getKey().charAt(0)) && !(entry.getValue() instanceof Class)
|
||||||
&& !(entry.getValue() instanceof Enum)) {
|
&& !(entry.getValue() instanceof Enum)) {
|
||||||
|
@ -98,7 +99,8 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scopeValues(ScriptEngine scriptEngine, Map<String, Object> scopeValues) {
|
public void scopeValues(ScriptEngine scriptEngine, Map<String, Object> scopeValues) {
|
||||||
// Empty comments prevent the formatter from breaking up the correct streams chaining
|
// Empty comments prevent the formatter from breaking up the correct streams
|
||||||
|
// chaining
|
||||||
logger.debug("Scope Values: {}", scopeValues);
|
logger.debug("Scope Values: {}", scopeValues);
|
||||||
Map<String, Object> filteredScopeValues = //
|
Map<String, Object> filteredScopeValues = //
|
||||||
scopeValues //
|
scopeValues //
|
||||||
|
@ -113,20 +115,23 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory {
|
||||||
.collect(Collectors.partitioningBy(entry -> (entry.getValue() instanceof Class),
|
.collect(Collectors.partitioningBy(entry -> (entry.getValue() instanceof Class),
|
||||||
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
|
Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||||
|
|
||||||
importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>()));
|
|
||||||
super.scopeValues(scriptEngine, partitionedMap.getOrDefault(false, new HashMap<>()));
|
super.scopeValues(scriptEngine, partitionedMap.getOrDefault(false, new HashMap<>()));
|
||||||
|
importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>()));
|
||||||
|
|
||||||
Object scriptExtension = scopeValues.get("scriptExtension");
|
Object scriptExtension = scopeValues.get("scriptExtension");
|
||||||
if (scriptExtension instanceof ScriptExtensionManagerWrapper) {
|
if (scriptExtension instanceof ScriptExtensionManagerWrapper) {
|
||||||
ScriptExtensionManagerWrapper wrapper = (ScriptExtensionManagerWrapper) scriptExtension;
|
ScriptExtensionManagerWrapper wrapper = (ScriptExtensionManagerWrapper) scriptExtension;
|
||||||
// we inject like this instead of using the script context, because
|
// we inject like this instead of using the script context, because
|
||||||
// this is executed _before_ the dependency tracker is added to the script context.
|
// this is executed _before_ the dependency tracker is added to the script
|
||||||
|
// context.
|
||||||
// But we need this set up before we inject our requires
|
// But we need this set up before we inject our requires
|
||||||
scriptEngine.put("$dependencyListener", jrubyDependencyTracker.getTracker(wrapper.getScriptIdentifier()));
|
scriptEngine.put("$dependencyListener", jrubyDependencyTracker.getTracker(wrapper.getScriptIdentifier()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// scopeValues is called twice. The first call only passed 'se'. The second call passed the rest of the
|
// scopeValues is called twice. The first call only passed 'se'. The second call
|
||||||
// presets, including 'ir'. We wait for the second call before running the require statements.
|
// passed the rest of the
|
||||||
|
// presets, including 'ir'. We wait for the second call before running the
|
||||||
|
// require statements.
|
||||||
if (scopeValues.containsKey("ir")) {
|
if (scopeValues.containsKey("ir")) {
|
||||||
configuration.injectRequire(scriptEngine);
|
configuration.injectRequire(scriptEngine);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue