KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > ResolveTest


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy;
7
8 import java.io.File JavaDoc;
9 import java.util.Arrays JavaDoc;
10 import java.util.Date JavaDoc;
11 import java.util.HashSet JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.Set JavaDoc;
14
15 import javax.xml.parsers.SAXParser JavaDoc;
16 import javax.xml.parsers.SAXParserFactory JavaDoc;
17
18 import junit.framework.TestCase;
19
20 import org.apache.tools.ant.Project;
21 import org.apache.tools.ant.taskdefs.Delete;
22 import org.xml.sax.SAXException JavaDoc;
23 import org.xml.sax.helpers.DefaultHandler JavaDoc;
24
25 import fr.jayasoft.ivy.circular.CircularDependencyException;
26 import fr.jayasoft.ivy.circular.ErrorCircularDependencyStrategy;
27 import fr.jayasoft.ivy.circular.IgnoreCircularDependencyStrategy;
28 import fr.jayasoft.ivy.circular.WarnCircularDependencyStrategy;
29 import fr.jayasoft.ivy.report.ArtifactDownloadReport;
30 import fr.jayasoft.ivy.report.ConfigurationResolveReport;
31 import fr.jayasoft.ivy.report.DownloadStatus;
32 import fr.jayasoft.ivy.report.ResolveReport;
33 import fr.jayasoft.ivy.report.XmlReportOutputter;
34 import fr.jayasoft.ivy.resolver.BasicResolver;
35 import fr.jayasoft.ivy.resolver.DualResolver;
36 import fr.jayasoft.ivy.resolver.FileSystemResolver;
37 import fr.jayasoft.ivy.util.FileUtil;
38
39 /**
40  * @author Xavier Hanin
41  *
42  */

43 public class ResolveTest extends TestCase {
44     private final Ivy _ivy;
45     private File JavaDoc _cache;
46
47     public ResolveTest() throws Exception JavaDoc {
48         _ivy = new Ivy();
49         _ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
50     }
51
52     protected void setUp() throws Exception JavaDoc {
53         createCache();
54     }
55
56     private void createCache() {
57         _cache = new File JavaDoc("build/cache");
58         _cache.mkdirs();
59     }
60     
61     protected void tearDown() throws Exception JavaDoc {
62         cleanCache();
63     }
64
65     private void cleanCache() {
66         Delete del = new Delete();
67         del.setProject(new Project());
68         del.setDir(_cache);
69         del.execute();
70     }
71     
72     public void testResolveWithRetainingArtifactName() throws Exception JavaDoc {
73         _ivy.setCacheArtifactPattern(_ivy.substitute("[module]/[originalname].[ext]"));
74         ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod15.2/ivy-1.1.xml").toURL(),
75                 null, new String JavaDoc[] {"default"}, _cache, null, true);
76         assertNotNull(report);
77         
78         ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.1", "1.1"));
79         assertNotNull(dReports);
80         assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
81         
82         Artifact artifact = dReports[0].getArtifact();
83         assertNotNull(artifact);
84         
85         String JavaDoc cachePath = _ivy.getArchivePathInCache(artifact);
86         assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("library.jar"));
87         
88         dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
89         assertNotNull(dReports);
90         assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
91         
92         artifact = dReports[0].getArtifact();
93         assertNotNull(artifact);
94         
95         cachePath = _ivy.getArchivePathInCache(artifact);
96         assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
97     }
98     
99     public void testArtifactOrigin() throws Exception JavaDoc {
100         ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
101                 null, new String JavaDoc[] {"default"}, _cache, null, true);
102         assertNotNull(report);
103
104         ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
105         assertNotNull(dReports);
106         assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
107         
108         Artifact artifact = dReports[0].getArtifact();
109         assertNotNull(artifact);
110         
111         String JavaDoc expectedLocation = new File JavaDoc("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
112
113         // verify the origin in the report
114
ArtifactOrigin reportOrigin = dReports[0].getArtifactOrigin();
115         assertNotNull(reportOrigin);
116         assertEquals("isLocal for artifact not correct", true, reportOrigin.isLocal());
117         assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
118         
119         // verify the saved origin on disk
120
ArtifactOrigin ivyOrigin = _ivy.getSavedArtifactOrigin(_cache, artifact);
121         assertNotNull(ivyOrigin);
122         assertEquals("isLocal for artifact not correct", true, ivyOrigin.isLocal());
123         assertEquals("location for artifact not correct", expectedLocation, ivyOrigin.getLocation());
124         
125         // now resolve the same artifact again and verify the origin of the (not-downloaded) artifact
126
report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
127                 null, new String JavaDoc[] {"default"}, _cache, null, true);
128         assertNotNull(report);
129
130         dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
131         assertNotNull(dReports);
132         assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
133         assertEquals("download status not correct", DownloadStatus.NO, dReports[0].getDownloadStatus());
134         reportOrigin = dReports[0].getArtifactOrigin();
135         assertNotNull(reportOrigin);
136         assertEquals("isLocal for artifact not correct", true, reportOrigin.isLocal());
137         assertEquals("location for artifact not correct", expectedLocation, reportOrigin.getLocation());
138     }
139
140     public void testUseOrigin() throws Exception JavaDoc {
141         ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
142                 null, new String JavaDoc[] {"default"}, _cache, null, true, false, true, true, null);
143         assertNotNull(report);
144
145         ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
146         assertNotNull(dReports);
147         assertEquals("number of downloaded artifacts not correct.", 1, dReports.length);
148         assertEquals("download status not correct: should not download the artifact in useOrigin mode.", DownloadStatus.NO, dReports[0].getDownloadStatus());
149         
150         Artifact artifact = dReports[0].getArtifact();
151         assertNotNull(artifact);
152         
153         String JavaDoc expectedLocation = new File JavaDoc("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
154
155         ArtifactOrigin origin = _ivy.getSavedArtifactOrigin(_cache, artifact);
156         File JavaDoc artInCache = new File JavaDoc(_cache, _ivy.getArchivePathInCache(artifact, origin));
157         assertFalse("should not download artifact in useOrigin mode.", artInCache.exists());
158         assertEquals("location for artifact not correct.", expectedLocation, _ivy.getArchiveFileInCache(_cache, artifact).getAbsolutePath());
159     }
160
161     public void testResolveSimple() throws Exception JavaDoc {
162         // mod1.1 depends on mod1.2
163
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
164                 null, new String JavaDoc[] {"*"}, _cache, null, true);
165         assertNotNull(report);
166         ModuleDescriptor md = report.getModuleDescriptor();
167         assertNotNull(md);
168         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
169         assertEquals(mrid, md.getModuleRevisionId());
170         
171         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
172         
173         // dependencies
174
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
175         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
176     }
177
178     public void testResolveBadStatus() throws Exception JavaDoc {
179         // mod1.4 depends on modfailure, modfailure has a bad status
180
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml").toURL(),
181                 null, new String JavaDoc[] {"*"}, _cache, null, true);
182         assertNotNull(report);
183         assertTrue(report.hasError());
184     }
185
186     public void testResolveNoRevisionInPattern() throws Exception JavaDoc {
187         // module1 depends on latest version of module2, for which there is no revision in the pattern
188
Ivy ivy = new Ivy();
189         ivy.configure(new File JavaDoc("test/repositories/norev/ivyconf.xml").toURL());
190         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/norev/ivy.xml").toURL(),
191                 null, new String JavaDoc[] {"*"}, _cache, null, true);
192         assertNotNull(report);
193         assertFalse(report.hasError());
194     }
195
196     public void testResolveNoRevisionInDep() throws Exception JavaDoc {
197         // mod1.4 depends on mod1.6, in which the ivy file has no revision
198
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml").toURL(),
199                 null, new String JavaDoc[] {"*"}, _cache, null, true);
200         assertNotNull(report);
201         assertTrue(report.hasError());
202     }
203
204     public void testResolveNoRevisionNowhere() throws Exception JavaDoc {
205         // test case for IVY-258
206
// module1 depends on latest version of module2, which contains no revision in its ivy file, nor in the pattern
207
Ivy ivy = new Ivy();
208         ivy.configure(new File JavaDoc("test/repositories/IVY-258/ivyconf.xml").toURL());
209         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-258/ivy.xml").toURL(),
210                 null, new String JavaDoc[] {"*"}, _cache, null, true);
211         assertFalse(report.hasError());
212         
213         ((BasicResolver)ivy.getResolver("myresolver")).setCheckconsistency(false);
214         report = ivy.resolve(new File JavaDoc("test/repositories/IVY-258/ivy.xml").toURL(),
215                 null, new String JavaDoc[] {"*"}, _cache, null, true);
216         assertFalse(report.hasError());
217     }
218
219     public void testResolveRequiresIvyFile() throws Exception JavaDoc {
220         // mod1.1 depends on mod1.2, mod1.2 has no ivy file
221
Ivy ivy = new Ivy();
222         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
223         ((FileSystemResolver)ivy.getResolver("1")).setAllownomd(false);
224         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
225                 null, new String JavaDoc[] {"*"}, _cache, null, true);
226         assertNotNull(report);
227         assertTrue(report.hasError());
228     }
229
230     public void testResolveOtherConfiguration() throws Exception JavaDoc {
231         ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-other.xml"), null, new String JavaDoc[] {"test"}, _cache, null, true);
232         
233         assertNotNull(report);
234         assertFalse(report.hasError());
235         
236         assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("test").getArtifactsNumber());
237     }
238
239     public void testResolveWithSlashes() throws Exception JavaDoc {
240         // test case for IVY-198
241
// module depends on mod1.2
242
ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-198.xml"),
243                 null, new String JavaDoc[] {"*"}, _cache, null, true);
244         assertNotNull(report);
245         ModuleDescriptor md = report.getModuleDescriptor();
246         assertNotNull(md);
247         ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg/mydep", "system/module", "1.0");
248         assertEquals(mrid, md.getModuleRevisionId());
249         
250         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
251         
252         // dependencies
253
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
254         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
255
256         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("yourorg/yourdep", "yoursys/yourmod", "1.0")).exists());
257         assertTrue(_ivy.getArchiveFileInCache(_cache, "yourorg/yourdep", "yoursys/yourmod", "1.0", "yourmod", "jar", "jar").exists());
258     }
259
260     public void testFromCache() throws Exception JavaDoc {
261         // mod1.1 depends on mod1.2
262

263         // we first do a simple resolve so that module is in cache
264
_ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
265                 null, new String JavaDoc[] {"*"}, _cache, null, true);
266
267         // we now use a badly configured ivy, so that it can't find module in repository
268
Ivy ivy = new Ivy();
269         ivy.configure(new File JavaDoc("test/repositories/bugIVY-56/ivyconf.xml"));
270         
271         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
272                 null, new String JavaDoc[] {"*"}, _cache, null, true);
273         assertFalse(report.hasError());
274
275         ModuleDescriptor md = report.getModuleDescriptor();
276
277         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
278         assertEquals(mrid, md.getModuleRevisionId());
279         
280         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
281         
282         // dependencies
283
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
284         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
285     }
286
287     public void testFromCache2() throws Exception JavaDoc {
288         // mod1.1 depends on mod1.2
289

290         // configuration
291
Ivy ivy = new Ivy();
292         DualResolver resolver = new DualResolver();
293         resolver.setName("dual");
294         FileSystemResolver r = new FileSystemResolver();
295         r.setName("1");
296         r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]");
297         resolver.add(r);
298         r = new FileSystemResolver();
299         r.setName("2");
300         r.addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]");
301         resolver.add(r);
302         ivy.addResolver(resolver);
303         ivy.setDefaultResolver("dual");
304         
305         // set up repository
306
File JavaDoc art = new File JavaDoc("build/testCache2/mod1.2-2.0.jar");
307         FileUtil.copy(new File JavaDoc("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null);
308
309         // we first do a simple resolve so that module is in cache
310
ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
311                 null, new String JavaDoc[] {"*"}, _cache, null, true);
312         assertFalse(report.hasError());
313
314         // now we clean the repository to simulate repo not available (network pb for instance)
315
Delete del = new Delete();
316         del.setProject(new Project());
317         del.setDir(new File JavaDoc("build/testCache2"));
318         del.execute();
319         
320         // now do a new resolve: it should use cached data
321
report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
322                 null, new String JavaDoc[] {"*"}, _cache, null, true);
323         assertFalse(report.hasError());
324
325         ModuleDescriptor md = report.getModuleDescriptor();
326
327         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
328         assertEquals(mrid, md.getModuleRevisionId());
329         
330         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
331         
332         // dependencies
333
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
334         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
335     }
336
337     public void testFromCacheOnly() throws Exception JavaDoc {
338         Ivy ivy = new Ivy();
339         ivy.configure(new File JavaDoc("test/repositories/bugIVY-56/ivyconf.xml"));
340         
341 // ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
342
// null, new String[] {"*"}, _cache, null, true);
343
// // should have an error, the conf is bad and the dependency should not be found
344
// assertTrue(report.hasError());
345

346         // put necessary stuff in cache, and it should now be ok
347
File JavaDoc ivyfile = ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
348         File JavaDoc art = ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar");
349         FileUtil.copy(ResolveTest.class.getResource("ivy-mod1.2.xml"), ivyfile, null);
350         FileUtil.copy(new File JavaDoc("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), art, null);
351
352         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
353                 null, new String JavaDoc[] {"*"}, _cache, null, true);
354         assertFalse(report.hasError());
355     }
356
357     public void testChangeCacheLayout() throws Exception JavaDoc {
358         Ivy ivy = new Ivy();
359         ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
360         ivy.setCacheIvyPattern("[module]/ivy.xml");
361         ivy.setCacheArtifactPattern("[artifact].[ext]");
362
363         // mod1.1 depends on mod1.2
364
ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
365                 null, new String JavaDoc[] {"*"}, _cache, null, true);
366         assertNotNull(report);
367         ModuleDescriptor md = report.getModuleDescriptor();
368         assertNotNull(md);
369         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
370         assertEquals(mrid, md.getModuleRevisionId());
371         
372         assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
373         
374         // dependencies
375
assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
376         assertTrue(new File JavaDoc(_cache, "mod1.2/ivy.xml").exists());
377         assertTrue(ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
378         assertTrue(new File JavaDoc(_cache, "mod1.2.jar").exists());
379     }
380
381     public void testResolveExtends() throws Exception JavaDoc {
382         // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
383
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(),
384                 null, new String JavaDoc[] {"extension"}, _cache, null, true);
385         assertNotNull(report);
386         ModuleDescriptor md = report.getModuleDescriptor();
387         assertNotNull(md);
388         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3");
389         assertEquals(mrid, md.getModuleRevisionId());
390         
391         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
392         
393         // dependencies from default
394
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
395         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
396     }
397
398     public void testResolveExtended() throws Exception JavaDoc {
399         // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
400
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(),
401                 null, new String JavaDoc[] {"default"}, _cache, null, true);
402         assertNotNull(report);
403         ModuleDescriptor md = report.getModuleDescriptor();
404         assertNotNull(md);
405         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3");
406         assertEquals(mrid, md.getModuleRevisionId());
407         
408         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
409         
410         // dependencies from default
411
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
412         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
413     }
414
415     public void testResolveExtendedAndExtends() throws Exception JavaDoc {
416         // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
417
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml").toURL(),
418                 null, new String JavaDoc[] {"default", "extension"}, _cache, null, true);
419         assertNotNull(report);
420         ModuleDescriptor md = report.getModuleDescriptor();
421         assertNotNull(md);
422         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "0.3");
423         assertEquals(mrid, md.getModuleRevisionId());
424         ConfigurationResolveReport crr = report.getConfigurationReport("default");
425         assertNotNull(crr);
426         assertEquals(1, crr.getArtifactsNumber());
427         crr = report.getConfigurationReport("extension");
428         assertNotNull(crr);
429         assertEquals(1, crr.getArtifactsNumber());
430         
431         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
432         
433         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
434         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
435     }
436
437     public void testResolveMultipleExtends() throws Exception JavaDoc {
438         // mod6.2 has two confs default and extension
439
// mod6.2 depends on mod6.1 in conf (default->extension)
440
// conf extension extends default
441
// mod6.1 has two confs default and extension
442
// mod6.1 depends on mod1.2 2.0 in conf (default->default)
443
// conf extension extends default
444
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml").toURL(),
445                 null, new String JavaDoc[] {"default", "extension"}, _cache, null, true);
446         assertNotNull(report);
447         assertFalse(report.hasError());
448         ModuleDescriptor md = report.getModuleDescriptor();
449         assertNotNull(md);
450         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.3");
451         assertEquals(mrid, md.getModuleRevisionId());
452         ConfigurationResolveReport crr = report.getConfigurationReport("default");
453         assertNotNull(crr);
454         assertEquals(2, crr.getArtifactsNumber());
455         crr = report.getConfigurationReport("extension");
456         assertNotNull(crr);
457         assertEquals(2, crr.getArtifactsNumber());
458         
459         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
460         
461         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists());
462         assertTrue(_ivy.getArchiveFileInCache(_cache, "org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists());
463
464         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
465         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
466     }
467
468     public void testResolveMultipleExtendsAndConfs() throws Exception JavaDoc {
469         // Test case for IVY-240
470
//
471
// mod6.3 1.1 has four confs libraries, run (extends libraries), compile (extends run) and test (extends libraries)
472
// mod6.3 depends on mod6.2 2.0 in conf (run->default)
473
// mod6.3 depends on mod6.1 2.+ in conf (test->default)
474
// mod6.2 2.0 depends on mod6.1 2.0 in conf (default->standalone)
475
// mod6.1 2.0 has two confs default and standalone
476
// mod6.1 2.0 depends on mod1.2 2.2 in conf (default->default)
477
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.3/ivy-1.1.xml").toURL(),
478                 null, new String JavaDoc[] {"*"}, _cache, null, true);
479         assertNotNull(report);
480         assertFalse(report.hasError());
481         ModuleDescriptor md = report.getModuleDescriptor();
482         assertNotNull(md);
483         ConfigurationResolveReport crr = report.getConfigurationReport("libraries");
484         assertEquals(0, crr.getArtifactsNumber());
485         
486         crr = report.getConfigurationReport("run");
487         assertEquals(2, crr.getArtifactsNumber());
488         assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr);
489         assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr);
490         
491         crr = report.getConfigurationReport("compile");
492         assertEquals(2, crr.getArtifactsNumber());
493         assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2", "jar", "jar", crr);
494         assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr);
495         
496         crr = report.getConfigurationReport("test");
497         assertEquals(2, crr.getArtifactsNumber());
498         assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1", "jar", "jar", crr);
499         assertContainsArtifact("org1", "mod1.2", "2.2", "mod1.2", "jar", "jar", crr);
500     }
501
502     public void testResolveMultipleConfsWithLatest() throws Exception JavaDoc {
503         // Test case for IVY-188
504
//
505
// mod6.2 has two confs compile and run
506
// depends on mod6.1 in conf (compile->default)
507
// depends on mod1.2 latest (which is 2.2) in conf (run->default)
508
// mod6.1
509
// depends on mod1.2 2.2
510
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml").toURL(),
511                 null, new String JavaDoc[] {"compile", "run"}, _cache, null, true);
512         assertNotNull(report);
513         assertFalse(report.hasError());
514
515         ConfigurationResolveReport crr = report.getConfigurationReport("compile");
516         assertNotNull(crr);
517         assertEquals(2, crr.getArtifactsNumber());
518         crr = report.getConfigurationReport("run");
519         assertNotNull(crr);
520         assertEquals(1, crr.getArtifactsNumber());
521
522         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
523         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
524     }
525
526     public void testResolveMultipleConfsWithConflicts() throws Exception JavaDoc {
527         // Test case for IVY-173
528
//
529
// mod6.2 has two confs compile and run
530
// depends on mod1.2 2.1 in conf (compile->default)
531
// depends on mod1.1 1.0 in conf (*->default)
532
// depends on mod6.1 in conf (*->default)
533
// mod6.1
534
// depends on mod1.2 2.1
535
// mod1.1
536
// depends on mod1.2 2.0
537
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml").toURL(),
538                 null, new String JavaDoc[] {"compile", "run"}, _cache, null, true);
539         assertNotNull(report);
540         assertFalse(report.hasError());
541         ModuleDescriptor md = report.getModuleDescriptor();
542         assertNotNull(md);
543         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.5");
544         assertEquals(mrid, md.getModuleRevisionId());
545         ConfigurationResolveReport crr = report.getConfigurationReport("compile");
546         assertNotNull(crr);
547         assertEquals(3, crr.getArtifactsNumber());
548         crr = report.getConfigurationReport("run");
549         assertNotNull(crr);
550         assertEquals(3, crr.getArtifactsNumber());
551         
552         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
553         
554         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org6", "mod6.1", "0.5")).exists());
555         assertTrue(_ivy.getArchiveFileInCache(_cache, "org6", "mod6.1", "0.5", "mod6.1", "jar", "jar").exists());
556
557         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
558         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
559
560         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
561         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
562
563         assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
564         assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
565     }
566
567     public void testResolveMultipleExtends2() throws Exception JavaDoc {
568         // same as before, except that mod6.2 depends on mod1.2 2.1 extension->default
569
// so mod1.2 2.0 should be evicted in conf extension
570
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml").toURL(),
571                 null, new String JavaDoc[] {"default", "extension"}, _cache, null, true);
572         assertNotNull(report);
573         assertFalse(report.hasError());
574         ModuleDescriptor md = report.getModuleDescriptor();
575         assertNotNull(md);
576         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.2", "0.4");
577         assertEquals(mrid, md.getModuleRevisionId());
578         ConfigurationResolveReport crr = report.getConfigurationReport("default");
579         assertNotNull(crr);
580         assertEquals(2, crr.getArtifactsNumber());
581         IvyNode node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
582         assertNotNull(node);
583         assertFalse(node.isEvicted("default"));
584         crr = report.getConfigurationReport("extension");
585         assertNotNull(crr);
586         assertEquals(2, crr.getArtifactsNumber());
587         node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
588         assertNotNull(node);
589         assertTrue(node.isEvicted("extension"));
590         node = crr.getDependency(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"));
591         assertNotNull(node);
592         assertFalse(node.isEvicted("extension"));
593         
594         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
595         
596         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org6", "mod6.1", "0.4")).exists());
597         assertTrue(_ivy.getArchiveFileInCache(_cache, "org6", "mod6.1", "0.4", "mod6.1", "jar", "jar").exists());
598
599         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
600         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
601
602         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
603         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
604     }
605
606     public void testResolveSeveralDefaultWithArtifacts() throws Exception JavaDoc {
607         // test case for IVY-261
608
// mod1.6 depends on
609
// mod1.4, which depends on mod1.3 and selects one of its artifacts
610
// mod1.3 and selects two of its artifacts
611
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml").toURL(),
612                 null, new String JavaDoc[] {"*"}, _cache, null, true);
613         assertFalse(report.hasError());
614         
615         // dependencies
616
assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar").exists());
617         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar").exists());
618     }
619
620     public void testResolveSeveralDefaultWithArtifactsAndConfs() throws Exception JavaDoc {
621         // test case for IVY-283
622
Ivy ivy = new Ivy();
623         ivy.configure(new File JavaDoc("test/repositories/IVY-283/ivyconf.xml"));
624         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-283/ivy.xml").toURL(),
625                 null, new String JavaDoc[] {"*"}, _cache, null, true);
626         assertFalse(report.hasError());
627         
628         // dependencies
629
ConfigurationResolveReport crr = report.getConfigurationReport("build");
630         assertNotNull(crr);
631         assertEquals(3, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "C", "1.0")).length);
632
633         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "C", "1.0", "lib_c_a", "jar", "jar").exists());
634         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "C", "1.0", "lib_c_b", "jar", "jar").exists());
635         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "C", "1.0", "lib_c_d", "jar", "jar").exists());
636     }
637     
638     public void testResolveSeveralDefaultWithArtifactsAndConfs2() throws Exception JavaDoc {
639         // second test case for IVY-283
640
Ivy ivy = new Ivy();
641         ivy.configure(new File JavaDoc("test/repositories/IVY-283/ivyconf.xml"));
642         ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-283/ivy-d.xml").toURL(),
643                 null, new String JavaDoc[] {"*"}, _cache, null, true);
644         assertFalse(report.hasError());
645         
646         // dependencies
647
ConfigurationResolveReport crr = report.getConfigurationReport("build");
648         assertNotNull(crr);
649         assertEquals(9, crr.getDownloadReports(ModuleRevisionId.newInstance("medicel", "module_a", "local")).length);
650
651         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_a", "jar", "jar").exists());
652         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_b", "jar", "jar").exists());
653         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_c", "jar", "jar").exists());
654         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_d", "jar", "jar").exists());
655         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_e", "jar", "jar").exists());
656         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_f", "jar", "jar").exists());
657         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_g", "jar", "jar").exists());
658         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_h", "jar", "jar").exists());
659         assertTrue(_ivy.getArchiveFileInCache(_cache, "medicel", "module_a", "local", "lib_a_i", "jar", "jar").exists());
660     }
661     
662
663
664     public void testResolveDefaultWithArtifactsConf1() throws Exception JavaDoc {
665         // mod2.2 depends on mod1.3 and selects its artifacts
666
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(),
667                 null, new String JavaDoc[] {"myconf1"}, _cache, null, true);
668         assertNotNull(report);
669         ModuleDescriptor md = report.getModuleDescriptor();
670         assertNotNull(md);
671         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5");
672         assertEquals(mrid, md.getModuleRevisionId());
673         
674         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
675         
676         // dependencies
677
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists());
678         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar").exists());
679         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar").exists());
680         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists());
681     }
682     
683     public void testResolveDefaultWithArtifactsConf2() throws Exception JavaDoc {
684         // mod2.2 depends on mod1.3 and selects its artifacts
685
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURL(),
686                 null, new String JavaDoc[] {"myconf2"}, _cache, null, true);
687         assertNotNull(report);
688         ModuleDescriptor md = report.getModuleDescriptor();
689         assertNotNull(md);
690         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.2", "0.5");
691         assertEquals(mrid, md.getModuleRevisionId());
692         
693         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
694         
695         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.3", "3.0")).exists());
696         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-A", "jar", "jar").exists());
697         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3-B", "jar", "jar").exists());
698         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org1", "mod1.3", "3.0", "mod1.3", "jar", "jar").exists());
699     }
700     
701     public void testResolveWithDependencyArtifactsConf1() throws Exception JavaDoc {
702         // mod2.3 depends on mod2.1 and selects its artifacts in myconf1
703
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(),
704                 null, new String JavaDoc[] {"myconf1"}, _cache, null, true);
705         assertNotNull(report);
706         ModuleDescriptor md = report.getModuleDescriptor();
707         assertNotNull(md);
708         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4");
709         assertEquals(mrid, md.getModuleRevisionId());
710         
711         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
712         
713         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
714         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
715         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
716         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
717     }
718     
719     public void testResolveWithDependencyArtifactsConf2() throws Exception JavaDoc {
720         // mod2.3 depends on mod2.1 and selects its artifacts in myconf1
721
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml").toURL(),
722                 null, new String JavaDoc[] {"myconf2"}, _cache, null, true);
723         assertNotNull(report);
724         ModuleDescriptor md = report.getModuleDescriptor();
725         assertNotNull(md);
726         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.4");
727         assertEquals(mrid, md.getModuleRevisionId());
728         
729         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
730         
731         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
732         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
733         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
734         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
735     }
736     
737     public void testResolveWithDependencyArtifactsWithoutConf() throws Exception JavaDoc {
738         // mod2.3 depends on mod2.1 and selects its artifacts
739
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml").toURL(),
740                 null, new String JavaDoc[] {"*"}, _cache, null, true);
741         assertNotNull(report);
742         ModuleDescriptor md = report.getModuleDescriptor();
743         assertNotNull(md);
744         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.5");
745         assertEquals(mrid, md.getModuleRevisionId());
746         
747         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
748         
749         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
750         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
751         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
752         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
753     }
754     
755     public void testResolveWithExcludesArtifacts() throws Exception JavaDoc {
756         // mod2.3 depends on mod2.1 and selects its artifacts
757
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml").toURL(),
758                 null, new String JavaDoc[] {"*"}, _cache, null, true);
759         assertNotNull(report);
760         ModuleDescriptor md = report.getModuleDescriptor();
761         assertNotNull(md);
762         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6");
763         assertEquals(mrid, md.getModuleRevisionId());
764         
765         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
766         
767         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
768         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
769         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
770         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
771     }
772     
773     public void testResolveWithExcludesArtifacts2() throws Exception JavaDoc {
774         // mod2.3 depends on mod2.1 and badly excludes artifacts with incorrect matcher
775
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml").toURL(),
776                 null, new String JavaDoc[] {"*"}, _cache, null, true);
777         assertNotNull(report);
778         ModuleDescriptor md = report.getModuleDescriptor();
779         assertNotNull(md);
780         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.2");
781         assertEquals(mrid, md.getModuleRevisionId());
782         
783         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
784         
785         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
786         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
787         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
788         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
789     }
790     
791     public void testResolveWithExcludesArtifacts3() throws Exception JavaDoc {
792         // mod2.3 depends on mod2.1 and excludes artifacts with exact matcher
793
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml").toURL(),
794                 null, new String JavaDoc[] {"*"}, _cache, null, true);
795         assertNotNull(report);
796         ModuleDescriptor md = report.getModuleDescriptor();
797         assertNotNull(md);
798         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.3");
799         assertEquals(mrid, md.getModuleRevisionId());
800         
801         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
802         
803         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
804         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
805         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
806         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
807     }
808     
809     public void testResolveWithExcludesArtifacts4() throws Exception JavaDoc {
810         // mod2.3 depends on mod2.1 and excludes artifacts with regexp matcher
811
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml").toURL(),
812                 null, new String JavaDoc[] {"*"}, _cache, null, true);
813         assertNotNull(report);
814         ModuleDescriptor md = report.getModuleDescriptor();
815         assertNotNull(md);
816         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.4");
817         assertEquals(mrid, md.getModuleRevisionId());
818         
819         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
820         
821         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
822         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
823         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
824         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
825     }
826     
827     public void testResolveWithExcludesArtifacts5() throws Exception JavaDoc {
828         // mod2.3 depends on mod2.1 and excludes artifacts with glob matcher
829
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml").toURL(),
830                 null, new String JavaDoc[] {"*"}, _cache, null, true);
831         assertNotNull(report);
832         ModuleDescriptor md = report.getModuleDescriptor();
833         assertNotNull(md);
834         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.3", "0.6.5");
835         assertEquals(mrid, md.getModuleRevisionId());
836         
837         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
838         
839         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
840         assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
841         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
842         assertTrue(!_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "mod2.1", "jar", "jar").exists());
843     }
844     
845     public void testResolveTransitiveDependencies() throws Exception JavaDoc {
846         // mod2.1 depends on mod1.1 which depends on mod1.2
847
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(),
848                 null, new String JavaDoc[] {"*"}, _cache, null, true);
849         assertNotNull(report);
850         ModuleDescriptor md = report.getModuleDescriptor();
851         assertNotNull(md);
852         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3");
853         assertEquals(mrid, md.getModuleRevisionId());
854         
855         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
856         
857         // dependencies
858
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
859         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
860
861         assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
862         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
863     }
864     
865     public void testResolveTransitiveDisabled() throws Exception JavaDoc {
866         // mod2.1 depends on mod1.1 which depends on mod1.2
867
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml").toURL(),
868                 null, new String JavaDoc[] {"*"}, _cache, null, true, false, false, null);
869         assertNotNull(report);
870         ModuleDescriptor md = report.getModuleDescriptor();
871         assertNotNull(md);
872         ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.3");
873         assertEquals(mrid, md.getModuleRevisionId());
874         
875         assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
876         
877         // dependencies
878
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
879         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
880
881         assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
882         assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
883     }
884     
885     public void testDependenciesOrder() throws Exception JavaDoc {
886         ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-225.xml"),
887                 null, new String JavaDoc[] {"default"}, _cache, null, true);
888         
889         Set JavaDoc revisions = report.getConfigurationReport("default").getModuleRevisionIds();
890         assertTrue("number of revisions is not correct", revisions.size() >= 3);
891         
892         // verify the first 3 modules against the ones in the ivy file
893
Iterator JavaDoc it = revisions.iterator();
894         ModuleRevisionId revId1 = (ModuleRevisionId) it.next();
895         assertEquals("mod1.2", revId1.getName());
896         assertEquals("1.1", revId1.getRevision());
897         
898         ModuleRevisionId revId2 = (ModuleRevisionId) it.next();
899         assertEquals("mod3.2", revId2.getName());
900         assertEquals("1.4", revId2.getRevision());
901         
902         ModuleRevisionId revId3 = (ModuleRevisionId) it.next();
903         assertEquals("mod5.1", revId3.getName());
904         assertEquals("4.2", revId3.getRevision());
905     }
906     
907     public void testDisableTransitivityPerConfiguration() throws Exception JavaDoc {
908         // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
909
// compile conf is not transitive
910

911         // first we resolve compile conf only
912
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(),
913                 null, new String JavaDoc[] {"compile"}, _cache, null, true);
914         
915         // dependencies
916
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
917         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
918
919         assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
920         assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
921
922         // then we resolve runtime conf
923
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(),
924                 null, new String JavaDoc[] {"runtime"}, _cache, null, true);
925         
926         // dependencies
927
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
928         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
929
930         // same as before, but resolve both confs in one call
931
ResolveReport r = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml").toURL(),
932                 null, new String JavaDoc[] {"runtime", "compile"}, _cache, null, true);
933         assertFalse(r.hasError());
934         assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber());
935         assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber());
936     }
937     
938     public void testDisableTransitivityPerConfiguration2() throws Exception JavaDoc {
939         // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
940
// compile conf is not transitive
941
// compile extends runtime
942

943         // first we resolve compile conf only
944
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(),
945                 null, new String JavaDoc[] {"compile"}, _cache, null, true);
946         
947         // dependencies
948
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
949         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
950
951         assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
952         assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
953
954         // then we resolve runtime conf
955
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(),
956                 null, new String JavaDoc[] {"runtime"}, _cache, null, true);
957         
958         // dependencies
959
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
960         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
961
962         // same as before, but resolve both confs in one call
963
ResolveReport r = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml").toURL(),
964                 null, new String JavaDoc[] {"runtime", "compile"}, _cache, null, true);
965         assertFalse(r.hasError());
966         assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber());
967         assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber());
968     }
969     
970     public void testDisableTransitivityPerConfiguration3() throws Exception JavaDoc {
971         // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
972
// compile conf is not transitive
973
// runtime extends compile
974

975         // first we resolve compile conf only
976
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(),
977                 null, new String JavaDoc[] {"compile"}, _cache, null, true);
978         
979         // dependencies
980
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
981         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
982
983         assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
984         assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
985
986         // then we resolve runtime conf
987
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(),
988                 null, new String JavaDoc[] {"runtime"}, _cache, null, true);
989         
990         // dependencies
991
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
992         assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
993
994         // same as before, but resolve both confs in one call
995
ResolveReport r = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml").toURL(),
996                 null, new String JavaDoc[] {"compile", "runtime"}, _cache, null, true);
997         assertFalse(r.hasError());
998         assertEquals(1, r.getConfigurationReport("compile").getArtifactsNumber());
999         assertEquals(2, r.getConfigurationReport("runtime").getArtifactsNumber());
1000    }
1001    
1002    public void testDisableTransitivityPerConfiguration4() throws Exception JavaDoc {
1003        // mod2.2 (A,B,compile) depends on mod 2.1 (A->runtime;B->compile)
1004
// compile is not transitive and extends A and B
1005
//
1006
// mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
1007
// compile conf is not transitive and extends runtime
1008

1009        ResolveReport r = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml").toURL(),
1010                null, new String JavaDoc[] {"*"}, _cache, null, true);
1011        assertFalse(r.hasError());
1012
1013        // here we should get all three recursive dependencies
1014
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1015                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1016                ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
1017                ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
1018        })), r.getConfigurationReport("A").getModuleRevisionIds());
1019
1020        // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1
1021
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1022                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1023                ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
1024        })), r.getConfigurationReport("B").getModuleRevisionIds());
1025        
1026        // here we should get only mod2.1 cause compile is not transitive
1027
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1028                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1029        })), r.getConfigurationReport("compile").getModuleRevisionIds());
1030    }
1031    
1032    public void testDisableTransitivityPerConfiguration5() throws Exception JavaDoc {
1033        // mod2.2 (A,B,compile) depends on
1034
// mod 2.1 (A->runtime;B->compile)
1035
// mod1.1 (A->*) ]0.9.9,1.0] (which resolves to 1.0)
1036
// compile is not transitive and extends A and B
1037
//
1038
// mod2.1 (compile, runtime) depends on mod1.1 1.0 which depends on mod1.2 2.0
1039
// compile conf is not transitive and extends runtime
1040

1041        ResolveReport r = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml").toURL(),
1042                null, new String JavaDoc[] {"A","B","compile"}, _cache, null, true);
1043        assertFalse(r.hasError());
1044        
1045        // here we should get all three recursive dependencies
1046
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1047                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1048                ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
1049                ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"),
1050        })), r.getConfigurationReport("A").getModuleRevisionIds());
1051
1052        // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1
1053
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1054                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1055                ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
1056        })), r.getConfigurationReport("B").getModuleRevisionIds());
1057        
1058        // here we should get only mod2.1 cause compile is not transitive
1059
assertEquals(new HashSet JavaDoc(Arrays.asList(new ModuleRevisionId[] {
1060                ModuleRevisionId.newInstance("org2", "mod2.1", "0.3.2"),
1061                ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"),
1062        })), r.getConfigurationReport("compile").getModuleRevisionIds());
1063    }
1064    
1065    public void testResolveDiamond() throws Exception JavaDoc {
1066        // mod4.1 depends on
1067
// - mod1.1 which depends on mod1.2
1068
// - mod3.1 which depends on mod1.2
1069
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.0.xml").toURL(),
1070                null, new String JavaDoc[] {"*"}, _cache, null, true);
1071        assertNotNull(report);
1072        ModuleDescriptor md = report.getModuleDescriptor();
1073        assertNotNull(md);
1074        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.0");
1075        assertEquals(mrid, md.getModuleRevisionId());
1076        
1077        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1078        
1079        // dependencies
1080
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
1081        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
1082
1083        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1084        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1085
1086        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.0")).exists());
1087        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.0", "mod3.1", "jar", "jar").exists());
1088    }
1089
1090    public void testResolveConflict() throws Exception JavaDoc {
1091        // mod4.1 v 4.1 depends on
1092
// - mod1.1 v 1.0 which depends on mod1.2 v 2.0
1093
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1094
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.1.xml").toURL(),
1095                null, new String JavaDoc[] {"*"}, _cache, null, true);
1096        assertNotNull(report);
1097        ModuleDescriptor md = report.getModuleDescriptor();
1098        assertNotNull(md);
1099        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.1");
1100        assertEquals(mrid, md.getModuleRevisionId());
1101        
1102        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1103        
1104        // dependencies
1105
ConfigurationResolveReport crr = report.getConfigurationReport("default");
1106        assertNotNull(crr);
1107        assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).length);
1108        assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).length);
1109        
1110        File JavaDoc r = new File JavaDoc(_cache, XmlReportOutputter.getReportFileName(mrid.getModuleId(), "default"));
1111        assertTrue(r.exists());
1112        final boolean[] found = new boolean[] {false};
1113        SAXParser JavaDoc saxParser = SAXParserFactory.newInstance().newSAXParser();
1114        saxParser.parse(r, new DefaultHandler JavaDoc() {
1115            public void startElement(String JavaDoc uri,String JavaDoc localName,String JavaDoc qName,org.xml.sax.Attributes JavaDoc attributes) throws SAXException JavaDoc {
1116                if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) {
1117                    found[0] = true;
1118                }
1119            }
1120        });
1121        assertTrue(found[0]); // the report should contain the evicted revision
1122

1123        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
1124        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
1125
1126        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
1127        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
1128
1129        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1130
1131        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1132        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1133    }
1134    
1135    public void testResolveConflict2() throws Exception JavaDoc {
1136        // mod4.1 v 4.14 depends on
1137
// - mod1.1 v 1.0 which depends on mod1.2 v 2.0
1138
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1139
// - mod6.1 v 0.3 which depends on mod1.2 v 2.0
1140
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.14.xml").toURL(),
1141                null, new String JavaDoc[] {"*"}, _cache, null, true);
1142        
1143        // dependencies
1144
ConfigurationResolveReport crr = report.getConfigurationReport("default");
1145        assertNotNull(crr);
1146        assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).length);
1147        assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).length);
1148        
1149        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.14");
1150        File JavaDoc r = new File JavaDoc(_cache, XmlReportOutputter.getReportFileName(mrid.getModuleId(), "default"));
1151        assertTrue(r.exists());
1152        final boolean[] found = new boolean[] {false};
1153        SAXParser JavaDoc saxParser = SAXParserFactory.newInstance().newSAXParser();
1154        saxParser.parse(r, new DefaultHandler JavaDoc() {
1155            public void startElement(String JavaDoc uri,String JavaDoc localName,String JavaDoc qName,org.xml.sax.Attributes JavaDoc attributes) throws SAXException JavaDoc {
1156                if ("revision".equals(qName) && "2.0".equals(attributes.getValue("name"))) {
1157                    found[0] = true;
1158                }
1159            }
1160        });
1161        assertTrue(found[0]); // the report should contain the evicted revision
1162

1163        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
1164        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
1165
1166        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
1167        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
1168
1169        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1170
1171        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1172        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1173    }
1174    
1175    public void testResolveConflict3() throws Exception JavaDoc {
1176        // test case for IVY-264
1177
// a depends on x latest, y latest, z latest
1178
// x and z depends on commons-lang 1.0.1
1179
// y depends on commons-lang 2.0
1180
Ivy ivy = new Ivy();
1181        ivy.configure(new File JavaDoc("test/repositories/IVY-264/ivyconf.xml"));
1182        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-264/ivy.xml").toURL(),
1183                null, new String JavaDoc[] {"*"}, _cache, null, true);
1184        assertFalse(report.hasError());
1185        
1186        // dependencies
1187
ConfigurationResolveReport crr = report.getConfigurationReport("default");
1188        assertNotNull(crr);
1189        assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", "commons-lang", "1.0.1")).length);
1190        assertEquals(1, crr.getDownloadReports(ModuleRevisionId.newInstance("myorg", "commons-lang", "2.0")).length);
1191
1192        assertFalse(_ivy.getArchiveFileInCache(_cache, "myorg", "commons-lang", "1.0.1", "commons-lang", "jar", "jar").exists());
1193
1194        assertTrue(_ivy.getArchiveFileInCache(_cache, "myorg", "commons-lang", "2.0", "commons-lang", "jar", "jar").exists());
1195    }
1196
1197    public void testTransitiveEviction() throws Exception JavaDoc {
1198        // mod7.3 depends on mod7.2 v1.0 and on mod7.1 v2.0
1199
// mod7.2 v1.0 depends on mod7.1 v1.0 (which then should be evicted)
1200
// mod7.1 v1.0 depends on mod 1.2 v1.0 (which should be evicted by transitivity)
1201

1202        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod7.3/ivy-1.0.xml").toURL(),
1203                null, new String JavaDoc[] {"*"}, _cache, null, true);
1204        assertNotNull(report);
1205        ModuleDescriptor md = report.getModuleDescriptor();
1206        assertNotNull(md);
1207        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org7", "mod7.3", "1.0");
1208        assertEquals(mrid, md.getModuleRevisionId());
1209        
1210        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1211        
1212        // dependencies
1213
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org7", "mod7.2", "1.0")).exists());
1214        assertTrue(_ivy.getArchiveFileInCache(_cache, "org7", "mod7.2", "1.0", "mod7.2", "jar", "jar").exists());
1215
1216        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org7", "mod7.1", "2.0")).exists());
1217        assertTrue(_ivy.getArchiveFileInCache(_cache, "org7", "mod7.1", "2.0", "mod7.1", "jar", "jar").exists());
1218
1219        assertTrue(!_ivy.getArchiveFileInCache(_cache, "org7", "mod7.1", "1.0", "mod7.1", "jar", "jar").exists());
1220
1221        assertTrue(!_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1222    }
1223    
1224    public void testTransitiveEviction2() throws Exception JavaDoc {
1225        // IVY-199
1226
// mod4.1 v 4.13 depends on
1227
// - mod3.2 v 1.2.1 which depends on
1228
// - mod3.1 v 1.0 which depends on mod1.2 v 2.0
1229
// - mod1.2 v 2.1
1230
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.13.xml").toURL(),
1231                null, new String JavaDoc[] {"*"}, _cache, null, true);
1232        assertNotNull(report);
1233        
1234        // dependencies
1235
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1236        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1237
1238        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1239    }
1240    
1241    public void testResolveConflictInConf() throws Exception JavaDoc {
1242        // conflicts in separate confs are not conflicts
1243

1244        // mod2.1 conf A depends on mod1.1 which depends on mod1.2 2.0
1245
// mod2.1 conf B depends on mod1.2 2.1
1246
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml").toURL(),
1247                null, new String JavaDoc[] {"*"}, _cache, null, true);
1248        assertNotNull(report);
1249        ModuleDescriptor md = report.getModuleDescriptor();
1250        assertNotNull(md);
1251        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.1", "0.4");
1252        assertEquals(mrid, md.getModuleRevisionId());
1253        
1254        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1255        
1256        // dependencies
1257
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
1258        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
1259
1260        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1261        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1262
1263        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1264        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1265    }
1266    
1267    public void testEvictWithConf() throws Exception JavaDoc {
1268        // bug 105 - test #1
1269

1270        // mod6.1 r1.0 depends on
1271
// mod5.1 r4.2 conf A
1272
// mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
1273
//
1274
// mod5.1 r4.2 conf B depends on mod1.2 r2.0
1275
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.1/ivy-1.0.xml").toURL(),
1276                null, new String JavaDoc[] {"*"}, _cache, null, true);
1277        assertNotNull(report);
1278        ModuleDescriptor md = report.getModuleDescriptor();
1279        assertNotNull(md);
1280        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.0");
1281        assertEquals(mrid, md.getModuleRevisionId());
1282        
1283        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1284        
1285        // dependencies
1286
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists());
1287        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists());
1288        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists());
1289
1290        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists());
1291        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists());
1292
1293        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1294        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1295
1296        // should have been evicted before download
1297
assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists());
1298        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
1299        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
1300    }
1301    
1302    public void testEvictWithConf2() throws Exception JavaDoc {
1303        // same as preceding one but with inverse order, so that
1304
// eviction is done after download
1305
// bug 105 - test #2
1306

1307        // mod6.1 r1.1 depends on
1308
// mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
1309
// mod5.1 r4.2 conf A
1310
//
1311
// mod5.1 r4.2 conf B depends on mod1.2 r2.0
1312
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.1/ivy-1.1.xml").toURL(),
1313                null, new String JavaDoc[] {"*"}, _cache, null, true);
1314        assertNotNull(report);
1315        ModuleDescriptor md = report.getModuleDescriptor();
1316        assertNotNull(md);
1317        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.1");
1318        assertEquals(mrid, md.getModuleRevisionId());
1319        
1320        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1321        
1322        // dependencies
1323
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists());
1324        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists());
1325        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists());
1326
1327        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists());
1328        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists());
1329
1330        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1331        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1332
1333        // even late eviction should avoid artifact downloading
1334
assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
1335        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
1336    }
1337    
1338    public void testEvictWithConfInMultiConf() throws Exception JavaDoc {
1339        // same as preceding ones but the conflict appears in several root confs
1340
// bug 105 - test #3
1341

1342        // mod6.1 r1.2 conf A and conf B depends on
1343
// mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
1344
// mod5.1 r4.2 conf A
1345
//
1346
// mod5.1 r4.2 conf B depends on mod1.2 r2.0
1347
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.1/ivy-1.2.xml").toURL(),
1348                null, new String JavaDoc[] {"*"}, _cache, null, true);
1349        assertNotNull(report);
1350        ModuleDescriptor md = report.getModuleDescriptor();
1351        assertNotNull(md);
1352        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.2");
1353        assertEquals(mrid, md.getModuleRevisionId());
1354        
1355        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1356        
1357        // dependencies
1358
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists());
1359        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists());
1360        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists());
1361
1362        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists());
1363        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists());
1364
1365        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1366        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1367
1368        // all artifacts should be present in both confs
1369
ConfigurationResolveReport crr = report.getConfigurationReport("A");
1370        assertNotNull(crr);
1371        assertEquals(2, crr.getDownloadReports(ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).length);
1372
1373        crr = report.getConfigurationReport("B");
1374        assertNotNull(crr);
1375        assertEquals(2, crr.getDownloadReports(ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).length);
1376        
1377        // even late eviction should avoid artifact downloading
1378
assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
1379        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
1380    }
1381    
1382    public void testEvictWithConfInMultiConf2() throws Exception JavaDoc {
1383        // same as preceding one but the conflict appears in a root conf and not in another
1384
// which should keep the evicted
1385
// bug 105 - test #4
1386

1387        // mod6.1 r1.3 conf A depends on
1388
// mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
1389
//
1390
// mod6.1 r1.3 conf B depends on
1391
// mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
1392
// mod5.1 r4.2 conf A
1393
//
1394
// mod5.1 r4.2 conf B depends on mod1.2 r2.0
1395
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.1/ivy-1.3.xml").toURL(),
1396                null, new String JavaDoc[] {"*"}, _cache, null, true);
1397        assertNotNull(report);
1398        ModuleDescriptor md = report.getModuleDescriptor();
1399        assertNotNull(md);
1400        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6", "mod6.1", "1.3");
1401        assertEquals(mrid, md.getModuleRevisionId());
1402        
1403        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1404        
1405        // dependencies
1406
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).exists());
1407        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51A", "jar", "jar").exists());
1408        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.2", "art51B", "jar", "jar").exists());
1409
1410        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists());
1411        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
1412        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
1413
1414        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.2", "1.0")).exists());
1415        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.2", "1.0", "mod5.2", "jar", "jar").exists());
1416
1417        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1418        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1419
1420        // 4.2 artifacts should be present in conf B only
1421
ConfigurationResolveReport crr = report.getConfigurationReport("A");
1422        assertNotNull(crr);
1423        assertEquals(0, crr.getDownloadReports(ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).length);
1424
1425        crr = report.getConfigurationReport("B");
1426        assertNotNull(crr);
1427        assertEquals(2, crr.getDownloadReports(ModuleRevisionId.newInstance("org5", "mod5.1", "4.2")).length);
1428    }
1429    
1430    public void testResolveForce() throws Exception JavaDoc {
1431        // mod4.1 v 4.2 depends on
1432
// - mod1.2 v 2.0 and forces it
1433
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1434
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.2.xml").toURL(),
1435                null, new String JavaDoc[] {"*"}, _cache, null, true);
1436        assertNotNull(report);
1437        ModuleDescriptor md = report.getModuleDescriptor();
1438        assertNotNull(md);
1439        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.2");
1440        assertEquals(mrid, md.getModuleRevisionId());
1441        
1442        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1443        
1444        // dependencies
1445
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.1")).exists());
1446        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.1", "mod3.1", "jar", "jar").exists());
1447
1448        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1449        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1450
1451        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1452        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1453    }
1454    
1455    public void testResolveForceAfterConflictSolved() throws Exception JavaDoc {
1456        // IVY-193
1457
// mod4.1 v 4.9 depends on
1458
// - mod3.2 v 1.1 which depends on mod1.2 v 2.0
1459
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1460
// - mod1.2 v 2.0 and forces it
1461
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.9.xml").toURL(),
1462                null, new String JavaDoc[] {"*"}, _cache, null, true);
1463        assertNotNull(report);
1464        ModuleDescriptor md = report.getModuleDescriptor();
1465        assertNotNull(md);
1466        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.9");
1467        assertEquals(mrid, md.getModuleRevisionId());
1468        
1469        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1470        
1471        // dependencies
1472
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1473        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1474
1475        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1476    }
1477    
1478    public void testResolveForceAfterDependencyExist() throws Exception JavaDoc {
1479        // IVY-193
1480
// mod4.1 v 4.10 depends on
1481
// - mod3.1 v 1.0.1 which depends on mod1.2 v 2.0 and forces it
1482
// - mod3.2 v 1.2 which depends on mod1.2 v 2.1 and on mod3.1 v1.0.1
1483
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.10.xml").toURL(),
1484                null, new String JavaDoc[] {"*"}, _cache, null, true);
1485        assertNotNull(report);
1486        
1487        // dependencies
1488
assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1489
1490        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1491        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1492    }
1493    
1494    public void testResolveForceInDepOnly() throws Exception JavaDoc {
1495        // IVY-193
1496
// mod4.1 v 4.11 depends on
1497
// - mod1.2 v 2.0
1498
// - mod3.2 v 1.3 which depends on
1499
// - mod3.1 v1.1 which depends on
1500
// - mod1.2 v 2.1
1501
// - mod1.2 v 1.0 and forces it
1502
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.11.xml").toURL(),
1503                null, new String JavaDoc[] {"*"}, _cache, null, true);
1504        assertNotNull(report);
1505        
1506        // dependencies
1507
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1508        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1509
1510        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1511        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "1.0", "mod1.2", "jar", "jar").exists());
1512    }
1513    
1514    public void testResolveForceInDepOnly2() throws Exception JavaDoc {
1515        // IVY-193
1516
// mod4.1 v 4.12 depends on
1517
// - mod3.1 v1.0 which depends on
1518
// - mod1.2 v 2.0
1519
// - mod3.2 v 1.4 which depends on
1520
// - mod1.2 v 2.0 and forces it
1521
// - mod3.1 v1.1 which depends on
1522
// - mod1.2 v 2.1
1523
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.12.xml").toURL(),
1524                null, new String JavaDoc[] {"*"}, _cache, null, true);
1525        assertNotNull(report);
1526        
1527        // dependencies
1528
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1529        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1530
1531        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1532    }
1533    
1534    public void testResolveForceWithDynamicRevisions() throws Exception JavaDoc {
1535        // mod4.1 v 4.5 depends on
1536
// - mod1.2 v 1+ and forces it
1537
// - mod3.1 v 1.2 which depends on mod1.2 v 2+
1538
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.5.xml").toURL(),
1539                null, new String JavaDoc[] {"*"}, _cache, null, true);
1540        assertNotNull(report);
1541        ModuleDescriptor md = report.getModuleDescriptor();
1542        assertNotNull(md);
1543        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.5");
1544        assertEquals(mrid, md.getModuleRevisionId());
1545        
1546        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1547        
1548        // dependencies
1549
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists());
1550        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists());
1551
1552        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists());
1553        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists());
1554
1555        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
1556        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1557    }
1558    
1559    public void testResolveForceWithDynamicRevisionsAndSeveralConfs() throws Exception JavaDoc {
1560        // mod4.1 v 4.6 (conf compile, test extends compile) depends on
1561
// - mod1.2 v 1+ and forces it in conf compile
1562
// - mod3.1 v 1.2 in conf test which depends on mod1.2 v 2+
1563
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.6.xml").toURL(),
1564                null, new String JavaDoc[] {"*"}, _cache, null, true);
1565        assertNotNull(report);
1566        ModuleDescriptor md = report.getModuleDescriptor();
1567        assertNotNull(md);
1568        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.6");
1569        assertEquals(mrid, md.getModuleRevisionId());
1570        
1571        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1572        
1573        // dependencies
1574
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.2")).exists());
1575        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.2", "mod3.1", "jar", "jar").exists());
1576
1577        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists());
1578        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists());
1579
1580        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
1581        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1582    }
1583    
1584    public void testResolveForceWithDynamicRevisionsAndSeveralConfs2() throws Exception JavaDoc {
1585        // mod4.1 v 4.7 (conf compile, test extends compile) depends on
1586
// - mod1.2 v 1+ and forces it in conf compile
1587
// - mod3.1 v 1.3 in conf test->runtime
1588
// which defines confs compile, runtime extends compile
1589
// which depends on mod1.2 v 2+ in conf compile->default
1590
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod4.1/ivy-4.7.xml").toURL(),
1591                null, new String JavaDoc[] {"*"}, _cache, null, true);
1592        assertNotNull(report);
1593        ModuleDescriptor md = report.getModuleDescriptor();
1594        assertNotNull(md);
1595        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4", "mod4.1", "4.7");
1596        assertEquals(mrid, md.getModuleRevisionId());
1597        
1598        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1599        
1600        // dependencies
1601
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.3")).exists());
1602        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.3", "mod3.1", "jar", "jar").exists());
1603
1604        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists());
1605        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists());
1606
1607        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
1608        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1609    }
1610    
1611    public void testResolveForceWithDynamicRevisionsAndCyclicDependencies() throws Exception JavaDoc {
1612        // IVY-182
1613
// * has no revision
1614
// * declares conf compile, test extends compile,
1615
// * depends on
1616
// - mod1.2 v 1+ and forces it in conf compile
1617
// - mod3.1 v 1+ in conf test->runtime excluding mod4.1 (to avoid cyclic dep failure)
1618
// which defines confs compile, runtime extends compile
1619
// which depends on mod1.2 v 2+ in conf compile->default
1620
// which depends on mod4.1 v 4+ in conf compile->compile
1621
ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-182.xml"),
1622                null, new String JavaDoc[] {"*"}, _cache, null, true);
1623        assertNotNull(report);
1624        ModuleDescriptor md = report.getModuleDescriptor();
1625        assertNotNull(md);
1626        ModuleId mid = new ModuleId("test", "IVY-182");
1627        assertEquals(mid, md.getModuleRevisionId().getModuleId());
1628        
1629        // dependencies
1630
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org3", "mod3.1", "1.4")).exists());
1631        assertTrue(_ivy.getArchiveFileInCache(_cache, "org3", "mod3.1", "1.4", "mod3.1", "jar", "jar").exists());
1632
1633        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "1.1")).exists());
1634        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "1.1", "mod1.2", "jar", "jar").exists());
1635
1636        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
1637        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1638    }
1639    
1640    public void testResolveContradictoryConflictResolution() throws Exception JavaDoc {
1641        // mod10.1 v 1.0 depends on
1642
// - mod1.2 v 2.0 and forces it
1643
// - mod4.1 v 4.1 (which selects mod1.2 v 2.1 and evicts mod1.2 v 2.0)
1644
// mod4.1 v 4.1 depends on
1645
// - mod1.1 v 1.0 which depends on mod1.2 v 2.0
1646
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1647
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod10.1/ivy-1.0.xml").toURL(),
1648                null, new String JavaDoc[] {"*"}, _cache, null, true);
1649        assertNotNull(report);
1650        ModuleDescriptor md = report.getModuleDescriptor();
1651        assertNotNull(md);
1652        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org10", "mod10.1", "1.0");
1653        assertEquals(mrid, md.getModuleRevisionId());
1654        
1655        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1656        
1657        // conflicting dependencies
1658
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1659        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1660
1661        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1662        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1663    }
1664    
1665    public void testResolveContradictoryConflictResolution2() throws Exception JavaDoc {
1666        // BUG IVY-130 : only mod1.2 v2.0 should be resolved and not v2.1 (because of force)
1667
// mod10.1 v 1.1 depends on
1668
// - mod1.2 v 2.0 and forces it
1669
// - mod4.1 v 4.3
1670
// mod4.1 v 4.3 depends on
1671
// - mod1.2 v 2.1
1672
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1673
_ivy.resolve(new File JavaDoc("test/repositories/2/mod10.1/ivy-1.1.xml").toURL(),
1674                null, new String JavaDoc[] {"*"}, _cache, null, true);
1675        
1676        // conflicting dependencies
1677
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
1678        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
1679
1680        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.1")).exists());
1681        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.1", "mod1.2", "jar", "jar").exists());
1682    }
1683    
1684    public void testResolveContradictoryConflictResolution3() throws Exception JavaDoc {
1685        // mod 1.2 v2.0 should be selected (despite conflict manager in 4.1, because of force in 10.1)
1686
// mod10.1 v 1.3 depends on
1687
// - mod1.2 v 2.0 and forces it
1688
// - mod4.1 v 4.4
1689
// mod4.1 v 4.4 depends on
1690
// - mod1.2 v 2.0 but selects mod1.2 v 2.1
1691
// - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1692
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod10.1/ivy-1.3.xml").toURL(),
1693                null, new String JavaDoc[] {"*"}, _cache, null, true);
1694        
1695        IvyNode[] evicted = report.getConfigurationReport("default").getEvictedNodes();
1696        assertEquals(1, evicted.length);
1697        assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"), evicted[0].getResolvedId());
1698    }
1699    
1700    public void testExtends() throws Exception JavaDoc {
1701        // mod 5.2 depends on mod5.1 conf B
1702
// mod5.1 conf B publishes art51B
1703
// mod5.1 conf B extends conf A
1704
// mod5.1 conf A publishes art51A
1705
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod5.2/ivy-1.0.xml").toURL(),
1706                null, new String JavaDoc[] {"*"}, _cache, null, true);
1707        assertNotNull(report);
1708        ModuleDescriptor md = report.getModuleDescriptor();
1709        assertNotNull(md);
1710        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "1.0");
1711        assertEquals(mrid, md.getModuleRevisionId());
1712        
1713        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1714        
1715        // dependencies
1716
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org5", "mod5.1", "4.0")).exists());
1717        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
1718        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
1719    }
1720    
1721    public void testMultiConfs() throws Exception JavaDoc {
1722        // mod 5.2 depends on mod5.1 conf B in its conf B and conf A in its conf A
1723
// mod5.1 conf B publishes art51B
1724
// mod5.1 conf A publishes art51A
1725
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod5.2/ivy-2.0.xml").toURL(),
1726                null, new String JavaDoc[] {"B", "A"}, _cache, null, true);
1727        assertNotNull(report);
1728        ModuleDescriptor md = report.getModuleDescriptor();
1729        assertNotNull(md);
1730        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5", "mod5.2", "2.0");
1731        assertEquals(mrid, md.getModuleRevisionId());
1732        
1733        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1734        
1735        // dependencies
1736
ModuleRevisionId depId = ModuleRevisionId.newInstance("org5", "mod5.1", "4.1");
1737
1738        ConfigurationResolveReport crr = report.getConfigurationReport("A");
1739        assertNotNull(crr);
1740        assertEquals(1, crr.getDownloadReports(depId).length);
1741        
1742        File JavaDoc r = new File JavaDoc(_cache, XmlReportOutputter.getReportFileName(mrid.getModuleId(), "A"));
1743        assertTrue(r.exists());
1744        final boolean[] found = new boolean[] {false};
1745        SAXParser JavaDoc saxParser = SAXParserFactory.newInstance().newSAXParser();
1746        saxParser.parse(r, new DefaultHandler JavaDoc() {
1747            public void startElement(String JavaDoc uri,String JavaDoc localName,String JavaDoc qName,org.xml.sax.Attributes JavaDoc attributes) throws SAXException JavaDoc {
1748                if ("artifact".equals(qName) && "art51B".equals(attributes.getValue("name"))) {
1749                    found[0] = true;
1750                }
1751            }
1752        });
1753        assertFalse(found[0]);
1754
1755        assertTrue(_ivy.getIvyFileInCache(_cache, depId).exists());
1756        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists());
1757        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists());
1758    }
1759    
1760    public void testThisConfiguration() throws Exception JavaDoc {
1761        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod14.4/ivy-1.1.xml").toURL(),
1762                null, new String JavaDoc[] {"compile"}, _cache, null, true);
1763        assertNotNull(report);
1764        ModuleDescriptor md = report.getModuleDescriptor();
1765        assertNotNull(md);
1766        
1767        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org14", "mod14.4", "1.1");
1768        assertEquals(mrid, md.getModuleRevisionId());
1769        ConfigurationResolveReport crr = report.getConfigurationReport("compile");
1770        assertNotNull(crr);
1771        assertEquals(4, crr.getArtifactsNumber());
1772        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists());
1773        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists());
1774        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists());
1775        assertTrue(!_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists());
1776        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists());
1777        
1778        cleanCache();
1779        createCache();
1780        report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod14.4/ivy-1.1.xml").toURL(),
1781                null, new String JavaDoc[] {"standalone"}, _cache, null, true);
1782        crr = report.getConfigurationReport("standalone");
1783        assertNotNull(crr);
1784        assertEquals(7, crr.getArtifactsNumber());
1785        
1786        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists());
1787        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.1", "1.1")).exists());
1788        assertTrue(!_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.2", "1.1")).exists());
1789        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org14", "mod14.3", "1.1")).exists());
1790        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.3", "1.0")).exists());
1791        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.1", "1.0")).exists());
1792        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.4", "1.1")).exists());
1793        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org8", "mod8.2", "1.1")).exists());
1794    }
1795    
1796    public void testLatest() throws Exception JavaDoc {
1797        // mod1.4 depends on latest mod1.2
1798
Ivy ivy = new Ivy();
1799        ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
1800        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml").toURL(),
1801                null, new String JavaDoc[] {"default"}, _cache, null, true);
1802        assertNotNull(report);
1803        ModuleDescriptor md = report.getModuleDescriptor();
1804        assertNotNull(md);
1805        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.4", "1.0.1");
1806        assertEquals(mrid, md.getModuleRevisionId());
1807        
1808        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
1809        
1810        // dependencies
1811
ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "2.2");
1812
1813        ConfigurationResolveReport crr = report.getConfigurationReport("default");
1814        assertNotNull(crr);
1815        assertEquals(1, crr.getDownloadReports(depId).length);
1816        
1817        File JavaDoc r = new File JavaDoc(_cache, XmlReportOutputter.getReportFileName(mrid.getModuleId(), "default"));
1818        assertTrue(r.exists());
1819        final boolean[] found = new boolean[] {false};
1820        SAXParser JavaDoc saxParser = SAXParserFactory.newInstance().newSAXParser();
1821        saxParser.parse(r, new DefaultHandler JavaDoc() {
1822            public void startElement(String JavaDoc uri,String JavaDoc localName,String JavaDoc qName,org.xml.sax.Attributes JavaDoc attributes) throws SAXException JavaDoc {
1823                if ("artifact".equals(qName) && "mod1.2".equals(attributes.getValue("name"))) {
1824                    found[0] = true;
1825                }
1826            }
1827        });
1828        assertTrue(found[0]);
1829        
1830        assertTrue(ivy.getIvyFileInCache(_cache, depId).exists());
1831        assertTrue(ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1832    }
1833    
1834    public void testLatestMultiple() throws Exception JavaDoc {
1835        // mod1.5 depends on
1836
// latest mod1.4, which depends on mod1.2 2.2
1837
// latest mod1.2 (which is 2.2)
1838
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml").toURL(),
1839                null, new String JavaDoc[] {"default"}, _cache, null, true);
1840        assertFalse(report.hasError());
1841                
1842        // dependencies
1843
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.4", "2.0")).exists());
1844        
1845        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.2")).exists());
1846        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.2", "mod1.2", "jar", "jar").exists());
1847    }
1848    
1849    
1850    public void testVersionRange1() throws Exception JavaDoc {
1851        // mod 1.4 depends on mod1.2 [1.0,2.0[
1852
Ivy ivy = new Ivy();
1853        ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
1854        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml").toURL(),
1855                null, new String JavaDoc[] {"default"}, _cache, null, true);
1856        assertFalse(report.hasError());
1857        
1858        // dependencies
1859
ModuleRevisionId depId = ModuleRevisionId.newInstance("org1", "mod1.2", "1.1");
1860        
1861        ConfigurationResolveReport crr = report.getConfigurationReport("default");
1862        assertNotNull(crr);
1863        assertEquals(1, crr.getDownloadReports(depId).length);
1864        
1865        assertTrue(ivy.getIvyFileInCache(_cache, depId).exists());
1866    }
1867    
1868    public void testVersionRange2() throws Exception JavaDoc {
1869        // mod 1.4 depends on mod1.2 [1.5,2.0[
1870
Ivy ivy = new Ivy();
1871        ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
1872        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml").toURL(),
1873                null, new String JavaDoc[] {"default"}, _cache, null, true);
1874        assertTrue(report.hasError());
1875    }
1876    
1877    public void testLatestMilestone() throws Exception JavaDoc {
1878        // mod9.2 depends on latest.milestone of mod6.4
1879
Ivy ivy = new Ivy();
1880        ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
1881        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml").toURL(),
1882                null, new String JavaDoc[] {"default"}, _cache, null, true);
1883        assertFalse(report.hasError());
1884        
1885        // dependencies
1886
ModuleRevisionId depId = ModuleRevisionId.newInstance("org6", "mod6.4", "3");
1887        
1888        ConfigurationResolveReport crr = report.getConfigurationReport("default");
1889        assertNotNull(crr);
1890        assertEquals(1, crr.getDownloadReports(depId).length);
1891        
1892        assertTrue(ivy.getIvyFileInCache(_cache, depId).exists());
1893    }
1894    
1895    public void testLatestMilestone2() throws Exception JavaDoc {
1896        // mod9.2 depends on latest.milestone of mod6.2, but there is no milestone
1897
// test case for IVY-318
1898
Ivy ivy = new Ivy();
1899        ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
1900        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml").toURL(),
1901                null, new String JavaDoc[] {"default"}, _cache, null, true);
1902        // we should have an error since there is no milestone version, it should be considered as a non resolved dependency
1903
assertTrue(report.hasError());
1904        
1905        // dependencies
1906
ConfigurationResolveReport crr = report.getConfigurationReport("default");
1907        assertNotNull(crr);
1908        assertEquals(0, crr.getArtifactsNumber());
1909    }
1910    
1911    public void testIVY56() throws Exception JavaDoc {
1912        Ivy ivy = new Ivy();
1913        ivy.configure(new File JavaDoc("test/repositories/bugIVY-56/ivyconf.xml"));
1914        
1915        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-56.xml"),
1916                null, new String JavaDoc[] {"default"}, _cache, null, true);
1917        assertNotNull(report);
1918    }
1919        
1920    public void testIVY214() throws Exception JavaDoc {
1921        ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-214.xml"), null, new String JavaDoc[] {"compile"}, _cache, null, true);
1922        
1923        assertNotNull(report);
1924        assertFalse(report.hasError());
1925        
1926        assertEquals("Number of artifacts not correct", 1, report.getConfigurationReport("compile").getArtifactsNumber());
1927    }
1928
1929    public void testIVY218() throws Exception JavaDoc {
1930        ResolveReport report = _ivy.resolve(ResolveTest.class.getResource("ivy-218.xml"), null, new String JavaDoc[] {"test"}, _cache, null, true);
1931        
1932        assertNotNull(report);
1933        assertFalse(report.hasError());
1934        
1935        assertEquals("Number of artifacts not correct", 3, report.getConfigurationReport("test").getArtifactsNumber());
1936    }
1937
1938    public void testCircular() throws Exception JavaDoc {
1939        // mod6.3 depends on mod6.2, which itself depends on mod6.3
1940

1941        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
1942                null, new String JavaDoc[] {"default"}, _cache, null, true);
1943        assertFalse(report.hasError());
1944        
1945        _ivy.setCircularDependencyStrategy(IgnoreCircularDependencyStrategy.getInstance());
1946        report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
1947                null, new String JavaDoc[] {"default"}, _cache, null, true);
1948        assertFalse(report.hasError());
1949        
1950        _ivy.setCircularDependencyStrategy(WarnCircularDependencyStrategy.getInstance());
1951        report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
1952                null, new String JavaDoc[] {"default"}, _cache, null, true);
1953        assertFalse(report.hasError());
1954        
1955        _ivy.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
1956        try {
1957            _ivy.resolve(new File JavaDoc("test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
1958                    null, new String JavaDoc[] {"default"}, _cache, null, true);
1959            fail("no exception with circular dependency strategy set to error");
1960        } catch (CircularDependencyException ex) {
1961            assertEquals("[ org6 | mod6.3 | 1.0 ]->[ org6 | mod6.2 | 1.0 ]->[ org6 | mod6.3 | latest.integration ]", ex.getMessage());
1962        }
1963    }
1964    
1965    public void testCircular2() throws Exception JavaDoc {
1966        // mod 9.1 (no revision) depends on mod9.2, which depends on mod9.1 2.+
1967

1968        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/circular/ivy.xml").toURL(),
1969                null, new String JavaDoc[] {"*"}, _cache, null, true);
1970        assertFalse(report.hasError());
1971        
1972        _ivy.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
1973        try {
1974            _ivy.resolve(new File JavaDoc("test/repositories/circular/ivy.xml").toURL(),
1975                    null, new String JavaDoc[] {"*"}, _cache, null, true);
1976            fail("no exception with circular dependency strategy set to error");
1977        } catch (CircularDependencyException ex) {
1978            // ok
1979
assertEquals("[ org8 | mod8.5 | NONE ]->[ org8 | mod8.6 | 2.+ ]->[ org8 | mod8.5 | 2.+ ]", ex.getMessage());
1980        }
1981    }
1982    
1983    public void testRegularCircular() throws Exception JavaDoc {
1984        // mod11.1 depends on mod11.2 but excludes itself
1985
// mod11.2 depends on mod11.1
1986
_ivy.setCircularDependencyStrategy(ErrorCircularDependencyStrategy.getInstance());
1987        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod11.1/ivy-1.0.xml").toURL(),
1988                null, new String JavaDoc[] {"test"}, _cache, null, true);
1989        
1990        assertNotNull(report);
1991        assertFalse(report.hasError());
1992            
1993        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org11", "mod11.2", "1.0")).exists());
1994        assertTrue(_ivy.getArchiveFileInCache(_cache, "org11", "mod11.2", "1.0", "mod11.2", "jar", "jar").exists());
1995
1996        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org11", "mod11.1", "1.0")).exists());
1997        assertFalse(_ivy.getArchiveFileInCache(_cache, "org11", "mod11.1", "1.0", "mod11.1", "jar", "jar").exists());
1998    }
1999    
2000    public void testResolveDualChain() throws Exception JavaDoc {
2001        Ivy ivy = new Ivy();
2002        ivy.configure(ResolveTest.class.getResource("dualchainresolverconf.xml"));
2003        
2004        DependencyResolver resolver = ivy.getResolver("default");
2005        assertNotNull(resolver);
2006        assertTrue(resolver instanceof DualResolver);
2007        
2008        // first without cache
2009
ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), null, new String JavaDoc[] {"default"}, new File JavaDoc("build/cache"), null, true);
2010        
2011        assertTrue(new File JavaDoc("build/cache/xerces/xerces/ivy-2.6.2.xml").exists());
2012        assertTrue(new File JavaDoc("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
2013        assertTrue(new File JavaDoc("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
2014
2015        // second with cache for ivy file only
2016
new File JavaDoc("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").delete();
2017        new File JavaDoc("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").delete();
2018        assertFalse(new File JavaDoc("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
2019        assertFalse(new File JavaDoc("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
2020        ivy.resolve(ResolveTest.class.getResource("ivy-dualchainresolver.xml"), null, new String JavaDoc[] {"default"}, new File JavaDoc("build/cache"), null, true);
2021        
2022        assertTrue(new File JavaDoc("build/cache/xerces/xerces/ivy-2.6.2.xml").exists());
2023        assertTrue(new File JavaDoc("build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar").exists());
2024        assertTrue(new File JavaDoc("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar").exists());
2025    }
2026
2027    
2028    public void testBug148() throws Exception JavaDoc {
2029        Ivy ivy = new Ivy();
2030        ivy.configure(new File JavaDoc("test/repositories/bug148/ivyconf.xml"));
2031        
2032        ivy.resolve(ResolveTest.class.getResource("ivy-148.xml"), null, new String JavaDoc[] {"*"}, new File JavaDoc("build/cache"), null, true);
2033        
2034        assertTrue(new File JavaDoc("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists());
2035        assertTrue(new File JavaDoc("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists());
2036        assertTrue(new File JavaDoc("build/cache/idautomation/barcode/ivy-4.10.xml").exists());
2037        assertTrue(new File JavaDoc("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar").exists());
2038    }
2039    
2040    public void testBug148b() throws Exception JavaDoc {
2041        Ivy ivy = new Ivy();
2042        ivy.configure(new File JavaDoc("test/repositories/bug148/ivyconf.xml"));
2043        
2044        ivy.resolve(ResolveTest.class.getResource("ivy-148b.xml"), null, new String JavaDoc[] {"*"}, new File JavaDoc("build/cache"), null, true);
2045        
2046        assertTrue(new File JavaDoc("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml").exists());
2047        assertTrue(new File JavaDoc("build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar").exists());
2048        assertTrue(new File JavaDoc("build/cache/idautomation/barcode/ivy-4.10.xml").exists());
2049        assertTrue(new File JavaDoc("build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar").exists());
2050    }
2051
2052    public void testBadFiles() throws Exception JavaDoc {
2053        Ivy ivy = new Ivy();
2054        ivy.configure(new File JavaDoc("test/repositories/badfile/ivyconf.xml"));
2055        
2056        try {
2057            ivy.resolve(new File JavaDoc("test/repositories/badfile/ivys/ivy-badorg.xml").toURL(), null, new String JavaDoc[] {"*"}, new File JavaDoc("build/cache"), null, true);
2058            fail("bad org should have raised an exception !");
2059        } catch (Exception JavaDoc ex) {
2060            // OK, it raised an exception
2061
}
2062        try {
2063            ivy.resolve(new File JavaDoc("test/repositories/badfile/ivys/ivy-badmodule.xml").toURL(), null, new String JavaDoc[] {"*"}, new File JavaDoc("build/cache"), null, true);
2064            fail("bad module should have raised an exception !");
2065        } catch (Exception JavaDoc ex) {
2066            // OK, it raised an exception
2067
}
2068        try {
2069            ivy.resolve(new File JavaDoc("test/repositories/badfile/ivys/ivy-badrevision.xml").toURL(), null, new String JavaDoc[] {"*"}, new File JavaDoc("build/cache"), null, true);
2070            fail("bad revision should have raised an exception !");
2071        } catch (Exception JavaDoc ex) {
2072            // OK, it raised an exception
2073
}
2074    }
2075    
2076    public void testTransitiveSetting() throws Exception JavaDoc {
2077        // mod2.4 depends on mod1.1 with transitive set to false
2078
// mod1.1 depends on mod1.2, which should not be resolved because of the transitive setting
2079
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(),
2080                null, new String JavaDoc[] {"*"}, _cache, null, true);
2081        assertNotNull(report);
2082        ModuleDescriptor md = report.getModuleDescriptor();
2083        assertNotNull(md);
2084        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3");
2085        assertEquals(mrid, md.getModuleRevisionId());
2086        
2087        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2088        
2089        // dependencies
2090
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
2091        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
2092
2093        assertTrue(!_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
2094        assertTrue(!_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
2095    }
2096    
2097    public void testResolverDirectlyUsingCache() throws Exception JavaDoc {
2098        Ivy ivy = new Ivy();
2099        ivy.configure(ResolveTest.class.getResource("badcacheconf.xml"));
2100        File JavaDoc depIvyFileInCache = ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"));
2101        FileUtil.copy(File.createTempFile("test", "xml"), depIvyFileInCache, null); // creates a fake dependency file in cache
2102
ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml").toURL(),
2103                null, new String JavaDoc[] {"*"}, _cache, null, true);
2104        
2105        assertNotNull(report);
2106        ModuleDescriptor md = report.getModuleDescriptor();
2107        assertNotNull(md);
2108        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.4", "0.3");
2109        assertEquals(mrid, md.getModuleRevisionId());
2110        
2111        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2112        
2113        // dependencies
2114
assertTrue(depIvyFileInCache.exists());
2115        assertTrue(!ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
2116    }
2117    
2118    public void testVisibility1() throws Exception JavaDoc {
2119        _ivy.resolve(new File JavaDoc("test/repositories/2/mod8.2/ivy-1.0.xml").toURL(),
2120                null, new String JavaDoc[] {"*"}, _cache, null, true);
2121        
2122        assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists());
2123    }
2124    
2125    public void testVisibility2() throws Exception JavaDoc {
2126        _ivy.resolve(new File JavaDoc("test/repositories/2/mod8.3/ivy-1.0.xml").toURL(),
2127                null, new String JavaDoc[] {"private"}, _cache, null, true);
2128        
2129        assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists());
2130        assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a", "txt", "txt").exists());
2131    }
2132    
2133    public void testVisibility3() throws Exception JavaDoc {
2134        _ivy.resolve(new File JavaDoc("test/repositories/2/mod8.4/ivy-1.0.xml").toURL(),
2135                null, new String JavaDoc[] {"*"}, _cache, null, true);
2136        
2137        assertFalse(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a-private", "txt", "txt").exists());
2138        assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.0", "a", "txt", "txt").exists());
2139    }
2140    
2141    public void testVisibility4() throws Exception JavaDoc {
2142        _ivy.resolve(new File JavaDoc("test/repositories/2/mod8.4/ivy-1.1.xml").toURL(),
2143                null, new String JavaDoc[] {"*"}, _cache, null, true);
2144        
2145        assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.1", "a-private", "txt", "txt").exists());
2146        assertTrue(_ivy.getArchiveFileInCache(_cache, "org8", "mod8.1", "1.1", "a", "txt", "txt").exists());
2147    }
2148    
2149    ///////////////////////////////////////////////////////////
2150
// here comes a series of test provided by Chris Rudd
2151
// about configuration mapping and eviction
2152
///////////////////////////////////////////////////////////
2153

2154    public void testConfigurationMapping1() throws Exception JavaDoc {
2155        Ivy ivy = new Ivy();
2156        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2157        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/1/ivy.xml").toURL(),
2158                null, new String JavaDoc[] {"*"}, _cache, null, true);
2159        
2160        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2161        
2162        assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2163        assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2164        assertContainsArtifact("test", "b", "1.0.2", "b", "txt", "txt", conf);
2165        assertDoesntContainArtifact("test", "b", "1.0.2", "b-bt", "txt", "txt", conf);
2166        assertContainsArtifact("test", "c", "1.0.2", "c", "txt", "txt", conf);
2167        assertDoesntContainArtifact("test", "c", "1.0.2", "c-bt", "txt", "txt", conf);
2168    }
2169
2170    public void testConfigurationMapping2() throws Exception JavaDoc {
2171        Ivy ivy = new Ivy();
2172        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2173        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/2/ivy.xml").toURL(),
2174                null, new String JavaDoc[] {"*"}, _cache, null, true);
2175        
2176        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2177        
2178        assertContainsArtifact("test", "a", "1.0.1", "a", "txt", "txt", conf);
2179        assertDoesntContainArtifact("test", "a", "1.0.1", "a-bt", "txt", "txt", conf);
2180        assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2181        assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2182        assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2183        assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2184    }
2185
2186    public void testConfigurationMapping3() throws Exception JavaDoc {
2187        Ivy ivy = new Ivy();
2188        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2189        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/3/ivy.xml").toURL(),
2190                null, new String JavaDoc[] {"buildtime"}, _cache, null, true);
2191        
2192        ConfigurationResolveReport conf = report.getConfigurationReport("buildtime");
2193        
2194        assertContainsArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2195        assertDoesntContainArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2196        assertContainsArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2197        assertDoesntContainArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2198        assertContainsArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2199        assertDoesntContainArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2200    }
2201
2202    public void testConfigurationMapping4() throws Exception JavaDoc {
2203        Ivy ivy = new Ivy();
2204        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2205        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/4/ivy.xml").toURL(),
2206                null, new String JavaDoc[] {"default"}, _cache, null, true);
2207        
2208        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2209        
2210        assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2211        assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2212        assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2213        assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2214        assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2215        assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2216    }
2217
2218    public void testConfigurationMapping5() throws Exception JavaDoc {
2219        Ivy ivy = new Ivy();
2220        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2221        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/5/ivy.xml").toURL(),
2222                null, new String JavaDoc[] {"*"}, _cache, null, true);
2223        
2224        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2225        
2226        assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2227        assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2228        assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2229        assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2230        assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2231        assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2232    }
2233
2234    public void testConfigurationMapping6() throws Exception JavaDoc {
2235        Ivy ivy = new Ivy();
2236        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2237        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/6/ivy.xml").toURL(),
2238                null, new String JavaDoc[] {"default", "buildtime"}, _cache, null, true);
2239        
2240        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2241        
2242        assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2243        assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2244        assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2245        assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2246        assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2247        assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2248    }
2249
2250    public void testConfigurationMapping7() throws Exception JavaDoc {
2251        Ivy ivy = new Ivy();
2252        ivy.configure(new File JavaDoc("test/repositories/IVY-84/ivyconf.xml"));
2253        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/IVY-84/tests/7/ivy.xml").toURL(),
2254                null, new String JavaDoc[] {"buildtime", "default"}, _cache, null, true);
2255        
2256        ConfigurationResolveReport conf = report.getConfigurationReport("default");
2257        
2258        assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt", conf);
2259        assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt", "txt", "txt", conf);
2260        assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt", conf);
2261        assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt", "txt", "txt", conf);
2262        assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt", conf);
2263        assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt", "txt", "txt", conf);
2264    }
2265
2266    public void testIVY97() throws Exception JavaDoc {
2267        // mod9.2 depends on mod9.1 and mod1.2
2268
// mod9.1 depends on mod1.2
2269
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml").toURL(),
2270                null, new String JavaDoc[] {"*"}, _cache, null, true);
2271        assertNotNull(report);
2272        ModuleDescriptor md = report.getModuleDescriptor();
2273        assertNotNull(md);
2274        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org9", "mod9.2", "1.0");
2275        assertEquals(mrid, md.getModuleRevisionId());
2276        
2277        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2278        
2279        // dependencies
2280
assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org9", "mod9.1", "1.0")).exists());
2281        assertTrue(_ivy.getArchiveFileInCache(_cache, "org9", "mod9.1", "1.0", "mod9.1", "jar", "jar").exists());
2282
2283        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
2284        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
2285    }
2286    
2287    public void testResolveTransitiveExcludesSimple() throws Exception JavaDoc {
2288        // mod2.5 depends on mod2.3 and excludes one artifact from mod2.1
2289
// mod2.3 depends on mod2.1
2290
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml").toURL(),
2291                null, new String JavaDoc[] {"*"}, _cache, null, true);
2292        assertNotNull(report);
2293        ModuleDescriptor md = report.getModuleDescriptor();
2294        assertNotNull(md);
2295        ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2", "mod2.5", "0.6");
2296        assertEquals(mrid, md.getModuleRevisionId());
2297        
2298        assertTrue(_ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2299        
2300        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.3", "0.7")).exists());
2301        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.3", "0.7", "mod2.3", "jar", "jar").exists());
2302        
2303        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org2", "mod2.1", "0.3")).exists());
2304        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
2305        assertFalse(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
2306    }
2307    
2308    public void testResolveTransitiveExcludesDiamond1() throws Exception JavaDoc {
2309        // mod2.6 depends on mod2.3 and mod2.5
2310
// mod2.3 depends on mod2.1 and excludes art21B
2311
// mod2.5 depends on mod2.1 and excludes art21A
2312
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml").toURL(),
2313                null, new String JavaDoc[] {"*"}, _cache, null, true);
2314        
2315        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
2316        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
2317    }
2318    
2319    public void testResolveTransitiveExcludesDiamond2() throws Exception JavaDoc {
2320        // mod2.6 depends on mod2.3 and mod2.5
2321
// mod2.3 depends on mod2.1 and excludes art21B
2322
// mod2.5 depends on mod2.1 and excludes art21B
2323
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml").toURL(),
2324                null, new String JavaDoc[] {"*"}, _cache, null, true);
2325        
2326        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
2327        assertFalse(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
2328    }
2329    
2330    public void testResolveTransitiveExcludesDiamond3() throws Exception JavaDoc {
2331        // mod2.6 depends on mod2.3 and mod2.5 and on mod2.1 for which it excludes art21A
2332
// mod2.3 depends on mod2.1 and excludes art21B
2333
// mod2.5 depends on mod2.1 and excludes art21B
2334
_ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml").toURL(),
2335                null, new String JavaDoc[] {"*"}, _cache, null, true);
2336        
2337        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
2338        assertTrue(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
2339    }
2340    
2341    public void testResolveTransitiveExcludes2() throws Exception JavaDoc {
2342        // mod2.6 depends on mod2.3 for which it excludes art21A
2343
// mod2.3 depends on mod2.1 and excludes art21B
2344
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml").toURL(),
2345                null, new String JavaDoc[] {"*"}, _cache, null, true);
2346        ModuleDescriptor md = report.getModuleDescriptor();
2347        assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.9"), md.getModuleRevisionId());
2348        
2349        assertFalse(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21A", "jar", "jar").exists());
2350        assertFalse(_ivy.getArchiveFileInCache(_cache, "org2", "mod2.1", "0.3", "art21B", "jar", "jar").exists());
2351    }
2352    
2353    public void testResolveExcludesModule() throws Exception JavaDoc {
2354        // mod2.6 depends on mod2.1 and excludes mod1.1
2355
// mod2.1 depends on mod1.1 which depends on mod1.2
2356
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml").toURL(),
2357                null, new String JavaDoc[] {"*"}, _cache, null, true);
2358        ModuleDescriptor md = report.getModuleDescriptor();
2359        assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6", "0.10"), md.getModuleRevisionId());
2360        
2361        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.1", "1.0")).exists());
2362        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.1", "1.0", "mod1.1", "jar", "jar").exists());
2363        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
2364        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
2365    }
2366    
2367    public void testResolveExceptConfiguration() throws Exception JavaDoc {
2368        // mod10.2 depends on mod5.1 conf *, !A
2369
_ivy.resolve(new File JavaDoc("test/repositories/2/mod10.2/ivy-2.0.xml").toURL(),
2370                null, new String JavaDoc[] {"*"}, _cache, null, true);
2371        
2372        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.1", "art51A", "jar", "jar").exists());
2373        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.1", "art51B", "jar", "jar").exists());
2374    }
2375    
2376    public void testResolveFallbackConfiguration() throws Exception JavaDoc {
2377        // mod10.2 depends on mod5.1 conf runtime(default)
2378
_ivy.resolve(new File JavaDoc("test/repositories/2/mod10.2/ivy-1.0.xml").toURL(),
2379                null, new String JavaDoc[] {"*"}, _cache, null, true);
2380        
2381        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
2382    }
2383    
2384    public void testResolveFallbackConfiguration2() throws Exception JavaDoc {
2385        // mod10.2 depends on mod5.1 conf runtime(*)
2386
_ivy.resolve(new File JavaDoc("test/repositories/2/mod10.2/ivy-1.1.xml").toURL(),
2387                null, new String JavaDoc[] {"*"}, _cache, null, true);
2388        
2389        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
2390        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
2391    }
2392    
2393    public void testResolveFallbackConfiguration3() throws Exception JavaDoc {
2394        // mod10.2 depends on mod5.1 conf runtime(*),compile(*)
2395
_ivy.resolve(new File JavaDoc("test/repositories/2/mod10.2/ivy-1.2.xml").toURL(),
2396                null, new String JavaDoc[] {"*"}, _cache, null, true);
2397        
2398        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
2399        assertTrue(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
2400    }
2401    
2402    public void testResolveFallbackConfiguration4() throws Exception JavaDoc {
2403        // mod10.2 depends on mod5.1 conf runtime()
2404
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod10.2/ivy-1.3.xml").toURL(),
2405                null, new String JavaDoc[] {"*"}, _cache, null, true);
2406        assertFalse(report.hasError());
2407        
2408        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51A", "jar", "jar").exists());
2409        assertFalse(_ivy.getArchiveFileInCache(_cache, "org5", "mod5.1", "4.0", "art51B", "jar", "jar").exists());
2410    }
2411    
2412    public void testResolveMaven2() throws Exception JavaDoc {
2413        // test3 depends on test2 which depends on test
2414
Ivy ivy = new Ivy();
2415        ivy.configure(new File JavaDoc("test/repositories/m2/ivyconf.xml"));
2416        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/m2/fr/jayasoft/test3/1.0/test3-1.0.pom").toURL(),
2417                null, new String JavaDoc[] {"*"}, _cache, null, true);
2418        assertNotNull(report);
2419        ModuleDescriptor md = report.getModuleDescriptor();
2420        assertNotNull(md);
2421        ModuleRevisionId mrid = ModuleRevisionId.newInstance("fr.jayasoft", "test3", "1.0");
2422        assertEquals(mrid, md.getModuleRevisionId());
2423        
2424        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2425        
2426        // dependencies
2427
assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("fr.jayasoft", "test2", "1.0")).exists());
2428        assertTrue(ivy.getArchiveFileInCache(_cache, "fr.jayasoft", "test2", "1.0", "test2", "jar", "jar").exists());
2429
2430        assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("fr.jayasoft", "test", "1.0")).exists());
2431        assertTrue(ivy.getArchiveFileInCache(_cache, "fr.jayasoft", "test", "1.0", "test", "jar", "jar").exists());
2432    }
2433    
2434    public void testNamespaceMapping() throws Exception JavaDoc {
2435        // the dependency is in another namespace
2436
Ivy ivy = new Ivy();
2437        ivy.configure(new File JavaDoc("test/repositories/namespace/ivyconf.xml"));
2438        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace.xml"),
2439                null, new String JavaDoc[] {"*"}, _cache, null, true);
2440        assertNotNull(report);
2441        ModuleDescriptor md = report.getModuleDescriptor();
2442        assertNotNull(md);
2443        ModuleRevisionId mrid = ModuleRevisionId.newInstance("jayasoft", "namespace", "1.0");
2444        assertEquals(mrid, md.getModuleRevisionId());
2445        
2446        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2447        
2448        // dependencies
2449
assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists());
2450        assertTrue(ivy.getArchiveFileInCache(_cache, "systemorg", "systemmod", "1.0", "A", "jar", "jar").exists());
2451    }
2452    
2453    public void testNamespaceMapping2() throws Exception JavaDoc {
2454        // the dependency is in another namespace and has itself a dependency on a module available in the same namespace
2455
Ivy ivy = new Ivy();
2456        ivy.configure(new File JavaDoc("test/repositories/namespace/ivyconf.xml"));
2457        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace2.xml"),
2458                null, new String JavaDoc[] {"*"}, _cache, null, true);
2459        assertNotNull(report);
2460        ModuleDescriptor md = report.getModuleDescriptor();
2461        assertNotNull(md);
2462        ModuleRevisionId mrid = ModuleRevisionId.newInstance("jayasoft", "namespace", "2.0");
2463        assertEquals(mrid, md.getModuleRevisionId());
2464        
2465        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2466        
2467        // dependencies
2468
assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("systemorg", "systemmod2", "1.0")).exists());
2469        assertTrue(ivy.getArchiveFileInCache(_cache, "systemorg", "systemmod2", "1.0", "B", "jar", "jar").exists());
2470
2471        assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("systemorg", "systemmod", "1.0")).exists());
2472        assertTrue(ivy.getArchiveFileInCache(_cache, "systemorg", "systemmod", "1.0", "A", "jar", "jar").exists());
2473    }
2474    
2475    public void testNamespaceMapping3() throws Exception JavaDoc {
2476        // same as 2 but with poms
2477
Ivy ivy = new Ivy();
2478        ivy.configure(new File JavaDoc("test/repositories/namespace/ivyconf.xml"));
2479        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace3.xml"),
2480                null, new String JavaDoc[] {"*"}, _cache, null, true);
2481        assertNotNull(report);
2482        ModuleDescriptor md = report.getModuleDescriptor();
2483        assertNotNull(md);
2484        ModuleRevisionId mrid = ModuleRevisionId.newInstance("jayasoft", "namespace", "3.0");
2485        assertEquals(mrid, md.getModuleRevisionId());
2486        
2487        assertTrue(ivy.getResolvedIvyFileInCache(_cache, mrid).exists());
2488        
2489        // dependencies
2490
assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("systemorg2", "system-2", "1.0")).exists());
2491        assertTrue(ivy.getArchiveFileInCache(_cache, "systemorg2", "system-2", "1.0", "2", "jar", "jar").exists());
2492
2493        assertTrue(ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("systemorg2", "system-1", "1.0")).exists());
2494        assertTrue(ivy.getArchiveFileInCache(_cache, "systemorg2", "system-1", "1.0", "1", "jar", "jar").exists());
2495    }
2496    
2497    public void testNamespaceMapping4() throws Exception JavaDoc {
2498        // same as 2 but with incorrect dependency asked: the first ivy file asks for a dependency
2499
// in the resolver namespace and not the system one: this should fail
2500
Ivy ivy = new Ivy();
2501        ivy.configure(new File JavaDoc("test/repositories/namespace/ivyconf.xml"));
2502        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-namespace4.xml"),
2503                null, new String JavaDoc[] {"*"}, _cache, null, true);
2504        assertNotNull(report);
2505        ModuleDescriptor md = report.getModuleDescriptor();
2506        assertNotNull(md);
2507        ModuleRevisionId mrid = ModuleRevisionId.newInstance("jayasoft", "namespace", "4.0");
2508        assertEquals(mrid, md.getModuleRevisionId());
2509        
2510        assertTrue(report.hasError());
2511    }
2512    
2513    public void testIVY151() throws Exception JavaDoc {
2514        Ivy ivy = new Ivy();
2515        ivy.configure(new File JavaDoc("test/repositories/multirevisions/ivyconf.xml"));
2516        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/multirevisions/ivy.xml").toURL(), null, new String JavaDoc[] {"compile", "test"}, _cache, null, true);
2517
2518        assertNotNull(report);
2519        assertNotNull(report.getUnresolvedDependencies());
2520        assertEquals("Number of unresolved dependencies not correct", 0, report.getUnresolvedDependencies().length);
2521    }
2522    
2523    public void testCheckRevision() throws Exception JavaDoc {
2524        // mod12.2 depends on mod12.1 1.0 which depends on mod1.2
2525
// mod12.1 doesn't have revision in its ivy file
2526
ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod12.2/ivy-1.0.xml").toURL(),
2527                null, new String JavaDoc[] {"*"}, _cache, null, true);
2528        
2529        assertTrue(report.hasError());
2530        
2531        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists());
2532        assertFalse(_ivy.getArchiveFileInCache(_cache, "org12", "mod12.1", "1.0", "mod12.1", "jar", "jar").exists());
2533        
2534        assertFalse(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
2535        assertFalse(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
2536    }
2537
2538    public void testTrustRevision() throws Exception JavaDoc {
2539        // mod12.2 depends on mod12.1 1.0 which depends on mod1.2
2540
// mod12.1 doesn't have revision in its ivy file
2541

2542        ((BasicResolver)_ivy.getResolver("2-ivy")).setCheckconsistency(false);
2543        
2544        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod12.2/ivy-1.0.xml").toURL(),
2545                null, new String JavaDoc[] {"*"}, _cache, null, true);
2546        
2547        assertFalse(report.hasError());
2548        
2549        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org12", "mod12.1", "1.0")).exists());
2550        assertTrue(_ivy.getArchiveFileInCache(_cache, "org12", "mod12.1", "1.0", "mod12.1", "jar", "jar").exists());
2551        
2552        assertTrue(_ivy.getIvyFileInCache(_cache, ModuleRevisionId.newInstance("org1", "mod1.2", "2.0")).exists());
2553        assertTrue(_ivy.getArchiveFileInCache(_cache, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar").exists());
2554    }
2555
2556    public void testTransitiveConfMapping() throws Exception JavaDoc {
2557        // IVY-168
2558
// mod13.3 depends on mod13.2 which depends on mod13.1
2559
// each module has two confs: j2ee and compile
2560
// each module only publishes one artifact in conf compile
2561
// each module has the following conf mapping on its dependencies: *->@
2562
// moreover, mod13.1 depends on mod1.2 in with the following conf mapping: compile->default
2563
// thus conf j2ee should be empty for each modules
2564

2565        ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/2/mod13.3/ivy-1.0.xml").toURL(),
2566                null, new String JavaDoc[] {"*"}, _cache, null, true);
2567        
2568        assertFalse(report.hasError());
2569        
2570        assertEquals(3, report.getConfigurationReport("compile").getArtifactsNumber());
2571        assertEquals(0, report.getConfigurationReport("j2ee").getArtifactsNumber());
2572    }
2573
2574    public void testExtraAttributes() throws Exception JavaDoc {
2575        Ivy ivy = new Ivy();
2576        ivy.configure(new File JavaDoc("test/repositories/extra-attributes/ivyconf.xml"));
2577        
2578        ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att.xml"),
2579                null, new String JavaDoc[] {"*"}, _cache, null, false);
2580        assertFalse(report.hasError());
2581        
2582        assertTrue(new File JavaDoc(_cache, "jayasoft/mymodule/task1/1854/ivy.xml").exists());
2583        assertTrue(new File JavaDoc(_cache, "jayasoft/mymodule/task1/1854/mymodule-windows.jar").exists());
2584        assertTrue(new File JavaDoc(_cache, "jayasoft/mymodule/task1/1854/mymodule-linux.jar").exists());
2585    }
2586
2587    public void testBranches1() throws Exception JavaDoc {
2588        Ivy ivy = new Ivy();
2589        ivy.configure(new File JavaDoc("test/repositories/branches/ivyconf.xml"));
2590        
2591        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(),
2592                null, new String JavaDoc[] {"*"}, _cache, null, false);
2593        assertFalse(report.hasError());
2594        
2595        assertTrue(_ivy.getArchiveFileInCache(_cache, "foo", "foo1", "3", "foo1", "jar", "jar").exists());
2596    }
2597
2598    public void testBranches2() throws Exception JavaDoc {
2599        Ivy ivy = new Ivy();
2600        ivy.configure(new File JavaDoc("test/repositories/branches/ivyconf.xml"));
2601        
2602        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/branches/bar/bar1/trunk/2/ivy.xml").toURL(),
2603                null, new String JavaDoc[] {"*"}, _cache, null, false);
2604        assertFalse(report.hasError());
2605        
2606        assertTrue(_ivy.getArchiveFileInCache(_cache, "foo", "foo1", "4", "foo1", "jar", "jar").exists());
2607    }
2608
2609    public void testBranches3() throws Exception JavaDoc {
2610        Ivy ivy = new Ivy();
2611        ivy.configure(new File JavaDoc("test/repositories/branches/ivyconf-defaultbranch1.xml"));
2612        
2613        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/branches/bar/bar1/trunk/1/ivy.xml").toURL(),
2614                null, new String JavaDoc[] {"*"}, _cache, null, false);
2615        assertFalse(report.hasError());
2616        
2617        assertTrue(_ivy.getArchiveFileInCache(_cache, "foo", "foo1", "4", "foo1", "jar", "jar").exists());
2618    }
2619
2620    public void testBranches4() throws Exception JavaDoc {
2621        Ivy ivy = new Ivy();
2622        ivy.configure(new File JavaDoc("test/repositories/branches/ivyconf.xml"));
2623        
2624        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(),
2625                null, new String JavaDoc[] {"*"}, _cache, null, false);
2626        assertFalse(report.hasError());
2627        
2628        assertTrue(_ivy.getArchiveFileInCache(_cache, "foo", "foo1", "3", "foo1", "jar", "jar").exists());
2629        assertTrue(_ivy.getArchiveFileInCache(_cache, "bar", "bar2", "2", "bar2", "jar", "jar").exists());
2630    }
2631
2632    public void testBranches5() throws Exception JavaDoc {
2633        Ivy ivy = new Ivy();
2634        ivy.configure(new File JavaDoc("test/repositories/branches/ivyconf-fooonbranch1.xml"));
2635        
2636        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/branches/bar/bar1/trunk/3/ivy.xml").toURL(),
2637                null, new String JavaDoc[] {"*"}, _cache, null, false);
2638        assertFalse(report.hasError());
2639        
2640        assertTrue(_ivy.getArchiveFileInCache(_cache, "foo", "foo1", "4", "foo1", "jar", "jar").exists());
2641        assertTrue(_ivy.getArchiveFileInCache(_cache, "bar", "bar2", "2", "bar2", "jar", "jar").exists());
2642    }
2643
2644    public void testExternalArtifacts() throws Exception JavaDoc {
2645        Ivy ivy = new Ivy();
2646        ivy.setVariable("test.base.url", new File JavaDoc("test/repositories/external-artifacts").toURL().toString());
2647        ivy.configure(new File JavaDoc("test/repositories/external-artifacts/ivyconf.xml"));
2648        
2649        ResolveReport report = ivy.resolve(new File JavaDoc("test/repositories/external-artifacts/ivy.xml").toURL(),
2650                null, new String JavaDoc[] {"*"}, _cache, null, false);
2651        assertFalse(report.hasError());
2652        
2653        assertTrue(_ivy.getArchiveFileInCache(_cache, "jayasoft", "A", "1.0", "a", "jar", "jar").exists());
2654        assertTrue(_ivy.getArchiveFileInCache(_cache, "jayasoft", "B", "2.0", "b", "jar", "jar").exists());
2655        assertTrue(_ivy.getArchiveFileInCache(_cache, "jayasoft", "C", "3.0", "C", "jar", "jar").exists());
2656    }
2657
2658
2659    ////////////////////////////////////////////////////////////
2660
// helper methods to ease the tests
2661
////////////////////////////////////////////////////////////
2662

2663    private void assertContainsArtifact(String JavaDoc org, String JavaDoc module, String JavaDoc rev, String JavaDoc artName, String JavaDoc type, String JavaDoc ext, ConfigurationResolveReport conf) {
2664        Artifact art = getArtifact(org, module, rev, artName, type, ext);
2665        if (!containsArtifact(art, conf.getDownloadedArtifactsReports())) {
2666            fail("artifact "+art+" should be part of "+conf.getConfiguration()+" from "+conf.getModuleDescriptor().getModuleRevisionId());
2667        }
2668    }
2669    
2670    private void assertDoesntContainArtifact(String JavaDoc org, String JavaDoc module, String JavaDoc rev, String JavaDoc artName, String JavaDoc type, String JavaDoc ext, ConfigurationResolveReport conf) {
2671        Artifact art = getArtifact(org, module, rev, artName, type, ext);
2672        if (containsArtifact(art, conf.getDownloadedArtifactsReports())) {
2673            fail("artifact "+art+" should NOT be part of "+conf.getConfiguration()+" from "+conf.getModuleDescriptor().getModuleRevisionId());
2674        }
2675    }
2676
2677    private Artifact getArtifact(String JavaDoc org, String JavaDoc module, String JavaDoc rev, String JavaDoc artName, String JavaDoc type, String JavaDoc ext) {
2678         return new DefaultArtifact(ModuleRevisionId.newInstance(org, module, rev), new Date JavaDoc(), artName, type, ext);
2679    }
2680
2681    private boolean containsArtifact(Artifact art, ArtifactDownloadReport[] adr) {
2682        for (int i = 0; i < adr.length; i++) {
2683            Artifact artifact = adr[i].getArtifact();
2684            if (artifact.getModuleRevisionId().equals(art.getModuleRevisionId())
2685                    && artifact.getName().equals(art.getName())
2686                    && artifact.getType().equals(art.getType())
2687                    && artifact.getExt().equals(art.getExt())) {
2688                return true;
2689            }
2690        }
2691        return false;
2692    }
2693
2694}
2695
Popular Tags