mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[jrubyscripting] allow disabling dependency tracking (#13944)
* [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>
This commit is contained in:
parent
e5e067b79b
commit
74f22a5325
@ -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
|
||||
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -14,11 +14,13 @@
|
||||
<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">
|
||||
@ -28,6 +30,12 @@
|
||||
]]></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.
|
||||
@ -38,12 +46,7 @@
|
||||
<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">
|
||||
@ -53,12 +56,23 @@
|
||||
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">
|
||||
@ -90,6 +104,5 @@
|
||||
<advanced>true</advanced>
|
||||
</parameter>
|
||||
|
||||
|
||||
</config-description>
|
||||
</config-description:config-descriptions>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user