1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23 import org.codehaus.plexus.util.xml.Xpp3Dom;
24 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
25
26 import java.io.File;
27 import java.io.FileReader;
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32
33
34
35
36
37 public class MavenITmng5224InjectedSettings
38 extends AbstractMavenIntegrationTestCase
39 {
40 public MavenITmng5224InjectedSettings()
41 {
42
43 super( "[2.0.3,3.0-alpha-1),[3.0.4,)" );
44 }
45
46
47
48
49
50
51 public void testmng5224_ReadSettings()
52 throws Exception
53 {
54 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5224" );
55
56 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57
58 verifier.addCliOption( "--settings" );
59 verifier.addCliOption( "settings.xml" );
60
61 verifier.executeGoal( "validate" );
62
63 File settingsFile = new File( verifier.getBasedir(), "target/settings-dump.xml" );
64
65 FileReader fr = new FileReader( settingsFile );
66
67 Xpp3Dom dom = Xpp3DomBuilder.build( fr );
68
69 Xpp3Dom profilesNode = dom.getChild( "profiles" );
70
71 Xpp3Dom[] profileNodes = profilesNode.getChildren( "profile" );
72
73
74 assertEquals( 4, profileNodes.length );
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 List<String> profileIds = new ArrayList<>( 4 );
104
105 for ( Xpp3Dom node : profileNodes )
106 {
107 Xpp3Dom idNode = node.getChild( "id" );
108 profileIds.add( idNode.getValue() );
109 if ( "apache".equals( idNode.getName() ) )
110 {
111 Xpp3Dom propsNode = node.getChild( "properties" );
112 assertEquals( "true", propsNode.getChild( "run-its" ).getValue() );
113 }
114 if ( "release".equals( idNode.getName() ) )
115 {
116 Xpp3Dom propsNode = node.getChild( "properties" );
117 assertEquals( "verycomplicatedpassphrase", propsNode.getChild( "gpg.passphrase" ).getValue() );
118 }
119 if ( "fast".equals( idNode.getName() ) )
120 {
121 Xpp3Dom propsNode = node.getChild( "properties" );
122 assertEquals( "true", propsNode.getChild( "maven.test.skip" ).getValue() );
123 assertEquals( "true", propsNode.getChild( "skipTests" ).getValue() );
124 }
125 }
126
127 assertTrue( profileIds.contains( "apache" ) );
128 assertTrue( profileIds.contains( "release" ) );
129 assertTrue( profileIds.contains( "fast" ) );
130 assertTrue( profileIds.contains( "it-defaults" ) );
131
132
133
134
135
136
137
138
139 Xpp3Dom activeProfilesNode = dom.getChild( "activeProfiles" );
140
141
142
143
144 if ( matchesVersionRange( "[2.0.3,3.0-alpha-1)" ) )
145 {
146 assertEquals( 2, activeProfilesNode.getChildCount() );
147 }
148 else
149 {
150 assertEquals( 1, activeProfilesNode.getChildCount() );
151 }
152
153 List<String> activeProfiles = new ArrayList<>( 2 );
154
155 for ( Xpp3Dom node : activeProfilesNode.getChildren() )
156 {
157 activeProfiles.add( node.getValue() );
158 }
159
160 if ( matchesVersionRange( "[2.0.3,3.0-alpha-1)" ) )
161 {
162 assertTrue( activeProfiles.contains( "apache" ) );
163 }
164 assertTrue( activeProfiles.contains( "it-defaults" ) );
165
166 }
167
168
169 }