-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Hi team,
MetadataJDOMWriter would call org.apache.maven.io.util.WriterUtils#replaceXpp3DOM on writing plugin/configuration, since sub elements of configuration accept attributes namedcombine.children and combine.self to control how Maven combine the configurations from parent, a use case like below may output wrong result as WriterUtils only compare the name of elements.
I think the we also should compare the attribute name and value at https://github.com/Commonjava/maven-model-jdom-support/blob/master/src/main/java/org/apache/maven/io/util/WriterUtils.java#L137, how do you think about it? I can send a pull request for it if you'd like to.
Test pom:
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>test.group</groupId>
<artifactId>test-name</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<artifactId>plugin-1</artifactId>
<version>1</version>
<configuration>
<properties combine.children="append">
<property>1</property>
</properties>
</configuration>
</plugin>
<plugin>
<artifactId>plugin-2</artifactId>
<version>1</version>
<configuration>
<properties combine.children="override">
<property>2</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>Test case:
@Test
public void removePlugin() throws Exception {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.pom");
File file = temp.newFile();
FileUtils.copyInputStreamToFile(in, file);
in = new FileInputStream(file);
Model model = new MavenXpp3Reader().read(in);
in.close();
// remove first
model.getBuild().getPlugins().remove(0);
new MavenJDOMWriter(model).write(model, file);
System.out.println(FileUtils.readFileToString(file));
// build the model after change
in = new FileInputStream(file);
model = new MavenXpp3Reader().read(in);
in.close();
Plugin plugin = model.getBuild().getPlugins().get(0);
assertEquals("plugin-2", plugin.getArtifactId());
Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
Xpp3Dom properties = config.getChild("properties");
// WOULD FAIL HERE
assertEquals("override", properties.getAttribute("combine.children"));
}Metadata
Metadata
Assignees
Labels
No labels