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

[automation] Added ScriptModuleTypeProvider for Jython and Groovy scripted Actions and Conditions #635

Merged
merged 1 commit into from
Apr 11, 2019

Conversation

5iver
Copy link

@5iver 5iver commented Mar 7, 2019

Fixes #521. This PR replaces #519. As discussed there, this PR will provide a dynamic list of script languages when using ScriptAction or ScriptCondition, based on the ScriptEngines in use on the system. It implements the ScriptModuleTypeProvider, which replaces the ScriptTypes ResourceBundle. I do not see anything that would make this a breaking change. The ParameterOption labels and values for the currently known working script languages are...

options
0
label "ECMAScript (ECMA - 262 Edition 5.1)"
value "application/javascript"
1
label "Groovy (2.4.12)"
value "application/x-groovy"
2
label "Python (2.7)"
value "application/python"

Things to be aware of:

  1. The dropdown will not have Javascript as an option label, but ECMAScript (ECMA - 262 Edition 5.1).
  2. When an engine is upgraded, the label will change to the upgraded version, but no change will be required by the user, as the value of the option should not have changed. I've tested this by upgrading/downgrading the package.
  3. This PR removes the NashornScriptEngineFactory, as it was a duplicate of GenericScriptEngineFactory after this PR, except for how the scopeValues() method was implemented. I did not see any need for both files, so I added special handling of ECMAScripts in GenericScriptEngineFactory.scopeValues(). It's a little strange to put something specific in something names Generic, but this elimiated a file and a lot of duplicated code.
  4. This provider is setup to use localization, but it is not yet implemented.

@kaikreuzer, you had suggested a ConfigOptionProvider, but I could not find a way to add one to a ResourceBundle. I based this provider off of your MediaActionTypeProvider, in which you state...

This is necessary since there is no other way to provide dynamic config param options for module types

ConfigOptionProvider had been around for about a year when you wrote this, so I figured you would have used one if it was possible. That is why I went this route.

@openhab/core-maintainers, please review. I've tested this, and everything seemed to function properly, but I don't think of myself as much of a Java developer. 😉

Signed-off-by: Scott Rushworth openhab@5iver.com (github: openhab-5iver)

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/multi-zone-home-alarm-script-for-openhab/41425/37

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

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

This PR removes the NashornScriptEngineFactory, as it was a duplicate of GenericScriptEngineFactory after this PR, except for how the scopeValues() method was implemented. I did not see any need for both files, so I added special handling of ECMAScripts in GenericScriptEngineFactory.scopeValues(). It's a little strange to put something specific in something names Generic, but this elimiated a file and a lot of duplicated code.

If you would like to remove duplicate code, then we should improve the generic implementation to allow the specific child to modify / implement only the special scopeValues part without code duplication of all the remaining one.

Adding specific code to a generic class is IMHO nothing we should do ever in OOP.

@5iver
Copy link
Author

5iver commented Mar 12, 2019

If you would like to remove duplicate code, then we should improve the generic implementation to allow the specific child to modify / implement only the special scopeValues part without code duplication of all the remaining one.

To expedite things, I'll add NashornScriptEngineFactory back in. That way it is no worse off than it was. Cleaning up the duplicated code can then be done in a separate PR.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/paperui-rule-bug-state-with-decimal/70627/8

@5iver 5iver force-pushed the ScriptModuleTypeProvider branch 2 times, most recently from 2e52513 to d223e7f Compare March 24, 2019 16:25
@5iver
Copy link
Author

5iver commented Mar 24, 2019

@maggu2810, I've reworked this PR, so hopefully all of your comments have now been addressed. I'm not looking forward to wait a couple weeks for a review, so I'm hoping @wborn, @cweitkamp, or @kaikreuzer might take a look at it. Hope your vacation is going well! I have tested this PR for a while now, and am running it on my production system without issues.

  • Completely changed how the ParameterOptions were being generated in the previous commit
  • Added GenericScriptEngineFactory as a service. ESH #6284 only setup NashornSEF as a service.
  • Readded NashornSEF
  • Added an AbstractSEF for the others to inherit from, in order to remove duplication of code in the SEFs. This is the one change I questioned most, as I was uncertain if there might be issues with making services from both a parent and child class. If there are no issues, then the other factories can be extended from GenericSEF. I will keep looking at this.
  • Refactored ScriptEngineManagerImpl a bit, utilizing the fact that all factories are now services.
  • Moved the instantiation of the javax.script.ScriptEngineManagers from the factories to a static in the ScriptEngineFactory interface

I have noticed something though, which also occurs in the current production code. When OH starts up, the SEFs, or the ScriptEningManagerImpl, are started twice. Every now and then, after clearing the cache, this does not happen. The code seems to handle this, but I'm not sure what's causing it yet. This is unrelated to this PR, but I thought I'd mention it in case someone noticed it or had an explanation for it.

@maggu2810
Copy link
Contributor

Thank you for all your work and effort.
This PR is still part of the things I need to do.
Just the usual "spare time problem".
Please give me some time.

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

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

A few comments left.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/user-enhancements/71953/12

@maggu2810
Copy link
Contributor

@openhab-5iver Please ping me if you think all is done and I should start another review round.

@5iver
Copy link
Author

5iver commented Apr 10, 2019

@maggu2810, will do! A few more tests and I'll commit the changes.

@5iver
Copy link
Author

5iver commented Apr 10, 2019

@maggu2810, it's ready... and thank you!

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

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

Some minor comments, after that ones it should be ready.

Added ScriptModuleTypeProvider, which dynamically adds available script
languages to the ParameterOptions used in Paper UI when configuring a
ScriptAction or ScriptCondition.

Signed-off-by: Scott Rushworth <openhab@5iver.com>
@5iver
Copy link
Author

5iver commented Apr 10, 2019

@maggu2810, thank you very much for your patience and the time you have spent working with me. I have learned a lot from this! I've pushed the latest changes.

Copy link
Contributor

@maggu2810 maggu2810 left a comment

Choose a reason for hiding this comment

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

I need to give it back to you: thank you very much for your patience and the time you have spent working with me. 😉

@maggu2810 maggu2810 merged commit 5f880e1 into openhab:master Apr 11, 2019
@5iver 5iver deleted the ScriptModuleTypeProvider branch April 11, 2019 10:09
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/wip-ngre-jsr223-documentation-refactoring/73569/6

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/preparation-for-2-5m2/75738/1

@wborn wborn added this to the 2.5 milestone Jul 30, 2019
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/windows-all-oh-logs-stop-when-jython-is-in-the-classpath/79654/24

@cweitkamp cweitkamp added the enhancement An enhancement or new feature of the Core label Dec 7, 2019
@cweitkamp cweitkamp changed the title Added ScriptModuleTypeProvider for Jython and Groovy scripted Actions and Conditions [automation] Added ScriptModuleTypeProvider for Jython and Groovy scripted Actions and Conditions Dec 7, 2019
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/namespaces-packaging-for-scripting-apis/86940/6

@kaikreuzer kaikreuzer removed the enhancement An enhancement or new feature of the Core label Dec 13, 2019
Rosi2143 pushed a commit to Rosi2143/openhab-core that referenced this pull request Dec 26, 2020
…n page and added an explanation f… (openhab#635)

* Clarified Misc on systems integration page and added an explanation for the different installation options.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Review improvements.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Changes due to second review

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Adressed review comments. Added feature command family to console part.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Again some review based changes.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Removed console part, Added addons.cfg part and added a warning to jar file part.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Image not needed without console section.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Again some small improvements for introduction and addons.cfg part.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Improvements to addons.cfg section.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Adressed review comments

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Pointed needed addon types for trailing 1 out.

Signed-off-by: Jerome Luckenbach <github@luckenba.ch>

* Adressed review comments and fixed one remaining typo

Signed-off-by: Confectrician <github@luckenba.ch>
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 11, 2023
Added ScriptModuleTypeProvider, which dynamically adds available script
languages to the ParameterOptions used in Paper UI when configuring a
ScriptAction or ScriptCondition.

Signed-off-by: Scott Rushworth <openhab@5iver.com>
GitOrigin-RevId: 5f880e1
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.

[Automation - Feature Request] Add Jython and Groovy scripted Actions to Paper UI
7 participants