groovy
  1. groovy
  2. GROOVY-5017

[PATCH] SimpleTemplateEngine line number is off by one

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.3, 1.9-beta-4
    • Component/s: None
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      Line number reported from scripts compiled by SimpleTemplateEngine is off by one because it generates an extra new line that's not found in the original source file. Patch attached.

      1. DIFF
        0.7 kB
        Kohsuke Kawaguchi

        Activity

        Hide
        Roshan Dawrani added a comment -

        Thanks for the patch. A slight improvement suggested below.

        If we currently have script generated as a), with the patch it looks like b)

        a)

        -- script source --
        /* Generated by SimpleTemplateEngine */
        out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        -- script end --
        

        b)

        -- script source --
        /* Generated by SimpleTemplateEngine */out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        -- script end --
        

        With slightld modified patch, it looks like c)

                 private void startScript(StringWriter sw) {
        -            sw.write("/* Generated by SimpleTemplateEngine */\n");
                     sw.write("out.print(\"\"\"");
                 }
         
                 private void endScript(StringWriter sw) {
        -            sw.write("\"\"\");\n");
        +            sw.write("\"\"\");\n\n/* Generated by SimpleTemplateEngine */");
                 }
        

        Suggested new output that preserves the line numbers of the original script, but reads slightly better

        -- script source --
        out.print("""Hello \"$firstname\",
        Nice to meet you in """); print city ;
        out.print("""""");
        
        /* Generated by SimpleTemplateEngine */
        -- script end --
        
        Show
        Roshan Dawrani added a comment - Thanks for the patch. A slight improvement suggested below. If we currently have script generated as a), with the patch it looks like b) a) -- script source -- /* Generated by SimpleTemplateEngine */ out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); -- script end -- b) -- script source -- /* Generated by SimpleTemplateEngine */out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); -- script end -- With slightld modified patch, it looks like c) private void startScript(StringWriter sw) { - sw.write( "/* Generated by SimpleTemplateEngine */\n" ); sw.write( "out.print(\" \ "\" "); } private void endScript(StringWriter sw) { - sw.write( "\" \ "\" );\n"); + sw.write( "\" \ "\" );\n\n/* Generated by SimpleTemplateEngine */"); } Suggested new output that preserves the line numbers of the original script, but reads slightly better -- script source -- out.print("""Hello \"$firstname\", Nice to meet you in """); print city ; out.print(""""""); /* Generated by SimpleTemplateEngine */ -- script end --
        Hide
        Kohsuke Kawaguchi added a comment -

        I don't have any objection at all (in fact as far as I'm concerned, I couldn't care less about this "generated by" comment.)

        Show
        Kohsuke Kawaguchi added a comment - I don't have any objection at all (in fact as far as I'm concerned, I couldn't care less about this "generated by" comment.)
        Hide
        Roshan Dawrani added a comment -

        Good. There shouldn't probably be, but will just wait for a little bit to see if other devs see any potential impact.

        Show
        Roshan Dawrani added a comment - Good. There shouldn't probably be, but will just wait for a little bit to see if other devs see any potential impact.
        Hide
        blackdrag blackdrag added a comment -

        looks like a good idea to me

        Show
        blackdrag blackdrag added a comment - looks like a good idea to me
        Hide
        Guillaume Laforge added a comment -

        Good idea too here!

        Show
        Guillaume Laforge added a comment - Good idea too here!

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Kohsuke Kawaguchi
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: