Maven 2.x Resources Plugin

An escape mechanism for property interpolation is missing.

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.3
  • Fix Version/s: 2.3
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

It would be great, if there was a mechanism that let's you escape a property so that it is not replaced by the filtering machism. E.g. in a log4j.xml configuration file you might want to preserve ${user.home}, but replace some other property like ${log.dir}. Currently there is no convenient way to achieve that.

Alternatively to escaping, it would be helpful, if one could choose the token format. So, if one could say, only honor @token@ and not ${token} (or the other way around) one could easily work around the escape problem.

Workaround for the problem mentioned above:

replace the ${user.home} in log4j.xml with @start@user.home@end@ and define start=${ and end=$} in the property file

Issue Links

Activity

Hide
Franz Allan Valencia See added a comment -

Actually, your workaround works with the current maven-resources-plugin.

maven-resources-plugin supports two token formats: %{token} , and @token@

Show
Franz Allan Valencia See added a comment - Actually, your workaround works with the current maven-resources-plugin. maven-resources-plugin supports two token formats: %{token} , and @token@
Hide
Wendy Smoak added a comment -

Would the Velocity EscapeTool be useful here? It seems to work to solve a similar problem in Archetype.

http://jira.codehaus.org/browse/ARCHETYPE-39

Show
Wendy Smoak added a comment - Would the Velocity EscapeTool be useful here? It seems to work to solve a similar problem in Archetype. http://jira.codehaus.org/browse/ARCHETYPE-39
Hide
Dan Hardiker added a comment -

I have tried the following, none of which work:

  • ${dollarSign}{id} where dollarSign = $
  • ${dollarSign}@start@id@end@ where dollarSIgn = $, start = {, end = }
  • @start@id@end@ where start = ${, end = }

All yeild in the same result - the artifact's full ID being spat out. What I am looking for is a simple solution where I can put down $${id} or \${id} and have that come out the other side as literally ${id}.

Any working work-arounds are appreciated!

Show
Dan Hardiker added a comment - I have tried the following, none of which work:
  • ${dollarSign}{id} where dollarSign = $
  • ${dollarSign}@start@id@end@ where dollarSIgn = $, start = {, end = }
  • @start@id@end@ where start = ${, end = }
All yeild in the same result - the artifact's full ID being spat out. What I am looking for is a simple solution where I can put down $${id} or \${id} and have that come out the other side as literally ${id}. Any working work-arounds are appreciated!
Hide
Immo Huneke added a comment -

I have tried using the XML escape for $ - $ - but to no avail. I suspect that the problem is not so much the value I am trying to match in my activation criterion, but the fact that the referenced property has not been defined yet. Does anyone have information on the order in which this happens?

My pom contains the following:

. . .
    <properties>
        <appserver.root>${env.APPSERVER_ROOT}</appserver.root>
    </properties>
    <profiles>
        <profile>
            <id>without-tomcat</id>
            <activation>
                <property>
                    <name>appserver.root</name>
                    <value>&#36;{env.APPSERVER_ROOT}</value>
                </property>
            </activation>
            <properties>
                <webapp.dir>target/dummy-deploy</webapp.dir>
            </properties>
        </profile>
. . .

There's a clue in that I had to use "target" instead of "${project.build.directory}" - the latter was not being expanded.

Show
Immo Huneke added a comment - I have tried using the XML escape for $ - $ - but to no avail. I suspect that the problem is not so much the value I am trying to match in my activation criterion, but the fact that the referenced property has not been defined yet. Does anyone have information on the order in which this happens? My pom contains the following:
. . .
    <properties>
        <appserver.root>${env.APPSERVER_ROOT}</appserver.root>
    </properties>
    <profiles>
        <profile>
            <id>without-tomcat</id>
            <activation>
                <property>
                    <name>appserver.root</name>
                    <value>&#36;{env.APPSERVER_ROOT}</value>
                </property>
            </activation>
            <properties>
                <webapp.dir>target/dummy-deploy</webapp.dir>
            </properties>
        </profile>
. . .
There's a clue in that I had to use "target" instead of "${project.build.directory}" - the latter was not being expanded.
Hide
Immo Huneke added a comment -

Oops - the comment above interpreted the XML escape for $ as $. The actual code is of course &#36; .

Show
Immo Huneke added a comment - Oops - the comment above interpreted the XML escape for $ as $. The actual code is of course &#36; .
Hide
Immo Huneke added a comment -

No, actually I have verified that writing &#36; is PRECISELY equivalent to writing $ - if you use it to introduce a property reference then the value is interpolated. So we're still looking for a workable escape mechanism.

Show
Immo Huneke added a comment - No, actually I have verified that writing &#36; is PRECISELY equivalent to writing $ - if you use it to introduce a property reference then the value is interpolated. So we're still looking for a workable escape mechanism.
Hide
Ian Springer added a comment -

An way to escape $'s should certainly be provided.

But further, as the original poster suggested, there should be a way to configure what the token format is. Here is a use case for providing this:

I am using the resources plugin to copy over a bunch of JBoss config files. If you've used JBoss, you know that it supports runtime replacement of ${foo} tokens with system properties. So, in most cases, I don't want Maven messing with the ${foo} tokens in these files. However, there are a handful of tokens I do want Maven to replace. If I could change the token format to something other than the ${foo} default, then I could use that alternate format for the tokens I do want Maven to replace.

Here's an example of how this might be specified in the POM:

<resources>

<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<tokenStartDelimiter>@@</tokenStartDelimiter>
<tokenEndDelimiter>@@</tokenEndDelimiter>
</resource>

...

</resources>

This would tell the resources plugin to replace tokens of the form @@foo@@ instead of the default form ${foo}.

If others could benefit from this feature, say so. If there's enough interest, I'll whip up a patch.

Show
Ian Springer added a comment - An way to escape $'s should certainly be provided. But further, as the original poster suggested, there should be a way to configure what the token format is. Here is a use case for providing this: I am using the resources plugin to copy over a bunch of JBoss config files. If you've used JBoss, you know that it supports runtime replacement of ${foo} tokens with system properties. So, in most cases, I don't want Maven messing with the ${foo} tokens in these files. However, there are a handful of tokens I do want Maven to replace. If I could change the token format to something other than the ${foo} default, then I could use that alternate format for the tokens I do want Maven to replace. Here's an example of how this might be specified in the POM: <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <tokenStartDelimiter>@@</tokenStartDelimiter> <tokenEndDelimiter>@@</tokenEndDelimiter> </resource> ... </resources> This would tell the resources plugin to replace tokens of the form @@foo@@ instead of the default form ${foo}. If others could benefit from this feature, say so. If there's enough interest, I'll whip up a patch.
Hide
Richard Wallace added a comment -

Has there been any movement or further discussion of this elsewhere? I've looked through the mailing list and can't find any further references and as far as I can tell no one has found a solution that works.

Show
Richard Wallace added a comment - Has there been any movement or further discussion of this elsewhere? I've looked through the mailing list and can't find any further references and as far as I can tell no one has found a solution that works.
Hide
Ian Springer added a comment -

I'm still willing to code up my previously suggested fix for this and submit a patch, if I can get a confirmation from one or more committers that they are ok with the fix.

Show
Ian Springer added a comment - I'm still willing to code up my previously suggested fix for this and submit a patch, if I can get a confirmation from one or more committers that they are ok with the fix.
Hide
Dave O'Flanagan added a comment -

I've tried $${user.id} in maven 2.0.9 and it works fine. I get ${user.id} in the output.

Show
Dave O'Flanagan added a comment - I've tried $${user.id} in maven 2.0.9 and it works fine. I get ${user.id} in the output.
Hide
Hendrik Schreiber added a comment -

Great.
Is this an old feature documented somewhere, or is this new and needs to be documented?

Show
Hendrik Schreiber added a comment - Great. Is this an old feature documented somewhere, or is this new and needs to be documented?
Hide
Felipe Kamakura added a comment -

Odd...
I've tried here the $${} in Maven 2.0.9 and it didn't work out. I'm using in Linux.

Show
Felipe Kamakura added a comment - Odd... I've tried here the $${} in Maven 2.0.9 and it didn't work out. I'm using in Linux.
Hide
Olivier Lamy added a comment -

fixed in rev 693989
SNAPSHOT deployed.
This feature is off by default no default escapeString value to preserve backwardComp.
The mojo parameter to configure is escapeString expression="${maven.resources.escapeString}"

Show
Olivier Lamy added a comment - fixed in rev 693989 SNAPSHOT deployed. This feature is off by default no default escapeString value to preserve backwardComp. The mojo parameter to configure is escapeString expression="${maven.resources.escapeString}"
Hide
Maik Ebert added a comment -

Will this also be documented on the plugin homepage?

Show
Maik Ebert added a comment - Will this also be documented on the plugin homepage?
Hide
Olivier Lamy added a comment -
Show
Olivier Lamy added a comment - yup have a look here http://svn.apache.org/viewvc?view=rev&revision=694005
Hide
Daniel Beland added a comment -

None of the suggested workarounds worked for me and I don't want to use the 2.3-SNAPSHOT.
So until it is released here is how we can achieve it, works for me:

Use $${property} when you want to escape a property and simply process the resources with ant after the filtering is done

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>escape-properties</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<replace dir="${project.build.directory}/classes" includes="*/.properties,*/.xml,*/.vm">
<replacetoken><![CDATA[$$]]></replacetoken>
<replacevalue><![CDATA[$]]></replacevalue>
</replace>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>

Show
Daniel Beland added a comment - None of the suggested workarounds worked for me and I don't want to use the 2.3-SNAPSHOT. So until it is released here is how we can achieve it, works for me: Use $${property} when you want to escape a property and simply process the resources with ant after the filtering is done <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>escape-properties</id> <phase>process-resources</phase> <configuration> <tasks> <replace dir="${project.build.directory}/classes" includes="*/.properties,*/.xml,*/.vm"> <replacetoken><![CDATA[$$]]></replacetoken> <replacevalue><![CDATA[$]]></replacevalue> </replace> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant-nodeps</artifactId> <version>1.7.1</version> </dependency> </dependencies> </plugin>

People

Vote (10)
Watch (12)

Dates

  • Created:
    Updated:
    Resolved: