Skip to content
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

Add Jython Scripting #9404

Merged
merged 2 commits into from
Dec 17, 2020
Merged

Add Jython Scripting #9404

merged 2 commits into from
Dec 17, 2020

Conversation

wborn
Copy link
Member

@wborn wborn commented Dec 16, 2020

Ports #7208 to OH3 and addresses review comments like removing the bnd.bnd file and using an annotation for the dynamic import.

I'm not a Jython expert but some Hello World examples seemed to work in rules so at least something is functional.
Perhaps some seasoned Jython users can further test and improve it?
As expected it is also a pretty big add-on with a size of 42 MB, so it will have a big impact on the add-ons KAR file.

See also #4801 (comment)

Also-by: Scott Rushworth <openhab@5iver.com>
Signed-off-by: Wouter Born <github@maindrain.net>
@wborn wborn requested review from 5iver and a team December 16, 2020 22:56
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks!
The dependencies of Jython are indeed quite nasty and make the standalone jar pretty huge.
But I think we can live with the blown up KAR file size, although it's not ideal.
Although this is a feature PR, I'd definitely vote for merging it for RC2.

Signed-off-by: Wouter Born <github@maindrain.net>
Copy link
Contributor

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this. I would love to see it in OH3 release.

I tested this port and it seems to be working smoothly. The only thing I do not understand is the recreation of the ScriptEngineManager. I asked it before but it could not be explained. But as it is working I am fine with it. See my linked comment inside.

.get(OpenHAB.getConfigFolder(), "automation", "lib", "python").toString();

private static final String SCRIPT_TYPE = "py";
private static final javax.script.ScriptEngineManager ENGINE_MANAGER = new javax.script.ScriptEngineManager();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for testing! The issue is that the org.openhab.core.automation.module.script.ScriptEngineFactory.ENGINE_MANAGER has a different classloader. So it only detects engines that are on the boot classpath (like Nashorn). I ran into the same issue with the Groovy add-on. I looked into ways to get engines registered in the ScriptEngineFactory.ENGINE_MANAGER. IIRC it wasn't possible to call methods on ScriptEngineFactory.ENGINE_MANAGER to (un)register engines provided by OSGi bundles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any concerns regarding SecurityException which might be thrown by this method?

We don't seem to handle any SecurityExceptions in openhab-core either when modifying System properties:

https://github.com/openhab/openhab-core/search?q=System.setProperty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Sounds reasonable. Thanks for clarification.

Do we need to handle it?

I think it is okay to not handle it. If the exceptions will be thrown there might be a bigger issue regarding permissions and other stuff will fail too.

@cweitkamp cweitkamp added this to the 3.0.0.RC2 milestone Dec 17, 2020
@cpmeister cpmeister merged commit e773444 into openhab:main Dec 17, 2020
@wborn wborn deleted the add-jythonscripting branch December 17, 2020 19:54
@fwolter
Copy link
Member

fwolter commented Dec 18, 2020

This seems to make the build unstable:
[ERROR] Failed to execute goal org.openhab.tools.sat:sat-plugin:0.10.0:spotbugs (sat-all) on project org.openhab.automation.jythonscripting: Unable to execute mojo: Execution null of goal com.github.spotbugs:spotbugs-maven-plugin:4.0.0:spotbugs failed: Timeout: killed the sub-process -> [Help 1]

https://ci.openhab.org/job/PR-openHAB-Addons/1451/

MarkusGafner pushed a commit to MarkusGafner/openhab-addons that referenced this pull request Dec 19, 2020
* Add Jython Scripting

Also-by: Scott Rushworth <openhab@5iver.com>
Signed-off-by: Wouter Born <github@maindrain.net>
seaside1 pushed a commit to seaside1/openhab-addons that referenced this pull request Dec 28, 2020
* Add Jython Scripting

Also-by: Scott Rushworth <openhab@5iver.com>
Signed-off-by: Wouter Born <github@maindrain.net>
seaside1 pushed a commit to seaside1/openhab-addons that referenced this pull request Dec 28, 2020
* Add Jython Scripting

Also-by: Scott Rushworth <openhab@5iver.com>
Signed-off-by: Wouter Born <github@maindrain.net>
Signed-off-by: Joseph Hagberg <joseph@zoidberg.se>
nowaterman pushed a commit to nowaterman/openhab-addons that referenced this pull request Jan 19, 2021
* Add Jython Scripting

Also-by: Scott Rushworth <openhab@5iver.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* Add Jython Scripting

Also-by: Scott Rushworth <openhab@5iver.com>
Signed-off-by: Wouter Born <github@maindrain.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants