]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jrubyscripting] Reverses order of class imports and ScriptEngine puts calls to fix...
authorboc-tothefuture <broconne+github@gmail.com>
Sun, 11 Dec 2022 10:00:13 +0000 (05:00 -0500)
committerGitHub <noreply@github.com>
Sun, 11 Dec 2022 10:00:13 +0000 (11:00 +0100)
Signed-off-by: Brian OConnell <broconne@gmail.com>
bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java

index a53fb534bb1f67a2280a5468e72f3044e9f1d598..62030cc19c74c01f08468b0fe0a17b04253ae2b2 100644 (file)
@@ -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<String, Object> mapGlobalPresets(Map.Entry<String, Object> 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<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);
         Map<String, Object> 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);
         }