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

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

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1-beta-2
    • Fix Version/s: 1.1-rc-1
    • Component/s: Groovlet / GSP
    • Labels:
      None
    • Flags:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: