Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

org.apache.maven.io.util.WriterUtils#replaceXpp3DOM may fail on some specific case #10

@keshin

Description

@keshin

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions