[jrubyscripting] Allow multiple version specifiers for gems (#13779)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
parent
3912487305
commit
735089a7c7
@ -9,7 +9,7 @@ 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/`
|
Alternatively, JRuby configuration parameters may be set by creating a `jruby.cfg` file in `conf/services/`
|
||||||
|
|
||||||
| Parameter | Default | Description |
|
| 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: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: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_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 |
|
||||||
@ -23,6 +23,7 @@ Alternatively, JRuby configuration parameters may be set by creating a `jruby.cf
|
|||||||
This automation add-on will install user specified gems and make them available on the library search path.
|
This automation add-on will install user specified gems and make them available on the library search path.
|
||||||
Gem versions may be specified using the standard ruby gem_name=version format.
|
Gem versions may be specified using the standard ruby gem_name=version format.
|
||||||
The version number follows the [pessimistic version constraint](https://guides.rubygems.org/patterns/#pessimistic-version-constraint) syntax.
|
The version number follows the [pessimistic version constraint](https://guides.rubygems.org/patterns/#pessimistic-version-constraint) syntax.
|
||||||
|
Multiple version specifiers can be added by separating them with a semicolon.
|
||||||
|
|
||||||
For example this configuration will install the latest version of the [openHAB JRuby Scripting Library](https://boc-tothefuture.github.io/openhab-jruby/), and instruct the scripting engine to automatically insert `require 'openhab'` at the start of the script.
|
For example this configuration will install the latest version of the [openHAB JRuby Scripting Library](https://boc-tothefuture.github.io/openhab-jruby/), and instruct the scripting engine to automatically insert `require 'openhab'` at the start of the script.
|
||||||
|
|
||||||
@ -31,6 +32,12 @@ org.openhab.automation.jrubyscripting:gems=openhab-scripting
|
|||||||
org.openhab.automation.jrubyscripting:require=openhab
|
org.openhab.automation.jrubyscripting:require=openhab
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example with multiple version specifiers:
|
||||||
|
|
||||||
|
```text
|
||||||
|
org.openhab.automation.jrubyscripting:gems=library= >= 2.2.0; < 3.0, another-gem= > 4.0.0.a; < 5
|
||||||
|
```
|
||||||
|
|
||||||
## Creating JRuby Scripts
|
## Creating JRuby Scripts
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|||||||
@ -171,11 +171,11 @@ public class JRubyScriptEngineConfiguration {
|
|||||||
int validGems = 0;
|
int validGems = 0;
|
||||||
for (String gem : gems) {
|
for (String gem : gems) {
|
||||||
gem = gem.trim();
|
gem = gem.trim();
|
||||||
String version = "";
|
String[] versions = {};
|
||||||
if (gem.contains("=")) {
|
if (gem.contains("=")) {
|
||||||
String[] gemParts = gem.split("=");
|
String[] gemParts = gem.split("=", 2);
|
||||||
gem = gemParts[0].trim();
|
gem = gemParts[0].trim();
|
||||||
version = gemParts[1].trim();
|
versions = gemParts[1].split(";");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gem.isEmpty()) {
|
if (gem.isEmpty()) {
|
||||||
@ -183,9 +183,12 @@ public class JRubyScriptEngineConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gemCommand += " gem '" + gem + "'";
|
gemCommand += " gem '" + gem + "'";
|
||||||
|
for (String version : versions) {
|
||||||
|
version = version.trim();
|
||||||
if (!version.isEmpty()) {
|
if (!version.isEmpty()) {
|
||||||
gemCommand += ", '" + version + "'";
|
gemCommand += ", '" + version + "'";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
gemCommand += ", require: false\n";
|
gemCommand += ", require: false\n";
|
||||||
validGems += 1;
|
validGems += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user