Mulit Line Merge Mappings not working

Description

There seams to be a problem with Multi Line Merge Mappings (Single Line Merge Mappings work without a problem).

Example: SpringMergeMapping.xml:

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
<mapping>
<from><![CDATA[<property reference="driver"/>
<property reference="username"/>]]></from>
<to><![CDATA[<test/>]]></to>
</mapping>

Unfortunately, the two lines (<property reference="driver"/> and <property reference="username"/>) are not getting recognized by the org.andromda.core.common.Merger.

The problem seams to be in the org.andromda.core.common.XmlObjectFactory. The method getObject() receives the mapping-file with the original CR & LF (\r \n). The returned org.andromda.core.mapping.Mappings, which contains the parsed mappings however replaced the \r \n by only \n.

Now of course the String to be replaced cannot be found in the cartridge.xml, and no replacement takes place.

I can be fixed with the following workaround in org.andromda.core.common.Merger.getMergedString():

remove all line breaks from both "string" and "from".

for (String from : froms) {
from = StringUtils.trimToEmpty(from);
string = string.replaceAll("\\r|
n", "");
from = string.replaceAll("\\r|
n", "");
if (StringUtils.isNotBlank(from) && string.contains(from)) {
final String to = StringUtils.trimToEmpty(mapping.getTo());
string = StringUtils.replace(string, from, to);
}
}

This should work on all plattforms. It would be nice, if this could be added the 3.4-SNAPSHOT.

Environment

Windows 7

Activity

Show:
Bob Fields
April 17, 2011, 1:50 PM

See http://forum.andromda.org/viewtopic.php?f=10&t=7195&p=30273&hilit=Merger.java#p30273.

This change causes the build to fail because it removes the linefeeds in the output string before replacement, causing mismatched tags in the vsl templates. You'll need to keep the linefeeds intact in the string where replacement is necessary, either by fixing the XmlObjectFactory or somehow putting the values back after the string to be replaced has been found.

To submit a change, you need to check out the source (anonymous SVN is OK), make the change locally, and build the entire project, then test the change. That doesn't take too long, but it saves us from trying to figure out why the submitted change doesn't work. Normally we like to see a SVN patch submitted as a fix plus additional unit tests.

Andy Flury
April 17, 2011, 7:44 PM

Hi Bob

You are right. Just removing all linefeeds does not work.

I did some more research. The "from" String gets read by Digester which conforms to XML standards and replaces \r\n to \n according to this document:
http://www.w3.org/TR/REC-xml/#sec-line-ends

On the other hand the "string" is just read by a InputStreamReader which preserves the Input as is.

So doing the following will replace the \r\n to \n also in the "string"

from = StringUtils.trimToEmpty(from);
string = string.replaceAll("
r", "");
if (StringUtils.isNotBlank(from) && string.contains(from))
{
final String to = StringUtils.trimToEmpty(mapping.getTo());
string = StringUtils.replace(string, from, to);
}

I will attach a patch also.

Hope, this can be put into the SNAPSHOT.

thanks
andy

Bob Fields
April 22, 2011, 2:50 AM

Also fixed the CartridgeTest maven plugin to be non-platform specific.

Assignee

Former user

Reporter

Andy Flury

Labels

None

Time tracking

1h

Fix versions

Affects versions

Priority

Minor
Configure