]> git.basschouten.com Git - openhab-addons.git/commitdiff
[jrubyscripting] allow disabling dependency tracking (#13944)
authorCody Cutrer <cody@cutrer.us>
Mon, 30 Jan 2023 22:24:54 +0000 (15:24 -0700)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 22:24:54 +0000 (23:24 +0100)
* [jrubyscripting] allow disabling dependency tracking

in case your helper library doesn't support it. or you just don't like
the behavior.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.automation.jrubyscripting/README.md
bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java
bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineFactory.java
bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/i18n/jruby.properties

index b145bd0784a9657d16def166e6c4f8a6d1112a49..d1748a11b38944ddb165928dac6f8c12c5298914 100644 (file)
@@ -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
 
index 7b4d6b0446cc21339bc936b5701c3c83286ee8f9..97823253926c9996cb9567990a65be9594ec32d4 100644 (file)
@@ -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<String, OptionalConfigurationElement> 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
      * 
index 5c0613aa97abccf429fa96c3c2c9ca88fb924b92..dc08a85b912a920911bf45d5bab20c341b9b6e4c 100644 (file)
@@ -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
index c548ff69b04b28204246d081ddd327cea79a6605..50b356ee27f6d0624ed11933a9b69302df19edaa 100644 (file)
                <parameter-group name="environment">
                        <label>Ruby Environment</label>
                        <description>This group defines Ruby's environment.</description>
+                       <advanced>true</advanced>
                </parameter-group>
 
                <parameter-group name="system">
                        <label>System Properties</label>
                        <description>This group defines JRuby system properties.</description>
+                       <advanced>true</advanced>
                </parameter-group>
 
                <parameter name="gems" type="text" required="false" groupName="gems">
                                ]]></description>
                </parameter>
 
+               <parameter name="require" type="text" required="false" groupName="gems">
+                       <label>Require Scripts</label>
+                       <description>A comma separated list of script names to be required by the JRuby Scripting Engine before running user
+                               scripts.</description>
+               </parameter>
+
                <parameter name="check_update" type="boolean" required="true" groupName="gems">
                        <label>Check for Gem Updates</label>
                        <description>Check RubyGems for updates to the above gems when OpenHAB starts or JRuby settings are changed.
                                <option value="false">Do Not Check For Updates</option>
                        </options>
                        <default>true</default>
-               </parameter>
-
-               <parameter name="require" type="text" required="false" groupName="gems">
-                       <label>Require Scripts</label>
-                       <description>A comma separated list of script names to be required by the JRuby Scripting Engine before running user
-                               scripts.</description>
+                       <advanced>true</advanced>
                </parameter>
 
                <parameter name="gem_home" type="text" required="false" groupName="environment">
                                a new directory when the addon is updated with a new version of JRuby.
                                Defaults to "<tt>OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION}</tt>" when not specified.
                                ]]></description>
+                       <advanced>true</advanced>
                </parameter>
 
                <parameter name="rubylib" type="text" required="false" groupName="environment">
                        <label>RUBYLIB</label>
                        <description><![CDATA[Search path for user libraries. Separate each path with a colon (semicolon in Windows). Defaults to
                                "<tt>OPENHAB_CONF/automation/ruby/lib</tt>" when not specified.]]></description>
+                       <advanced>true</advanced>
+               </parameter>
+
+               <parameter name="dependency_tracking" type="boolean" required="true" groupName="environment">
+                       <label>Enable Dependency Tracking</label>
+                       <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.</description>
+                       <default>true</default>
+                       <advanced>true</advanced>
                </parameter>
 
                <parameter name="local_context" type="text" required="false" groupName="system">
                        <advanced>true</advanced>
                </parameter>
 
-
        </config-description>
 </config-description:config-descriptions>
index 2d2d7e45cb63e5884005571bd42e590e4d6a8687..2fb8b2a96be88bb95e1b995df7df0fa739e6e219 100644 (file)
@@ -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 <tt>{RUBY_ENGINE_VERSION}</tt>, <tt>{RUBY_ENGINE}</tt> and/or <tt>{RUBY_VERSION}</tt> replacements in this value to automatically point to a new directory when the addon is updated with a new version of JRuby. Defaults to "<tt>OPENHAB_CONF/automation/ruby/.gem/{RUBY_ENGINE_VERSION}</tt>" when not specified.
 automation.config.jruby.gems.label = Ruby Gems