Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3946

Allow overriding the default Groovy class loader

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.6.7
    • 1.6.8, 1.7.1, 1.8-beta-1
    • None
    • None

    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.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            guillaume Guillaume Sauthier
            tiago182 Tiago Fernandez
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment