-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[jrubyscripting] Add JRuby REPL and other utilities inside karaf console #18374
base: main
Are you sure you want to change the base?
Conversation
6b2209c
to
2eb74b6
Compare
2eb74b6
to
547ac87
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
Signed-off-by: Jimmy Tanagra <[email protected]>
547ac87
to
81d7750
Compare
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/openhab/automation/jrubyscripting/internal/JRubyConsoleCommandExtension.java
Outdated
Show resolved
Hide resolved
Updated to use repl code from the helper library openhab/openhab-jruby#405 |
Signed-off-by: Jimmy Tanagra <[email protected]>
6d8eca4
to
9f01a5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to run mvn i18n-generate-default-translations
, no?
bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml
Show resolved
Hide resolved
} | ||
|
||
executeWithFullJRuby(console, engine -> { | ||
engine.getContext().setAttribute("$console", console, ScriptContext.ENGINE_SCOPE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need console? or would session be enough? (really, all I'm using right now is terminal - which you get from session). then you don't event need the JRubyConsole. in the one or two places that need session, just pass it through from execute().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to just $terminal. However, we still need JRubyConsole
because the OSGiConsole class from core is in an internal package. We still want to have a console
object to keep a resemblance to the standard ConsoleCommandExtension in case we need to refactor this back if openhab/openhab-core#4635 is accepted.
e8d4c09
to
04d2f9f
Compare
…ties Signed-off-by: Jimmy Tanagra <[email protected]>
04d2f9f
to
0618843
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
Signed-off-by: Jimmy Tanagra <[email protected]>
a4ecdce
to
c94593c
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
c94593c
to
2411ea4
Compare
Signed-off-by: Jimmy Tanagra <[email protected]>
Signed-off-by: Jimmy Tanagra <[email protected]>
console.println("Available console scripts:"); | ||
String defaultConsole = jRubyScriptEngineFactory.getConfiguration().getConsole(); | ||
consoles.forEach((name, description) -> { | ||
if (defaultConsole.endsWith(name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be more discerning here. if (defaultConsole.equals("openhab/console/" + name)) {
cause what if I have default console configured to be "ccutrer/irb"? that would match the "irb" from the registry, but is decidedly not the default console.
and along those lines, perhaps if the default console isn't found in the registry, add an extra line at the bottom along the lines of " (default) - " + defaultConsole
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch! refactored.
bundles/org.openhab.automation.jrubyscripting/src/main/resources/OH-INF/config/config.xml
Outdated
Show resolved
Hide resolved
Signed-off-by: Jimmy Tanagra <[email protected]>
f77b6e2
to
ae05598
Compare
Add Karaf console utilities for JRuby, including a REPL environment that runs inside the same script engine as normal rules.
The REPL shell supports:
This next screenshot shows it running in my production instance:

An alternative implementation can be done should openhab/openhab-core#4635 be merged. For the time being, this PR stands alone and will work without the linked core PR. When the core PR is merged and this is refactored, we can remove the dependency to karaf in pom.xml.
If the core PR gets merged, I can refactor this later if necessary. I don't want the core PR be a blocker for this PR though.