From: boc-tothefuture Date: Sun, 11 Dec 2022 10:00:13 +0000 (-0500) Subject: [jrubyscripting] Reverses order of class imports and ScriptEngine puts calls to fix... X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=48b471a313a099e57952002f01b8accdf32e2773;p=openhab-addons.git [jrubyscripting] Reverses order of class imports and ScriptEngine puts calls to fix incompatability introduced after M5 (#13904) Signed-off-by: Brian OConnell --- diff --git a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java index a53fb534bb..62030cc19c 100644 --- a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java +++ b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java @@ -61,7 +61,8 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory { 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 mapGlobalPresets(Map.Entry entry) { if (Character.isLowerCase(entry.getKey().charAt(0)) && !(entry.getValue() instanceof Class) && !(entry.getValue() instanceof Enum)) { @@ -98,7 +99,8 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory { @Override public void scopeValues(ScriptEngine scriptEngine, Map 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); Map filteredScopeValues = // scopeValues // @@ -113,20 +115,23 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory { .collect(Collectors.partitioningBy(entry -> (entry.getValue() instanceof Class), Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); - importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>())); super.scopeValues(scriptEngine, partitionedMap.getOrDefault(false, new HashMap<>())); + importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>())); Object scriptExtension = scopeValues.get("scriptExtension"); if (scriptExtension instanceof ScriptExtensionManagerWrapper) { ScriptExtensionManagerWrapper wrapper = (ScriptExtensionManagerWrapper) scriptExtension; // 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 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 - // presets, including 'ir'. We wait for the second call before running the require statements. + // scopeValues is called twice. The first call only passed 'se'. The second call + // passed the rest of the + // presets, including 'ir'. We wait for the second call before running the + // require statements. if (scopeValues.containsKey("ir")) { configuration.injectRequire(scriptEngine); }