Skip to content

Commit

Permalink
#26 Support combine.keys (in sync with xml-combiner implementation)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Dec 8, 2019
1 parent b93d9fa commit e1304dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java
Expand Up @@ -171,11 +171,12 @@ private static void mergeIntoXpp3Dom( Xpp3Dom dominant, Xpp3Dom recessive, Boole
}
}

final String keysValue = recessive.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE );

Xpp3Dom[] children = recessive.getChildren();
for ( Xpp3Dom recessiveChild : children )
{
String idValue = recessiveChild.getAttribute( ID_COMBINATION_MODE_ATTRIBUTE );
String keysValue = recessiveChild.getAttribute( KEYS_COMBINATION_MODE_ATTRIBUTE );

Xpp3Dom childDom = null;
if ( isNotEmpty( idValue ) )
Expand All @@ -196,15 +197,15 @@ else if ( isNotEmpty( keysValue ) )
Map<String, String> recessiveKeyValues = new HashMap<String, String>( keys.length );
for ( String key : keys )
{
recessiveKeyValues.put( key, recessiveChild.getChild( key ).getValue() );
recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) );
}

for ( Xpp3Dom dominantChild : dominant.getChildren() )
{
Map<String, String> dominantKeyValues = new HashMap<String, String>( keys.length );
for ( String key : keys )
{
dominantKeyValues.put( key, dominantChild.getChild( key ).getValue() );
dominantKeyValues.put( key, dominantChild.getAttribute( key ) );
}

if ( recessiveKeyValues.equals( dominantKeyValues ) )
Expand Down
Expand Up @@ -64,10 +64,10 @@ public void testCombineId()
public void testCombineKeys()
throws Exception
{
String lhs = "<props>" + "<property combine.keys='name'><name>LHS-ONLY</name><value>LHS</value></property>"
String lhs = "<props combine.keys='key'>" + "<property key=\"LHS-ONLY\"><name>LHS-ONLY</name><value>LHS</value></property>"
+ "<property combine.keys='name'><name>TOOVERWRITE</name><value>LHS</value></property>" + "</props>";

String rhs = "<props>" + "<property combine.keys='name'><name>RHS-ONLY</name><value>RHS</value></property>"
String rhs = "<props combine.keys='key'>" + "<property key=\"RHS-ONLY\"><name>RHS-ONLY</name><value>RHS</value></property>"
+ "<property combine.keys='name'><name>TOOVERWRITE</name><value>RHS</value></property>" + "</props>";

Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );
Expand Down

1 comment on commit e1304dd

@belingueres
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried the combine.keys example merge in the https://github.com/atteo/xml-combiner readme: not the same result. Additionally, I realized the (same?) merge functionality is implemented in both Xpp3Dom and Xpp3DomUtils classes...very confusing...we should have only one implementation.

Please sign in to comment.