Fix BOM packaging in consumer POMs (#11427) · gnodet/maven@7d6fd87 (original) (raw)
``
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
`+
`
``
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.it;
`
``
20
+
``
21
`+
import java.nio.file.Files;
`
``
22
`+
import java.nio.file.Path;
`
``
23
`+
import java.nio.file.Paths;
`
``
24
`+
import java.util.List;
`
``
25
`+
import java.util.stream.Stream;
`
``
26
+
``
27
`+
import org.junit.jupiter.api.Test;
`
``
28
+
``
29
`+
import static org.junit.jupiter.api.Assertions.assertFalse;
`
``
30
`+
import static org.junit.jupiter.api.Assertions.assertTrue;
`
``
31
+
``
32
`+
/**
`
``
33
`+
- This is a test set for BOM consumer POM issues.
`
``
34
`+
- Verifies that:
`
``
35
`+
- BOM packaging is transformed to POM in consumer POMs (not "bom" which is invalid in Maven 4.0.0)
`
``
36
`+
- Dependency versions are preserved in dependencyManagement when using flatten=true
`
``
37
`+
`
``
38
`+
- @since 4.0.0
`
``
39
`+
*/
`
``
40
`+
class MavenITgh11427BomConsumerPomTest extends AbstractMavenIntegrationTestCase {
`
``
41
+
``
42
`+
/**
`
``
43
`+
- Verify BOM consumer POM without flattening has correct packaging.
`
``
44
`+
*/
`
``
45
`+
@Test
`
``
46
`+
void testBomConsumerPomWithoutFlatten() throws Exception {
`
``
47
`+
Path basedir = extractResources("/gh-11427-bom-consumer-pom")
`
``
48
`+
.getAbsoluteFile()
`
``
49
`+
.toPath();
`
``
50
+
``
51
`+
Verifier verifier = newVerifier(basedir.toString());
`
``
52
`+
verifier.addCliArguments("install");
`
``
53
`+
verifier.execute();
`
``
54
`+
verifier.verifyErrorFreeLog();
`
``
55
+
``
56
`+
Path consumerPomPath = Paths.get(
`
``
57
`+
verifier.getArtifactPath("org.apache.maven.its.gh-11427", "bom", "1.0.0-SNAPSHOT", "pom"));
`
``
58
+
``
59
`+
assertTrue(Files.exists(consumerPomPath), "consumer pom not found at " + consumerPomPath);
`
``
60
+
``
61
`+
List consumerPomLines;
`
``
62
`+
try (Stream lines = Files.lines(consumerPomPath)) {
`
``
63
`+
consumerPomLines = lines.toList();
`
``
64
`+
}
`
``
65
+
``
66
`+
// Verify packaging is "pom" not "bom"
`
``
67
`+
assertTrue(
`
``
68
`+
consumerPomLines.stream().anyMatch(s -> s.contains("pom")),
`
``
69
`+
"Consumer pom should have pom");
`
``
70
`+
assertFalse(
`
``
71
`+
consumerPomLines.stream().anyMatch(s -> s.contains("bom")),
`
``
72
`+
"Consumer pom should NOT have bom");
`
``
73
+
``
74
`+
// Verify dependencyManagement is present
`
``
75
`+
assertTrue(
`
``
76
`+
consumerPomLines.stream().anyMatch(s -> s.contains("")),
`
``
77
`+
"Consumer pom should have dependencyManagement");
`
``
78
`+
}
`
``
79
+
``
80
`+
/**
`
``
81
`+
- Verify BOM consumer POM with flattening has correct packaging and versions.
`
``
82
`+
*/
`
``
83
`+
@Test
`
``
84
`+
void testBomConsumerPomWithFlatten() throws Exception {
`
``
85
`+
Path basedir = extractResources("/gh-11427-bom-consumer-pom")
`
``
86
`+
.getAbsoluteFile()
`
``
87
`+
.toPath();
`
``
88
+
``
89
`+
Verifier verifier = newVerifier(basedir.toString());
`
``
90
`+
verifier.addCliArguments("install", "-Dmaven.consumer.pom.flatten=true");
`
``
91
`+
verifier.execute();
`
``
92
`+
verifier.verifyErrorFreeLog();
`
``
93
+
``
94
`+
Path consumerPomPath = Paths.get(
`
``
95
`+
verifier.getArtifactPath("org.apache.maven.its.gh-11427", "bom", "1.0.0-SNAPSHOT", "pom"));
`
``
96
+
``
97
`+
assertTrue(Files.exists(consumerPomPath), "consumer pom not found at " + consumerPomPath);
`
``
98
+
``
99
`+
List consumerPomLines;
`
``
100
`+
try (Stream lines = Files.lines(consumerPomPath)) {
`
``
101
`+
consumerPomLines = lines.toList();
`
``
102
`+
}
`
``
103
+
``
104
`+
// Verify packaging is "pom" not "bom"
`
``
105
`+
assertTrue(
`
``
106
`+
consumerPomLines.stream().anyMatch(s -> s.contains("pom")),
`
``
107
`+
"Consumer pom should have pom");
`
``
108
`+
assertFalse(
`
``
109
`+
consumerPomLines.stream().anyMatch(s -> s.contains("bom")),
`
``
110
`+
"Consumer pom should NOT have bom");
`
``
111
+
``
112
`+
// Verify dependencyManagement is present
`
``
113
`+
assertTrue(
`
``
114
`+
consumerPomLines.stream().anyMatch(s -> s.contains("")),
`
``
115
`+
"Consumer pom should have dependencyManagement");
`
``
116
+
``
117
`+
// Verify versions are present in dependencies
`
``
118
`+
String content = String.join("\n", consumerPomLines);
`
``
119
`+
assertTrue(
`
``
120
`+
content.contains("1.0.0-SNAPSHOT") || content.contains("${"),
`
``
121
`+
"Consumer pom should have version for module dependency");
`
``
122
`+
assertTrue(
`
``
123
`+
content.contains("4.13.2"),
`
``
124
`+
"Consumer pom should have version for junit dependency");
`
``
125
`+
}
`
``
126
`+
}
`
``
127
+