-
-
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] Implement dependency tracking #13810
[jrubyscripting] Implement dependency tracking #13810
Conversation
inject ourselves into file and gem loading, and then notify OpenHAB of every file and gem that's loaded depends on openhab/openhab-addons#13810 to have any effect
ccutrer/openhab-jrubyscripting@3ba1054 is the commit to enable this functionality in the helper library |
Reference openhab/openhab-addons#13810. Signed-off-by: Cody Cutrer <cody@cutrer.us>
watchers had to be refactored similiar 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>
78f80b1
to
716d1fc
Compare
This works well in my installation. |
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.
...main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java
Show resolved
Hide resolved
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
// Copy of org.openhab.core.automation.module.script.rulesupport.internal.loader.collection.BidiSetBag |
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.
For my understanding, why does it need to be copied? Is it modified in any way, or just plain duplication?
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.
It's in an internal package and therefore not exported from the core package.
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.
If there is a need to reuse it in addons, would it make sense to expose it then (to avoid duplication)?
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.
Honestly, I'd prefer if I didn't have to copy or reference it. I had to because the AbstractDependencyTracker isn't flexible enough for my needs - it assumes a single library directory that it must watch. If it were to be improved, then I could not need to reference this class at all.
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.
Otherwise LGTM
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
// Copy of org.openhab.core.automation.module.script.rulesupport.internal.loader.collection.BidiSetBag |
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.
It's in an internal package and therefore not exported from the core package.
* @author Cody Cutrer - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class JRubyGemWatchService extends AbstractWatchService { |
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'm not so happy with these tons of new watch services, but this might improve after we have openhab/openhab-core#3004 merged which simplifies the interface.
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.
Oooh. That'll be nice. To slightly assuage your concerns in the meantime, while this is setup to allow an arbitrary number of watch services, 99% of the time it will be the default config, and there will be just 2 - one for GEM_HOME, and a single one for RUBYLIB. And both of those will be directories nested underneath the JRubyScriptFileWatcher, so the underlying WatchQueueReader won't actually be watching any more, but will have more bookkeeping.
* @author Cody Cutrer - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class JRubyDependencyTracker implements ScriptDependencyTracker { |
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.
This could be a service (component) itself which then is injected into the script engine factory (like in js). I didn't check where the individual configurations values come from, but likely they can be derived from the ConfigAdmin.
Edit another option would be that the script engine factory itself implements ScriptDependencyTracker
and returns this
in getDependencyTracker()
.
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 tried really hard to get this to be an OSGi component. I actually started by just copying the JS files. But I couldn't get around the circular dependence - JRubyScriptEngineFactory
needs to return the dependency tracker. But the dependency tracker needs access to the config. On the one hand, like you say, I could just use ConfigAdmin
directly to get the current configuration values, but the raw configuration is wrapped by Java both to provide non-constant defaults (well, it is theoretically constant, but dependent on values from the JRuby bundle), as well as providing some post-processing to the values. I definitely didn't want to attempt to duplicate that.
I also considered just having the JRubyScriptEngineFactory
implement ScriptDependencyTracker
like you said, but I wanted to keep it separate in hopes of eliminating the bulk of this class by inheriting from AbstractScriptDependencyTracker
as discussed in the other comment.
Another option I've thought of, but didn't really explore, is having the configuration itself be an independent component that both JRubyScriptEngineFactory
and JRubyDependencyTracker
depend on. If you're adamant that you really want this to be an OSGi component, I can explore that.
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 would suggest to keep it like it is now and refactor it later when the core watch service is changed. As a result it should also be possible to easily adapt the AbstractScriptDependencyTracker
to watch for more than one directory. Since that one needs refactoring anyway with the new watch service, I would prefer not to touch it before the release because time is a bit short.
… exist Signed-off-by: Cody Cutrer <cody@cutrer.us>
even though Ruby prefers dependency_listener over dependencyListener, it just felt weird when in a list next to the other globals injected by openHAB Signed-off-by: Cody Cutrer <cody@cutrer.us>
No, let's merge. :-) |
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.
LGTM
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/jruby-scripting-with-jruby-9-4/141395/1 |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/jruby-scripting-with-jruby-9-4/141395/4 |
* [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> Signed-off-by: Ben Rosenblum <rosenblumb@gmail.com>
* [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> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
* [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>
* [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>
* [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>
* [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> Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
watchers had to be refactored similiar 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.