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
24 import java.io.File;
25 import java.util.List;
26 import java.util.Properties;
27
28
29
30
31
32
33 public class MavenIT0143TransitiveDependencyScopesTest
34 extends AbstractMavenIntegrationTestCase
35 {
36
37
38
39
40
41 public MavenIT0143TransitiveDependencyScopesTest()
42 {
43 super( ALL_MAVEN_VERSIONS );
44 }
45
46
47
48
49
50
51
52 public void testitCompileScope()
53 throws Exception
54 {
55 Verifier verifier = run( "compile" );
56 String targetDir = "target-compile";
57
58
59
60
61
62
63 List<String> compileArtifacts = verifier.loadLines( targetDir + "/compile-artifacts.txt", "UTF-8" );
64 assertTrue( compileArtifacts.toString(), compileArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
65 assertTrue( compileArtifacts.toString(), compileArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
66 assertEquals( 2, compileArtifacts.size() );
67
68 List<String> compileClassPath = verifier.loadLines( targetDir + "/compile-cp.txt", "UTF-8" );
69 assertTrue( compileClassPath.toString(), compileClassPath.contains( "classes" ) );
70 assertTrue( compileClassPath.toString(), compileClassPath.contains( "direct-0.1.jar" ) );
71 assertTrue( compileClassPath.toString(), compileClassPath.contains( "compile-0.1.jar" ) );
72 assertEquals( 3, compileClassPath.size() );
73
74 List<String> runtimeArtifacts = verifier.loadLines( targetDir + "/runtime-artifacts.txt", "UTF-8" );
75 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
76 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
77 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
78 assertEquals( 3, runtimeArtifacts.size() );
79
80 List<String> runtimeClassPath = verifier.loadLines( targetDir + "/runtime-cp.txt", "UTF-8" );
81 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "classes" ) );
82 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "direct-0.1.jar" ) );
83 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "compile-0.1.jar" ) );
84 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "runtime-0.1.jar" ) );
85 assertEquals( 4, runtimeClassPath.size() );
86
87 List<String> testArtifacts = verifier.loadLines( targetDir + "/test-artifacts.txt", "UTF-8" );
88 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
89 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
90 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
91 assertEquals( 3, testArtifacts.size() );
92
93 List<String> testClassPath = verifier.loadLines( targetDir + "/test-cp.txt", "UTF-8" );
94 assertTrue( testClassPath.toString(), testClassPath.contains( "classes" ) );
95 assertTrue( testClassPath.toString(), testClassPath.contains( "test-classes" ) );
96 assertTrue( testClassPath.toString(), testClassPath.contains( "direct-0.1.jar" ) );
97 assertTrue( testClassPath.toString(), testClassPath.contains( "compile-0.1.jar" ) );
98 assertTrue( testClassPath.toString(), testClassPath.contains( "runtime-0.1.jar" ) );
99 assertEquals( 5, testClassPath.size() );
100 }
101
102
103
104
105
106
107
108 public void testitProvidedScope()
109 throws Exception
110 {
111 Verifier verifier = run( "provided" );
112 String targetDir = "target-provided";
113
114 List<String> compileArtifacts = verifier.loadLines( targetDir + "/compile-artifacts.txt", "UTF-8" );
115 assertTrue( compileArtifacts.toString(), compileArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
116 assertTrue( compileArtifacts.toString(), compileArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
117 assertTrue( compileArtifacts.toString(), compileArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
118 assertEquals( 3, compileArtifacts.size() );
119
120 List<String> compileClassPath = verifier.loadLines( targetDir + "/compile-cp.txt", "UTF-8" );
121 assertTrue( compileClassPath.toString(), compileClassPath.contains( "classes" ) );
122 assertTrue( compileClassPath.toString(), compileClassPath.contains( "direct-0.1.jar" ) );
123 assertTrue( compileClassPath.toString(), compileClassPath.contains( "compile-0.1.jar" ) );
124 assertTrue( compileClassPath.toString(), compileClassPath.contains( "runtime-0.1.jar" ) );
125 assertEquals( 4, compileClassPath.size() );
126
127 List<String> runtimeArtifacts = verifier.loadLines( targetDir + "/runtime-artifacts.txt", "UTF-8" );
128 assertEquals( 0, runtimeArtifacts.size() );
129
130 List<String> runtimeClassPath = verifier.loadLines( targetDir + "/runtime-cp.txt", "UTF-8" );
131 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "classes" ) );
132 assertEquals( 1, runtimeClassPath.size() );
133
134 List<String> testArtifacts = verifier.loadLines( targetDir + "/test-artifacts.txt", "UTF-8" );
135 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
136 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
137 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
138 assertEquals( 3, testArtifacts.size() );
139
140 List<String> testClassPath = verifier.loadLines( targetDir + "/test-cp.txt", "UTF-8" );
141 assertTrue( testClassPath.toString(), testClassPath.contains( "classes" ) );
142 assertTrue( testClassPath.toString(), testClassPath.contains( "test-classes" ) );
143 assertTrue( testClassPath.toString(), testClassPath.contains( "direct-0.1.jar" ) );
144 assertTrue( testClassPath.toString(), testClassPath.contains( "compile-0.1.jar" ) );
145 assertTrue( testClassPath.toString(), testClassPath.contains( "runtime-0.1.jar" ) );
146 assertEquals( 5, testClassPath.size() );
147 }
148
149
150
151
152
153
154
155 public void testitRuntimeScope()
156 throws Exception
157 {
158 Verifier verifier = run( "runtime" );
159 String targetDir = "target-runtime";
160
161 List<String> compileArtifacts = verifier.loadLines( targetDir + "/compile-artifacts.txt", "UTF-8" );
162 assertEquals( 0, compileArtifacts.size() );
163
164 List<String> compileClassPath = verifier.loadLines( targetDir + "/compile-cp.txt", "UTF-8" );
165 assertTrue( compileClassPath.toString(), compileClassPath.contains( "classes" ) );
166 assertEquals( 1, compileClassPath.size() );
167
168 List<String> runtimeArtifacts = verifier.loadLines( targetDir + "/runtime-artifacts.txt", "UTF-8" );
169 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
170 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
171 assertTrue( runtimeArtifacts.toString(), runtimeArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
172 assertEquals( 3, runtimeArtifacts.size() );
173
174 List<String> runtimeClassPath = verifier.loadLines( targetDir + "/runtime-cp.txt", "UTF-8" );
175 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "classes" ) );
176 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "direct-0.1.jar" ) );
177 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "compile-0.1.jar" ) );
178 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "runtime-0.1.jar" ) );
179 assertEquals( 4, runtimeClassPath.size() );
180
181 List<String> testArtifacts = verifier.loadLines( targetDir + "/test-artifacts.txt", "UTF-8" );
182 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
183 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
184 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
185 assertEquals( 3, testArtifacts.size() );
186
187 List<String> testClassPath = verifier.loadLines( targetDir + "/test-cp.txt", "UTF-8" );
188 assertTrue( testClassPath.toString(), testClassPath.contains( "classes" ) );
189 assertTrue( testClassPath.toString(), testClassPath.contains( "test-classes" ) );
190 assertTrue( testClassPath.toString(), testClassPath.contains( "direct-0.1.jar" ) );
191 assertTrue( testClassPath.toString(), testClassPath.contains( "compile-0.1.jar" ) );
192 assertTrue( testClassPath.toString(), testClassPath.contains( "runtime-0.1.jar" ) );
193 assertEquals( 5, testClassPath.size() );
194 }
195
196
197
198
199
200
201
202 public void testitTestScope()
203 throws Exception
204 {
205 Verifier verifier = run( "test" );
206 String targetDir = "target-test";
207
208 List<String> compileArtifacts = verifier.loadLines( targetDir + "/compile-artifacts.txt", "UTF-8" );
209 assertEquals( 0, compileArtifacts.size() );
210
211 List<String> compileClassPath = verifier.loadLines( targetDir + "/compile-cp.txt", "UTF-8" );
212 assertTrue( compileClassPath.toString(), compileClassPath.contains( "classes" ) );
213 assertEquals( 1, compileClassPath.size() );
214
215 List<String> runtimeArtifacts = verifier.loadLines( targetDir + "/runtime-artifacts.txt", "UTF-8" );
216 assertEquals( 0, runtimeArtifacts.size() );
217
218 List<String> runtimeClassPath = verifier.loadLines( targetDir + "/runtime-cp.txt", "UTF-8" );
219 assertTrue( runtimeClassPath.toString(), runtimeClassPath.contains( "classes" ) );
220 assertEquals( 1, runtimeClassPath.size() );
221
222 List<String> testArtifacts = verifier.loadLines( targetDir + "/test-artifacts.txt", "UTF-8" );
223 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:direct:jar:0.1" ) );
224 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:compile:jar:0.1" ) );
225 assertTrue( testArtifacts.toString(), testArtifacts.contains( "org.apache.maven.its.it0143:runtime:jar:0.1" ) );
226 assertEquals( 3, testArtifacts.size() );
227
228 List<String> testClassPath = verifier.loadLines( targetDir + "/test-cp.txt", "UTF-8" );
229 assertTrue( testClassPath.toString(), testClassPath.contains( "classes" ) );
230 assertTrue( testClassPath.toString(), testClassPath.contains( "test-classes" ) );
231 assertTrue( testClassPath.toString(), testClassPath.contains( "direct-0.1.jar" ) );
232 assertTrue( testClassPath.toString(), testClassPath.contains( "compile-0.1.jar" ) );
233 assertTrue( testClassPath.toString(), testClassPath.contains( "runtime-0.1.jar" ) );
234 assertEquals( 5, testClassPath.size() );
235 }
236
237 private Verifier run( String scope )
238 throws Exception
239 {
240 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/it0143" );
241
242 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
243 verifier.setAutoclean( false );
244 verifier.deleteDirectory( "target-" + scope );
245 verifier.deleteArtifacts( "org.apache.maven.its.it0143" );
246 Properties filterProps = verifier.newDefaultFilterProperties();
247 filterProps.setProperty( "@scope@", scope );
248 verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", filterProps );
249 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
250 verifier.addCliOption( "--settings" );
251 verifier.addCliOption( "settings.xml" );
252 verifier.setLogFileName( "log-" + scope + ".txt" );
253 verifier.executeGoal( "validate" );
254 verifier.verifyErrorFreeLog();
255 verifier.resetStreams();
256
257 return verifier;
258 }
259
260 }