From e1304ddeb9aef72ac27a1b7f7e58908cc7cee286 Mon Sep 17 00:00:00 2001 From: rfscholte Date: Sun, 8 Dec 2019 13:27:08 +0100 Subject: [PATCH] #26 Support combine.keys (in sync with xml-combiner implementation) --- .../java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java | 7 ++++--- .../org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java index 71efe467..90213329 100644 --- a/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java +++ b/src/main/java/org/codehaus/plexus/util/xml/Xpp3DomUtils.java @@ -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 ) ) @@ -196,7 +197,7 @@ else if ( isNotEmpty( keysValue ) ) Map recessiveKeyValues = new HashMap( keys.length ); for ( String key : keys ) { - recessiveKeyValues.put( key, recessiveChild.getChild( key ).getValue() ); + recessiveKeyValues.put( key, recessiveChild.getAttribute( key ) ); } for ( Xpp3Dom dominantChild : dominant.getChildren() ) @@ -204,7 +205,7 @@ else if ( isNotEmpty( keysValue ) ) Map dominantKeyValues = new HashMap( keys.length ); for ( String key : keys ) { - dominantKeyValues.put( key, dominantChild.getChild( key ).getValue() ); + dominantKeyValues.put( key, dominantChild.getAttribute( key ) ); } if ( recessiveKeyValues.equals( dominantKeyValues ) ) diff --git a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java index e5a68e77..9a03fa35 100644 --- a/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/util/xml/Xpp3DomUtilsTest.java @@ -64,10 +64,10 @@ public void testCombineId() public void testCombineKeys() throws Exception { - String lhs = "" + "LHS-ONLYLHS" + String lhs = "" + "LHS-ONLYLHS" + "TOOVERWRITELHS" + ""; - String rhs = "" + "RHS-ONLYRHS" + String rhs = "" + "RHS-ONLYRHS" + "TOOVERWRITERHS" + ""; Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ), new FixedInputLocationBuilder( "left" ) );