diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileReference.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileReference.java index f82e14987..cfb46a089 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileReference.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileReference.java @@ -105,6 +105,10 @@ public class ScriptFileReference implements Comparable { String name2 = path2.getFileName().toString(); LOGGER.trace("o2 [{}], path2 [{}], name2 [{}]", other.scriptFileURL, path2, name2); + int startLevelCompare = Integer.compare(getStartLevel(), other.getStartLevel()); + if (startLevelCompare != 0) { + return startLevelCompare; + } int nameCompare = name1.compareToIgnoreCase(name2); if (nameCompare != 0) { return nameCompare; diff --git a/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcherTest.java b/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcherTest.java index 5dc073c12..664211454 100644 --- a/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcherTest.java +++ b/bundles/org.openhab.core.automation.module.script.rulesupport/src/test/java/org/openhab/core/automation/module/script/rulesupport/loader/ScriptFileWatcherTest.java @@ -266,6 +266,33 @@ class ScriptFileWatcherTest { p66.toFile().toURI().toString()); } + @Test + public void testOrderingStartlevelFolders() { + when(scriptEngineManager.isSupported("js")).thenReturn(true); + ScriptEngineContainer scriptEngineContainer = mock(ScriptEngineContainer.class); + when(scriptEngineContainer.getScriptEngine()).thenReturn(mock(ScriptEngine.class)); + + when(scriptEngineManager.createScriptEngine(anyString(), anyString())).thenReturn(scriptEngineContainer); + + Path p50 = getFile("a_script.js"); + scriptFileWatcher.processWatchEvent(null, ENTRY_CREATE, p50); + Path p40 = getFile("sl40/b_script.js"); + scriptFileWatcher.processWatchEvent(null, ENTRY_CREATE, p40); + Path p30 = getFile("sl30/script.js"); + scriptFileWatcher.processWatchEvent(null, ENTRY_CREATE, p30); + + updateStartLevel(70); + + InOrder inOrder = inOrder(scriptEngineManager); + + inOrder.verify(scriptEngineManager, timeout(10000).times(1)).createScriptEngine("js", + p30.toFile().toURI().toString()); + inOrder.verify(scriptEngineManager, timeout(10000).times(1)).createScriptEngine("js", + p40.toFile().toURI().toString()); + inOrder.verify(scriptEngineManager, timeout(10000).times(1)).createScriptEngine("js", + p50.toFile().toURI().toString()); + } + @Test public void testReloadActiveWhenDependencyChanged() { when(scriptEngineManager.isSupported("js")).thenReturn(true);