diff --git a/bundles/org.openhab.automation.jrubyscripting/README.md b/bundles/org.openhab.automation.jrubyscripting/README.md index b145bd078..d1748a11b 100644 --- a/bundles/org.openhab.automation.jrubyscripting/README.md +++ b/bundles/org.openhab.automation.jrubyscripting/README.md @@ -8,15 +8,16 @@ After installing this add-on, you will find configuration options in the openHAB Alternatively, JRuby configuration parameters may be set by creating a `jruby.cfg` file in `conf/services/` -| Parameter | Default | Description | -| ----------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| org.openhab.automation.jrubyscripting:gem_home | $OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION} | Location Ruby Gems will be installed to and loaded from. Directory will be created if necessary. You can use `{RUBY_ENGINE_VERSION}`, `{RUBY_ENGINE}` and/or `{RUBY_VERSION}` replacements in this value to automatically point to a new directory when the addon is updated with a new version of JRuby. | -| org.openhab.automation.jrubyscripting:rubylib | $OPENHAB_CONF/automation/ruby/lib | Search path for user libraries. Separate each path with a colon (semicolon in Windows). | -| org.openhab.automation.jrubyscripting:local_context | singlethread | The local context holds Ruby runtime, name-value pairs for sharing variables between Java and Ruby. See [this](https://github.com/jruby/jruby/wiki/RedBridge#Context_Instance_Type) for options and details | -| org.openhab.automation.jrubyscripting:local_variables | transient | Defines how variables are shared between Ruby and Java. See [this](https://github.com/jruby/jruby/wiki/RedBridge#local-variable-behavior-options) for options and details | -| org.openhab.automation.jrubyscripting:gems | | A comma separated list of [Ruby Gems](https://rubygems.org/) to install. | -| org.openhab.automation.jrubyscripting:require | | A comma separated list of script names to be required by the JRuby Scripting Engine at the beginning of user scripts. | -| org.openhab.automation.jrubyscripting:check_update | true | Check RubyGems for updates to the above gems when OpenHAB starts or JRuby settings are changed. Otherwise it will try to fulfil the requirements with locally installed gems, and you can manage them yourself with an external Ruby by setting the same GEM_HOME. | +| Parameter | Default | Description | +| --------------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| org.openhab.automation.jrubyscripting:gem_home | $OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION} | Location Ruby Gems will be installed to and loaded from. Directory will be created if necessary. You can use `{RUBY_ENGINE_VERSION}`, `{RUBY_ENGINE}` and/or `{RUBY_VERSION}` replacements in this value to automatically point to a new directory when the addon is updated with a new version of JRuby. | +| org.openhab.automation.jrubyscripting:rubylib | $OPENHAB_CONF/automation/ruby/lib | Search path for user libraries. Separate each path with a colon (semicolon in Windows). | +| org.openhab.automation.jrubyscripting:local_context | singlethread | The local context holds Ruby runtime, name-value pairs for sharing variables between Java and Ruby. See [this](https://github.com/jruby/jruby/wiki/RedBridge#Context_Instance_Type) for options and details | +| org.openhab.automation.jrubyscripting:local_variables | transient | Defines how variables are shared between Ruby and Java. See [this](https://github.com/jruby/jruby/wiki/RedBridge#local-variable-behavior-options) for options and details | +| org.openhab.automation.jrubyscripting:gems | | A comma separated list of [Ruby Gems](https://rubygems.org/) to install. | +| org.openhab.automation.jrubyscripting:require | | A comma separated list of script names to be required by the JRuby Scripting Engine at the beginning of user scripts. | +| org.openhab.automation.jrubyscripting:check_update | true | Check RubyGems for updates to the above gems when OpenHAB starts or JRuby settings are changed. Otherwise it will try to fulfil the requirements with locally installed gems, and you can manage them yourself with an external Ruby by setting the same GEM_HOME. | +| org.openhab.automation.jrubyscripting:dependency_tracking | true | Dependency tracking allows your scripts to automatically reload when one of its dependencies is updated. You may want to disable dependency tracking if you plan on editing or updating a shared library, but don't want all your scripts to reload until you can test it. | ## Ruby Gems diff --git a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java index 7b4d6b044..978232539 100644 --- a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java +++ b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java @@ -59,6 +59,7 @@ public class JRubyScriptEngineConfiguration { private static final String GEMS_CONFIG_KEY = "gems"; private static final String REQUIRE_CONFIG_KEY = "require"; private static final String CHECK_UPDATE_CONFIG_KEY = "check_update"; + private static final String DEPENDENCY_TRACKING_CONFIG_KEY = "dependency_tracking"; // Map of configuration parameters private final Map configurationParameters = Map.ofEntries( @@ -82,7 +83,9 @@ public class JRubyScriptEngineConfiguration { Map.entry(REQUIRE_CONFIG_KEY, new OptionalConfigurationElement("")), - Map.entry(CHECK_UPDATE_CONFIG_KEY, new OptionalConfigurationElement("true"))); + Map.entry(CHECK_UPDATE_CONFIG_KEY, new OptionalConfigurationElement("true")), + + Map.entry(DEPENDENCY_TRACKING_CONFIG_KEY, new OptionalConfigurationElement("true"))); /** * Update configuration @@ -327,6 +330,10 @@ public class JRubyScriptEngineConfiguration { return List.of(rubyLib.split(File.pathSeparator)); } + public boolean enableDependencyTracking() { + return "true".equals(get(DEPENDENCY_TRACKING_CONFIG_KEY)); + } + /** * Configure system properties * 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 5c0613aa9..dc08a85b9 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 @@ -89,7 +89,9 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory { configuration.update(config, factory); // Re-initialize the dependency tracker's watchers. jrubyDependencyTracker.deactivate(); - jrubyDependencyTracker.activate(); + if (configuration.enableDependencyTracking()) { + jrubyDependencyTracker.activate(); + } } @Override @@ -119,7 +121,7 @@ public class JRubyScriptEngineFactory extends AbstractScriptEngineFactory { importClassesToRuby(scriptEngine, partitionedMap.getOrDefault(true, new HashMap<>())); Object scriptExtension = scopeValues.get("scriptExtension"); - if (scriptExtension instanceof ScriptExtensionManagerWrapper) { + if (scriptExtension instanceof ScriptExtensionManagerWrapper && configuration.enableDependencyTracking()) { 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 diff --git a/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml b/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml index c548ff69b..50b356ee2 100644 --- a/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml +++ b/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml @@ -14,11 +14,13 @@ This group defines Ruby's environment. + true This group defines JRuby system properties. + true @@ -28,6 +30,12 @@ ]]> + + + A comma separated list of script names to be required by the JRuby Scripting Engine before running user + scripts. + + Check RubyGems for updates to the above gems when OpenHAB starts or JRuby settings are changed. @@ -38,12 +46,7 @@ true - - - - - A comma separated list of script names to be required by the JRuby Scripting Engine before running user - scripts. + true @@ -53,12 +56,23 @@ a new directory when the addon is updated with a new version of JRuby. Defaults to "OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION}" when not specified. ]]> + true OPENHAB_CONF/automation/ruby/lib" when not specified.]]> + true + + + + + Dependency tracking allows your scripts to automatically reload when one of its dependencies is updated. + You may want to disable dependency tracking if you plan on editing or updating a shared library, but don't want all + your scripts to reload until you can test it. + true + true @@ -90,6 +104,5 @@ true - diff --git a/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/i18n/jruby.properties b/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/i18n/jruby.properties index 2d2d7e45c..2fb8b2a96 100644 --- a/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/i18n/jruby.properties +++ b/bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/i18n/jruby.properties @@ -2,6 +2,8 @@ automation.config.jruby.check_update.label = Check for Gem Updates automation.config.jruby.check_update.description = Check RubyGems for updates to the above gems when OpenHAB starts or JRuby settings are changed. Otherwise it will try to fulfill the requirements with locally installed gems, and you can manage them yourself with an external Ruby by setting the same GEM_HOME. automation.config.jruby.check_update.option.true = Check For Updates automation.config.jruby.check_update.option.false = Do Not Check For Updates +automation.config.jruby.dependency_tracking.label = Enable Dependency Tracking +automation.config.jruby.dependency_tracking.description = Dependency tracking allows your scripts to automatically reload when one of its dependencies is updated. You may want to disable dependency tracking if you plan on editing or updating a shared library, but don't want all your scripts to reload until you can test it. automation.config.jruby.gem_home.label = GEM_HOME automation.config.jruby.gem_home.description = Location Ruby Gems will be installed to and loaded from. Directory will be created if necessary. You can use {RUBY_ENGINE_VERSION}, {RUBY_ENGINE} and/or {RUBY_VERSION} replacements in this value to automatically point to a new directory when the addon is updated with a new version of JRuby. Defaults to "OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION}" when not specified. automation.config.jruby.gems.label = Ruby Gems