Fix BOM packaging in consumer POMs (#11427) · gnodet/maven@7d6fd87 (original) (raw)

``

1

`+

/*

`

``

2

`+

`

``

3

`+

`

``

4

`+

`

``

5

`+

`

``

6

`+

`

``

7

`+

`

``

8

`+

`

``

9

`+

`

``

10

`+

`

``

11

`+

`

``

12

`+

`

``

13

`+

`

``

14

`+

`

``

15

`+

`

``

16

`+

`

``

17

`+

`

``

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

`+

`

``

34

`+

`

``

35

`+

`

``

36

`+

`

``

37

`+

`

``

38

`+

`

``

39

`+

*/

`

``

40

`+

class MavenITgh11427BomConsumerPomTest extends AbstractMavenIntegrationTestCase {

`

``

41

+

``

42

`+

/**

`

``

43

`+

`

``

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

`+

`

``

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

+