Skip to content

Commit 85f63af

Browse files
committed
fix reportSet inheritance in Maven 4 model building
1 parent f927773 commit 85f63af

6 files changed

Lines changed: 143 additions & 1 deletion

File tree

‎compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-configuration-child.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,20 @@ under the License.
5858
</plugin>
5959
</plugins>
6060
</build>
61+
62+
<reporting>
63+
<plugins>
64+
<plugin>
65+
<artifactId>MNG-5115-2</artifactId>
66+
<reportSets>
67+
<reportSet>
68+
<id>inherited-append</id>
69+
<reports>
70+
<report>from-child</report>
71+
</reports>
72+
</reportSet>
73+
</reportSets>
74+
</plugin>
75+
</plugins>
76+
</reporting>
6177
</project>

‎compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-configuration-expected.xml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ under the License.
8282
<!-- reportSet with inherited=false is not here -->
8383
</reportSets>
8484
</plugin>
85+
<plugin>
86+
<artifactId>MNG-5115-2</artifactId>
87+
<reportSets>
88+
<reportSet>
89+
<id>inherited-append</id>
90+
<reports>
91+
<report>from-child</report>
92+
<report>to-be-inherited</report>
93+
</reports>
94+
</reportSet>
95+
</reportSets>
96+
</plugin>
8597
</plugins>
8698
</reporting>
8799
</project>

‎compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-configuration-parent.xml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ under the License.
8484
</reportSet>
8585
</reportSets>
8686
</plugin>
87+
<plugin>
88+
<artifactId>MNG-5115-2</artifactId>
89+
<reportSets>
90+
<reportSet>
91+
<id>inherited-append</id>
92+
<reports>
93+
<report>to-be-inherited</report>
94+
</reports>
95+
</reportSet>
96+
</reportSets>
97+
</plugin>
8798
</plugins>
8899
</reporting>
89100
</project>

‎impl/maven-impl/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ under the License.
180180
<artifactId>jmh-generator-annprocess</artifactId>
181181
<scope>test</scope>
182182
</dependency>
183+
<dependency>
184+
<groupId>org.xmlunit</groupId>
185+
<artifactId>xmlunit-core</artifactId>
186+
<scope>test</scope>
187+
</dependency>
183188
</dependencies>
184189

185190
<build>

‎impl/maven-impl/src/main/java/org/apache/maven/impl/model/MavenModelMerger.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ protected void mergeReportPlugin_ReportSets(
599599
Object key = getReportSetKey().apply(element);
600600
ReportSet existing = merged.get(key);
601601
if (existing != null) {
602-
mergeReportSet(element, existing, sourceDominant, context);
602+
element = mergeReportSet(element, existing, sourceDominant, context);
603603
}
604604
merged.put(key, element);
605605
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.impl.model;
20+
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
25+
import org.apache.maven.api.model.Model;
26+
import org.apache.maven.api.services.xml.XmlReaderRequest;
27+
import org.apache.maven.api.services.xml.XmlWriterRequest;
28+
import org.apache.maven.impl.DefaultModelXmlFactory;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
31+
import org.xmlunit.builder.DiffBuilder;
32+
import org.xmlunit.diff.Diff;
33+
34+
import static org.junit.jupiter.api.Assertions.assertFalse;
35+
36+
class DefaultInheritanceAssemblerTest {
37+
38+
private DefaultModelXmlFactory xmlFactory;
39+
40+
private DefaultInheritanceAssembler assembler;
41+
42+
@BeforeEach
43+
void setUp() {
44+
xmlFactory = new DefaultModelXmlFactory();
45+
assembler = new DefaultInheritanceAssembler();
46+
}
47+
48+
private Path getPom(String name) {
49+
return Paths.get("../../compat/maven-model-builder/src/test/resources/poms/inheritance/" + name + ".xml");
50+
}
51+
52+
private Model getModel(String name) throws Exception {
53+
return xmlFactory.read(XmlReaderRequest.builder().path(getPom(name)).build());
54+
}
55+
56+
@Test
57+
void testPluginConfiguration() throws Exception {
58+
testInheritance("plugin-configuration");
59+
}
60+
61+
public void testInheritance(String baseName) throws Exception {
62+
testInheritance(baseName, false);
63+
testInheritance(baseName, true);
64+
}
65+
66+
public void testInheritance(String baseName, boolean fromRepo) throws Exception {
67+
Model parent = getModel(baseName + "-parent");
68+
Model child = getModel(baseName + "-child");
69+
70+
if (!fromRepo) {
71+
// when model is built from disk, pomFile is set
72+
// (has consequences in inheritance algorithm since getProjectDirectory() returns non-null)
73+
parent = parent.withPomFile(getPom(baseName + "-parent").toAbsolutePath());
74+
child = child.withPomFile(getPom(baseName + "-child").toAbsolutePath());
75+
}
76+
77+
Model assembled = assembler.assembleModelInheritance(child, parent, null, null);
78+
79+
// write baseName + "-actual"
80+
Path actual = Paths.get(
81+
"target/test-classes/poms/inheritance/" + baseName + (fromRepo ? "-build" : "-repo") + "-actual.xml");
82+
Files.createDirectories(actual.getParent());
83+
xmlFactory.write(XmlWriterRequest.<Model>builder()
84+
.content(assembled)
85+
.path(actual)
86+
.build());
87+
88+
// check with getPom( baseName + "-expected" )
89+
Path expected = getPom(baseName + "-expected");
90+
91+
Diff diff = DiffBuilder.compare(expected.toFile())
92+
.withTest(actual.toFile())
93+
.ignoreComments()
94+
.ignoreWhitespace()
95+
.build();
96+
assertFalse(diff.hasDifferences(), "XML files should be identical: " + diff.toString());
97+
}
98+
}

0 commit comments

Comments
 (0)