Maven Archetype
  1. Maven Archetype
  2. ARCHETYPE-39

Add tool for working with escaping in Velocity templates

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0-alpha-4
    • Fix Version/s: None
    • Component/s: Plugin
    • Labels:
      None
    • Flags:
      Patch

      Description

      e.g. I need to put $

      {archifactId}

      (without parameter replacement) into an assembly descriptor. I need to escape the dollar sign.

      This is the Escape Tool of Velocity - http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/EscapeTool.html. The embedded Velocity engine will be configured to use it, or archetype plugin allows further Velocity configuration.

        Issue Links

          Activity

          Hide
          Guillaume Nodet added a comment -

          Is there any workaround for that ?

          Show
          Guillaume Nodet added a comment - Is there any workaround for that ?
          Hide
          Joakim Erdfelt added a comment -

          Try using "$$

          {artifactId}

          " instead.

          This technique has proved useful for velocity templates i've created for custom Archetypes and such.

          Show
          Joakim Erdfelt added a comment - Try using "$$ {artifactId} " instead. This technique has proved useful for velocity templates i've created for custom Archetypes and such.
          Hide
          Guillaume Nodet added a comment -

          I need to use resource filtering to build my archetype.
          So I need a way to escape one velocity level, and a way to escape two verlocity levels.

          So in my src/main/resources/archetype-resources/pom.xml, i have something like

          <artifactId>\$

          {artifactId}</artifactId>
          ...
          <plugin>
          . ..
          <version>${servicemix-version}</version>
          </plugin>
          ...
          <sourceRoot>\$${basedir}/target/generated-sources</sourceRoot>

          When this file is bundled in the archtype, i want it to be

          <artifactId>${artifactId}

          </artifactId>
          ...
          <plugin>
          . ..
          <version>3.0-SNAPSHOT</version>
          </plugin>
          ...
          <sourceRoot>\$

          {basedir}/target/generated-sources</sourceRoot>

          So that the project created using this archtype will be


          <artifactId>my-archetype</artifactId>
          ...
          <plugin>
          . ..
          <version>3.0-SNAPSHOT</version>
          </plugin>
          ...
          <sourceRoot>${basedir}

          /target/generated-sources</sourceRoot>

          The problem is that i found no way to have a $

          {artifactId} generated after the resource filtering,
          because :
          $${artifactId}

          => $$

          {artifactId}
          ${artifactId}

          => org.apache.servicemix.tooling.servicemix-archetype
          \$

          {artifactId} => \org.apache.servicemix.tooling.servicemix-archetype
          $\${artifactId}

          => $\org.apache.servicemix.tooling.servicemix-archetype
          \$$

          {artifactId} => \$${artifactId}
          Show
          Guillaume Nodet added a comment - I need to use resource filtering to build my archetype. So I need a way to escape one velocity level, and a way to escape two verlocity levels. So in my src/main/resources/archetype-resources/pom.xml, i have something like <artifactId>\$ {artifactId}</artifactId> ... <plugin> . .. <version>${servicemix-version}</version> </plugin> ... <sourceRoot>\$${basedir}/target/generated-sources</sourceRoot> When this file is bundled in the archtype, i want it to be <artifactId>${artifactId} </artifactId> ... <plugin> . .. <version>3.0-SNAPSHOT</version> </plugin> ... <sourceRoot>\$ {basedir}/target/generated-sources</sourceRoot> So that the project created using this archtype will be <artifactId>my-archetype</artifactId> ... <plugin> . .. <version>3.0-SNAPSHOT</version> </plugin> ... <sourceRoot>${basedir} /target/generated-sources</sourceRoot> The problem is that i found no way to have a $ {artifactId} generated after the resource filtering, because : $${artifactId} => $$ {artifactId} ${artifactId} => org.apache.servicemix.tooling.servicemix-archetype \$ {artifactId} => \org.apache.servicemix.tooling.servicemix-archetype $\${artifactId} => $\org.apache.servicemix.tooling.servicemix-archetype \$$ {artifactId} => \$${artifactId}
          Hide
          mtkopone added a comment -

          One-liner to fix this.

          Usage:
          $

          {dollarSign}{artifactId}
          ${dollarSign} {whatever.else}
          Show
          mtkopone added a comment - One-liner to fix this. Usage: $ {dollarSign}{artifactId} ${dollarSign} {whatever.else}
          Hide
          Wendy Smoak added a comment -

          Mikko's suggestion works for me. Can we get it in as a workaround until someone has time to pursue the EscapeTool from Velocity?

          We really need some way of escaping expressions so they're not filtered.

          Right now I can't make an archetype for the Struts 2 Blank webapp, because of this line in a .properties file:
          requiredstring = $

          {getText(fieldName)}

          is required.

          Velocity complains.
          Embedded error: Error merging velocity templates
          Encountered "(fieldName)} is required.\r\npassword = Password\r\nusername = User
          Name\r\nMissing.message = This feature is under construction. Please try again
          in the next iteration.\r\n" at line 2, column 27.
          Was expecting one of:
          "}" ...
          <DOT> ...

          Show
          Wendy Smoak added a comment - Mikko's suggestion works for me. Can we get it in as a workaround until someone has time to pursue the EscapeTool from Velocity? We really need some way of escaping expressions so they're not filtered. Right now I can't make an archetype for the Struts 2 Blank webapp, because of this line in a .properties file: requiredstring = $ {getText(fieldName)} is required. Velocity complains. Embedded error: Error merging velocity templates Encountered "(fieldName)} is required.\r\npassword = Password\r\nusername = User Name\r\nMissing.message = This feature is under construction. Please try again in the next iteration.\r\n" at line 2, column 27. Was expecting one of: "}" ... <DOT> ...
          Hide
          Wendy Smoak added a comment -

          It turns out that adding EscapeTools to the Velocity context also takes only one line.

          context.put( "esc" , new EscapeTool() );

          With this change, we'll be able to escape all the characters listed in the docs:
          http://jakarta.apache.org/velocity/tools/generic/EscapeTool.html

          For example, to escape the dollar sign, it's
          $

          {esc.d} or ${esc.dollar}

          My problematic property becomes:
          requiredstring = ${esc.d} {getText(fieldName)}

          is required.

          Show
          Wendy Smoak added a comment - It turns out that adding EscapeTools to the Velocity context also takes only one line. context.put( "esc" , new EscapeTool() ); With this change, we'll be able to escape all the characters listed in the docs: http://jakarta.apache.org/velocity/tools/generic/EscapeTool.html For example, to escape the dollar sign, it's $ {esc.d} or ${esc.dollar} My problematic property becomes: requiredstring = ${esc.d} {getText(fieldName)} is required.
          Hide
          Wendy Smoak added a comment -

          The Velocity docs moved: http://velocity.apache.org/tools/devel/generic/EscapeTool.html

          Any comments on this one? I'd like to add the EscapeTool unless someone thinks it's not a good idea.

          Show
          Wendy Smoak added a comment - The Velocity docs moved: http://velocity.apache.org/tools/devel/generic/EscapeTool.html Any comments on this one? I'd like to add the EscapeTool unless someone thinks it's not a good idea.
          Hide
          skerrien added a comment -

          I'm having some problems too when velocity processes my pom.xml as have have a $

          {site.remote.basedir} hanging there.
          Wendy's last comment seems to be the solution as long as I rewrite my property ${esc.dollar}{site.remote.basedir}


          Is there already a timeline for the next release of the archetype plugin ?

          Show
          skerrien added a comment - I'm having some problems too when velocity processes my pom.xml as have have a $ {site.remote.basedir} hanging there. Wendy's last comment seems to be the solution as long as I rewrite my property ${esc.dollar}{site.remote.basedir} Is there already a timeline for the next release of the archetype plugin ?
          Hide
          Immo Huneke added a comment -

          Thanks Wendy - as ever, you are a goldmine of information. I'm trying to use the Velocity escape tool in Maven, so that I can escape strings that look like property references. Any idea how to configure Maven to support the use of this tool? Is it something you have to put in settings.xml?

          Show
          Immo Huneke added a comment - Thanks Wendy - as ever, you are a goldmine of information. I'm trying to use the Velocity escape tool in Maven, so that I can escape strings that look like property references. Any idea how to configure Maven to support the use of this tool? Is it something you have to put in settings.xml?
          Hide
          Wendy Smoak added a comment - - edited

          To get $

          {artifactId}

          in the output, use $ \

          { artifactId }

          (with no spaces) in the template.

          Show
          Wendy Smoak added a comment - - edited To get $ {artifactId} in the output, use $ \ { artifactId } (with no spaces) in the template.
          Hide
          Wendy Smoak added a comment -

          wrong resolution...

          Show
          Wendy Smoak added a comment - wrong resolution...
          Hide
          Wendy Smoak added a comment -

          corrected resolution.

          Show
          Wendy Smoak added a comment - corrected resolution.
          Hide
          William Ferguson added a comment -

          OK, I'm confused.

          The issue is marked as WON'T FIX, but the comment seem to imply that a change was made.
          Was a change made and if so which version of the archetype-plugin?

          Also, what is the syntax that is required to get it to work?
          Wendy's comment on 2-JUN-07 seem to imply that $

          {artifactId} in the archetype will produce ${artifactId}

          in the new project, but that doesn't work for me with maven-2.0.7 and maven-archetype-1.0-alpha-4.

          Tokens of the form $

          {artifactId} are converted to actual values when creating the new project.

          Just like Guillaume, I need ${artifactId}

          in the output.
          How do I get it?

          Show
          William Ferguson added a comment - OK, I'm confused. The issue is marked as WON'T FIX, but the comment seem to imply that a change was made. Was a change made and if so which version of the archetype-plugin? Also, what is the syntax that is required to get it to work? Wendy's comment on 2-JUN-07 seem to imply that $ {artifactId} in the archetype will produce ${artifactId} in the new project, but that doesn't work for me with maven-2.0.7 and maven-archetype-1.0-alpha-4. Tokens of the form $ {artifactId} are converted to actual values when creating the new project. Just like Guillaume, I need ${artifactId} in the output. How do I get it?
          Hide
          William Ferguson added a comment -

          For those interested in a solution, specify

          #set($dollar = '$')

          at the head of the archetype Velocity template in which you need the unescaped dollar signs.
          Then to get $

          {artifactId} in the output, specify

          ${dollar}{artifactId}
          Show
          William Ferguson added a comment - For those interested in a solution, specify #set($dollar = '$') at the head of the archetype Velocity template in which you need the unescaped dollar signs. Then to get $ {artifactId} in the output, specify ${dollar}{artifactId}
          Hide
          Wendy Smoak added a comment -

          I also edited the earlier comment, which wasn't displaying correctly. I haven't tested it with the latest releases, but in early June, this worked:

          To get $

          {artifactId}

          in the output, use $ \

          { artifactId }

          (with no spaces) in the template.

          Show
          Wendy Smoak added a comment - I also edited the earlier comment, which wasn't displaying correctly. I haven't tested it with the latest releases, but in early June, this worked: To get $ {artifactId} in the output, use $ \ { artifactId } (with no spaces) in the template.
          Hide
          William Ferguson added a comment -

          Thanks Wendy, though I think you meant
          \ $

          {artifactId}

          (without the spaces), ie backslash before the $ and not after.

          Though in the end I found using $

          {dollar}

          to be clearer in the template.

          Show
          William Ferguson added a comment - Thanks Wendy, though I think you meant \ $ {artifactId} (without the spaces), ie backslash before the $ and not after. Though in the end I found using $ {dollar} to be clearer in the template.
          Hide
          Kaizer added a comment -

          It'd be nice to access all Velocity Tools from the archetype (not just the EscapeTools). I have an archetype that need to generate unique serializationID and can't get archetype to replace this one. There is MathTool, but there is no way to inject this into current Context.

          See http://www.nabble.com/How-to-use-velocity-tools-from-a-non-web-application-td6299220.html#a6299317 for a background.

          Show
          Kaizer added a comment - It'd be nice to access all Velocity Tools from the archetype (not just the EscapeTools). I have an archetype that need to generate unique serializationID and can't get archetype to replace this one. There is MathTool, but there is no way to inject this into current Context. See http://www.nabble.com/How-to-use-velocity-tools-from-a-non-web-application-td6299220.html#a6299317 for a background.
          Hide
          Torben Knerr added a comment - - edited

          +1 vote for adding Velocity Tools

          Show
          Torben Knerr added a comment - - edited +1 vote for adding Velocity Tools

            People

            • Assignee:
              Unassigned
              Reporter:
              Willie Vu
            • Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development