-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MNG-7596] Upgrade to plexus 3.5.0 #866
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
maven-xml-impl/src/test/java/org/apache/maven/internal/xml/Xpp3DomTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.maven.internal.xml; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.apache.maven.api.xml.Dom; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParser; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class Xpp3DomTest { | ||
|
||
/** | ||
* <p>testCombineId.</p> | ||
* | ||
* @throws java.lang.Exception if any. | ||
*/ | ||
@Test | ||
public void testCombineId() throws Exception { | ||
String lhs = "<props>" + "<property combine.id='LHS-ONLY'><name>LHS-ONLY</name><value>LHS</value></property>" | ||
+ "<property combine.id='TOOVERWRITE'><name>TOOVERWRITE</name><value>LHS</value></property>" | ||
+ "</props>"; | ||
|
||
String rhs = "<props>" + "<property combine.id='RHS-ONLY'><name>RHS-ONLY</name><value>RHS</value></property>" | ||
+ "<property combine.id='TOOVERWRITE'><name>TOOVERWRITE</name><value>RHS</value></property>" | ||
+ "</props>"; | ||
|
||
Xpp3Dom leftDom = Xpp3DomBuilder.build(new StringReader(lhs), new FixedInputLocationBuilder("left")); | ||
Xpp3Dom rightDom = Xpp3DomBuilder.build(new StringReader(rhs), new FixedInputLocationBuilder("right")); | ||
|
||
Dom mergeResult = Xpp3Dom.merge(leftDom, rightDom, true); | ||
assertEquals(3, getChildren(mergeResult, "property").size()); | ||
|
||
Dom p0 = getNthChild(mergeResult, "property", 0); | ||
assertEquals("LHS-ONLY", p0.getChild("name").getValue()); | ||
assertEquals("left", p0.getChild("name").getInputLocation()); | ||
assertEquals("LHS", p0.getChild("value").getValue()); | ||
assertEquals("left", p0.getChild("value").getInputLocation()); | ||
|
||
Dom p1 = getNthChild(mergeResult, "property", 1); | ||
assertEquals( | ||
"TOOVERWRITE", | ||
getNthChild(mergeResult, "property", 1).getChild("name").getValue()); | ||
assertEquals("left", p1.getChild("name").getInputLocation()); | ||
assertEquals( | ||
"LHS", getNthChild(mergeResult, "property", 1).getChild("value").getValue()); | ||
assertEquals("left", p1.getChild("value").getInputLocation()); | ||
|
||
Dom p2 = getNthChild(mergeResult, "property", 2); | ||
assertEquals( | ||
"RHS-ONLY", | ||
getNthChild(mergeResult, "property", 2).getChild("name").getValue()); | ||
assertEquals("right", p2.getChild("name").getInputLocation()); | ||
assertEquals( | ||
"RHS", getNthChild(mergeResult, "property", 2).getChild("value").getValue()); | ||
assertEquals("right", p2.getChild("value").getInputLocation()); | ||
} | ||
|
||
/** | ||
* <p>testCombineKeys.</p> | ||
* | ||
* @throws java.lang.Exception if any. | ||
*/ | ||
@Test | ||
public void testCombineKeys() throws Exception { | ||
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 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")); | ||
Xpp3Dom rightDom = Xpp3DomBuilder.build(new StringReader(rhs), new FixedInputLocationBuilder("right")); | ||
|
||
Dom mergeResult = Xpp3Dom.merge(leftDom, rightDom, true); | ||
assertEquals(3, getChildren(mergeResult, "property").size()); | ||
|
||
Dom p0 = getNthChild(mergeResult, "property", 0); | ||
assertEquals("LHS-ONLY", p0.getChild("name").getValue()); | ||
assertEquals("left", p0.getChild("name").getInputLocation()); | ||
assertEquals("LHS", p0.getChild("value").getValue()); | ||
assertEquals("left", p0.getChild("value").getInputLocation()); | ||
|
||
Dom p1 = getNthChild(mergeResult, "property", 1); | ||
assertEquals( | ||
"TOOVERWRITE", | ||
getNthChild(mergeResult, "property", 1).getChild("name").getValue()); | ||
assertEquals("left", p1.getChild("name").getInputLocation()); | ||
assertEquals( | ||
"LHS", getNthChild(mergeResult, "property", 1).getChild("value").getValue()); | ||
assertEquals("left", p1.getChild("value").getInputLocation()); | ||
|
||
Dom p2 = getNthChild(mergeResult, "property", 2); | ||
assertEquals( | ||
"RHS-ONLY", | ||
getNthChild(mergeResult, "property", 2).getChild("name").getValue()); | ||
assertEquals("right", p2.getChild("name").getInputLocation()); | ||
assertEquals( | ||
"RHS", getNthChild(mergeResult, "property", 2).getChild("value").getValue()); | ||
assertEquals("right", p2.getChild("value").getInputLocation()); | ||
} | ||
|
||
@Test | ||
public void testPreserveDominantBlankValue() throws XmlPullParserException, IOException { | ||
String lhs = "<parameter xml:space=\"preserve\"> </parameter>"; | ||
|
||
String rhs = "<parameter>recessive</parameter>"; | ||
|
||
Xpp3Dom leftDom = Xpp3DomBuilder.build(new StringReader(lhs), new FixedInputLocationBuilder("left")); | ||
Xpp3Dom rightDom = Xpp3DomBuilder.build(new StringReader(rhs), new FixedInputLocationBuilder("right")); | ||
|
||
Dom mergeResult = Xpp3Dom.merge(leftDom, rightDom, true); | ||
assertEquals(" ", mergeResult.getValue()); | ||
} | ||
|
||
@Test | ||
public void testPreserveDominantEmptyNode() throws XmlPullParserException, IOException { | ||
String lhs = "<parameter></parameter>"; | ||
|
||
String rhs = "<parameter>recessive</parameter>"; | ||
|
||
Xpp3Dom leftDom = Xpp3DomBuilder.build(new StringReader(lhs), new FixedInputLocationBuilder("left")); | ||
Xpp3Dom rightDom = Xpp3DomBuilder.build(new StringReader(rhs), new FixedInputLocationBuilder("right")); | ||
|
||
Dom mergeResult = Xpp3Dom.merge(leftDom, rightDom, true); | ||
assertEquals("", mergeResult.getValue()); | ||
} | ||
|
||
@Test | ||
public void testPreserveDominantEmptyNode2() throws XmlPullParserException, IOException { | ||
String lhs = "<parameter/>"; | ||
|
||
String rhs = "<parameter>recessive</parameter>"; | ||
|
||
Xpp3Dom leftDom = Xpp3DomBuilder.build(new StringReader(lhs), new FixedInputLocationBuilder("left")); | ||
Xpp3Dom rightDom = Xpp3DomBuilder.build(new StringReader(rhs), new FixedInputLocationBuilder("right")); | ||
|
||
Dom mergeResult = Xpp3Dom.merge(leftDom, rightDom, true); | ||
assertEquals(null, mergeResult.getValue()); | ||
} | ||
|
||
private static List<Dom> getChildren(Dom node, String name) { | ||
return node.getChildren().stream().filter(n -> n.getName().equals(name)).collect(Collectors.toList()); | ||
} | ||
|
||
private static Dom getNthChild(Dom node, String name, int nth) { | ||
return node.getChildren().stream() | ||
.filter(n -> n.getName().equals(name)) | ||
.skip(nth) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
private static class FixedInputLocationBuilder implements Xpp3DomBuilder.InputLocationBuilder { | ||
private final Object location; | ||
|
||
public FixedInputLocationBuilder(Object location) { | ||
this.location = location; | ||
} | ||
|
||
public Object toInputLocation(XmlPullParser parser) { | ||
return location; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gnodet Why has this behavior been removed? Is there a migration path that you can share?
The following example has worked before that change where we have a parent pom and a child pom and a configuration that we'd like to merge. Here the parent and child pom definitions:
And the expected effective child pom that is used after the merge:
The problem we see now after this change, is that it will be merged the following way:
The problems are the following:
maven-compiler-plugin
configuration the<bar>
node is not merged from the parent pom configuration but rather the one from themaven-surefire-plugin
configuration from the parent pom.maven-surefire-plugin
configuration not as expected as the children of the<properties>
node are not appended as configured via thecombine.children="append"
property.Is that changed something that stays for Maven 4 ? I assume that then a migration path should be given as there are projects that use the behavior before this change and it would result in different effective pom files, which will change how the build is configured.
I'm also open to chat about it on the ASF Slack if required or if you have further questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if that can help, but big efforts were made in the past on maven-shared-utils reimplementation, with its test suite: https://github.com/apache/maven-shared-utils/blob/master/src/test/java/org/apache/maven/shared/utils/xml/pull/Xpp3DomTest.java
perhaps that can be reused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guylabs I'm not really the author of the change, I simply back ported it because the code is duplicated somehow from plexus-utils. The original change is codehaus-plexus/plexus-utils@67ac243