Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.6.7
-
Fix Version/s: 1.6.8, 1.7.1, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
I am using Groovy with JSR-223 and I need to override the default Groovy class loader so I can provide a custom CompilationUnit with an additional PrimaryClassNodeOperation in the SEMANTIC_ANALYSIS phase.
I don't know too much about Groovy internals, but as GroovyScriptEngineImpl's loader field is private and never gets reassigned, the only way I found for making it work is using reflection:
private void overrideDefaultGroovyClassLoader(final ScriptEngine engine) throws Exception { final Field classLoader = engine.getClass().getDeclaredField("loader"); classLoader.setAccessible(true); classLoader.set(engine, new CustomGroovyClassLoader()); }
If there is not a better way for doing this today, maybe GroovyScriptEngineImpl should provide a setter or a post construct-like callback method for allowing overriding such field.
We can certainly open up the implementation a bit, if needs be.
But you're aware of the fact it'd be a specific feature of the Groovy JSR-223 engine, right?
The purpose of JSR-223 being to be non-specific to any language, but to provide a common way of invoking scripts, etc.
(hence why I often advise to use Groovy's integration mechanisms if anyone wants to do something a bit more advanced that only Groovy can provide)