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 import org.mortbay.jetty.Server;
26
27 import java.io.File;
28 import java.io.FileReader;
29 import java.util.ArrayList;
30 import java.util.List;
31
32
33
34
35
36
37
38 public class MavenITmng5224InjectedSettings
39 extends AbstractMavenIntegrationTestCase
40 {
41 private Server server;
42
43 private int port;
44
45 public MavenITmng5224InjectedSettings()
46 {
47
48 super( "[2.0.3,3.0-alpha-1),[3.0.4,)" );
49 }
50
51
52
53
54
55 public void testmng5224_ReadSettings()
56 throws Exception
57 {
58 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5224" );
59
60 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
61
62 verifier.getCliOptions().add( "--settings" );
63 verifier.getCliOptions().add( "settings.xml" );
64
65 verifier.executeGoal( "validate" );
66
67 File settingsFile = new File( verifier.getBasedir(), "target/settings-dump.xml" );
68
69 FileReader fr = new FileReader( settingsFile );
70
71 Xpp3Dom dom = Xpp3DomBuilder.build( fr );
72
73 Xpp3Dom profilesNode = dom.getChild( "profiles" );
74
75 Xpp3Dom[] profileNodes = profilesNode.getChildren( "profile" );
76
77
78 assertEquals( 4, profileNodes.length );
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
104
105
106
107 List<String> profileIds = new ArrayList<String>( 4 );
108
109 for ( Xpp3Dom node : profileNodes )
110 {
111 Xpp3Dom idNode = node.getChild( "id" );
112 profileIds.add( idNode.getValue() );
113 if ( "apache".equals( idNode.getName() ) )
114 {
115 Xpp3Dom propsNode = node.getChild( "properties" );
116 assertEquals( "true", propsNode.getChild( "run-its" ).getValue() );
117 }
118 if ( "release".equals( idNode.getName() ) )
119 {
120 Xpp3Dom propsNode = node.getChild( "properties" );
121 assertEquals( "verycomplicatedpassphrase", propsNode.getChild( "gpg.passphrase" ).getValue() );
122 }
123 if ( "fast".equals( idNode.getName() ) )
124 {
125 Xpp3Dom propsNode = node.getChild( "properties" );
126 assertEquals( "true", propsNode.getChild( "maven.test.skip" ).getValue() );
127 assertEquals( "true", propsNode.getChild( "skipTests" ).getValue() );
128 }
129 }
130
131 assertTrue( profileIds.contains( "apache" ) );
132 assertTrue( profileIds.contains( "release" ) );
133 assertTrue( profileIds.contains( "fast" ) );
134 assertTrue( profileIds.contains( "it-defaults" ) );
135
136
137
138
139
140
141
142
143 Xpp3Dom activeProfilesNode = dom.getChild( "activeProfiles" );
144
145
146
147
148 if ( matchesVersionRange( "[2.0.3,3.0-alpha-1)" ) )
149 {
150 assertEquals( 2, activeProfilesNode.getChildCount() );
151 }
152 else
153 {
154 assertEquals( 1, activeProfilesNode.getChildCount() );
155 }
156
157 List<String> activeProfiles = new ArrayList<String>( 2 );
158
159 for ( Xpp3Dom node : activeProfilesNode.getChildren() )
160 {
161 activeProfiles.add( node.getValue() );
162 }
163
164 if ( matchesVersionRange( "[2.0.3,3.0-alpha-1)" ) )
165 {
166 assertTrue( activeProfiles.contains( "apache" ) );
167 }
168 assertTrue( activeProfiles.contains( "it-defaults" ) );
169
170 }
171
172
173 }