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] Pass script context to script engines #1837
Conversation
|
||
SimpleScriptContext scriptContext = new SimpleScriptContext(); | ||
scriptContext.setAttribute(CONTEXT_KEY_ENGINE_IDENTIFIER, engineIdentifier, ScriptContext.ENGINE_SCOPE); | ||
engine.setContext(scriptContext); |
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.
Is it safe to set that here? Couldn't the script engine have already set up some initial context?
I'm especially concerned about the DSLScriptEngine, where I recently had a lot of trouble getting the handling of the context stable... Would be good if you could test that there's no issue by this on DSL rules.
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.
@kaikreuzer Good point; I was primarily thinking about the newer script engines which I don't believe set things up here. TBH my main goal here is passing context to script engine factories upon creation of script engines to allow them to be tailored.
The cleanest way to do this would be to modify the engineFactory.createScriptEngine(scriptTypes.get(0));
call eariler in the method to add a custom ScriptEngineContext
object as a second argument. However I chose not to do this because it would be a breaking change for existing implementors of the interface declaring this method (of course I could also introduce a 2nd interface and collect implementations of both, but that seems overkill). Or do you think this would be a better option? If not, I'll update the code to add context to whatever is there already (and create if not present) before testing on the DSLScriptEngine.
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.
(Updated code to only set context if it's not already been set)
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 think the current solution is fine, thanks.
fed910a
to
fd261bb
Compare
Did you notice that the build fails due to spotless errors? |
Signed-off-by: Jonathan Gilbert <jpg@trillica.com>
fd261bb
to
82a286f
Compare
I had not, thanks for pointing it out. Build is now passing. |
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.
thanks!
Signed-off-by: Jonathan Gilbert <jpg@trillica.com> GitOrigin-RevId: 60edebc
Pass explicit script context to script engines. Context initially includes only engine identifier.
Signed-off-by: Jonathan Gilbert jpg@trillica.com