[jrubyscripting] Implement dependency tracking (#13810)
* [jrubyscripting] implement dependency tracking watchers had to be refactored similar to jsscripting. it supports watching any directory referenced from RUBYLIB, as well as the gem home. it properly excludes lib and gem home (as well as other gem homes if you have multiple jruby versions installed) from loading as regular scripts. this is a breaking change if you don't have RUBYLIB explicitly configured, and you are using the old default directory. it's expected that the detection of what files and gems any given script uses will be self-identified by the script, presumably by the helper library. JRubyScriptEngineConfiguration was largely refactored as part of this. * CONFIGURATION_PARAMETERS was renamed, and is no longer static, since it's modified every time the configuration is changed * OptionalConfigurationElement was simplified since default values are always provided now. this also simplified lots of other code that accesses the current settings. Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
@@ -8,15 +8,15 @@ 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/scripts/lib/ruby/gem_home | Location ruby gems will be installed and loaded, directory will be created if missing and gem installs are specified |
|
||||
| org.openhab.automation.jrubyscripting:rubylib | $OPENHAB_CONF/automation/lib/ruby/ | 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. |
|
||||
|
||||
## Ruby Gems
|
||||
|
||||
@@ -42,7 +42,7 @@ org.openhab.automation.jrubyscripting:gems=library= >= 2.2.0; < 3.0, another-gem
|
||||
|
||||
When this add-on is installed, you can select JRuby as a scripting language when creating a script action within the rule editor of the UI.
|
||||
|
||||
Alternatively, you can create scripts in the `automation/jsr223/ruby/personal` configuration directory.
|
||||
Alternatively, you can create scripts in the `automation/ruby` configuration directory.
|
||||
If you create an empty file called `test.rb`, you will see a log line with information similar to:
|
||||
|
||||
```text
|
||||
@@ -62,7 +62,7 @@ log:set DEBUG org.openhab.automation.jrubyscripting
|
||||
All [ScriptExtensions]({{base}}/configuration/jsr223.html#scriptextension-objects-all-jsr223-languages) are available in JRuby with the following exceptions/modifications:
|
||||
|
||||
- The `File` variable, referencing `java.io.File` is not available as it conflicts with Ruby's File class preventing Ruby from initializing
|
||||
- Globals `scriptExtension`, `automationManager`, `ruleRegistry`, `items`, `voice`, `rules`, `things`, `events`, `itemRegistry`, `ir`, `actions`, `se`, `audio`, `lifecycleTracker` are prepended with a `$` (e.g. `$automationManager`) making them available as global objects in Ruby.
|
||||
- Globals `scriptExtension`, `automationManager`, `ruleRegistry`, `items`, `voice`, `rules`, `things`, `events`, `itemRegistry`, `ir`, `actions`, `se`, `audio`, `lifecycleTracker` are prepended with a `$` (e.g. `$automationManager`) making them available as global variables in Ruby.
|
||||
|
||||
## Script Examples
|
||||
|
||||
|
||||
Reference in New Issue
Block a user