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

SimpleTemplateEngine (and poentially other TemplateEngines) should allow caller to specify classloader

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.1-beta-2
    • 1.1-rc-1
    • Groovlet / GSP
    • None
    • Patch

    Description

      SimpleTemplateEngine doesn't allow the caller to specify a parent classloader. When it creates a GroovyShell, it just uses the loader for that class.

      Index: src/main/groovy/text/SimpleTemplateEngine.java
      ===================================================================
      --- src/main/groovy/text/SimpleTemplateEngine.java      (revision 6601)
      +++ src/main/groovy/text/SimpleTemplateEngine.java      (working copy)
      @@ -69,8 +69,14 @@
           }
           public Template createTemplate(Reader reader) throws CompilationFailedException, IOException {
      +        return createTemplate(GroovyShell.class.getClassLoader(), reader);
      +    }
      +
      +    public Template createTemplate(ClassLoader parentLoader, Reader reader)
      +        throws CompilationFailedException, IOException
      +    {
               SimpleTemplate template = new SimpleTemplate();
      -        GroovyShell shell = new GroovyShell();
      +        GroovyShell shell = new GroovyShell(parentLoader);
               String script = template.parse(reader);
               if (verbose) {
                   System.out.println("\n-- script source --");
      

      Other template engines should have consistent features with this enhancement.

      Attachments

        Activity

          People

            paulk Paul King
            jtravis Jon Travis
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: