jmporterog / maven-replacer-plugin

Automatically exported from code.google.com/p/maven-replacer-plugin
MIT License
0 stars 0 forks source link

variableTokenValueMap should be replaced with a real map and non comma-separated key=value pairs #55

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes the key or value to be replaced contains an equals sign and this can 
cause failures to properly transform even though the key is matched.

For example if I have the following in the pom.xml:

<variableTokenValueMap>
    pid_=<![CDATA[<portlet:namespace/>]]>,
    rcp_=<![CDATA[<%=request.getContextPath()%>]]>,
    <![CDATA[var getUrl = 'replaced_during_packaging_see_pom.xml';]]>=<![CDATA[<portlet:resourceURL escapeXml='false' id='get' var='getUrl'/>]]>,
    <![CDATA[var updateUrl = 'replaced_during_packaging_see_pom.xml';]]>=<![CDATA[<portlet:resourceURL escapeXml='false' id='update' var='updateUrl'/>]]>,
    <![CDATA[<!-- do not remove or move this comment -->]]>=<![CDATA[<portlet:defineObjects/><portlet:actionURL var="actionURL" portletMode="view"/>]]>
</variableTokenValueMap>

and this in the file to transform:

    var getUrl = 'replaced_during_packaging_see_pom.xml';
    var updateUrl = 'replaced_during_packaging_see_pom.xml';

then this transforms into:

    'replaced_during_packaging_see_pom.xml';= = 'replaced_during_packaging_see_pom.xml';
    'replaced_during_packaging_see_pom.xml';= = 'replaced_during_packaging_see_pom.xml';

I need to be able to replace multiple things in the file, and the 
comma-separated key value pairs not only are hard to read but they also don't 
work.

Instead, something like this would be nice:

    <replacements>
      <property>
        <name>key1</name>
        <value>value1</value>
      <property>
      <property>
        <name>key2</name>
        <value>value2</value>
      <property>
    </replacements>

However, maybe this bug is not just an issue of escaped equals. Not sure yet.

Original issue reported on code.google.com by garyswea...@gmail.com on 20 Jul 2011 at 4:36

GoogleCodeExporter commented 9 years ago
Thanks for the Issue report.
Have you tried replacements:replacement as a workaround whilst I look into this?
There is an example in the UsageGuide (last example).

Original comment by baker.st...@gmail.com on 21 Jul 2011 at 12:24

GoogleCodeExporter commented 9 years ago
That's perfect! I have no idea how I missed that before.

I've not tried replacements:replacement with the exact text I had the bug with, 
because I've since changed that, but I'm using it now for the replacements I 
need to make and it looks much cleaner, e.g.:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <version>1.3.8</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <ignoreMissingFile>false</ignoreMissingFile>
        <file>target/${portletName}/WEB-INF/jsp/view.jsp</file>
        <regex>false</regex>
        <replacements>
            <replacement>
                <token>pid_</token>
                <value><![CDATA[<portlet:namespace/>]]></value>
            </replacement>
            <replacement>
                <token>rcp_</token>
                <value><![CDATA[<%=request.getContextPath()%>]]></value>
            </replacement>
            <replacement>
                <token>//replaceme2</token>
                <value>
                    <![CDATA[<portlet:resourceURL escapeXml='false' id='get' var='getUrl'/><portlet:resourceURL escapeXml='false' id='update' var='updateUrl'/>]]></value>
            </replacement>
            <replacement>
                <token><![CDATA[<!--replaceme1-->]]></token>
                <value>
                    <![CDATA[<portlet:defineObjects/><portlet:actionURL var="actionURL" portletMode="view"/>]]></value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

Thanks for the tip!
Gary

Original comment by garyswea...@gmail.com on 21 Jul 2011 at 1:56

GoogleCodeExporter commented 9 years ago
No problem Gary.
Would you like me to close this Issue as there is a suitable workaround?

Original comment by baker.st...@gmail.com on 22 Jul 2011 at 1:08

GoogleCodeExporter commented 9 years ago
Thanks! Yes, please close this ticket. Thanks again.

Original comment by garyswea...@gmail.com on 22 Jul 2011 at 2:31