openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.71k forks source link

[JSR223] Broken access to the classes like RuleBuilder, PersistenceExtensions, TriggerHandler #5821

Closed lewie closed 5 years ago

lewie commented 5 years ago

Expected Behavior and Current Behavior

Since openHAB 2.x overJSR223 for example javascript nashorn we could access these classes and use it for scripting: org.eclipse.smarthome.automation.core.util.RuleBuilder org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions org.eclipse.smarthome.automation.handler.TriggerHandler ...

Since openHAB 2.5 access to these classes is broken. JSR223 is unusable. Current I have tested access only with javascript language, but suspect the other script languages are in the same situation?!

Possible Solution

Probably I overlooked something. I don't assign any announcement or change to this serious behavioral change. I can't yet categorize whether it's an oversight, bug, or a architectural measure. I would very much like to learn about possible solutions! ;-)

Steps to Reproduce (for bugs)

Install openHAB 2.5 nightly and run a script, calling any of these 3 classes like in JavaScript: var RuleBuilder = Java.type("org.eclipse.smarthome.automation.core.util.RuleBuilder");

RuleBuilder is currently indispensable, and we don't have an alternative. RuleBuilder is https://github.com/lewie/openhab2-javascript/blob/master/jslib/JSRule.js#L119

openhab> log:tail
14:59:34.794 [INFO ] [e.core.internal.i18n.I18nProviderImpl] - Location set to '49.714168199999996,11.1331782'.
14:59:35.233 [INFO ] [mebuilder.internal.HomeBuilderServlet] - Started Home Builder at /homebuilder
14:59:35.269 [INFO ] [bpanel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel
14:59:36.260 [WARN ] [d.internal.element.HttpContextElement] - Registered http context [null] did not contain a valid http context id
14:59:40.316 [INFO ] [rthome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
14:59:41.174 [INFO ] [i.dashboard.internal.DashboardService] - Started Dashboard at http://192.168.0.45:8080
14:59:41.179 [INFO ] [i.dashboard.internal.DashboardService] - Started Dashboard at https://192.168.0.45:8443
14:59:41.485 [INFO ] [.openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
14:59:41.653 [INFO ] [t.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript
14:59:41.674 [INFO ] [t.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript
15:00:06.703 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'ActionExamples.js'
15:00:07.436 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/ActionExamples.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.core.util.RuleBuilder
15:00:07.438 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'controltest.js'
15:00:07.552 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/controltest.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.core.util.RuleBuilder
15:00:07.555 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/astronomy.js'
15:00:07.590 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/b64.js'
15:00:07.654 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/eventLoopNashorn.js'
15:00:07.692 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/helper.js'
15:00:07.747 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/jslib/helper.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.core.util.RuleBuilder
15:00:07.749 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/hysteresis.js'
15:00:07.776 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/JSRule.js'
15:00:07.865 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/jslib/JSRule.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.core.util.RuleBuilder
15:00:07.867 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/lewi.js'
15:00:07.896 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/jslib/lewi.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.model.persistence.extensions.PersistenceExtensions
15:00:07.899 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/PersistenceExtensions.js'
15:00:07.939 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/jslib/PersistenceExtensions.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.model.persistence.extensions.Persis
15:00:07.948 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/suncalc.js'
15:00:08.037 [INFO ] [ort.internal.loader.ScriptFileWatcher] - Loading script 'jslib/triggersAndConditions.js'
15:00:08.099 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/E:/dev/OpenHab/openhab-2.5.0-SNAPSHOT/conf/automation/jsr223/jslib/triggersAndConditions.js': java.lang.ClassNotFoundException: org.eclipse.smarthome.automation.handler.TriggerHandler
5iver commented 5 years ago

Since openHAB 2.5 access to these classes is broken. JSR223 is unusable. Current I have tested access only with javascript language, but suspect the other script languages are in the same situation?!

Some classes have been moved from org.eclipse.smarthome.automation to org.openhab.core.automation. Using the raw API to create rules with JSR223 is working. But there are some org.eclipse.smarthome.core packages that have not been renamed, and I haven't found a way to access them yet.

After testing, this is the only one that worked for me...

org.openhab.core.automation.handler.TriggerHandler

This issue should be moved to openhab-core, but I plan to create one tonight, and will reference this issue. BTW, did you see this question?

lewie commented 5 years ago

@openhab-5iver, Thank You! Now I'm on the right track.

lewie commented 5 years ago

The topics are discussed at the right place: https://github.com/openhab/openhab-core/pull/663 https://github.com/openhab/openhab-core/issues/610