groovy
  1. groovy
  2. GROOVY-1979

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

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1-beta-2
    • Fix Version/s: 1.1-rc-1
    • Component/s: Groovlet / GSP
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      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.

        Activity

        Hide
        Paul King added a comment -

        added to HEAD

        Show
        Paul King added a comment - added to HEAD
        Hide
        Paul King added a comment -

        Re-opened to track changes to other TemplateEngines.

        Show
        Paul King added a comment - Re-opened to track changes to other TemplateEngines.
        Hide
        Paul King added a comment -

        Jon, I am looking at providing consistent options for all of the template engines. One option is to remove this added functionality but instead allow a parentLoader to be provided in the SimpleTemplateEngine constructor (for use by all templates created with that engine). This may be the easiest way to supply this functionality across all the template. I am not sure which way to go yet but if we did go that way, would that still meet your need? I am trying to get this resolved before 1.1 goes final - after that it will be much harder to remove anything we have provided for now.

        Show
        Paul King added a comment - Jon, I am looking at providing consistent options for all of the template engines. One option is to remove this added functionality but instead allow a parentLoader to be provided in the SimpleTemplateEngine constructor (for use by all templates created with that engine). This may be the easiest way to supply this functionality across all the template. I am not sure which way to go yet but if we did go that way, would that still meet your need? I am trying to get this resolved before 1.1 goes final - after that it will be much harder to remove anything we have provided for now.
        Hide
        Paul King added a comment - - edited

        Jon, no feedback given, assuming OK to refactor slightly.

        Now parentLoader can be specified for Simple, Xml and GString TemplateEngines (in the constructor).
        GroovyShell can be specified for Simple and Xml variations (again via a construction option).

        Show
        Paul King added a comment - - edited Jon, no feedback given, assuming OK to refactor slightly. Now parentLoader can be specified for Simple, Xml and GString TemplateEngines (in the constructor). GroovyShell can be specified for Simple and Xml variations (again via a construction option).
        Hide
        Paul King added a comment -

        No further feedback, assuming fixed

        Show
        Paul King added a comment - No further feedback, assuming fixed

          People

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

            Dates

            • Created:
              Updated:
              Resolved: