-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
[JSR223] Most Java classes are no longer available after ESH migration #610
Comments
I assume the code that executes your scripts defines package imports only for the packages that are used by its Java code. |
If that were the case, then I don't see how they were accessible before. There are classes that are available, but have nothing to do with scripted automation, like Metadata. So, I think there is more to it. I'm still investogating. BTW, I realize org.joda.time was removed, but left it in the list. Or was that reverted? Wait... I just imported org.joda.time.DateTime into a DSL Rule... hmmm. |
Before the migration the imports has been added in the manifest manually. I was not aware that |
I also have problems with missing classes in my groovy rules. The most simple example does not work:
It does not help if I try to import either
|
@openhab-5iver I never used JSR223 -- at least I cannot remember 😉 |
@maggu2810, JSR223 is under org.openhab.automation, and was introduced with ESH #1783. If you'd like to reproduce the issue, just install the new rule engine, and save this to a .js file in OPENHAB_CONF/automation/jsr223/...
I'm no help at all when it comes to Maven and bnd, but from researching, I found a number of references where using |
I can try to reproduce and solve it but I need to know: |
The list I provided in the OP was everything that I could find that was missing. The only thing not in openhab-core was org.joda.time, but I wouldn't say that is necessary but nice to have. |
@openhab-5iver You need to start from the beginning 😉 I added the automation bundles to the my runtime.
After that I created a directory And now? |
Add the rule engine and watch the log |
What a bundle is missing (can you tell me the BSN or GAV)? |
Sorry... I meant start the rule engine, if it isn't. Are you trying to reproduce this in the IDE, or in a build that you've made? It looks to me like you have everything. |
Hm, more or less both. I habe an IDE that contains the openHAB Core bundles only. The source tree of my openHAB Core code base is only minimal modified. I am using the Bnd based launch demo configuration (only added bundles). |
Sorry, I named the directory |
I assume if I see
instead of
it is better |
Yes, the use of the scriptLoaded() and scriptUnloaded() functions in your script are optional, so that message is normal. |
The automation has been moved from ESH to OH namespace (package names). Let me ask if it make sense to access that Java classes in scripts at all. Wouldn't it make sense to create separate classes -- perhaps they only wrap the whole current function. |
The majority of imports will be in the helper libraries. When this issue is resolved, I will be providing a release of the libraries to support the changes. This release will require that they are using a minimum version of OH that contains the fix. There have been other breaking changes in the API that required upgrades of the libraries. Users may need to change some imports in their scripts and modules, but that shoiuld be minor, and these will be the more experienced users. Anyone not using the libraries will have some work to do, but it would also be a good opportunity for them to switch over to using the libraries.
For the future, maybe OH3, the helper libraries, which show what users actually want to be doing with scripted automation, can be absorbed into some of the Automation classes and a new scripting API. Some (most?) can also be turned into Actions, which could then also be accessible directly through the NGRE. The ESH reintegration, repo moves, and lack of UI in the Core Development IDE have really been holding me back. But things seem to be settling down now, and with #635 finally committed, I will be working on Jython and Groovy bundles, and some of the Automation bugs. While doing this, I plan to open some discussions in the Developer section of the forum to discuss plans for moving forward with the NGRE and scripted automation... specifically, what needs to be done to get it mainstream in OH3. I would really like to see some Github projects setup in this repo for better visibility, prioritization, and coordination of efforts for Automation. I like what you're thinking, but for the time being, I think they just need to be made accessible again in order to get things working. 😄 BTW, could you please share the Demo app changes that you used to be able to test this? I think I am at the same place you were, where the engine is running, but scripts aren't loading. At some point, I really need to get Jython scripts working in the IDE again too. |
When the classes are assessable again, I will adjust the JS helper classes, so that they are backward compatible to older openHAB versions with ESH . |
When I replied to Markus, I completely forgot that I had planned to do the same! This avoids requiring a minimum OH version for the libraries, and can be implemented now, if this is the path we're taking.
|
With the ESH integration finished, is the entire core accessible again? I have been working on some scripts that require access to add, modify, and identify the class of items, metadata, things, and channel links. I had upgraded to S1522 some weeks ago but had to rollback to S1512 because most of the classes in automation and the core were not available. @openhab-5iver let me know if I can help in any way to get the libraries work again or with the integration of scripting into a bundle |
@openhab-5iver: I will fix the missing imports and explain what to changes are required for the demo application. Till then we hopefully get this one merged: #640 For the work with openHAB Core and Maven + Bnd bundles I assume that you would like to use that commit in your working copy: maggu2810/openhab-core@f1c74e5 |
@openhab-5iver: Should joda still be provided? AFAIK we already tried to drop it... |
@maggu2810, it was available before the reintegration, so I woud think it should be available after. It would be a breaking change if it were not included. |
Yes, it will be a breaking change. |
@openhab-5iver I cannot test myself ATM, but you could perhaps check the branch "dev" in my fork and give it a try. |
@maggu2810 I think it would be a good idea to remove joda given its depreciation in favour of java.time. On the other hand, my DSL rules make heavy use of it, so it disappearing suddenly would be a shock. Perhaps a warning in the log on parsing rules files that import it in snapshots starting now and up until the release that phases it out. For the purposes of Jython that I am converting all my rules to I am using java.time, and the portion of Scott's scripts that use it can be rewritten to handle the possibility that it isn't available gracefully. |
@maggu2810, that's very true. When this issue is resolved, we will need to communicate that to the JSR223 users. I will have an update to the Jython helper libraries released to mitigate that, and @lewie will hopefully have one for JS. But removing Joda from JSR223 would be MUCH harder to mitigate, as it will effect people's scripts/rules.
I'm still working on getting automation working in the IDE, but I'll do a build of your branch. |
If you are using the demo app in my branch, the automation bundles will be present at runtime (I modified the demo app "now", so update your working copy). |
@openhab-5iver |
I setup a Core Development IDE, imported your dev branch, removed the OH repo, did a Run as Maven Build... with clean install. Added /conf/automation/jsr223/ with a JS script. Debugged and got...
And then I changed the import 😊 and got this (made it past the RuleBuilder import!)...
... using this script...
Line 7 is where SimpleRule is called, so it looks like the ScriptExtensions aren't working. This will be a lot easier to debug using Jython (I can see everything available in the context using dir()), so I'm going to try getting it setup. With PDE, there was an option for adding environment variable, where I could add the Jython jar into the classpath and specify the home and path directories. In a non-ide install, these go into EXTRA_JAVA_OPTS. Any suggestions of how to do this using the Demo app? Edit: The JVM arguments look like a good spot. Now I need to figure out the paths. |
@openhab-5iver Please also follow openhab/openhab-distro#889 Have a look at these options: https://bnd.bndtools.org/chapters/300-launching.html |
@maggu2810, I saw that, and will try it out next... thank you! |
@maggu2810, I have Jython running in the IDE now, using...
Everything I've checked so far in org.openhab.core appears to be available. But I found some external libraries that are used in the modules that I did not include in the original list. After adding these...
...to the org.openhab.core.automation.module.script bdn.bdn, everything seems back to normal except for...
... which is odd, since it looks like you had taken care of that one. There's also still a problem with SimpleRule n JS, but Jython doesn't have this problem...
In regards to SimpleRule, these looked interesting... eclipse-archived/smarthome#3819, eclipse-archived/smarthome#3361. |
The compat1x ActionService is optional. Is the jython-standalone-2.7.0.jar platform independent? |
By 'add the bundle', do you mean in the console? I got it installed, but there was an unresolved module...
Adding this one as optional didn't help. I'm still banging on it though.
Yes, it's all Java.
There is some instruction for installing Jython with the helper libraries. Here is a link to Jython 2.7.0. I recommend the standalone jar for simplicity. That website is supposedly moving to the new official site, where you can find the latest version, 2.7.1, but there are some quirks to using it. I have updates for the helper libraries so that 2.7.1 can be used, but I was waiting to release them with any changes needed for the ESH reintegration. Details for some of the issues with using 2.7.1 can be found here, along with a link to the Jython Maven repo with 2.7.1.patch2618, which resolved one if the issues. I haven't been successful in getting Groovy to load in the demo app. |
@openhab-5iver I have added a commit that contains the modification for compat1x support to maggu2810/openhab-demo. I assume you missed only to press the "Resolve" button. |
@openhab-5iver I have created a branch "jython" that you could perhaps use to work on. |
OK, thank you... I just pulled the other one and got everything back in place 😄. |
@openhab-5iver Are all missing Java packages available now? |
@maggu2810, sorry, I got distracted fixing up my PR. From my testing, it looks like everything that the Jython helper libraries accessed is available now. I'm sure there will be more to add as the libraries evolve, but I am pretty clear on how to add them in the future, if needed. The only thing I never got to completely check on was I had setup a recent snapshot (S1553) with automation jars that I'd build from your branch, and found that the error that was happening with Javascript was not occurring. So, that may be an issue in the IDE only. However, Groovy still seemed to have an issue. We're much better off after these changes, but there will need to be some more cleanup. Thank you for all you do! |
Fixes openhab#610 Signed-off-by: Scott Rushworth openhab@5iver.com (github: openhab-5iver)
Fixes openhab#610 Signed-off-by: Scott Rushworth openhab@5iver.com (github: openhab-5iver) Signed-off-by: Scott Rushworth <openhab@5iver.com>
Fixes openhab#610 Signed-off-by: Scott Rushworth <openhab@5iver.com> (github: openhab-5iver)
Fixes openhab#610 Signed-off-by: Scott Rushworth <openhab@5iver.com>
Fixes #610 Signed-off-by: Scott Rushworth <openhab@5iver.com>
Closes openhab#610 Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
I'm testing this on S1534. Classes that were previously available can no longer be imported. Here is a list of the ones I have tested, when trying to update the openhab2-jython libraries. The ones with ##### worked, but the others did not.
@lewie reported this in openhab1-addons/#5281. @vbier also reported something similar in the forum.
The text was updated successfully, but these errors were encountered: