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.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28
29
30
31
32
33
34 public class MavenITmng2883LegacyRepoOfflineTest
35 extends AbstractMavenIntegrationTestCase
36 {
37
38 public MavenITmng2883LegacyRepoOfflineTest()
39 {
40 super( "(2.0.9,2.1.0-M1),(2.1.0-M1,3.0-alpha-1)" );
41 }
42
43 public void testParentUnresolvable()
44 throws Exception
45 {
46 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2883" );
47 testDir = new File( testDir, "parent" );
48
49 Verifier verifier;
50
51 verifier = newVerifier( testDir.getAbsolutePath() );
52 verifier.setAutoclean( false );
53 verifier.deleteDirectory( "target" );
54 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
55
56 File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
57 verifier.newDefaultFilterProperties() );
58
59
60 verifier.addCliOption( "-s" );
61 verifier.addCliOption( settings.getName() );
62
63
64 try
65 {
66 verifier.setLogFileName( "log-parent-a.txt" );
67
68 verifier.executeGoal( "validate" );
69 }
70 catch ( VerificationException e )
71 {
72 throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!",
73 e );
74 }
75
76
77 verifier.addCliOption( "-o" );
78
79
80 verifier.setLogFileName( "log-parent-b.txt" );
81 verifier.executeGoal( "validate" );
82
83
84 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
85
86 try
87 {
88 verifier.setLogFileName( "log-parent-c.txt" );
89 verifier.executeGoal( "validate" );
90
91 fail( "Build should fail with unresolvable parent POM." );
92 }
93 catch ( VerificationException e )
94 {
95
96 }
97
98 List<String> missingMessages = new ArrayList<>();
99 missingMessages.add( " is offline" );
100 missingMessages.add( "org.apache.maven.its.mng2883:parent:pom:1.0-SNAPSHOT" );
101
102 List<String> lines = verifier.loadFile( new File( testDir, verifier.getLogFileName() ), false );
103
104 for ( String line : lines )
105 {
106 for ( Iterator<String> messageIt = missingMessages.iterator(); messageIt.hasNext(); )
107 {
108 String message = messageIt.next();
109
110 if ( line.contains( message ) )
111 {
112 messageIt.remove();
113 }
114 }
115 }
116
117 if ( !missingMessages.isEmpty() )
118 {
119 StringBuilder buffer = new StringBuilder();
120
121 buffer.append( "The following key messages were missing from build output:\n\n" );
122
123 for ( String message : missingMessages )
124 {
125 if ( buffer.length() < 1 )
126 {
127 buffer.append( "\n" );
128 }
129 buffer.append( '\'' ).append( message ).append( '\'' );
130 }
131
132 fail( buffer.toString() );
133 }
134 }
135
136 public void testDependencyUnresolvable()
137 throws Exception
138 {
139 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2883" );
140 testDir = new File( testDir, "dependency" );
141
142 Verifier verifier;
143
144 verifier = newVerifier( testDir.getAbsolutePath() );
145 verifier.setAutoclean( false );
146 verifier.deleteDirectory( "target" );
147 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
148
149 File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
150 verifier.newDefaultFilterProperties() );
151
152
153 verifier.addCliOption( "-s" );
154 verifier.addCliOption( settings.getName() );
155
156
157 try
158 {
159 verifier.setLogFileName( "log-dep-a.txt" );
160
161 verifier.executeGoal( "validate" );
162 }
163 catch ( VerificationException e )
164 {
165 throw new VerificationException( "Build should succeed the first time through when NOT in offline mode!",
166 e );
167 }
168
169
170 verifier.addCliOption( "-o" );
171
172
173 verifier.setLogFileName( "log-dep-b.txt" );
174 verifier.executeGoal( "validate" );
175
176
177 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
178
179 try
180 {
181 verifier.setLogFileName( "log-dep-c.txt" );
182 verifier.executeGoal( "validate" );
183
184 fail( "Build should fail with unresolvable dependency artifact." );
185 }
186 catch ( VerificationException e )
187 {
188
189 }
190
191 List<String> missingMessages = new ArrayList<>();
192
193
194 missingMessages.add( "offline mode." );
195 missingMessages.add( "org.apache.maven.its.mng2883:dep:jar:1.0-SNAPSHOT" );
196
197 List<String> lines = verifier.loadFile( new File( testDir, verifier.getLogFileName() ), false );
198
199 for ( String line : lines )
200 {
201 for ( Iterator<String> messageIt = missingMessages.iterator(); messageIt.hasNext(); )
202 {
203 String message = (String) messageIt.next();
204
205 if ( line.contains( message ) )
206 {
207 messageIt.remove();
208 }
209 }
210 }
211
212 if ( !missingMessages.isEmpty() )
213 {
214 StringBuilder buffer = new StringBuilder();
215
216 buffer.append( "The following key messages were missing from build output:\n\n" );
217
218 for ( String message : missingMessages )
219 {
220 if ( buffer.length() < 1 )
221 {
222 buffer.append( "\n" );
223 }
224 buffer.append( '\'' ).append( message ).append( '\'' );
225 }
226
227 fail( buffer.toString() );
228 }
229 }
230
231 public void testPluginUnresolvable()
232 throws Exception
233 {
234 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2883" );
235 testDir = new File( testDir, "plugin" );
236
237 Verifier verifier;
238
239 verifier = newVerifier( testDir.getAbsolutePath() );
240 verifier.setAutoclean( false );
241 verifier.deleteDirectory( "target" );
242 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
243
244 File settings = verifier.filterFile( "../settings-template.xml", "settings.xml", "UTF-8",
245 verifier.newDefaultFilterProperties() );
246
247
248 verifier.addCliOption( "-s" );
249 verifier.addCliOption( settings.getName() );
250
251 verifier.setLogFileName( "log-plugin-a.txt" );
252 verifier.executeGoal( "org.apache.maven.its.mng2883:plugin:1.0-SNAPSHOT:run" );
253
254
255 verifier.addCliOption( "-o" );
256
257
258 verifier.setLogFileName( "log-plugin-b.txt" );
259 verifier.executeGoal( "org.apache.maven.its.mng2883:plugin:1.0-SNAPSHOT:run" );
260
261
262 verifier.deleteArtifacts( "org.apache.maven.its.mng2883" );
263
264 try
265 {
266 verifier.setLogFileName( "log-plugin-c.txt" );
267 verifier.executeGoal( "org.apache.maven.its.mng2883:plugin:1.0-SNAPSHOT:run" );
268
269 fail( "Build should fail with unresolvable plugin artifact." );
270 }
271 catch ( VerificationException e )
272 {
273
274 }
275
276 List<String> missingMessages = new ArrayList<>();
277 missingMessages.add( " is offline" );
278 missingMessages.add( "org.apache.maven.its.mng2883:plugin" );
279
280 List<String> lines = verifier.loadFile( new File( testDir, verifier.getLogFileName() ), false );
281
282 for ( String line : lines )
283 {
284 for ( Iterator<String> messageIt = missingMessages.iterator(); messageIt.hasNext(); )
285 {
286 String message = messageIt.next();
287
288 if ( line.contains( message ) )
289 {
290 messageIt.remove();
291 }
292 }
293 }
294
295 if ( !missingMessages.isEmpty() )
296 {
297 StringBuilder buffer = new StringBuilder();
298
299 buffer.append( "The following key messages were missing from build output:\n\n" );
300
301 for ( String message : missingMessages )
302 {
303 if ( buffer.length() < 1 )
304 {
305 buffer.append( "\n" );
306 }
307 buffer.append( '\'' ).append( message ).append( '\'' );
308 }
309
310 fail( buffer.toString() );
311 }
312 }
313
314 }