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 MavenITmng1895ScopeConflictResolutionTest
34 extends AbstractMavenIntegrationTestCase
35 {
36
37 public MavenITmng1895ScopeConflictResolutionTest()
38 {
39 super( "[2.0.3,)" );
40 }
41
42
43
44
45
46
47
48 public void testitDirectVsIndirect()
49 throws Exception
50 {
51 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-1895/direct-vs-indirect" );
52
53 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
54 verifier.setAutoclean( false );
55 verifier.deleteArtifacts( "org.apache.maven.its.mng1895" );
56 verifier.deleteDirectory( "target" );
57 verifier.addCliOption( "-s" );
58 verifier.addCliOption( "settings.xml" );
59 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
60 verifier.executeGoal( "validate" );
61 verifier.verifyErrorFreeLog();
62 verifier.resetStreams();
63
64 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
65 assertTrue( compile.toString(), compile.contains( "a-0.1.jar" ) );
66 assertFalse( compile.toString(), compile.contains( "b-0.1.jar" ) );
67 assertFalse( compile.toString(), compile.contains( "c-0.1.jar" ) );
68 assertTrue( compile.toString(), compile.contains( "d-0.1.jar" ) );
69
70 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
71 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
72 assertTrue( runtime.toString(), runtime.contains( "b-0.1.jar" ) );
73 assertFalse( runtime.toString(), runtime.contains( "c-0.1.jar" ) );
74 assertTrue( runtime.toString(), runtime.contains( "d-0.1.jar" ) );
75
76 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
77 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
78 assertTrue( test.toString(), test.contains( "b-0.1.jar" ) );
79 assertTrue( test.toString(), test.contains( "c-0.1.jar" ) );
80 assertTrue( test.toString(), test.contains( "d-0.1.jar" ) );
81 }
82
83
84
85
86
87
88 public void testitCompileVsRuntime()
89 throws Exception
90 {
91 Verifier verifier = run( "compile", "runtime" );
92
93 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
94 assertTrue( compile.toString(), compile.contains( "x-0.1.jar" ) );
95 assertFalse( compile.toString(), compile.contains( "a-0.1.jar" ) );
96
97 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
98 assertTrue( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
99 assertTrue( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
100
101 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
102 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
103 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
104 }
105
106
107
108
109
110
111 public void testitCompileVsTest()
112 throws Exception
113 {
114 Verifier verifier = run( "compile", "test" );
115
116 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
117 assertTrue( compile.toString(), compile.contains( "x-0.1.jar" ) );
118 assertFalse( compile.toString(), compile.contains( "a-0.1.jar" ) );
119
120 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
121 assertTrue( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
122 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
123
124 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
125 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
126 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
127 }
128
129
130
131
132
133
134 public void testitCompileVsProvided()
135 throws Exception
136 {
137 Verifier verifier = run( "compile", "provided" );
138
139 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
140 assertTrue( compile.toString(), compile.contains( "x-0.1.jar" ) );
141 assertTrue( compile.toString(), compile.contains( "a-0.1.jar" ) );
142
143 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
144 assertTrue( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
145 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
146
147 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
148 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
149 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
150 }
151
152
153
154
155
156
157 public void testitRuntimeVsTest()
158 throws Exception
159 {
160 Verifier verifier = run( "runtime", "test" );
161
162 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
163 assertFalse( compile.toString(), compile.contains( "x-0.1.jar" ) );
164 assertFalse( compile.toString(), compile.contains( "a-0.1.jar" ) );
165
166 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
167 assertTrue( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
168 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
169
170 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
171 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
172 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
173 }
174
175
176
177
178
179
180 public void testitRuntimeVsProvided()
181 throws Exception
182 {
183 Verifier verifier = run( "runtime", "provided" );
184
185 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
186 assertFalse( compile.toString(), compile.contains( "x-0.1.jar" ) );
187 assertTrue( compile.toString(), compile.contains( "a-0.1.jar" ) );
188
189 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
190 assertTrue( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
191 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
192
193 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
194 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
195 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
196 }
197
198
199
200
201
202
203 public void testitProvidedVsTest()
204 throws Exception
205 {
206 requiresMavenVersion( "[3.0-beta-3,)" );
207
208 Verifier verifier = run( "provided", "test" );
209
210 List<String> compile = verifier.loadLines( "target/compile.txt", "UTF-8" );
211 assertTrue( compile.toString(), compile.contains( "x-0.1.jar" ) );
212 assertFalse( compile.toString(), compile.contains( "a-0.1.jar" ) );
213
214 List<String> runtime = verifier.loadLines( "target/runtime.txt", "UTF-8" );
215 assertFalse( runtime.toString(), runtime.contains( "x-0.1.jar" ) );
216 assertFalse( runtime.toString(), runtime.contains( "a-0.1.jar" ) );
217
218 List<String> test = verifier.loadLines( "target/test.txt", "UTF-8" );
219 assertTrue( test.toString(), test.contains( "x-0.1.jar" ) );
220 assertTrue( test.toString(), test.contains( "a-0.1.jar" ) );
221 }
222
223 private Verifier run( String scopeB, String scopeA )
224 throws Exception
225 {
226 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-1895/strong-vs-weak" );
227
228 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
229 verifier.setAutoclean( false );
230 verifier.deleteArtifacts( "org.apache.maven.its.mng1895" );
231 verifier.deleteDirectory( "target" );
232 verifier.addCliOption( "-s" );
233 verifier.addCliOption( "settings.xml" );
234 Properties props = verifier.newDefaultFilterProperties();
235 props.setProperty( "@scope.a@", scopeA );
236 props.setProperty( "@scope.b@", scopeB );
237 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", props );
238 verifier.filterFile( "pom-template.xml", "pom.xml", "UTF-8", props );
239 verifier.setLogFileName( "log-" + scopeB + "-vs-" + scopeA + ".txt" );
240 verifier.executeGoal( "validate" );
241 verifier.verifyErrorFreeLog();
242 verifier.resetStreams();
243
244 return verifier;
245 }
246
247 }