Source Code Cross Referenced for ResolveTest.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » core » resolve » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » apache ivy » org.apache.ivy.core.resolve 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *      http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         *
0017:         */
0018:        package org.apache.ivy.core.resolve;
0019:
0020:        import java.io.File;
0021:        import java.util.ArrayList;
0022:        import java.util.Arrays;
0023:        import java.util.Collection;
0024:        import java.util.Date;
0025:        import java.util.HashSet;
0026:        import java.util.List;
0027:
0028:        import javax.xml.parsers.SAXParser;
0029:        import javax.xml.parsers.SAXParserFactory;
0030:
0031:        import junit.framework.TestCase;
0032:
0033:        import org.apache.ivy.Ivy;
0034:        import org.apache.ivy.TestHelper;
0035:        import org.apache.ivy.core.cache.ArtifactOrigin;
0036:        import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
0037:        import org.apache.ivy.core.module.descriptor.Artifact;
0038:        import org.apache.ivy.core.module.descriptor.DefaultArtifact;
0039:        import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
0040:        import org.apache.ivy.core.module.id.ModuleId;
0041:        import org.apache.ivy.core.module.id.ModuleRevisionId;
0042:        import org.apache.ivy.core.report.ArtifactDownloadReport;
0043:        import org.apache.ivy.core.report.ConfigurationResolveReport;
0044:        import org.apache.ivy.core.report.DownloadStatus;
0045:        import org.apache.ivy.core.report.ResolveReport;
0046:        import org.apache.ivy.core.settings.IvySettings;
0047:        import org.apache.ivy.plugins.circular.CircularDependencyException;
0048:        import org.apache.ivy.plugins.circular.ErrorCircularDependencyStrategy;
0049:        import org.apache.ivy.plugins.circular.IgnoreCircularDependencyStrategy;
0050:        import org.apache.ivy.plugins.circular.WarnCircularDependencyStrategy;
0051:        import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
0052:        import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
0053:        import org.apache.ivy.plugins.resolver.BasicResolver;
0054:        import org.apache.ivy.plugins.resolver.DependencyResolver;
0055:        import org.apache.ivy.plugins.resolver.DualResolver;
0056:        import org.apache.ivy.plugins.resolver.FileSystemResolver;
0057:        import org.apache.ivy.util.CacheCleaner;
0058:        import org.apache.ivy.util.FileUtil;
0059:        import org.xml.sax.SAXException;
0060:        import org.xml.sax.helpers.DefaultHandler;
0061:
0062:        /**
0063:         *
0064:         */
0065:        public class ResolveTest extends TestCase {
0066:            private Ivy ivy;
0067:
0068:            private IvySettings settings;
0069:
0070:            private File cache;
0071:
0072:            public ResolveTest() {
0073:            }
0074:
0075:            protected void setUp() throws Exception {
0076:                cache = new File("build/cache");
0077:                System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
0078:                createCache();
0079:
0080:                ivy = Ivy.newInstance();
0081:                ivy.configure(new File("test/repositories/ivysettings.xml"));
0082:                settings = ivy.getSettings();
0083:            }
0084:
0085:            private void createCache() {
0086:                cache.mkdirs();
0087:            }
0088:
0089:            protected void tearDown() throws Exception {
0090:                CacheCleaner.deleteDir(cache);
0091:            }
0092:
0093:            public void testResolveWithRetainingArtifactName() throws Exception {
0094:                ivy.pushContext();
0095:                try {
0096:                    ((DefaultRepositoryCacheManager) settings
0097:                            .getDefaultRepositoryCacheManager())
0098:                            .setArtifactPattern(ivy
0099:                                    .substitute("[module]/[originalname].[ext]"));
0100:                    ResolveReport report = ivy.resolve(new File(
0101:                            "test/repositories/2/mod15.2/ivy-1.1.xml").toURL(),
0102:                            getResolveOptions(new String[] { "default" }));
0103:                    assertNotNull(report);
0104:
0105:                    ArtifactDownloadReport[] dReports = report
0106:                            .getConfigurationReport("default")
0107:                            .getDownloadReports(
0108:                                    ModuleRevisionId.newInstance("org15",
0109:                                            "mod15.1", "1.1"));
0110:                    assertNotNull(dReports);
0111:                    assertEquals("number of downloaded artifacts not correct",
0112:                            1, dReports.length);
0113:
0114:                    Artifact artifact = dReports[0].getArtifact();
0115:                    assertNotNull(artifact);
0116:
0117:                    String cachePath = getArchivePathInCache(artifact);
0118:                    assertTrue("artifact name has not been retained: "
0119:                            + cachePath, cachePath.endsWith("library.jar"));
0120:
0121:                    dReports = report.getConfigurationReport("default")
0122:                            .getDownloadReports(
0123:                                    ModuleRevisionId.newInstance("org14",
0124:                                            "mod14.1", "1.1"));
0125:                    assertNotNull(dReports);
0126:                    assertEquals("number of downloaded artifacts not correct",
0127:                            1, dReports.length);
0128:
0129:                    artifact = dReports[0].getArtifact();
0130:                    assertNotNull(artifact);
0131:
0132:                    cachePath = getArchivePathInCache(artifact);
0133:                    assertTrue("artifact name has not been retained: "
0134:                            + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
0135:                } finally {
0136:                    ivy.popContext();
0137:                }
0138:            }
0139:
0140:            public void testArtifactOrigin() throws Exception {
0141:                ResolveReport report = ivy
0142:                        .resolve(
0143:                                new File(
0144:                                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0145:                                        .toURL(),
0146:                                getResolveOptions(new String[] { "default" }));
0147:                assertNotNull(report);
0148:
0149:                ArtifactDownloadReport[] dReports = report
0150:                        .getConfigurationReport("default").getDownloadReports(
0151:                                ModuleRevisionId.newInstance("org1", "mod1.2",
0152:                                        "2.0"));
0153:                assertNotNull(dReports);
0154:                assertEquals("number of downloaded artifacts not correct", 1,
0155:                        dReports.length);
0156:
0157:                Artifact artifact = dReports[0].getArtifact();
0158:                assertNotNull(artifact);
0159:
0160:                String expectedLocation = new File(
0161:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar")
0162:                        .getAbsolutePath();
0163:
0164:                // verify the origin in the report
0165:                ArtifactOrigin reportOrigin = dReports[0].getArtifactOrigin();
0166:                assertNotNull(reportOrigin);
0167:                assertEquals("isLocal for artifact not correct", true,
0168:                        reportOrigin.isLocal());
0169:                assertEquals("location for artifact not correct",
0170:                        expectedLocation, reportOrigin.getLocation());
0171:
0172:                // verify the saved origin on disk
0173:                ArtifactOrigin ivyOrigin = getSavedArtifactOrigin(artifact);
0174:                assertNotNull(ivyOrigin);
0175:                assertEquals("isLocal for artifact not correct", true,
0176:                        ivyOrigin.isLocal());
0177:                assertEquals("location for artifact not correct",
0178:                        expectedLocation, ivyOrigin.getLocation());
0179:
0180:                // now resolve the same artifact again and verify the origin of the (not-downloaded)
0181:                // artifact
0182:                report = ivy
0183:                        .resolve(
0184:                                new File(
0185:                                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0186:                                        .toURL(),
0187:                                getResolveOptions(new String[] { "default" }));
0188:                assertNotNull(report);
0189:
0190:                dReports = report.getConfigurationReport("default")
0191:                        .getDownloadReports(
0192:                                ModuleRevisionId.newInstance("org1", "mod1.2",
0193:                                        "2.0"));
0194:                assertNotNull(dReports);
0195:                assertEquals("number of downloaded artifacts not correct", 1,
0196:                        dReports.length);
0197:                assertEquals("download status not correct", DownloadStatus.NO,
0198:                        dReports[0].getDownloadStatus());
0199:                reportOrigin = dReports[0].getArtifactOrigin();
0200:                assertNotNull(reportOrigin);
0201:                assertEquals("isLocal for artifact not correct", true,
0202:                        reportOrigin.isLocal());
0203:                assertEquals("location for artifact not correct",
0204:                        expectedLocation, reportOrigin.getLocation());
0205:            }
0206:
0207:            public void testUseOrigin() throws Exception {
0208:                ((DefaultRepositoryCacheManager) ivy.getSettings()
0209:                        .getDefaultRepositoryCacheManager()).setUseOrigin(true);
0210:
0211:                ResolveReport report = ivy
0212:                        .resolve(
0213:                                new File(
0214:                                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0215:                                        .toURL(),
0216:                                getResolveOptions(new String[] { "default" }));
0217:                assertNotNull(report);
0218:
0219:                ArtifactDownloadReport[] dReports = report
0220:                        .getConfigurationReport("default").getDownloadReports(
0221:                                ModuleRevisionId.newInstance("org1", "mod1.2",
0222:                                        "2.0"));
0223:                assertNotNull(dReports);
0224:                assertEquals("number of downloaded artifacts not correct.", 1,
0225:                        dReports.length);
0226:                assertEquals(
0227:                        "download status not correct: should not download the artifact in useOrigin mode.",
0228:                        DownloadStatus.NO, dReports[0].getDownloadStatus());
0229:
0230:                Artifact artifact = dReports[0].getArtifact();
0231:                assertNotNull(artifact);
0232:
0233:                String expectedLocation = new File(
0234:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar")
0235:                        .getAbsolutePath();
0236:
0237:                ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
0238:                File artInCache = new File(cache, getArchivePathInCache(
0239:                        artifact, origin));
0240:                assertFalse("should not download artifact in useOrigin mode.",
0241:                        artInCache.exists());
0242:                assertEquals("location for artifact not correct.",
0243:                        expectedLocation, getArchiveFileInCache(artifact)
0244:                                .getAbsolutePath());
0245:            }
0246:
0247:            public void testResolveSimple() throws Exception {
0248:                // mod1.1 depends on mod1.2
0249:                ResolveReport report = ivy.resolve(new File(
0250:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0251:                        .toURL(), getResolveOptions(new String[] { "*" }));
0252:                assertNotNull(report);
0253:                ModuleDescriptor md = report.getModuleDescriptor();
0254:                assertNotNull(md);
0255:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
0256:                        "mod1.1", "1.0");
0257:                assertEquals(mrid, md.getModuleRevisionId());
0258:
0259:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0260:
0261:                // dependencies
0262:                assertTrue(getIvyFileInCache(
0263:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0264:                        .exists());
0265:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0266:                        "mod1.2", "jar", "jar").exists());
0267:            }
0268:
0269:            public void testResolveBadStatus() throws Exception {
0270:                // mod1.4 depends on modfailure, modfailure has a bad status
0271:                ResolveReport report = ivy.resolve(new File(
0272:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.1.xml")
0273:                        .toURL(), getResolveOptions(new String[] { "*" }));
0274:                assertNotNull(report);
0275:                assertTrue(report.hasError());
0276:            }
0277:
0278:            public void testResolveNoRevisionInPattern() throws Exception {
0279:                // module1 depends on latest version of module2, for which there is no revision in the
0280:                // pattern
0281:                Ivy ivy = new Ivy();
0282:                ivy.configure(new File(
0283:                        "test/repositories/norev/ivysettings.xml").toURL());
0284:                ResolveReport report = ivy.resolve(new File(
0285:                        "test/repositories/norev/ivy.xml").toURL(),
0286:                        getResolveOptions(new String[] { "*" }));
0287:                assertNotNull(report);
0288:                assertFalse(report.hasError());
0289:            }
0290:
0291:            public void testResolveNoRevisionInDep() throws Exception {
0292:                // mod1.4 depends on mod1.6, in which the ivy file has no revision
0293:                ResolveReport report = ivy.resolve(new File(
0294:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.2.xml")
0295:                        .toURL(), getResolveOptions(new String[] { "*" }));
0296:                assertNotNull(report);
0297:                assertTrue(report.hasError());
0298:            }
0299:
0300:            public void testResolveNoRevisionNowhere() throws Exception {
0301:                // test case for IVY-258
0302:                // module1 depends on latest version of module2, which contains no revision in its ivy file,
0303:                // nor in the pattern
0304:                Ivy ivy = new Ivy();
0305:                ivy.configure(new File(
0306:                        "test/repositories/IVY-258/ivysettings.xml").toURL());
0307:                ResolveReport report = ivy.resolve(new File(
0308:                        "test/repositories/IVY-258/ivy.xml").toURL(),
0309:                        getResolveOptions(new String[] { "*" }));
0310:                assertFalse(report.hasError());
0311:
0312:                ((BasicResolver) ivy.getSettings().getResolver("myresolver"))
0313:                        .setCheckconsistency(false);
0314:                report = ivy.resolve(new File(
0315:                        "test/repositories/IVY-258/ivy.xml").toURL(),
0316:                        getResolveOptions(new String[] { "*" }));
0317:                assertFalse(report.hasError());
0318:            }
0319:
0320:            public void testResolveWithConflictManagerPerModule()
0321:                    throws Exception {
0322:                // test case for IVY-448
0323:                // all modules from myorg
0324:                // module1
0325:                // -> module2-1.0
0326:                // -> module3-2.0
0327:                // module2
0328:                // -> module3-1.0
0329:                // settings use 'all' as default conflict manager, and latest-revision for modules from
0330:                // myorg
0331:                Ivy ivy = new Ivy();
0332:                ivy.configure(new File(
0333:                        "test/repositories/IVY-448/ivysettings.xml").toURL());
0334:                ResolveReport report = ivy.resolve(new File(
0335:                        "test/repositories/IVY-448/ivy.xml").toURL(),
0336:                        getResolveOptions(new String[] { "*" }));
0337:                assertFalse(report.hasError());
0338:
0339:                // rev 1.0 should have been evicted by latest-revision conflict manager
0340:                assertTrue(getArchiveFileInCache(ivy, "myorg", "module3",
0341:                        "2.0", "module3", "jar", "jar").exists());
0342:                assertFalse(getArchiveFileInCache(ivy, "myorg", "module3",
0343:                        "1.0", "module3", "jar", "jar").exists());
0344:            }
0345:
0346:            public void testResolveRequiresIvyFile() throws Exception {
0347:                // mod1.1 depends on mod1.2, mod1.2 has no ivy file
0348:                Ivy ivy = new Ivy();
0349:                ivy.configure(new File("test/repositories/ivysettings.xml"));
0350:                ((FileSystemResolver) ivy.getSettings().getResolver("1"))
0351:                        .setAllownomd(false);
0352:                ResolveReport report = ivy.resolve(new File(
0353:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0354:                        .toURL(), getResolveOptions(new String[] { "*" }));
0355:                assertNotNull(report);
0356:                assertTrue(report.hasError());
0357:            }
0358:
0359:            public void testResolveOtherConfiguration() throws Exception {
0360:                ResolveReport report = ivy.resolve(ResolveTest.class
0361:                        .getResource("ivy-other.xml"),
0362:                        getResolveOptions(new String[] { "test" }));
0363:
0364:                assertNotNull(report);
0365:                assertFalse(report.hasError());
0366:
0367:                assertEquals("Number of artifacts not correct", 1, report
0368:                        .getConfigurationReport("test").getArtifactsNumber());
0369:            }
0370:
0371:            public void testResolveWithSlashes() throws Exception {
0372:                // test case for IVY-198
0373:                // module depends on mod1.2
0374:                ResolveReport report = ivy.resolve(ResolveTest.class
0375:                        .getResource("ivy-198.xml"),
0376:                        getResolveOptions(new String[] { "*" }));
0377:                assertNotNull(report);
0378:                ModuleDescriptor md = report.getModuleDescriptor();
0379:                assertNotNull(md);
0380:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
0381:                        "myorg/mydep", "system/module", "1.0");
0382:                assertEquals(mrid, md.getModuleRevisionId());
0383:
0384:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0385:
0386:                // dependencies
0387:                assertTrue(getIvyFileInCache(
0388:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0389:                        .exists());
0390:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0391:                        "mod1.2", "jar", "jar").exists());
0392:
0393:                assertTrue(getIvyFileInCache(
0394:                        ModuleRevisionId.newInstance("yourorg/yourdep",
0395:                                "yoursys/yourmod", "1.0")).exists());
0396:                assertTrue(getArchiveFileInCache("yourorg/yourdep",
0397:                        "yoursys/yourmod", "1.0", "yourmod", "jar", "jar")
0398:                        .exists());
0399:            }
0400:
0401:            public void testFromCache() throws Exception {
0402:                // mod1.1 depends on mod1.2
0403:
0404:                // we first do a simple resolve so that module is in cache
0405:                ivy.resolve(new File(
0406:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0407:                        .toURL(), getResolveOptions(new String[] { "*" }));
0408:
0409:                // we now use a badly configured ivy, so that it can't find module in repository
0410:                Ivy ivy = new Ivy();
0411:                ivy.configure(new File(
0412:                        "test/repositories/bugIVY-56/ivysettings.xml"));
0413:                ivy.getSettings().setDefaultCache(cache);
0414:
0415:                ResolveReport report = ivy.resolve(new File(
0416:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0417:                        .toURL(), getResolveOptions(ivy.getSettings(),
0418:                        new String[] { "*" }));
0419:                assertFalse(report.hasError());
0420:
0421:                ModuleDescriptor md = report.getModuleDescriptor();
0422:
0423:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
0424:                        "mod1.1", "1.0");
0425:                assertEquals(mrid, md.getModuleRevisionId());
0426:
0427:                assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
0428:
0429:                // dependencies
0430:                assertTrue(getIvyFileInCache(
0431:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0432:                        .exists());
0433:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0434:                        "mod1.2", "jar", "jar").exists());
0435:            }
0436:
0437:            public void testFromCache2() throws Exception {
0438:                // mod1.1 depends on mod1.2
0439:
0440:                Ivy ivy = ivyTestCache();
0441:
0442:                // set up repository
0443:                FileUtil.forceDelete(new File("build/testCache2"));
0444:                File art = new File("build/testCache2/mod1.2-2.0.jar");
0445:                FileUtil.copy(new File(
0446:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0447:                        art, null);
0448:
0449:                // we first do a simple resolve so that module is in cache
0450:                ResolveReport report = ivy.resolve(new File(
0451:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0452:                        .toURL(), getResolveOptions(new String[] { "*" }));
0453:                assertFalse(report.hasError());
0454:
0455:                // now we clean the repository to simulate repo not available (network pb for instance)
0456:                FileUtil.forceDelete(new File("build/testCache2"));
0457:
0458:                // now do a new resolve: it should use cached data
0459:                report = ivy.resolve(new File(
0460:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0461:                        .toURL(), getResolveOptions(new String[] { "*" }));
0462:                assertFalse(report.hasError());
0463:
0464:                ModuleDescriptor md = report.getModuleDescriptor();
0465:
0466:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
0467:                        "mod1.1", "1.0");
0468:                assertEquals(mrid, md.getModuleRevisionId());
0469:
0470:                assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
0471:
0472:                // dependencies
0473:                assertTrue(getIvyFileInCache(
0474:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0475:                        .exists());
0476:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0477:                        "mod1.2", "jar", "jar").exists());
0478:            }
0479:
0480:            public void testDynamicFromCache() throws Exception {
0481:                // mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
0482:
0483:                Ivy ivy = ivyTestCache();
0484:                ivy.getSettings().setVariable("ivy.cache.ttl.default", "10s",
0485:                        true);
0486:
0487:                // set up repository
0488:                FileUtil.forceDelete(new File("build/testCache2"));
0489:                FileUtil.copy(new File(
0490:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0491:                        new File("build/testCache2/mod1.2-1.5.jar"), null);
0492:
0493:                // we first do a simple resolve so that module is in cache
0494:                ResolveReport report = ivy.resolve(new File(
0495:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0496:                        .toURL(), getResolveOptions(new String[] { "*" }));
0497:                assertFalse(report.hasError());
0498:
0499:                assertEquals(new HashSet(Arrays
0500:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0501:                                .newInstance("org1", "mod1.2", "1.5") })),
0502:                        report.getConfigurationReport("default")
0503:                                .getModuleRevisionIds());
0504:
0505:                // now we clean the repository to simulate repo not available (network pb for instance)
0506:                FileUtil.forceDelete(new File("build/testCache2"));
0507:
0508:                // now do a new resolve: it should use cached data
0509:                report = ivy.resolve(new File(
0510:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0511:                        .toURL(), getResolveOptions(new String[] { "*" }));
0512:                assertFalse(report.hasError());
0513:
0514:                assertEquals(new HashSet(Arrays
0515:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0516:                                .newInstance("org1", "mod1.2", "1.5") })),
0517:                        report.getConfigurationReport("default")
0518:                                .getModuleRevisionIds());
0519:            }
0520:
0521:            public void testDynamicFromCacheWithTTL0() throws Exception {
0522:                // mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
0523:
0524:                Ivy ivy = ivyTestCache();
0525:                ivy.getSettings().setVariable("ivy.cache.ttl.default", "0ms",
0526:                        true);
0527:
0528:                // set up repository
0529:                FileUtil.forceDelete(new File("build/testCache2"));
0530:                FileUtil.copy(new File(
0531:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0532:                        new File("build/testCache2/mod1.2-1.5.jar"), null);
0533:
0534:                // we first do a simple resolve so that module is in cache
0535:                ResolveReport report = ivy.resolve(new File(
0536:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0537:                        .toURL(), getResolveOptions(new String[] { "*" }));
0538:                assertFalse(report.hasError());
0539:
0540:                assertEquals(new HashSet(Arrays
0541:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0542:                                .newInstance("org1", "mod1.2", "1.5") })),
0543:                        report.getConfigurationReport("default")
0544:                                .getModuleRevisionIds());
0545:
0546:                // now we update the repository
0547:                FileUtil.copy(new File(
0548:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0549:                        new File("build/testCache2/mod1.2-1.6.jar"), null);
0550:
0551:                // now do a new resolve: it should not use cached data
0552:                report = ivy.resolve(new File(
0553:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0554:                        .toURL(), getResolveOptions(new String[] { "*" }));
0555:                assertFalse(report.hasError());
0556:
0557:                assertEquals(new HashSet(Arrays
0558:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0559:                                .newInstance("org1", "mod1.2", "1.6") })),
0560:                        report.getConfigurationReport("default")
0561:                                .getModuleRevisionIds());
0562:            }
0563:
0564:            public void testDynamicFromCacheWithTTL() throws Exception {
0565:                // mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
0566:                Ivy ivy = ivyTestCache();
0567:                ivy.getSettings().setVariable("ivy.cache.ttl.default", "10s",
0568:                        true);
0569:                ((DefaultRepositoryCacheManager) ivy.getSettings()
0570:                        .getDefaultRepositoryCacheManager()).addTTL(
0571:                        ModuleRevisionId.newInstance("org1", "*", "*")
0572:                                .getAttributes(), ExactPatternMatcher.INSTANCE,
0573:                        500);
0574:
0575:                // set up repository
0576:                FileUtil.forceDelete(new File("build/testCache2"));
0577:                FileUtil.copy(new File(
0578:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0579:                        new File("build/testCache2/mod1.2-1.5.jar"), null);
0580:
0581:                // we first do a simple resolve so that module is in cache
0582:                ResolveReport report = ivy.resolve(new File(
0583:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0584:                        .toURL(), getResolveOptions(new String[] { "*" }));
0585:                assertFalse(report.hasError());
0586:
0587:                // now we update the repository
0588:                FileUtil.copy(new File(
0589:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0590:                        new File("build/testCache2/mod1.2-1.6.jar"), null);
0591:
0592:                // now do a new resolve: it should use cached data
0593:                report = ivy.resolve(new File(
0594:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0595:                        .toURL(), getResolveOptions(new String[] { "*" }));
0596:                assertFalse(report.hasError());
0597:
0598:                assertEquals(new HashSet(Arrays
0599:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0600:                                .newInstance("org1", "mod1.2", "1.5") })),
0601:                        report.getConfigurationReport("default")
0602:                                .getModuleRevisionIds());
0603:
0604:                // wait for org1 TTL to expire
0605:                Thread.sleep(700);
0606:
0607:                // now do a new resolve: it should resolve the dynamic revision again
0608:                report = ivy.resolve(new File(
0609:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0610:                        .toURL(), getResolveOptions(new String[] { "*" }));
0611:                assertFalse(report.hasError());
0612:
0613:                assertEquals(new HashSet(Arrays
0614:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0615:                                .newInstance("org1", "mod1.2", "1.6") })),
0616:                        report.getConfigurationReport("default")
0617:                                .getModuleRevisionIds());
0618:            }
0619:
0620:            public void testRefreshDynamicFromCache() throws Exception {
0621:                // mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
0622:                Ivy ivy = ivyTestCache();
0623:                ivy.getSettings().setVariable("ivy.cache.ttl.default", "10s",
0624:                        true);
0625:
0626:                // set up repository
0627:                FileUtil.forceDelete(new File("build/testCache2"));
0628:                FileUtil.copy(new File(
0629:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0630:                        new File("build/testCache2/mod1.2-1.5.jar"), null);
0631:
0632:                // we first do a simple resolve so that module is in cache
0633:                ResolveReport report = ivy.resolve(new File(
0634:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0635:                        .toURL(), getResolveOptions(new String[] { "*" }));
0636:                assertFalse(report.hasError());
0637:
0638:                // now we update the repository
0639:                FileUtil.copy(new File(
0640:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0641:                        new File("build/testCache2/mod1.2-1.6.jar"), null);
0642:
0643:                // now do a new resolve: it should use cached data
0644:                report = ivy.resolve(new File(
0645:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0646:                        .toURL(), getResolveOptions(new String[] { "*" }));
0647:                assertFalse(report.hasError());
0648:
0649:                assertEquals(new HashSet(Arrays
0650:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0651:                                .newInstance("org1", "mod1.2", "1.5") })),
0652:                        report.getConfigurationReport("default")
0653:                                .getModuleRevisionIds());
0654:
0655:                // resolve again with refresh: it should find the new version
0656:                report = ivy.resolve(new File(
0657:                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
0658:                        .toURL(), getResolveOptions(new String[] { "*" })
0659:                        .setRefresh(true));
0660:                assertFalse(report.hasError());
0661:
0662:                assertEquals(new HashSet(Arrays
0663:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
0664:                                .newInstance("org1", "mod1.2", "1.6") })),
0665:                        report.getConfigurationReport("default")
0666:                                .getModuleRevisionIds());
0667:
0668:                FileUtil.forceDelete(new File("build/testCache2"));
0669:            }
0670:
0671:            /**
0672:             * Configures an Ivy instance using a resolver locating modules on file system, in a
0673:             * build/testCache2 location which is created for the test and removed after, and can thus
0674:             * easily simulate a repository availability problem
0675:             * 
0676:             * @return the configured ivy instance
0677:             */
0678:            private Ivy ivyTestCache() {
0679:                Ivy ivy = Ivy.newInstance();
0680:                DualResolver resolver = new DualResolver();
0681:                resolver.setName("dual");
0682:                FileSystemResolver r = new FileSystemResolver();
0683:                r.setName("1");
0684:                r
0685:                        .addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]");
0686:                resolver.add(r);
0687:                r = new FileSystemResolver();
0688:                r.setName("2");
0689:                r
0690:                        .addArtifactPattern("build/testCache2/[artifact]-[revision].[ext]");
0691:                resolver.add(r);
0692:                ivy.getSettings().addResolver(resolver);
0693:                ivy.getSettings().setDefaultResolver("dual");
0694:                return ivy;
0695:            }
0696:
0697:            public void testFromCacheOnly() throws Exception {
0698:                Ivy ivy = new Ivy();
0699:                ivy.configure(new File(
0700:                        "test/repositories/bugIVY-56/ivysettings.xml"));
0701:                ivy.getSettings().setDefaultCache(cache);
0702:
0703:                // ResolveReport report = ivy.resolve(new
0704:                // File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
0705:                // getResolveOptions(new String[] {"*"}));
0706:                // // should have an error, the conf is bad and the dependency should not be found
0707:                // assertTrue(report.hasError());
0708:
0709:                // put necessary stuff in cache, and it should now be ok
0710:                File ivyfile = getIvyFileInCache(ModuleRevisionId.newInstance(
0711:                        "org1", "mod1.2", "2.0"));
0712:                File art = getArchiveFileInCache(ivy, "org1", "mod1.2", "2.0",
0713:                        "mod1.2", "jar", "jar");
0714:                FileUtil.copy(ResolveTest.class.getResource("ivy-mod1.2.xml"),
0715:                        ivyfile, null);
0716:                FileUtil.copy(new File(
0717:                        "test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"),
0718:                        art, null);
0719:
0720:                ResolveReport report = ivy.resolve(new File(
0721:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0722:                        .toURL(), getResolveOptions(ivy.getSettings(),
0723:                        new String[] { "*" }));
0724:                assertFalse(report.hasError());
0725:            }
0726:
0727:            public void testChangeCacheLayout() throws Exception {
0728:                Ivy ivy = new Ivy();
0729:                ivy.configure(new File("test/repositories/ivysettings.xml"));
0730:                DefaultRepositoryCacheManager cacheMgr = (DefaultRepositoryCacheManager) ivy
0731:                        .getSettings().getDefaultRepositoryCacheManager();
0732:
0733:                cacheMgr.setIvyPattern("[module]/ivy.xml");
0734:                cacheMgr.setArtifactPattern("[artifact].[ext]");
0735:
0736:                // mod1.1 depends on mod1.2
0737:                ResolveReport report = ivy.resolve(new File(
0738:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0739:                        .toURL(), getResolveOptions(ivy.getSettings(),
0740:                        new String[] { "*" }));
0741:                assertNotNull(report);
0742:                ModuleDescriptor md = report.getModuleDescriptor();
0743:                assertNotNull(md);
0744:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
0745:                        "mod1.1", "1.0");
0746:                assertEquals(mrid, md.getModuleRevisionId());
0747:
0748:                assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
0749:
0750:                // dependencies
0751:                assertTrue(getIvyFileInCache(ivy,
0752:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0753:                        .exists());
0754:                assertTrue(new File(cache, "mod1.2/ivy.xml").exists());
0755:                assertTrue(getArchiveFileInCache(ivy, "org1", "mod1.2", "2.0",
0756:                        "mod1.2", "jar", "jar").exists());
0757:                assertTrue(new File(cache, "mod1.2.jar").exists());
0758:            }
0759:
0760:            public void testChangeCacheLayout2() throws Exception {
0761:                Ivy ivy = new Ivy();
0762:                ivy.configure(new File("test/repositories/ivysettings.xml"));
0763:                ivy.getSettings().setDefaultRepositoryCacheBasedir(
0764:                        new File(ivy.getSettings().getDefaultCache(),
0765:                                "repository").getAbsolutePath());
0766:                ivy.getSettings().setDefaultResolutionCacheBasedir(
0767:                        new File(ivy.getSettings().getDefaultCache(),
0768:                                "workspace").getAbsolutePath());
0769:                DefaultRepositoryCacheManager cacheMgr = (DefaultRepositoryCacheManager) ivy
0770:                        .getSettings().getDefaultRepositoryCacheManager();
0771:
0772:                cacheMgr.setIvyPattern("[module]/ivy.xml");
0773:                cacheMgr.setArtifactPattern("[artifact].[ext]");
0774:
0775:                // mod1.1 depends on mod1.2
0776:                ResolveReport report = ivy.resolve(new File(
0777:                        "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
0778:                        .toURL(), getResolveOptions(ivy.getSettings(),
0779:                        new String[] { "*" }));
0780:                assertNotNull(report);
0781:                assertFalse(report.hasError());
0782:
0783:                ModuleDescriptor md = report.getModuleDescriptor();
0784:                assertNotNull(md);
0785:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
0786:                        "mod1.1", "1.0");
0787:                assertEquals(mrid, md.getModuleRevisionId());
0788:
0789:                assertTrue(getResolvedIvyFileInCache(ivy, mrid).toString()
0790:                        .indexOf("workspace") != -1);
0791:                assertTrue(getResolvedIvyFileInCache(ivy, mrid).exists());
0792:                assertTrue(getConfigurationResolveReportInCache(ivy,
0793:                        report.getResolveId(), "default").exists());
0794:
0795:                // dependencies
0796:                assertTrue(getIvyFileInCache(ivy,
0797:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0798:                        .exists());
0799:                assertTrue(new File(cache, "repository/mod1.2/ivy.xml")
0800:                        .exists());
0801:                assertTrue(getArchiveFileInCache(ivy, "org1", "mod1.2", "2.0",
0802:                        "mod1.2", "jar", "jar").exists());
0803:                assertTrue(new File(cache, "repository/mod1.2.jar").exists());
0804:            }
0805:
0806:            public void testMultipleCache() throws Exception {
0807:                Ivy ivy = new Ivy();
0808:                ivy.configure(new File(
0809:                        "test/repositories/ivysettings-multicache.xml"));
0810:
0811:                // mod2.1 depends on mod1.1 which depends on mod1.2
0812:                ResolveReport report = ivy.resolve(new File(
0813:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml")
0814:                        .toURL(), getResolveOptions(new String[] { "*" }));
0815:                assertNotNull(report);
0816:                assertFalse(report.hasError());
0817:
0818:                // dependencies
0819:                DefaultArtifact depArtifact = TestHelper.newArtifact("org1",
0820:                        "mod1.1", "1.0", "mod1.1", "jar", "jar");
0821:                ModuleRevisionId depMrid = ModuleRevisionId.newInstance("org1",
0822:                        "mod1.1", "1.0");
0823:                DefaultRepositoryCacheManager cacheMgr1 = (DefaultRepositoryCacheManager) ivy
0824:                        .getSettings().getDefaultRepositoryCacheManager();
0825:                DefaultRepositoryCacheManager cacheMgr2 = (DefaultRepositoryCacheManager) ivy
0826:                        .getSettings().getRepositoryCacheManager("cache2");
0827:
0828:                // ivy file should be cached in default cache, and artifact in cache2
0829:                assertTrue(cacheMgr1.getIvyFileInCache(depMrid).exists());
0830:                assertFalse(cacheMgr1.getArchiveFileInCache(depArtifact)
0831:                        .exists());
0832:                assertEquals(new File(cache, "repo1/mod1.1/ivy-1.0.xml"),
0833:                        cacheMgr1.getIvyFileInCache(depMrid));
0834:
0835:                assertFalse(cacheMgr2.getIvyFileInCache(depMrid).exists());
0836:                assertTrue(cacheMgr2.getArchiveFileInCache(depArtifact)
0837:                        .exists());
0838:                assertEquals(new File(cache, "repo2/mod1.1-1.0/mod1.1.jar"),
0839:                        cacheMgr2.getArchiveFileInCache(depArtifact));
0840:            }
0841:
0842:            public void testResolveExtends() throws Exception {
0843:                // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
0844:                ResolveReport report = ivy.resolve(new File(
0845:                        "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml")
0846:                        .toURL(),
0847:                        getResolveOptions(new String[] { "extension" }));
0848:                assertNotNull(report);
0849:                ModuleDescriptor md = report.getModuleDescriptor();
0850:                assertNotNull(md);
0851:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
0852:                        "mod6.1", "0.3");
0853:                assertEquals(mrid, md.getModuleRevisionId());
0854:
0855:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0856:
0857:                // dependencies from default
0858:                assertTrue(getIvyFileInCache(
0859:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0860:                        .exists());
0861:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0862:                        "mod1.2", "jar", "jar").exists());
0863:            }
0864:
0865:            public void testResolveExtended() throws Exception {
0866:                // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
0867:                ResolveReport report = ivy
0868:                        .resolve(
0869:                                new File(
0870:                                        "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml")
0871:                                        .toURL(),
0872:                                getResolveOptions(new String[] { "default" }));
0873:                assertNotNull(report);
0874:                ModuleDescriptor md = report.getModuleDescriptor();
0875:                assertNotNull(md);
0876:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
0877:                        "mod6.1", "0.3");
0878:                assertEquals(mrid, md.getModuleRevisionId());
0879:
0880:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0881:
0882:                // dependencies from default
0883:                assertTrue(getIvyFileInCache(
0884:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0885:                        .exists());
0886:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0887:                        "mod1.2", "jar", "jar").exists());
0888:            }
0889:
0890:            public void testResolveExtendedAndExtends() throws Exception {
0891:                // mod6.1 depends on mod1.2 2.0 in conf default, and conf extension extends default
0892:                ResolveReport report = ivy.resolve(new File(
0893:                        "test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml")
0894:                        .toURL(), getResolveOptions(new String[] { "default",
0895:                        "extension" }));
0896:                assertNotNull(report);
0897:                ModuleDescriptor md = report.getModuleDescriptor();
0898:                assertNotNull(md);
0899:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
0900:                        "mod6.1", "0.3");
0901:                assertEquals(mrid, md.getModuleRevisionId());
0902:                ConfigurationResolveReport crr = report
0903:                        .getConfigurationReport("default");
0904:                assertNotNull(crr);
0905:                assertEquals(1, crr.getArtifactsNumber());
0906:                crr = report.getConfigurationReport("extension");
0907:                assertNotNull(crr);
0908:                assertEquals(1, crr.getArtifactsNumber());
0909:
0910:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0911:
0912:                assertTrue(getIvyFileInCache(
0913:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0914:                        .exists());
0915:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0916:                        "mod1.2", "jar", "jar").exists());
0917:            }
0918:
0919:            public void testResolveMultipleExtends() throws Exception {
0920:                // mod6.2 has two confs default and extension
0921:                // mod6.2 depends on mod6.1 in conf (default->extension)
0922:                // conf extension extends default
0923:                // mod6.1 has two confs default and extension
0924:                // mod6.1 depends on mod1.2 2.0 in conf (default->default)
0925:                // conf extension extends default
0926:                ResolveReport report = ivy.resolve(new File(
0927:                        "test/repositories/1/org6/mod6.2/ivys/ivy-0.3.xml")
0928:                        .toURL(), getResolveOptions(new String[] { "default",
0929:                        "extension" }));
0930:                assertNotNull(report);
0931:                assertFalse(report.hasError());
0932:                ModuleDescriptor md = report.getModuleDescriptor();
0933:                assertNotNull(md);
0934:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
0935:                        "mod6.2", "0.3");
0936:                assertEquals(mrid, md.getModuleRevisionId());
0937:                ConfigurationResolveReport crr = report
0938:                        .getConfigurationReport("default");
0939:                assertNotNull(crr);
0940:                assertEquals(2, crr.getArtifactsNumber());
0941:                crr = report.getConfigurationReport("extension");
0942:                assertNotNull(crr);
0943:                assertEquals(2, crr.getArtifactsNumber());
0944:
0945:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
0946:
0947:                assertTrue(getIvyFileInCache(
0948:                        ModuleRevisionId.newInstance("org6", "mod6.1", "0.4"))
0949:                        .exists());
0950:                assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4",
0951:                        "mod6.1", "jar", "jar").exists());
0952:
0953:                assertTrue(getIvyFileInCache(
0954:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
0955:                        .exists());
0956:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
0957:                        "mod1.2", "jar", "jar").exists());
0958:            }
0959:
0960:            public void testResolveMultipleExtendsAndConfs() throws Exception {
0961:                // Test case for IVY-240
0962:                //
0963:                // mod6.3 1.1 has four confs libraries, run (extends libraries), compile (extends run) and
0964:                // test (extends libraries)
0965:                // mod6.3 depends on mod6.2 2.0 in conf (run->default)
0966:                // mod6.3 depends on mod6.1 2.+ in conf (test->default)
0967:                // mod6.2 2.0 depends on mod6.1 2.0 in conf (default->standalone)
0968:                // mod6.1 2.0 has two confs default and standalone
0969:                // mod6.1 2.0 depends on mod1.2 2.2 in conf (default->default)
0970:                ResolveReport report = ivy.resolve(new File(
0971:                        "test/repositories/2/mod6.3/ivy-1.1.xml").toURL(),
0972:                        getResolveOptions(new String[] { "*" }));
0973:                assertNotNull(report);
0974:                assertFalse(report.hasError());
0975:                ModuleDescriptor md = report.getModuleDescriptor();
0976:                assertNotNull(md);
0977:                ConfigurationResolveReport crr = report
0978:                        .getConfigurationReport("libraries");
0979:                assertEquals(0, crr.getArtifactsNumber());
0980:
0981:                crr = report.getConfigurationReport("run");
0982:                assertEquals(2, crr.getArtifactsNumber());
0983:                assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2",
0984:                        "jar", "jar", crr);
0985:                assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1",
0986:                        "jar", "jar", crr);
0987:
0988:                crr = report.getConfigurationReport("compile");
0989:                assertEquals(2, crr.getArtifactsNumber());
0990:                assertContainsArtifact("org6", "mod6.2", "2.0", "mod6.2",
0991:                        "jar", "jar", crr);
0992:                assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1",
0993:                        "jar", "jar", crr);
0994:
0995:                crr = report.getConfigurationReport("test");
0996:                assertEquals(2, crr.getArtifactsNumber());
0997:                assertContainsArtifact("org6", "mod6.1", "2.0", "mod6.1",
0998:                        "jar", "jar", crr);
0999:                assertContainsArtifact("org1", "mod1.2", "2.2", "mod1.2",
1000:                        "jar", "jar", crr);
1001:            }
1002:
1003:            public void testResolveMultipleConfsWithLatest() throws Exception {
1004:                // Test case for IVY-188
1005:                //
1006:                // mod6.2 has two confs compile and run
1007:                // depends on mod6.1 in conf (compile->default)
1008:                // depends on mod1.2 latest (which is 2.2) in conf (run->default)
1009:                // mod6.1
1010:                // depends on mod1.2 2.2
1011:                ResolveReport report = ivy.resolve(new File(
1012:                        "test/repositories/1/org6/mod6.2/ivys/ivy-0.6.xml")
1013:                        .toURL(), getResolveOptions(new String[] { "compile",
1014:                        "run" }));
1015:                assertNotNull(report);
1016:                assertFalse(report.hasError());
1017:
1018:                ConfigurationResolveReport crr = report
1019:                        .getConfigurationReport("compile");
1020:                assertNotNull(crr);
1021:                assertEquals(2, crr.getArtifactsNumber());
1022:                crr = report.getConfigurationReport("run");
1023:                assertNotNull(crr);
1024:                assertEquals(1, crr.getArtifactsNumber());
1025:
1026:                assertTrue(getIvyFileInCache(
1027:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
1028:                        .exists());
1029:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2",
1030:                        "mod1.2", "jar", "jar").exists());
1031:            }
1032:
1033:            public void testResolveMultipleConfsWithConflicts()
1034:                    throws Exception {
1035:                // Test case for IVY-173
1036:                //
1037:                // mod6.2 has two confs compile and run
1038:                // depends on mod1.2 2.1 in conf (compile->default)
1039:                // depends on mod1.1 1.0 in conf (*->default)
1040:                // depends on mod6.1 in conf (*->default)
1041:                // mod6.1
1042:                // depends on mod1.2 2.1
1043:                // mod1.1
1044:                // depends on mod1.2 2.0
1045:                ResolveReport report = ivy.resolve(new File(
1046:                        "test/repositories/1/org6/mod6.2/ivys/ivy-0.5.xml")
1047:                        .toURL(), getResolveOptions(new String[] { "compile",
1048:                        "run" }));
1049:                assertNotNull(report);
1050:                assertFalse(report.hasError());
1051:                ModuleDescriptor md = report.getModuleDescriptor();
1052:                assertNotNull(md);
1053:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
1054:                        "mod6.2", "0.5");
1055:                assertEquals(mrid, md.getModuleRevisionId());
1056:                ConfigurationResolveReport crr = report
1057:                        .getConfigurationReport("compile");
1058:                assertNotNull(crr);
1059:                assertEquals(3, crr.getArtifactsNumber());
1060:                crr = report.getConfigurationReport("run");
1061:                assertNotNull(crr);
1062:                assertEquals(3, crr.getArtifactsNumber());
1063:
1064:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1065:
1066:                assertTrue(getIvyFileInCache(
1067:                        ModuleRevisionId.newInstance("org6", "mod6.1", "0.5"))
1068:                        .exists());
1069:                assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.5",
1070:                        "mod6.1", "jar", "jar").exists());
1071:
1072:                assertTrue(getIvyFileInCache(
1073:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1074:                        .exists());
1075:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1076:                        "mod1.1", "jar", "jar").exists());
1077:
1078:                assertTrue(getIvyFileInCache(
1079:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
1080:                        .exists());
1081:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
1082:                        "mod1.2", "jar", "jar").exists());
1083:
1084:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1085:                        "mod1.2", "jar", "jar").exists());
1086:            }
1087:
1088:            public void testResolveMultipleExtends2() throws Exception {
1089:                // same as before, except that mod6.2 depends on mod1.2 2.1 extension->default
1090:                // so mod1.2 2.0 should be evicted in conf extension
1091:                ResolveReport report = ivy.resolve(new File(
1092:                        "test/repositories/1/org6/mod6.2/ivys/ivy-0.4.xml")
1093:                        .toURL(), getResolveOptions(new String[] { "default",
1094:                        "extension" }));
1095:                assertNotNull(report);
1096:                assertFalse(report.hasError());
1097:                ModuleDescriptor md = report.getModuleDescriptor();
1098:                assertNotNull(md);
1099:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
1100:                        "mod6.2", "0.4");
1101:                assertEquals(mrid, md.getModuleRevisionId());
1102:                ConfigurationResolveReport crr = report
1103:                        .getConfigurationReport("default");
1104:                assertNotNull(crr);
1105:                assertEquals(2, crr.getArtifactsNumber());
1106:                IvyNode node = crr.getDependency(ModuleRevisionId.newInstance(
1107:                        "org1", "mod1.2", "2.0"));
1108:                assertNotNull(node);
1109:                assertFalse(node.isEvicted("default"));
1110:                crr = report.getConfigurationReport("extension");
1111:                assertNotNull(crr);
1112:                assertEquals(2, crr.getArtifactsNumber());
1113:                node = crr.getDependency(ModuleRevisionId.newInstance("org1",
1114:                        "mod1.2", "2.0"));
1115:                assertNotNull(node);
1116:                assertTrue(node.isEvicted("extension"));
1117:                node = crr.getDependency(ModuleRevisionId.newInstance("org1",
1118:                        "mod1.2", "2.1"));
1119:                assertNotNull(node);
1120:                assertFalse(node.isEvicted("extension"));
1121:
1122:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1123:
1124:                assertTrue(getIvyFileInCache(
1125:                        ModuleRevisionId.newInstance("org6", "mod6.1", "0.4"))
1126:                        .exists());
1127:                assertTrue(getArchiveFileInCache("org6", "mod6.1", "0.4",
1128:                        "mod6.1", "jar", "jar").exists());
1129:
1130:                assertTrue(getIvyFileInCache(
1131:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1132:                        .exists());
1133:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1134:                        "mod1.2", "jar", "jar").exists());
1135:
1136:                assertTrue(getIvyFileInCache(
1137:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
1138:                        .exists());
1139:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
1140:                        "mod1.2", "jar", "jar").exists());
1141:            }
1142:
1143:            public void testResolveSeveralDefaultWithArtifacts()
1144:                    throws Exception {
1145:                // test case for IVY-261
1146:                // mod1.6 depends on
1147:                // mod1.4, which depends on mod1.3 and selects one of its artifacts
1148:                // mod1.3 and selects two of its artifacts
1149:                ResolveReport report = ivy.resolve(new File(
1150:                        "test/repositories/1/org1/mod1.6/ivys/ivy-1.0.3.xml")
1151:                        .toURL(), getResolveOptions(new String[] { "*" }));
1152:                assertFalse(report.hasError());
1153:
1154:                // dependencies
1155:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1156:                        "mod1.3-A", "jar", "jar").exists());
1157:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1158:                        "mod1.3-B", "jar", "jar").exists());
1159:            }
1160:
1161:            public void testResolveSeveralDefaultWithArtifactsAndConfs()
1162:                    throws Exception {
1163:                // test case for IVY-283
1164:                Ivy ivy = new Ivy();
1165:                ivy.configure(new File(
1166:                        "test/repositories/IVY-283/ivysettings.xml"));
1167:                ResolveReport report = ivy.resolve(new File(
1168:                        "test/repositories/IVY-283/ivy.xml").toURL(),
1169:                        getResolveOptions(new String[] { "*" }));
1170:                assertFalse(report.hasError());
1171:
1172:                // dependencies
1173:                ConfigurationResolveReport crr = report
1174:                        .getConfigurationReport("build");
1175:                assertNotNull(crr);
1176:                assertEquals(3, crr.getDownloadReports(ModuleRevisionId
1177:                        .newInstance("medicel", "C", "1.0")).length);
1178:
1179:                assertTrue(getArchiveFileInCache(ivy, "medicel", "C", "1.0",
1180:                        "lib_c_a", "jar", "jar").exists());
1181:                assertTrue(getArchiveFileInCache(ivy, "medicel", "C", "1.0",
1182:                        "lib_c_b", "jar", "jar").exists());
1183:                assertTrue(getArchiveFileInCache(ivy, "medicel", "C", "1.0",
1184:                        "lib_c_d", "jar", "jar").exists());
1185:            }
1186:
1187:            public void testResolveSeveralDefaultWithArtifactsAndConfs2()
1188:                    throws Exception {
1189:                // second test case for IVY-283
1190:                Ivy ivy = new Ivy();
1191:                ivy.configure(new File(
1192:                        "test/repositories/IVY-283/ivysettings.xml"));
1193:                ResolveReport report = ivy.resolve(new File(
1194:                        "test/repositories/IVY-283/ivy-d.xml").toURL(),
1195:                        getResolveOptions(new String[] { "*" }));
1196:                assertFalse(report.hasError());
1197:
1198:                // dependencies
1199:                ConfigurationResolveReport crr = report
1200:                        .getConfigurationReport("build");
1201:                assertNotNull(crr);
1202:                assertEquals(9, crr.getDownloadReports(ModuleRevisionId
1203:                        .newInstance("medicel", "module_a", "local")).length);
1204:
1205:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1206:                        "local", "lib_a_a", "jar", "jar").exists());
1207:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1208:                        "local", "lib_a_b", "jar", "jar").exists());
1209:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1210:                        "local", "lib_a_c", "jar", "jar").exists());
1211:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1212:                        "local", "lib_a_d", "jar", "jar").exists());
1213:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1214:                        "local", "lib_a_e", "jar", "jar").exists());
1215:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1216:                        "local", "lib_a_f", "jar", "jar").exists());
1217:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1218:                        "local", "lib_a_g", "jar", "jar").exists());
1219:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1220:                        "local", "lib_a_h", "jar", "jar").exists());
1221:                assertTrue(getArchiveFileInCache(ivy, "medicel", "module_a",
1222:                        "local", "lib_a_i", "jar", "jar").exists());
1223:            }
1224:
1225:            public void testResolveWithStartPublicConf() throws Exception {
1226:                // mod2.2 depends on mod1.3 and selects its artifacts
1227:                ResolveReport report = ivy.resolve(new File(
1228:                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.8.xml")
1229:                        .toURL(),
1230:                        getResolveOptions(new String[] { "*(public)" }));
1231:                assertNotNull(report);
1232:                ModuleDescriptor md = report.getModuleDescriptor();
1233:                assertNotNull(md);
1234:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1235:                        "mod2.2", "0.8");
1236:                assertEquals(mrid, md.getModuleRevisionId());
1237:
1238:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1239:
1240:                // dependencies
1241:                assertTrue(getIvyFileInCache(
1242:                        ModuleRevisionId.newInstance("org1", "mod1.3", "3.0"))
1243:                        .exists());
1244:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1245:                        "mod1.3-A", "jar", "jar").exists());
1246:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1247:                        "mod1.3-B", "jar", "jar").exists());
1248:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1249:                        "mod1.3", "jar", "jar").exists());
1250:            }
1251:
1252:            public void testResolveWithPrivateConf() throws Exception {
1253:                // mod2.2 depends on mod1.3 and selects its artifacts
1254:                ResolveReport report = ivy.resolve(new File(
1255:                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.8.xml")
1256:                        .toURL(),
1257:                        getResolveOptions(new String[] { "*(private)" }));
1258:                assertNotNull(report);
1259:                ModuleDescriptor md = report.getModuleDescriptor();
1260:                assertNotNull(md);
1261:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1262:                        "mod2.2", "0.8");
1263:                assertEquals(mrid, md.getModuleRevisionId());
1264:
1265:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1266:
1267:                assertTrue(getIvyFileInCache(
1268:                        ModuleRevisionId.newInstance("org1", "mod1.3", "3.0"))
1269:                        .exists());
1270:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1271:                        "mod1.3-A", "jar", "jar").exists());
1272:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1273:                        "mod1.3-B", "jar", "jar").exists());
1274:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1275:                        "mod1.3", "jar", "jar").exists());
1276:            }
1277:
1278:            public void testResolveDefaultWithArtifactsConf1() throws Exception {
1279:                // mod2.2 depends on mod1.3 and selects its artifacts
1280:                ResolveReport report = ivy
1281:                        .resolve(
1282:                                new File(
1283:                                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml")
1284:                                        .toURL(),
1285:                                getResolveOptions(new String[] { "myconf1" }));
1286:                assertNotNull(report);
1287:                ModuleDescriptor md = report.getModuleDescriptor();
1288:                assertNotNull(md);
1289:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1290:                        "mod2.2", "0.5");
1291:                assertEquals(mrid, md.getModuleRevisionId());
1292:
1293:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1294:
1295:                // dependencies
1296:                assertTrue(getIvyFileInCache(
1297:                        ModuleRevisionId.newInstance("org1", "mod1.3", "3.0"))
1298:                        .exists());
1299:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1300:                        "mod1.3-A", "jar", "jar").exists());
1301:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1302:                        "mod1.3-B", "jar", "jar").exists());
1303:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1304:                        "mod1.3", "jar", "jar").exists());
1305:            }
1306:
1307:            public void testResolveDefaultWithArtifactsConf2() throws Exception {
1308:                // mod2.2 depends on mod1.3 and selects its artifacts
1309:                ResolveReport report = ivy
1310:                        .resolve(
1311:                                new File(
1312:                                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml")
1313:                                        .toURL(),
1314:                                getResolveOptions(new String[] { "myconf2" }));
1315:                assertNotNull(report);
1316:                ModuleDescriptor md = report.getModuleDescriptor();
1317:                assertNotNull(md);
1318:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1319:                        "mod2.2", "0.5");
1320:                assertEquals(mrid, md.getModuleRevisionId());
1321:
1322:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1323:
1324:                assertTrue(getIvyFileInCache(
1325:                        ModuleRevisionId.newInstance("org1", "mod1.3", "3.0"))
1326:                        .exists());
1327:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1328:                        "mod1.3-A", "jar", "jar").exists());
1329:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1330:                        "mod1.3-B", "jar", "jar").exists());
1331:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1332:                        "mod1.3", "jar", "jar").exists());
1333:            }
1334:
1335:            public void testResolveDefaultWithArtifactsAndConfMapping()
1336:                    throws Exception {
1337:                // mod2.2 depends on mod1.3 and specify its artifacts and a conf mapping
1338:                ResolveReport report = ivy
1339:                        .resolve(
1340:                                new File(
1341:                                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.5.1.xml")
1342:                                        .toURL(),
1343:                                getResolveOptions(new String[] { "myconf1" }));
1344:                assertNotNull(report);
1345:                assertFalse(report.hasError());
1346:                ModuleDescriptor md = report.getModuleDescriptor();
1347:                assertNotNull(md);
1348:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1349:                        "mod2.2", "0.5.1");
1350:                assertEquals(mrid, md.getModuleRevisionId());
1351:
1352:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1353:
1354:                assertTrue(getIvyFileInCache(
1355:                        ModuleRevisionId.newInstance("org1", "mod1.3", "3.0"))
1356:                        .exists());
1357:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1358:                        "mod1.3-A", "jar", "jar").exists());
1359:                assertTrue(getArchiveFileInCache("org1", "mod1.3", "3.0",
1360:                        "mod1.3-B", "jar", "jar").exists());
1361:                assertTrue(!getArchiveFileInCache("org1", "mod1.3", "3.0",
1362:                        "mod1.3", "jar", "jar").exists());
1363:            }
1364:
1365:            public void testResolveWithIncludeArtifactsConf1() throws Exception {
1366:                // mod2.3 depends on mod2.1 and selects its artifacts in myconf1
1367:                ResolveReport report = ivy
1368:                        .resolve(
1369:                                new File(
1370:                                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml")
1371:                                        .toURL(),
1372:                                getResolveOptions(new String[] { "myconf1" }));
1373:                assertNotNull(report);
1374:                ModuleDescriptor md = report.getModuleDescriptor();
1375:                assertNotNull(md);
1376:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1377:                        "mod2.3", "0.4");
1378:                assertEquals(mrid, md.getModuleRevisionId());
1379:
1380:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1381:
1382:                assertTrue(getIvyFileInCache(
1383:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1384:                        .exists());
1385:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1386:                        "art21A", "jar", "jar").exists());
1387:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1388:                        "art21B", "jar", "jar").exists());
1389:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1390:                        "mod2.1", "jar", "jar").exists());
1391:            }
1392:
1393:            public void testResolveWithIncludeArtifactsConf2() throws Exception {
1394:                // mod2.3 depends on mod2.1 and selects its artifacts in myconf1
1395:                ResolveReport report = ivy
1396:                        .resolve(
1397:                                new File(
1398:                                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.4.xml")
1399:                                        .toURL(),
1400:                                getResolveOptions(new String[] { "myconf2" }));
1401:                assertNotNull(report);
1402:                ModuleDescriptor md = report.getModuleDescriptor();
1403:                assertNotNull(md);
1404:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1405:                        "mod2.3", "0.4");
1406:                assertEquals(mrid, md.getModuleRevisionId());
1407:
1408:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1409:
1410:                assertTrue(getIvyFileInCache(
1411:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1412:                        .exists());
1413:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1414:                        "art21A", "jar", "jar").exists());
1415:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1416:                        "art21B", "jar", "jar").exists());
1417:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1418:                        "mod2.1", "jar", "jar").exists());
1419:            }
1420:
1421:            public void testResolveWithIncludeArtifactsWithoutConf()
1422:                    throws Exception {
1423:                // mod2.3 depends on mod2.1 and selects its artifacts
1424:                ResolveReport report = ivy.resolve(new File(
1425:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.5.xml")
1426:                        .toURL(), getResolveOptions(new String[] { "*" }));
1427:                assertNotNull(report);
1428:                ModuleDescriptor md = report.getModuleDescriptor();
1429:                assertNotNull(md);
1430:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1431:                        "mod2.3", "0.5");
1432:                assertEquals(mrid, md.getModuleRevisionId());
1433:
1434:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1435:
1436:                assertTrue(getIvyFileInCache(
1437:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1438:                        .exists());
1439:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1440:                        "art21A", "jar", "jar").exists());
1441:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1442:                        "art21B", "jar", "jar").exists());
1443:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1444:                        "mod2.1", "jar", "jar").exists());
1445:            }
1446:
1447:            public void testResolveWithExcludesArtifacts() throws Exception {
1448:                // mod2.3 depends on mod2.1 and selects its artifacts
1449:                ResolveReport report = ivy.resolve(new File(
1450:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.xml")
1451:                        .toURL(), getResolveOptions(new String[] { "*" }));
1452:                assertNotNull(report);
1453:                ModuleDescriptor md = report.getModuleDescriptor();
1454:                assertNotNull(md);
1455:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1456:                        "mod2.3", "0.6");
1457:                assertEquals(mrid, md.getModuleRevisionId());
1458:
1459:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1460:
1461:                assertTrue(getIvyFileInCache(
1462:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1463:                        .exists());
1464:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1465:                        "art21A", "jar", "jar").exists());
1466:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1467:                        "art21B", "jar", "jar").exists());
1468:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1469:                        "mod2.1", "jar", "jar").exists());
1470:            }
1471:
1472:            public void testResolveWithExcludesArtifacts2() throws Exception {
1473:                // mod2.3 depends on mod2.1 and badly excludes artifacts with incorrect matcher
1474:                ResolveReport report = ivy.resolve(new File(
1475:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.2.xml")
1476:                        .toURL(), getResolveOptions(new String[] { "*" }));
1477:                assertNotNull(report);
1478:                ModuleDescriptor md = report.getModuleDescriptor();
1479:                assertNotNull(md);
1480:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1481:                        "mod2.3", "0.6.2");
1482:                assertEquals(mrid, md.getModuleRevisionId());
1483:
1484:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1485:
1486:                assertTrue(getIvyFileInCache(
1487:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1488:                        .exists());
1489:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1490:                        "art21A", "jar", "jar").exists());
1491:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1492:                        "art21B", "jar", "jar").exists());
1493:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1494:                        "mod2.1", "jar", "jar").exists());
1495:            }
1496:
1497:            public void testResolveWithExcludesArtifacts3() throws Exception {
1498:                // mod2.3 depends on mod2.1 and excludes artifacts with exact matcher
1499:                ResolveReport report = ivy.resolve(new File(
1500:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.3.xml")
1501:                        .toURL(), getResolveOptions(new String[] { "*" }));
1502:                assertNotNull(report);
1503:                ModuleDescriptor md = report.getModuleDescriptor();
1504:                assertNotNull(md);
1505:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1506:                        "mod2.3", "0.6.3");
1507:                assertEquals(mrid, md.getModuleRevisionId());
1508:
1509:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1510:
1511:                assertTrue(getIvyFileInCache(
1512:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1513:                        .exists());
1514:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1515:                        "art21A", "jar", "jar").exists());
1516:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1517:                        "art21B", "jar", "jar").exists());
1518:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1519:                        "mod2.1", "jar", "jar").exists());
1520:            }
1521:
1522:            public void testResolveWithExcludesArtifacts4() throws Exception {
1523:                // mod2.3 depends on mod2.1 and excludes artifacts with regexp matcher
1524:                ResolveReport report = ivy.resolve(new File(
1525:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.4.xml")
1526:                        .toURL(), getResolveOptions(new String[] { "*" }));
1527:                assertNotNull(report);
1528:                ModuleDescriptor md = report.getModuleDescriptor();
1529:                assertNotNull(md);
1530:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1531:                        "mod2.3", "0.6.4");
1532:                assertEquals(mrid, md.getModuleRevisionId());
1533:
1534:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1535:
1536:                assertTrue(getIvyFileInCache(
1537:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1538:                        .exists());
1539:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1540:                        "art21A", "jar", "jar").exists());
1541:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1542:                        "art21B", "jar", "jar").exists());
1543:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1544:                        "mod2.1", "jar", "jar").exists());
1545:            }
1546:
1547:            public void testResolveWithExcludesArtifacts5() throws Exception {
1548:                // mod2.3 depends on mod2.1 and excludes artifacts with glob matcher
1549:                ResolveReport report = ivy.resolve(new File(
1550:                        "test/repositories/1/org2/mod2.3/ivys/ivy-0.6.5.xml")
1551:                        .toURL(), getResolveOptions(new String[] { "*" }));
1552:                assertNotNull(report);
1553:                ModuleDescriptor md = report.getModuleDescriptor();
1554:                assertNotNull(md);
1555:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1556:                        "mod2.3", "0.6.5");
1557:                assertEquals(mrid, md.getModuleRevisionId());
1558:
1559:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1560:
1561:                assertTrue(getIvyFileInCache(
1562:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
1563:                        .exists());
1564:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
1565:                        "art21A", "jar", "jar").exists());
1566:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1567:                        "art21B", "jar", "jar").exists());
1568:                assertTrue(!getArchiveFileInCache("org2", "mod2.1", "0.3",
1569:                        "mod2.1", "jar", "jar").exists());
1570:            }
1571:
1572:            public void testResolveTransitiveDependencies() throws Exception {
1573:                // mod2.1 depends on mod1.1 which depends on mod1.2
1574:                ResolveReport report = ivy.resolve(new File(
1575:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml")
1576:                        .toURL(), getResolveOptions(new String[] { "*" }));
1577:                assertNotNull(report);
1578:                ModuleDescriptor md = report.getModuleDescriptor();
1579:                assertNotNull(md);
1580:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1581:                        "mod2.1", "0.3");
1582:                assertEquals(mrid, md.getModuleRevisionId());
1583:
1584:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1585:
1586:                // dependencies
1587:                assertTrue(getIvyFileInCache(
1588:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1589:                        .exists());
1590:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1591:                        "mod1.1", "jar", "jar").exists());
1592:
1593:                assertTrue(getIvyFileInCache(
1594:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1595:                        .exists());
1596:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1597:                        "mod1.2", "jar", "jar").exists());
1598:            }
1599:
1600:            public void testResolveTransitiveDisabled() throws Exception {
1601:                // mod2.1 depends on mod1.1 which depends on mod1.2
1602:                ResolveReport report = ivy.resolve(new File(
1603:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.xml")
1604:                        .toURL(), getResolveOptions(new String[] { "*" })
1605:                        .setTransitive(false));
1606:                assertNotNull(report);
1607:                ModuleDescriptor md = report.getModuleDescriptor();
1608:                assertNotNull(md);
1609:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
1610:                        "mod2.1", "0.3");
1611:                assertEquals(mrid, md.getModuleRevisionId());
1612:
1613:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1614:
1615:                // dependencies
1616:                assertTrue(getIvyFileInCache(
1617:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1618:                        .exists());
1619:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1620:                        "mod1.1", "jar", "jar").exists());
1621:
1622:                assertFalse(getIvyFileInCache(
1623:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1624:                        .exists());
1625:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1626:                        "mod1.2", "jar", "jar").exists());
1627:            }
1628:
1629:            public void testDependenciesOrder() throws Exception {
1630:                ResolveReport report = ivy.resolve(ResolveTest.class
1631:                        .getResource("ivy-225.xml"),
1632:                        getResolveOptions(new String[] { "default" }));
1633:
1634:                List revisions = new ArrayList(report.getConfigurationReport(
1635:                        "default").getModuleRevisionIds());
1636:                assertTrue("number of revisions is not correct", revisions
1637:                        .size() >= 3);
1638:
1639:                int mod12Index = revisions.indexOf(ModuleRevisionId
1640:                        .newInstance("org1", "mod1.2", "1.1"));
1641:                int mod32Index = revisions.indexOf(ModuleRevisionId
1642:                        .newInstance("org3", "mod3.2", "1.4"));
1643:                int mod51Index = revisions.indexOf(ModuleRevisionId
1644:                        .newInstance("org5", "mod5.1", "4.2"));
1645:
1646:                // verify the order of the modules in the ivy file
1647:                assertTrue("[ org1 | mod1.2 | 1.1 ] was not found",
1648:                        mod12Index > -1);
1649:                assertTrue(
1650:                        "[ org1 | mod1.2 | 1.1 ] must come before [ org3 | mod3.2 | 1.4 ]",
1651:                        mod12Index < mod32Index);
1652:                assertTrue(
1653:                        "[ org3 | mod3.2 | 1.4 ] must come before [ org5 | mod5.1 | 4.2 ]",
1654:                        mod32Index < mod51Index);
1655:            }
1656:
1657:            public void testDisableTransitivityPerConfiguration()
1658:                    throws Exception {
1659:                // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
1660:                // compile conf is not transitive
1661:
1662:                // first we resolve compile conf only
1663:                ivy
1664:                        .resolve(
1665:                                new File(
1666:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml")
1667:                                        .toURL(),
1668:                                getResolveOptions(new String[] { "compile" }));
1669:
1670:                // dependencies
1671:                assertTrue(getIvyFileInCache(
1672:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1673:                        .exists());
1674:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1675:                        "mod1.1", "jar", "jar").exists());
1676:
1677:                assertFalse(getIvyFileInCache(
1678:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1679:                        .exists());
1680:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1681:                        "mod1.2", "jar", "jar").exists());
1682:
1683:                // then we resolve runtime conf
1684:                ivy
1685:                        .resolve(
1686:                                new File(
1687:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml")
1688:                                        .toURL(),
1689:                                getResolveOptions(new String[] { "runtime" }));
1690:
1691:                // dependencies
1692:                assertTrue(getIvyFileInCache(
1693:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1694:                        .exists());
1695:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1696:                        "mod1.2", "jar", "jar").exists());
1697:
1698:                // same as before, but resolve both confs in one call
1699:                ResolveReport r = ivy.resolve(new File(
1700:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.1.xml")
1701:                        .toURL(), getResolveOptions(new String[] { "runtime",
1702:                        "compile" }));
1703:                assertFalse(r.hasError());
1704:                assertEquals(1, r.getConfigurationReport("compile")
1705:                        .getArtifactsNumber());
1706:                assertEquals(2, r.getConfigurationReport("runtime")
1707:                        .getArtifactsNumber());
1708:            }
1709:
1710:            public void testDisableTransitivityPerConfiguration2()
1711:                    throws Exception {
1712:                // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
1713:                // compile conf is not transitive
1714:                // compile extends runtime
1715:
1716:                // first we resolve compile conf only
1717:                ivy
1718:                        .resolve(
1719:                                new File(
1720:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml")
1721:                                        .toURL(),
1722:                                getResolveOptions(new String[] { "compile" }));
1723:
1724:                // dependencies
1725:                assertTrue(getIvyFileInCache(
1726:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1727:                        .exists());
1728:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1729:                        "mod1.1", "jar", "jar").exists());
1730:
1731:                assertFalse(getIvyFileInCache(
1732:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1733:                        .exists());
1734:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1735:                        "mod1.2", "jar", "jar").exists());
1736:
1737:                // then we resolve runtime conf
1738:                ivy
1739:                        .resolve(
1740:                                new File(
1741:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml")
1742:                                        .toURL(),
1743:                                getResolveOptions(new String[] { "runtime" }));
1744:
1745:                // dependencies
1746:                assertTrue(getIvyFileInCache(
1747:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1748:                        .exists());
1749:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1750:                        "mod1.2", "jar", "jar").exists());
1751:
1752:                // same as before, but resolve both confs in one call
1753:                ResolveReport r = ivy.resolve(new File(
1754:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.2.xml")
1755:                        .toURL(), getResolveOptions(new String[] { "runtime",
1756:                        "compile" }));
1757:                assertFalse(r.hasError());
1758:                assertEquals(1, r.getConfigurationReport("compile")
1759:                        .getArtifactsNumber());
1760:                assertEquals(2, r.getConfigurationReport("runtime")
1761:                        .getArtifactsNumber());
1762:            }
1763:
1764:            public void testDisableTransitivityPerConfiguration3()
1765:                    throws Exception {
1766:                // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
1767:                // compile conf is not transitive
1768:                // runtime extends compile
1769:
1770:                // first we resolve compile conf only
1771:                ivy
1772:                        .resolve(
1773:                                new File(
1774:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml")
1775:                                        .toURL(),
1776:                                getResolveOptions(new String[] { "compile" }));
1777:
1778:                // dependencies
1779:                assertTrue(getIvyFileInCache(
1780:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1781:                        .exists());
1782:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1783:                        "mod1.1", "jar", "jar").exists());
1784:
1785:                assertFalse(getIvyFileInCache(
1786:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1787:                        .exists());
1788:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1789:                        "mod1.2", "jar", "jar").exists());
1790:
1791:                // then we resolve runtime conf
1792:                ivy
1793:                        .resolve(
1794:                                new File(
1795:                                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml")
1796:                                        .toURL(),
1797:                                getResolveOptions(new String[] { "runtime" }));
1798:
1799:                // dependencies
1800:                assertTrue(getIvyFileInCache(
1801:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1802:                        .exists());
1803:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1804:                        "mod1.2", "jar", "jar").exists());
1805:
1806:                // same as before, but resolve both confs in one call
1807:                ResolveReport r = ivy.resolve(new File(
1808:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.3.3.xml")
1809:                        .toURL(), getResolveOptions(new String[] { "runtime",
1810:                        "compile" }));
1811:                assertFalse(r.hasError());
1812:                assertEquals(1, r.getConfigurationReport("compile")
1813:                        .getArtifactsNumber());
1814:                assertEquals(2, r.getConfigurationReport("runtime")
1815:                        .getArtifactsNumber());
1816:            }
1817:
1818:            public void testDisableTransitivityPerConfiguration4()
1819:                    throws Exception {
1820:                // mod2.2 (A,B,compile) depends on mod 2.1 (A->runtime;B->compile)
1821:                // compile is not transitive and extends A and B
1822:                //
1823:                // mod2.1 (compile, runtime) depends on mod1.1 which depends on mod1.2
1824:                // compile conf is not transitive and extends runtime
1825:
1826:                ResolveReport r = ivy.resolve(new File(
1827:                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.6.xml")
1828:                        .toURL(), getResolveOptions(new String[] { "*" }));
1829:                assertFalse(r.hasError());
1830:
1831:                // here we should get all three recursive dependencies
1832:                assertEquals(new HashSet(Arrays
1833:                        .asList(new ModuleRevisionId[] {
1834:                                ModuleRevisionId.newInstance("org2", "mod2.1",
1835:                                        "0.3.2"),
1836:                                ModuleRevisionId.newInstance("org1", "mod1.1",
1837:                                        "1.0"),
1838:                                ModuleRevisionId.newInstance("org1", "mod1.2",
1839:                                        "2.0") })), r.getConfigurationReport(
1840:                        "A").getModuleRevisionIds());
1841:
1842:                // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1
1843:                assertEquals(new HashSet(Arrays
1844:                        .asList(new ModuleRevisionId[] {
1845:                                ModuleRevisionId.newInstance("org2", "mod2.1",
1846:                                        "0.3.2"),
1847:                                ModuleRevisionId.newInstance("org1", "mod1.1",
1848:                                        "1.0") })), r.getConfigurationReport(
1849:                        "B").getModuleRevisionIds());
1850:
1851:                // here we should get only mod2.1 cause compile is not transitive
1852:                assertEquals(new HashSet(Arrays
1853:                        .asList(new ModuleRevisionId[] { ModuleRevisionId
1854:                                .newInstance("org2", "mod2.1", "0.3.2") })), r
1855:                        .getConfigurationReport("compile")
1856:                        .getModuleRevisionIds());
1857:            }
1858:
1859:            public void testDisableTransitivityPerConfiguration5()
1860:                    throws Exception {
1861:                // mod2.2 (A,B,compile) depends on
1862:                // mod 2.1 (A->runtime;B->compile)
1863:                // mod1.1 (A->*) ]0.9.9,1.0] (which resolves to 1.0)
1864:                // compile is not transitive and extends A and B
1865:                //
1866:                // mod2.1 (compile, runtime) depends on mod1.1 1.0 which depends on mod1.2 2.0
1867:                // compile conf is not transitive and extends runtime
1868:
1869:                ResolveReport r = ivy.resolve(new File(
1870:                        "test/repositories/1/org2/mod2.2/ivys/ivy-0.7.xml")
1871:                        .toURL(), getResolveOptions(new String[] { "A", "B",
1872:                        "compile" }));
1873:                assertFalse(r.hasError());
1874:
1875:                // here we should get all three recursive dependencies
1876:                assertEquals(new HashSet(Arrays
1877:                        .asList(new ModuleRevisionId[] {
1878:                                ModuleRevisionId.newInstance("org2", "mod2.1",
1879:                                        "0.3.2"),
1880:                                ModuleRevisionId.newInstance("org1", "mod1.1",
1881:                                        "1.0"),
1882:                                ModuleRevisionId.newInstance("org1", "mod1.2",
1883:                                        "2.0") })), r.getConfigurationReport(
1884:                        "A").getModuleRevisionIds());
1885:
1886:                // here we should get only mod2.1 and mod1.1 cause compile is not transitive in mod2.1
1887:                assertEquals(new HashSet(Arrays
1888:                        .asList(new ModuleRevisionId[] {
1889:                                ModuleRevisionId.newInstance("org2", "mod2.1",
1890:                                        "0.3.2"),
1891:                                ModuleRevisionId.newInstance("org1", "mod1.1",
1892:                                        "1.0") })), r.getConfigurationReport(
1893:                        "B").getModuleRevisionIds());
1894:
1895:                // here we should get only mod2.1 cause compile is not transitive
1896:                assertEquals(new HashSet(Arrays
1897:                        .asList(new ModuleRevisionId[] {
1898:                                ModuleRevisionId.newInstance("org2", "mod2.1",
1899:                                        "0.3.2"),
1900:                                ModuleRevisionId.newInstance("org1", "mod1.1",
1901:                                        "1.0") })), r.getConfigurationReport(
1902:                        "compile").getModuleRevisionIds());
1903:            }
1904:
1905:            public void testResolveDiamond() throws Exception {
1906:                // mod4.1 depends on
1907:                // - mod1.1 which depends on mod1.2
1908:                // - mod3.1 which depends on mod1.2
1909:                ResolveReport report = ivy.resolve(new File(
1910:                        "test/repositories/2/mod4.1/ivy-4.0.xml").toURL(),
1911:                        getResolveOptions(new String[] { "*" }));
1912:                assertNotNull(report);
1913:                ModuleDescriptor md = report.getModuleDescriptor();
1914:                assertNotNull(md);
1915:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
1916:                        "mod4.1", "4.0");
1917:                assertEquals(mrid, md.getModuleRevisionId());
1918:
1919:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1920:
1921:                // dependencies
1922:                assertTrue(getIvyFileInCache(
1923:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1924:                        .exists());
1925:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1926:                        "mod1.1", "jar", "jar").exists());
1927:
1928:                assertTrue(getIvyFileInCache(
1929:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
1930:                        .exists());
1931:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
1932:                        "mod1.2", "jar", "jar").exists());
1933:
1934:                assertTrue(getIvyFileInCache(
1935:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.0"))
1936:                        .exists());
1937:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.0",
1938:                        "mod3.1", "jar", "jar").exists());
1939:            }
1940:
1941:            public void testResolveConflict() throws Exception {
1942:                // mod4.1 v 4.1 depends on
1943:                // - mod1.1 v 1.0 which depends on mod1.2 v 2.0
1944:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
1945:                ResolveReport report = ivy.resolve(new File(
1946:                        "test/repositories/2/mod4.1/ivy-4.1.xml").toURL(),
1947:                        getResolveOptions(new String[] { "*" }));
1948:                assertNotNull(report);
1949:                ModuleDescriptor md = report.getModuleDescriptor();
1950:                assertNotNull(md);
1951:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
1952:                        "mod4.1", "4.1");
1953:                assertEquals(mrid, md.getModuleRevisionId());
1954:
1955:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
1956:
1957:                // dependencies
1958:                ConfigurationResolveReport crr = report
1959:                        .getConfigurationReport("default");
1960:                assertNotNull(crr);
1961:                assertEquals(0, crr.getDownloadReports(ModuleRevisionId
1962:                        .newInstance("org1", "mod1.2", "2.0")).length);
1963:                assertEquals(1, crr.getDownloadReports(ModuleRevisionId
1964:                        .newInstance("org1", "mod1.2", "2.1")).length);
1965:
1966:                File r = getConfigurationResolveReportInCache(ResolveOptions
1967:                        .getDefaultResolveId(md), "default");
1968:                assertTrue(r.exists());
1969:                final boolean[] found = new boolean[] { false };
1970:                SAXParser saxParser = SAXParserFactory.newInstance()
1971:                        .newSAXParser();
1972:                saxParser.parse(r, new DefaultHandler() {
1973:                    public void startElement(String uri, String localName,
1974:                            String qName, org.xml.sax.Attributes attributes)
1975:                            throws SAXException {
1976:                        if ("revision".equals(qName)
1977:                                && "2.0".equals(attributes.getValue("name"))) {
1978:                            found[0] = true;
1979:                        }
1980:                    }
1981:                });
1982:                assertTrue(found[0]); // the report should contain the evicted revision
1983:
1984:                assertTrue(getIvyFileInCache(
1985:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
1986:                        .exists());
1987:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
1988:                        "mod1.1", "jar", "jar").exists());
1989:
1990:                assertTrue(getIvyFileInCache(
1991:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.1"))
1992:                        .exists());
1993:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1",
1994:                        "mod3.1", "jar", "jar").exists());
1995:
1996:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
1997:                        "mod1.2", "jar", "jar").exists());
1998:
1999:                assertTrue(getIvyFileInCache(
2000:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2001:                        .exists());
2002:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
2003:                        "mod1.2", "jar", "jar").exists());
2004:            }
2005:
2006:            public void testResolveConflict2() throws Exception {
2007:                // mod4.1 v 4.14 depends on
2008:                // - mod1.1 v 1.0 which depends on mod1.2 v 2.0
2009:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2010:                // - mod6.1 v 0.3 which depends on mod1.2 v 2.0
2011:                ResolveReport report = ivy.resolve(new File(
2012:                        "test/repositories/2/mod4.1/ivy-4.14.xml").toURL(),
2013:                        getResolveOptions(new String[] { "*" }));
2014:
2015:                // dependencies
2016:                ConfigurationResolveReport crr = report
2017:                        .getConfigurationReport("default");
2018:                assertNotNull(crr);
2019:                assertEquals(0, crr.getDownloadReports(ModuleRevisionId
2020:                        .newInstance("org1", "mod1.2", "2.0")).length);
2021:                assertEquals(1, crr.getDownloadReports(ModuleRevisionId
2022:                        .newInstance("org1", "mod1.2", "2.1")).length);
2023:
2024:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2025:                        "mod4.1", "4.14");
2026:                File r = getConfigurationResolveReportInCache(ResolveOptions
2027:                        .getDefaultResolveId(mrid.getModuleId()), "default");
2028:                assertTrue(r.exists());
2029:                final boolean[] found = new boolean[] { false };
2030:                SAXParser saxParser = SAXParserFactory.newInstance()
2031:                        .newSAXParser();
2032:                saxParser.parse(r, new DefaultHandler() {
2033:                    public void startElement(String uri, String localName,
2034:                            String qName, org.xml.sax.Attributes attributes)
2035:                            throws SAXException {
2036:                        if ("revision".equals(qName)
2037:                                && "2.0".equals(attributes.getValue("name"))) {
2038:                            found[0] = true;
2039:                        }
2040:                    }
2041:                });
2042:                assertTrue(found[0]); // the report should contain the evicted revision
2043:
2044:                assertTrue(getIvyFileInCache(
2045:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
2046:                        .exists());
2047:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
2048:                        "mod1.1", "jar", "jar").exists());
2049:
2050:                assertTrue(getIvyFileInCache(
2051:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.1"))
2052:                        .exists());
2053:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1",
2054:                        "mod3.1", "jar", "jar").exists());
2055:
2056:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
2057:                        "mod1.2", "jar", "jar").exists());
2058:
2059:                assertTrue(getIvyFileInCache(
2060:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2061:                        .exists());
2062:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
2063:                        "mod1.2", "jar", "jar").exists());
2064:            }
2065:
2066:            public void testResolveConflict3() throws Exception {
2067:                // test case for IVY-264
2068:                // a depends on x latest, y latest, z latest
2069:                // x and z depends on commons-lang 1.0.1
2070:                // y depends on commons-lang 2.0
2071:                Ivy ivy = new Ivy();
2072:                ivy.configure(new File(
2073:                        "test/repositories/IVY-264/ivysettings.xml"));
2074:                ResolveReport report = ivy.resolve(new File(
2075:                        "test/repositories/IVY-264/ivy.xml").toURL(),
2076:                        getResolveOptions(new String[] { "*" }));
2077:                assertFalse(report.hasError());
2078:
2079:                // dependencies
2080:                ConfigurationResolveReport crr = report
2081:                        .getConfigurationReport("default");
2082:                assertNotNull(crr);
2083:                assertEquals(0, crr.getDownloadReports(ModuleRevisionId
2084:                        .newInstance("myorg", "commons-lang", "1.0.1")).length);
2085:                assertEquals(1, crr.getDownloadReports(ModuleRevisionId
2086:                        .newInstance("myorg", "commons-lang", "2.0")).length);
2087:
2088:                assertFalse(getArchiveFileInCache(ivy, "myorg", "commons-lang",
2089:                        "1.0.1", "commons-lang", "jar", "jar").exists());
2090:
2091:                assertTrue(getArchiveFileInCache(ivy, "myorg", "commons-lang",
2092:                        "2.0", "commons-lang", "jar", "jar").exists());
2093:            }
2094:
2095:            /**
2096:             * Test IVY-618. 
2097:             */
2098:            public void testResolveConflictFromPoms() throws Exception {
2099:                ResolveReport report = ivy.resolve(new File(
2100:                        "test/repositories/2/mod17.1/ivy-1.0.xml").toURL(),
2101:                        getResolveOptions(new String[] { "*" }));
2102:                assertNotNull(report);
2103:                assertFalse(report.hasError());
2104:            }
2105:
2106:            public void testTransitiveEviction() throws Exception {
2107:                // mod7.3 depends on mod7.2 v1.0 and on mod7.1 v2.0
2108:                // mod7.2 v1.0 depends on mod7.1 v1.0 (which then should be evicted)
2109:                // mod7.1 v1.0 depends on mod 1.2 v2.0 (which should be evicted by transitivity)
2110:
2111:                ResolveReport report = ivy.resolve(new File(
2112:                        "test/repositories/2/mod7.3/ivy-1.0.xml").toURL(),
2113:                        getResolveOptions(new String[] { "*" }));
2114:                assertNotNull(report);
2115:                ModuleDescriptor md = report.getModuleDescriptor();
2116:                assertNotNull(md);
2117:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org7",
2118:                        "mod7.3", "1.0");
2119:                assertEquals(mrid, md.getModuleRevisionId());
2120:
2121:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2122:
2123:                // dependencies
2124:                assertTrue(getIvyFileInCache(
2125:                        ModuleRevisionId.newInstance("org7", "mod7.2", "1.0"))
2126:                        .exists());
2127:                assertTrue(getArchiveFileInCache("org7", "mod7.2", "1.0",
2128:                        "mod7.2", "jar", "jar").exists());
2129:
2130:                assertTrue(getIvyFileInCache(
2131:                        ModuleRevisionId.newInstance("org7", "mod7.1", "2.0"))
2132:                        .exists());
2133:                assertTrue(getArchiveFileInCache("org7", "mod7.1", "2.0",
2134:                        "mod7.1", "jar", "jar").exists());
2135:
2136:                assertFalse(getArchiveFileInCache("org7", "mod7.1", "1.0",
2137:                        "mod7.1", "jar", "jar").exists());
2138:
2139:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
2140:                        "mod1.2", "jar", "jar").exists());
2141:            }
2142:
2143:            public void testTransitiveEviction2() throws Exception {
2144:                // IVY-199
2145:                // mod4.1 v 4.13 depends on
2146:                // - mod3.2 v 1.2.1 which depends on
2147:                // - mod3.1 v 1.0 which depends on mod1.2 v 2.0
2148:                // - mod1.2 v 2.1
2149:                ResolveReport report = ivy.resolve(new File(
2150:                        "test/repositories/2/mod4.1/ivy-4.13.xml").toURL(),
2151:                        getResolveOptions(new String[] { "*" }));
2152:                assertNotNull(report);
2153:
2154:                // dependencies
2155:                assertTrue(getIvyFileInCache(
2156:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2157:                        .exists());
2158:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
2159:                        "mod1.2", "jar", "jar").exists());
2160:
2161:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
2162:                        "mod1.2", "jar", "jar").exists());
2163:            }
2164:
2165:            public void testTransitiveEvictionWithExtendingConf()
2166:                    throws Exception {
2167:                // IVY-590
2168:                ResolveReport report = ivy.resolve(ResolveTest.class
2169:                        .getResource("ivy-590.xml"),
2170:                        getResolveOptions(new String[] { "*" }));
2171:                assertNotNull(report);
2172:
2173:                // dependencies
2174:                assertTrue(getIvyFileInCache(
2175:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2176:                        .exists());
2177:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2178:                        "mod1.2", "jar", "jar").exists());
2179:
2180:                // test eviction
2181:                ConfigurationResolveReport compileReport = report
2182:                        .getConfigurationReport("compile");
2183:                IvyNode[] evicted = compileReport.getEvictedNodes();
2184:                assertNotNull(evicted);
2185:
2186:                Collection evictedModules = new ArrayList();
2187:                for (int i = 0; i < evicted.length; i++) {
2188:                    evictedModules.add(evicted[i].getId());
2189:                }
2190:
2191:                assertTrue(evictedModules.contains(ModuleRevisionId
2192:                        .newInstance("org1", "mod1.2", "2.0")));
2193:            }
2194:
2195:            public void testResolveConflictInConf() throws Exception {
2196:                // conflicts in separate confs are not conflicts
2197:
2198:                // mod2.1 conf A depends on mod1.1 which depends on mod1.2 2.0
2199:                // mod2.1 conf B depends on mod1.2 2.1
2200:                ResolveReport report = ivy.resolve(new File(
2201:                        "test/repositories/1/org2/mod2.1/ivys/ivy-0.4.xml")
2202:                        .toURL(), getResolveOptions(new String[] { "*" }));
2203:                assertNotNull(report);
2204:                ModuleDescriptor md = report.getModuleDescriptor();
2205:                assertNotNull(md);
2206:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
2207:                        "mod2.1", "0.4");
2208:                assertEquals(mrid, md.getModuleRevisionId());
2209:
2210:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2211:
2212:                // dependencies
2213:                assertTrue(getIvyFileInCache(
2214:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
2215:                        .exists());
2216:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
2217:                        "mod1.1", "jar", "jar").exists());
2218:
2219:                assertTrue(getIvyFileInCache(
2220:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2221:                        .exists());
2222:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2223:                        "mod1.2", "jar", "jar").exists());
2224:
2225:                assertTrue(getIvyFileInCache(
2226:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2227:                        .exists());
2228:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
2229:                        "mod1.2", "jar", "jar").exists());
2230:            }
2231:
2232:            public void testEvictWithConf() throws Exception {
2233:                // bug 105 - test #1
2234:
2235:                // mod6.1 r1.0 depends on
2236:                // mod5.1 r4.2 conf A
2237:                // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
2238:                //
2239:                // mod5.1 r4.2 conf B depends on mod1.2 r2.0
2240:                ResolveReport report = ivy.resolve(new File(
2241:                        "test/repositories/2/mod6.1/ivy-1.0.xml").toURL(),
2242:                        getResolveOptions(new String[] { "*" }));
2243:                assertNotNull(report);
2244:                ModuleDescriptor md = report.getModuleDescriptor();
2245:                assertNotNull(md);
2246:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
2247:                        "mod6.1", "1.0");
2248:                assertEquals(mrid, md.getModuleRevisionId());
2249:
2250:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2251:
2252:                // dependencies
2253:                assertTrue(getIvyFileInCache(
2254:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.2"))
2255:                        .exists());
2256:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2257:                        "art51A", "jar", "jar").exists());
2258:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2259:                        "art51B", "jar", "jar").exists());
2260:
2261:                assertTrue(getIvyFileInCache(
2262:                        ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"))
2263:                        .exists());
2264:                assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0",
2265:                        "mod5.2", "jar", "jar").exists());
2266:
2267:                assertTrue(getIvyFileInCache(
2268:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2269:                        .exists());
2270:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2271:                        "mod1.2", "jar", "jar").exists());
2272:
2273:                // should have been evicted before download
2274:                assertFalse(getIvyFileInCache(
2275:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.0"))
2276:                        .exists());
2277:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2278:                        "art51A", "jar", "jar").exists());
2279:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2280:                        "art51B", "jar", "jar").exists());
2281:            }
2282:
2283:            public void testEvictWithConf2() throws Exception {
2284:                // same as preceding one but with inverse order, so that
2285:                // eviction is done after download
2286:                // bug 105 - test #2
2287:
2288:                // mod6.1 r1.1 depends on
2289:                // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
2290:                // mod5.1 r4.2 conf A
2291:                //
2292:                // mod5.1 r4.2 conf B depends on mod1.2 r2.0
2293:                ResolveReport report = ivy.resolve(new File(
2294:                        "test/repositories/2/mod6.1/ivy-1.1.xml").toURL(),
2295:                        getResolveOptions(new String[] { "*" }));
2296:                assertNotNull(report);
2297:                ModuleDescriptor md = report.getModuleDescriptor();
2298:                assertNotNull(md);
2299:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
2300:                        "mod6.1", "1.1");
2301:                assertEquals(mrid, md.getModuleRevisionId());
2302:
2303:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2304:
2305:                // dependencies
2306:                assertTrue(getIvyFileInCache(
2307:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.2"))
2308:                        .exists());
2309:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2310:                        "art51A", "jar", "jar").exists());
2311:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2312:                        "art51B", "jar", "jar").exists());
2313:
2314:                assertTrue(getIvyFileInCache(
2315:                        ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"))
2316:                        .exists());
2317:                assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0",
2318:                        "mod5.2", "jar", "jar").exists());
2319:
2320:                assertTrue(getIvyFileInCache(
2321:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2322:                        .exists());
2323:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2324:                        "mod1.2", "jar", "jar").exists());
2325:
2326:                // even late eviction should avoid artifact downloading
2327:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2328:                        "art51A", "jar", "jar").exists());
2329:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2330:                        "art51B", "jar", "jar").exists());
2331:            }
2332:
2333:            public void testEvictWithConfInMultiConf() throws Exception {
2334:                // same as preceding ones but the conflict appears in several root confs
2335:                // bug 105 - test #3
2336:
2337:                // mod6.1 r1.2 conf A and conf B depends on
2338:                // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
2339:                // mod5.1 r4.2 conf A
2340:                //
2341:                // mod5.1 r4.2 conf B depends on mod1.2 r2.0
2342:                ResolveReport report = ivy.resolve(new File(
2343:                        "test/repositories/2/mod6.1/ivy-1.2.xml").toURL(),
2344:                        getResolveOptions(new String[] { "*" }));
2345:                assertNotNull(report);
2346:                ModuleDescriptor md = report.getModuleDescriptor();
2347:                assertNotNull(md);
2348:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
2349:                        "mod6.1", "1.2");
2350:                assertEquals(mrid, md.getModuleRevisionId());
2351:
2352:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2353:
2354:                // dependencies
2355:                assertTrue(getIvyFileInCache(
2356:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.2"))
2357:                        .exists());
2358:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2359:                        "art51A", "jar", "jar").exists());
2360:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2361:                        "art51B", "jar", "jar").exists());
2362:
2363:                assertTrue(getIvyFileInCache(
2364:                        ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"))
2365:                        .exists());
2366:                assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0",
2367:                        "mod5.2", "jar", "jar").exists());
2368:
2369:                assertTrue(getIvyFileInCache(
2370:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2371:                        .exists());
2372:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2373:                        "mod1.2", "jar", "jar").exists());
2374:
2375:                // all artifacts should be present in both confs
2376:                ConfigurationResolveReport crr = report
2377:                        .getConfigurationReport("A");
2378:                assertNotNull(crr);
2379:                assertEquals(2, crr.getDownloadReports(ModuleRevisionId
2380:                        .newInstance("org5", "mod5.1", "4.2")).length);
2381:
2382:                crr = report.getConfigurationReport("B");
2383:                assertNotNull(crr);
2384:                assertEquals(2, crr.getDownloadReports(ModuleRevisionId
2385:                        .newInstance("org5", "mod5.1", "4.2")).length);
2386:
2387:                // even late eviction should avoid artifact downloading
2388:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2389:                        "art51A", "jar", "jar").exists());
2390:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
2391:                        "art51B", "jar", "jar").exists());
2392:            }
2393:
2394:            public void testEvictWithConfInMultiConf2() throws Exception {
2395:                // same as preceding one but the conflict appears in a root conf and not in another
2396:                // which should keep the evicted
2397:                // bug 105 - test #4
2398:
2399:                // mod6.1 r1.3 conf A depends on
2400:                // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
2401:                //
2402:                // mod6.1 r1.3 conf B depends on
2403:                // mod5.2 r1.0 which depends on mod5.1 r4.0 conf B
2404:                // mod5.1 r4.2 conf A
2405:                //
2406:                // mod5.1 r4.2 conf B depends on mod1.2 r2.0
2407:                ResolveReport report = ivy.resolve(new File(
2408:                        "test/repositories/2/mod6.1/ivy-1.3.xml").toURL(),
2409:                        getResolveOptions(new String[] { "*" }));
2410:                assertNotNull(report);
2411:                ModuleDescriptor md = report.getModuleDescriptor();
2412:                assertNotNull(md);
2413:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org6",
2414:                        "mod6.1", "1.3");
2415:                assertEquals(mrid, md.getModuleRevisionId());
2416:
2417:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2418:
2419:                // dependencies
2420:                assertTrue(getIvyFileInCache(
2421:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.2"))
2422:                        .exists());
2423:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2424:                        "art51A", "jar", "jar").exists());
2425:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.2",
2426:                        "art51B", "jar", "jar").exists());
2427:
2428:                assertTrue(getIvyFileInCache(
2429:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.0"))
2430:                        .exists());
2431:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
2432:                        "art51A", "jar", "jar").exists());
2433:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
2434:                        "art51B", "jar", "jar").exists());
2435:
2436:                assertTrue(getIvyFileInCache(
2437:                        ModuleRevisionId.newInstance("org5", "mod5.2", "1.0"))
2438:                        .exists());
2439:                assertTrue(getArchiveFileInCache("org5", "mod5.2", "1.0",
2440:                        "mod5.2", "jar", "jar").exists());
2441:
2442:                assertTrue(getIvyFileInCache(
2443:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2444:                        .exists());
2445:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2446:                        "mod1.2", "jar", "jar").exists());
2447:
2448:                // 4.2 artifacts should be present in conf B only
2449:                ConfigurationResolveReport crr = report
2450:                        .getConfigurationReport("A");
2451:                assertNotNull(crr);
2452:                assertEquals(0, crr.getDownloadReports(ModuleRevisionId
2453:                        .newInstance("org5", "mod5.1", "4.2")).length);
2454:
2455:                crr = report.getConfigurationReport("B");
2456:                assertNotNull(crr);
2457:                assertEquals(2, crr.getDownloadReports(ModuleRevisionId
2458:                        .newInstance("org5", "mod5.1", "4.2")).length);
2459:            }
2460:
2461:            public void testMultipleEviction() throws Exception {
2462:
2463:                ResolveReport report = ivy.resolve(new File(
2464:                        "test/repositories/1/IVY-644/M1/ivys/ivy-1.0.xml")
2465:                        .toURL(), getResolveOptions(new String[] { "test",
2466:                        "runtime" })); //NB the order impact the bug
2467:                assertFalse(report.hasError());
2468:            }
2469:
2470:            public void testResolveForce() throws Exception {
2471:                // mod4.1 v 4.2 depends on
2472:                // - mod1.2 v 2.0 and forces it
2473:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2474:                ResolveReport report = ivy.resolve(new File(
2475:                        "test/repositories/2/mod4.1/ivy-4.2.xml").toURL(),
2476:                        getResolveOptions(new String[] { "*" }));
2477:                assertNotNull(report);
2478:                ModuleDescriptor md = report.getModuleDescriptor();
2479:                assertNotNull(md);
2480:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2481:                        "mod4.1", "4.2");
2482:                assertEquals(mrid, md.getModuleRevisionId());
2483:
2484:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2485:
2486:                // dependencies
2487:                assertTrue(getIvyFileInCache(
2488:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.1"))
2489:                        .exists());
2490:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.1",
2491:                        "mod3.1", "jar", "jar").exists());
2492:
2493:                assertTrue(getIvyFileInCache(
2494:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2495:                        .exists());
2496:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2497:                        "mod1.2", "jar", "jar").exists());
2498:
2499:                assertFalse(getIvyFileInCache(
2500:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2501:                        .exists());
2502:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2503:                        "mod1.2", "jar", "jar").exists());
2504:            }
2505:
2506:            public void testResolveForceAfterConflictSolved() throws Exception {
2507:                // IVY-193
2508:                // mod4.1 v 4.9 depends on
2509:                // - mod3.2 v 1.1 which depends on mod1.2 v 2.0
2510:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2511:                // - mod1.2 v 2.0 and forces it
2512:                ResolveReport report = ivy.resolve(new File(
2513:                        "test/repositories/2/mod4.1/ivy-4.9.xml").toURL(),
2514:                        getResolveOptions(new String[] { "*" }));
2515:                assertNotNull(report);
2516:                ModuleDescriptor md = report.getModuleDescriptor();
2517:                assertNotNull(md);
2518:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2519:                        "mod4.1", "4.9");
2520:                assertEquals(mrid, md.getModuleRevisionId());
2521:
2522:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2523:
2524:                // dependencies
2525:                assertTrue(getIvyFileInCache(
2526:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2527:                        .exists());
2528:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2529:                        "mod1.2", "jar", "jar").exists());
2530:
2531:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2532:                        "mod1.2", "jar", "jar").exists());
2533:            }
2534:
2535:            public void testResolveForceAfterDependencyExist() throws Exception {
2536:                // IVY-193
2537:                // mod4.1 v 4.10 depends on
2538:                // - mod3.1 v 1.0.1 which depends on mod1.2 v 2.0 and forces it
2539:                // - mod3.2 v 1.2 which depends on mod1.2 v 2.1 and on mod3.1 v1.0.1
2540:                ResolveReport report = ivy.resolve(new File(
2541:                        "test/repositories/2/mod4.1/ivy-4.10.xml").toURL(),
2542:                        getResolveOptions(new String[] { "*" }));
2543:                assertNotNull(report);
2544:
2545:                // dependencies
2546:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
2547:                        "mod1.2", "jar", "jar").exists());
2548:
2549:                assertTrue(getIvyFileInCache(
2550:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2551:                        .exists());
2552:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.1",
2553:                        "mod1.2", "jar", "jar").exists());
2554:            }
2555:
2556:            public void testResolveForceInDepOnly() throws Exception {
2557:                // IVY-193
2558:                // mod4.1 v 4.11 depends on
2559:                // - mod1.2 v 2.0
2560:                // - mod3.2 v 1.3 which depends on
2561:                // - mod3.1 v1.1 which depends on
2562:                // - mod1.2 v 2.1
2563:                // - mod1.2 v 1.0 and forces it
2564:                ResolveReport report = ivy.resolve(new File(
2565:                        "test/repositories/2/mod4.1/ivy-4.11.xml").toURL(),
2566:                        getResolveOptions(new String[] { "*" }));
2567:                assertNotNull(report);
2568:
2569:                // dependencies
2570:                assertTrue(getIvyFileInCache(
2571:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2572:                        .exists());
2573:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2574:                        "mod1.2", "jar", "jar").exists());
2575:
2576:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2577:                        "mod1.2", "jar", "jar").exists());
2578:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "1.0",
2579:                        "mod1.2", "jar", "jar").exists());
2580:            }
2581:
2582:            public void testResolveForceInDepOnly2() throws Exception {
2583:                // IVY-193
2584:                // mod4.1 v 4.12 depends on
2585:                // - mod3.1 v1.0 which depends on
2586:                // - mod1.2 v 2.0
2587:                // - mod3.2 v 1.4 which depends on
2588:                // - mod1.2 v 2.0 and forces it
2589:                // - mod3.1 v1.1 which depends on
2590:                // - mod1.2 v 2.1
2591:                ResolveReport report = ivy.resolve(new File(
2592:                        "test/repositories/2/mod4.1/ivy-4.12.xml").toURL(),
2593:                        getResolveOptions(new String[] { "*" }));
2594:                assertNotNull(report);
2595:
2596:                // dependencies
2597:                assertTrue(getIvyFileInCache(
2598:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2599:                        .exists());
2600:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2601:                        "mod1.2", "jar", "jar").exists());
2602:
2603:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2604:                        "mod1.2", "jar", "jar").exists());
2605:            }
2606:
2607:            public void testResolveForceWithDynamicRevisions() throws Exception {
2608:                // mod4.1 v 4.5 depends on
2609:                // - mod1.2 v 1+ and forces it
2610:                // - mod3.1 v 1.2 which depends on mod1.2 v 2+
2611:                ResolveReport report = ivy.resolve(new File(
2612:                        "test/repositories/2/mod4.1/ivy-4.5.xml").toURL(),
2613:                        getResolveOptions(new String[] { "*" }));
2614:                assertNotNull(report);
2615:                ModuleDescriptor md = report.getModuleDescriptor();
2616:                assertNotNull(md);
2617:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2618:                        "mod4.1", "4.5");
2619:                assertEquals(mrid, md.getModuleRevisionId());
2620:
2621:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2622:
2623:                // dependencies
2624:                assertTrue(getIvyFileInCache(
2625:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.2"))
2626:                        .exists());
2627:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2",
2628:                        "mod3.1", "jar", "jar").exists());
2629:
2630:                assertTrue(getIvyFileInCache(
2631:                        ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"))
2632:                        .exists());
2633:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1",
2634:                        "mod1.2", "jar", "jar").exists());
2635:
2636:                assertFalse(getIvyFileInCache(
2637:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
2638:                        .exists());
2639:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2",
2640:                        "mod1.2", "jar", "jar").exists());
2641:            }
2642:
2643:            public void testResolveForceWithDynamicRevisionsAndSeveralConfs()
2644:                    throws Exception {
2645:                // mod4.1 v 4.6 (conf compile, test extends compile) depends on
2646:                // - mod1.2 v 1+ and forces it in conf compile
2647:                // - mod3.1 v 1.2 in conf test which depends on mod1.2 v 2+
2648:                ResolveReport report = ivy.resolve(new File(
2649:                        "test/repositories/2/mod4.1/ivy-4.6.xml").toURL(),
2650:                        getResolveOptions(new String[] { "*" }));
2651:                assertNotNull(report);
2652:                ModuleDescriptor md = report.getModuleDescriptor();
2653:                assertNotNull(md);
2654:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2655:                        "mod4.1", "4.6");
2656:                assertEquals(mrid, md.getModuleRevisionId());
2657:
2658:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2659:
2660:                // dependencies
2661:                assertTrue(getIvyFileInCache(
2662:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.2"))
2663:                        .exists());
2664:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.2",
2665:                        "mod3.1", "jar", "jar").exists());
2666:
2667:                assertTrue(getIvyFileInCache(
2668:                        ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"))
2669:                        .exists());
2670:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1",
2671:                        "mod1.2", "jar", "jar").exists());
2672:
2673:                assertFalse(getIvyFileInCache(
2674:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
2675:                        .exists());
2676:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2",
2677:                        "mod1.2", "jar", "jar").exists());
2678:            }
2679:
2680:            public void testResolveForceWithDynamicRevisionsAndSeveralConfs2()
2681:                    throws Exception {
2682:                // mod4.1 v 4.7 (conf compile, test extends compile) depends on
2683:                // - mod1.2 v 1+ and forces it in conf compile
2684:                // - mod3.1 v 1.3 in conf test->runtime
2685:                // which defines confs compile, runtime extends compile
2686:                // which depends on mod1.2 v 2+ in conf compile->default
2687:                ResolveReport report = ivy.resolve(new File(
2688:                        "test/repositories/2/mod4.1/ivy-4.7.xml").toURL(),
2689:                        getResolveOptions(new String[] { "*" }));
2690:                assertNotNull(report);
2691:                ModuleDescriptor md = report.getModuleDescriptor();
2692:                assertNotNull(md);
2693:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org4",
2694:                        "mod4.1", "4.7");
2695:                assertEquals(mrid, md.getModuleRevisionId());
2696:
2697:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2698:
2699:                // dependencies
2700:                assertTrue(getIvyFileInCache(
2701:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.3"))
2702:                        .exists());
2703:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.3",
2704:                        "mod3.1", "jar", "jar").exists());
2705:
2706:                assertTrue(getIvyFileInCache(
2707:                        ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"))
2708:                        .exists());
2709:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1",
2710:                        "mod1.2", "jar", "jar").exists());
2711:
2712:                assertFalse(getIvyFileInCache(
2713:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
2714:                        .exists());
2715:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2",
2716:                        "mod1.2", "jar", "jar").exists());
2717:            }
2718:
2719:            public void testResolveForceWithDynamicRevisionsAndCyclicDependencies()
2720:                    throws Exception {
2721:                // IVY-182
2722:                // * has no revision
2723:                // * declares conf compile, test extends compile,
2724:                // * depends on
2725:                // - mod1.2 v 1+ and forces it in conf compile
2726:                // - mod3.1 v 1+ in conf test->runtime excluding mod4.1 (to avoid cyclic dep failure)
2727:                // which defines confs compile, runtime extends compile
2728:                // which depends on mod1.2 v 2+ in conf compile->default
2729:                // which depends on mod4.1 v 4+ in conf compile->compile
2730:                ResolveReport report = ivy.resolve(ResolveTest.class
2731:                        .getResource("ivy-182.xml"),
2732:                        getResolveOptions(new String[] { "*" }));
2733:                assertNotNull(report);
2734:                ModuleDescriptor md = report.getModuleDescriptor();
2735:                assertNotNull(md);
2736:                ModuleId mid = new ModuleId("test", "IVY-182");
2737:                assertEquals(mid, md.getModuleRevisionId().getModuleId());
2738:
2739:                // dependencies
2740:                assertTrue(getIvyFileInCache(
2741:                        ModuleRevisionId.newInstance("org3", "mod3.1", "1.4"))
2742:                        .exists());
2743:                assertTrue(getArchiveFileInCache("org3", "mod3.1", "1.4",
2744:                        "mod3.1", "jar", "jar").exists());
2745:
2746:                assertTrue(getIvyFileInCache(
2747:                        ModuleRevisionId.newInstance("org1", "mod1.2", "1.1"))
2748:                        .exists());
2749:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "1.1",
2750:                        "mod1.2", "jar", "jar").exists());
2751:
2752:                assertFalse(getIvyFileInCache(
2753:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
2754:                        .exists());
2755:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.2",
2756:                        "mod1.2", "jar", "jar").exists());
2757:            }
2758:
2759:            public void testResolveContradictoryConflictResolution()
2760:                    throws Exception {
2761:                // mod10.1 v 1.0 depends on
2762:                // - mod1.2 v 2.0 and forces it
2763:                // - mod4.1 v 4.1 (which selects mod1.2 v 2.1 and evicts mod1.2 v 2.0)
2764:                // mod4.1 v 4.1 depends on
2765:                // - mod1.1 v 1.0 which depends on mod1.2 v 2.0
2766:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2767:                ResolveReport report = ivy.resolve(new File(
2768:                        "test/repositories/2/mod10.1/ivy-1.0.xml").toURL(),
2769:                        getResolveOptions(new String[] { "*" }));
2770:                assertNotNull(report);
2771:                ModuleDescriptor md = report.getModuleDescriptor();
2772:                assertNotNull(md);
2773:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org10",
2774:                        "mod10.1", "1.0");
2775:                assertEquals(mrid, md.getModuleRevisionId());
2776:
2777:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2778:
2779:                // conflicting dependencies
2780:                assertTrue(getIvyFileInCache(
2781:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2782:                        .exists());
2783:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2784:                        "mod1.2", "jar", "jar").exists());
2785:
2786:                assertFalse(getIvyFileInCache(
2787:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2788:                        .exists());
2789:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2790:                        "mod1.2", "jar", "jar").exists());
2791:            }
2792:
2793:            public void testResolveContradictoryConflictResolution2()
2794:                    throws Exception {
2795:                // BUG IVY-130 : only mod1.2 v2.0 should be resolved and not v2.1 (because of force)
2796:                // mod10.1 v 1.1 depends on
2797:                // - mod1.2 v 2.0 and forces it
2798:                // - mod4.1 v 4.3
2799:                // mod4.1 v 4.3 depends on
2800:                // - mod1.2 v 2.1
2801:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2802:                ivy.resolve(new File("test/repositories/2/mod10.1/ivy-1.1.xml")
2803:                        .toURL(), getResolveOptions(new String[] { "*" }));
2804:
2805:                // conflicting dependencies
2806:                assertTrue(getIvyFileInCache(
2807:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
2808:                        .exists());
2809:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
2810:                        "mod1.2", "jar", "jar").exists());
2811:
2812:                assertFalse(getIvyFileInCache(
2813:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.1"))
2814:                        .exists());
2815:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.1",
2816:                        "mod1.2", "jar", "jar").exists());
2817:            }
2818:
2819:            public void testResolveContradictoryConflictResolution3()
2820:                    throws Exception {
2821:                // mod 1.2 v2.0 should be selected (despite conflict manager in 4.1, because of force in
2822:                // 10.1)
2823:                // mod10.1 v 1.3 depends on
2824:                // - mod1.2 v 2.0 and forces it
2825:                // - mod4.1 v 4.4
2826:                // mod4.1 v 4.4 depends on
2827:                // - mod1.2 v 2.0 but selects mod1.2 v 2.1
2828:                // - mod3.1 v 1.1 which depends on mod1.2 v 2.1
2829:                ResolveReport report = ivy.resolve(new File(
2830:                        "test/repositories/2/mod10.1/ivy-1.3.xml").toURL(),
2831:                        getResolveOptions(new String[] { "*" }));
2832:
2833:                IvyNode[] evicted = report.getConfigurationReport("default")
2834:                        .getEvictedNodes();
2835:                assertEquals(1, evicted.length);
2836:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
2837:                        "2.1"), evicted[0].getResolvedId());
2838:            }
2839:
2840:            public void testExtends() throws Exception {
2841:                // mod 5.2 depends on mod5.1 conf B
2842:                // mod5.1 conf B publishes art51B
2843:                // mod5.1 conf B extends conf A
2844:                // mod5.1 conf A publishes art51A
2845:                ResolveReport report = ivy.resolve(new File(
2846:                        "test/repositories/2/mod5.2/ivy-1.0.xml").toURL(),
2847:                        getResolveOptions(new String[] { "*" }));
2848:                assertNotNull(report);
2849:                ModuleDescriptor md = report.getModuleDescriptor();
2850:                assertNotNull(md);
2851:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5",
2852:                        "mod5.2", "1.0");
2853:                assertEquals(mrid, md.getModuleRevisionId());
2854:
2855:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2856:
2857:                // dependencies
2858:                assertTrue(getIvyFileInCache(
2859:                        ModuleRevisionId.newInstance("org5", "mod5.1", "4.0"))
2860:                        .exists());
2861:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
2862:                        "art51B", "jar", "jar").exists());
2863:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
2864:                        "art51A", "jar", "jar").exists());
2865:            }
2866:
2867:            public void testMultiConfs() throws Exception {
2868:                // mod 5.2 depends on mod5.1 conf B in its conf B and conf A in its conf A
2869:                // mod5.1 conf B publishes art51B
2870:                // mod5.1 conf A publishes art51A
2871:                ResolveReport report = ivy.resolve(new File(
2872:                        "test/repositories/2/mod5.2/ivy-2.0.xml").toURL(),
2873:                        getResolveOptions(new String[] { "B", "A" }));
2874:                assertNotNull(report);
2875:                ModuleDescriptor md = report.getModuleDescriptor();
2876:                assertNotNull(md);
2877:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org5",
2878:                        "mod5.2", "2.0");
2879:                assertEquals(mrid, md.getModuleRevisionId());
2880:
2881:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
2882:
2883:                // dependencies
2884:                ModuleRevisionId depId = ModuleRevisionId.newInstance("org5",
2885:                        "mod5.1", "4.1");
2886:
2887:                ConfigurationResolveReport crr = report
2888:                        .getConfigurationReport("A");
2889:                assertNotNull(crr);
2890:                assertEquals(1, crr.getDownloadReports(depId).length);
2891:
2892:                File r = new File(cache, ResolveOptions
2893:                        .getDefaultResolveId(mrid.getModuleId())
2894:                        + "-A.xml");
2895:                assertTrue(r.exists());
2896:                final boolean[] found = new boolean[] { false };
2897:                SAXParser saxParser = SAXParserFactory.newInstance()
2898:                        .newSAXParser();
2899:                saxParser.parse(r, new DefaultHandler() {
2900:                    public void startElement(String uri, String localName,
2901:                            String qName, org.xml.sax.Attributes attributes)
2902:                            throws SAXException {
2903:                        if ("artifact".equals(qName)
2904:                                && "art51B".equals(attributes.getValue("name"))) {
2905:                            found[0] = true;
2906:                        }
2907:                    }
2908:                });
2909:                assertFalse(found[0]);
2910:
2911:                assertTrue(getIvyFileInCache(depId).exists());
2912:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1",
2913:                        "art51A", "jar", "jar").exists());
2914:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1",
2915:                        "art51B", "jar", "jar").exists());
2916:            }
2917:
2918:            public void testThisConfiguration() throws Exception {
2919:                ResolveReport report = ivy.resolve(new File(
2920:                        "test/repositories/2/mod14.4/ivy-1.1.xml").toURL(),
2921:                        getResolveOptions(new String[] { "compile" }));
2922:                assertNotNull(report);
2923:                ModuleDescriptor md = report.getModuleDescriptor();
2924:                assertNotNull(md);
2925:
2926:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org14",
2927:                        "mod14.4", "1.1");
2928:                assertEquals(mrid, md.getModuleRevisionId());
2929:                ConfigurationResolveReport crr = report
2930:                        .getConfigurationReport("compile");
2931:                assertNotNull(crr);
2932:                assertEquals(4, crr.getArtifactsNumber());
2933:                assertTrue(getIvyFileInCache(
2934:                        ModuleRevisionId.newInstance("org14", "mod14.3", "1.1"))
2935:                        .exists());
2936:                assertTrue(getIvyFileInCache(
2937:                        ModuleRevisionId.newInstance("org14", "mod14.2", "1.1"))
2938:                        .exists());
2939:                assertTrue(getIvyFileInCache(
2940:                        ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"))
2941:                        .exists());
2942:                assertTrue(!getIvyFileInCache(
2943:                        ModuleRevisionId.newInstance("org8", "mod8.3", "1.0"))
2944:                        .exists());
2945:                assertTrue(getIvyFileInCache(
2946:                        ModuleRevisionId.newInstance("org8", "mod8.1", "1.0"))
2947:                        .exists());
2948:
2949:                CacheCleaner.deleteDir(cache);
2950:                createCache();
2951:                report = ivy.resolve(new File(
2952:                        "test/repositories/2/mod14.4/ivy-1.1.xml").toURL(),
2953:                        getResolveOptions(new String[] { "standalone" }));
2954:                crr = report.getConfigurationReport("standalone");
2955:                assertNotNull(crr);
2956:                assertEquals(7, crr.getArtifactsNumber());
2957:
2958:                assertTrue(getIvyFileInCache(
2959:                        ModuleRevisionId.newInstance("org14", "mod14.3", "1.1"))
2960:                        .exists());
2961:                assertTrue(getIvyFileInCache(
2962:                        ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"))
2963:                        .exists());
2964:                assertTrue(!getIvyFileInCache(
2965:                        ModuleRevisionId.newInstance("org14", "mod14.2", "1.1"))
2966:                        .exists());
2967:                assertTrue(getIvyFileInCache(
2968:                        ModuleRevisionId.newInstance("org14", "mod14.3", "1.1"))
2969:                        .exists());
2970:                assertTrue(getIvyFileInCache(
2971:                        ModuleRevisionId.newInstance("org8", "mod8.3", "1.0"))
2972:                        .exists());
2973:                assertTrue(getIvyFileInCache(
2974:                        ModuleRevisionId.newInstance("org8", "mod8.1", "1.0"))
2975:                        .exists());
2976:                assertTrue(getIvyFileInCache(
2977:                        ModuleRevisionId.newInstance("org8", "mod8.4", "1.1"))
2978:                        .exists());
2979:                assertTrue(getIvyFileInCache(
2980:                        ModuleRevisionId.newInstance("org8", "mod8.2", "1.1"))
2981:                        .exists());
2982:            }
2983:
2984:            public void testLatest() throws Exception {
2985:                // mod1.4 depends on latest mod1.2
2986:                ResolveReport report = ivy
2987:                        .resolve(
2988:                                new File(
2989:                                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.1.xml")
2990:                                        .toURL(),
2991:                                getResolveOptions(new String[] { "default" }));
2992:                assertNotNull(report);
2993:                ModuleDescriptor md = report.getModuleDescriptor();
2994:                assertNotNull(md);
2995:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
2996:                        "mod1.4", "1.0.1");
2997:                assertEquals(mrid, md.getModuleRevisionId());
2998:
2999:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
3000:
3001:                // dependencies
3002:                ModuleRevisionId depId = ModuleRevisionId.newInstance("org1",
3003:                        "mod1.2", "2.2");
3004:
3005:                ConfigurationResolveReport crr = report
3006:                        .getConfigurationReport("default");
3007:                assertNotNull(crr);
3008:                assertEquals(1, crr.getDownloadReports(depId).length);
3009:
3010:                File r = getConfigurationResolveReportInCache(ResolveOptions
3011:                        .getDefaultResolveId(mrid.getModuleId()), "default");
3012:                assertTrue(r.exists());
3013:                final boolean[] found = new boolean[] { false };
3014:                SAXParser saxParser = SAXParserFactory.newInstance()
3015:                        .newSAXParser();
3016:                saxParser.parse(r, new DefaultHandler() {
3017:                    public void startElement(String uri, String localName,
3018:                            String qName, org.xml.sax.Attributes attributes)
3019:                            throws SAXException {
3020:                        if ("artifact".equals(qName)
3021:                                && "mod1.2".equals(attributes.getValue("name"))) {
3022:                            found[0] = true;
3023:                        }
3024:                    }
3025:                });
3026:                assertTrue(found[0]);
3027:
3028:                assertTrue(getIvyFileInCache(depId).exists());
3029:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2",
3030:                        "mod1.2", "jar", "jar").exists());
3031:            }
3032:
3033:            public void testLatestMultiple() throws Exception {
3034:                // mod1.5 depends on
3035:                // latest mod1.4, which depends on mod1.2 2.2
3036:                // latest mod1.2 (which is 2.2)
3037:                ResolveReport report = ivy
3038:                        .resolve(
3039:                                new File(
3040:                                        "test/repositories/1/org1/mod1.5/ivys/ivy-1.0.2.xml")
3041:                                        .toURL(),
3042:                                getResolveOptions(new String[] { "default" }));
3043:                assertFalse(report.hasError());
3044:
3045:                // dependencies
3046:                assertTrue(getIvyFileInCache(
3047:                        ModuleRevisionId.newInstance("org1", "mod1.4", "2.0"))
3048:                        .exists());
3049:
3050:                assertTrue(getIvyFileInCache(
3051:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.2"))
3052:                        .exists());
3053:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.2",
3054:                        "mod1.2", "jar", "jar").exists());
3055:            }
3056:
3057:            public void testLatestWhenReleased() throws Exception {
3058:                // The test verify that latest.integration dependencies can be resolved with released
3059:                // version also.
3060:                ResolveReport report = ivy.resolve(ResolveTest.class
3061:                        .getResource("ivy-latestreleased.xml"),
3062:                        getResolveOptions(new String[] { "default" }));
3063:                assertFalse(report.hasError());
3064:
3065:                // dependencies
3066:                assertTrue(getIvyFileInCache(
3067:                        ModuleRevisionId.newInstance("org1", "mod_released",
3068:                                "1.1")).exists());
3069:            }
3070:
3071:            public void testLatestWithMultiplePatterns() throws Exception {
3072:                // The test verify that latest.integration dependencies can be resolved 
3073:                // when using a resolver with multiple patterns, when only the first pattern 
3074:                // finds something - test case for IVY-602
3075:
3076:                // mod9.2 depends on latest.integration of mod6.2
3077:                Ivy ivy = Ivy.newInstance();
3078:                ivy.configure(new File(
3079:                        "test/repositories/ivysettings-IVY602.xml"));
3080:
3081:                ResolveReport report = ivy
3082:                        .resolve(
3083:                                new File(
3084:                                        "test/repositories/1/org9/mod9.2/ivys/ivy-1.3.xml")
3085:                                        .toURL(),
3086:                                getResolveOptions(new String[] { "default" }));
3087:                assertNotNull(report);
3088:                assertFalse(report.hasError());
3089:
3090:                assertTrue(getArchiveFileInCache("org6", "mod6.2", "2.0",
3091:                        "mod6.2", "jar", "jar").exists());
3092:            }
3093:
3094:            public void testVersionRange1() throws Exception {
3095:                // mod 1.4 depends on mod1.2 [1.0,2.0[
3096:                ResolveReport report = ivy
3097:                        .resolve(
3098:                                new File(
3099:                                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml")
3100:                                        .toURL(),
3101:                                getResolveOptions(new String[] { "default" }));
3102:                assertFalse(report.hasError());
3103:
3104:                // dependencies
3105:                ModuleRevisionId depId = ModuleRevisionId.newInstance("org1",
3106:                        "mod1.2", "1.1");
3107:
3108:                ConfigurationResolveReport crr = report
3109:                        .getConfigurationReport("default");
3110:                assertNotNull(crr);
3111:                assertEquals(1, crr.getDownloadReports(depId).length);
3112:
3113:                assertTrue(getIvyFileInCache(depId).exists());
3114:            }
3115:
3116:            public void testVersionRange2() throws Exception {
3117:                // mod 1.4 depends on mod1.2 [1.5,2.0[
3118:                Ivy ivy = new Ivy();
3119:                ivy.configure(new File("test/repositories/ivysettings.xml"));
3120:                ResolveReport report = ivy
3121:                        .resolve(
3122:                                new File(
3123:                                        "test/repositories/1/org1/mod1.4/ivys/ivy-1.0.3.xml")
3124:                                        .toURL(),
3125:                                getResolveOptions(new String[] { "default" }));
3126:                assertTrue(report.hasError());
3127:            }
3128:
3129:            public void testLatestMilestone() throws Exception {
3130:                // mod9.2 depends on latest.milestone of mod6.4
3131:                ResolveReport report = ivy
3132:                        .resolve(
3133:                                new File(
3134:                                        "test/repositories/1/org9/mod9.2/ivys/ivy-1.1.xml")
3135:                                        .toURL(),
3136:                                getResolveOptions(new String[] { "default" }));
3137:                assertFalse(report.hasError());
3138:
3139:                // dependencies
3140:                ModuleRevisionId depId = ModuleRevisionId.newInstance("org6",
3141:                        "mod6.4", "3");
3142:
3143:                ConfigurationResolveReport crr = report
3144:                        .getConfigurationReport("default");
3145:                assertNotNull(crr);
3146:                assertEquals(1, crr.getDownloadReports(depId).length);
3147:
3148:                assertTrue(getIvyFileInCache(depId).exists());
3149:            }
3150:
3151:            public void testLatestMilestone2() throws Exception {
3152:                // mod9.2 depends on latest.milestone of mod6.2, but there is no milestone
3153:                // test case for IVY-318
3154:                ResolveReport report = ivy
3155:                        .resolve(
3156:                                new File(
3157:                                        "test/repositories/1/org9/mod9.2/ivys/ivy-1.2.xml")
3158:                                        .toURL(),
3159:                                getResolveOptions(new String[] { "default" }));
3160:                // we should have an error since there is no milestone version, it should be considered as a
3161:                // non resolved dependency
3162:                assertTrue(report.hasError());
3163:
3164:                // dependencies
3165:                ConfigurationResolveReport crr = report
3166:                        .getConfigurationReport("default");
3167:                assertNotNull(crr);
3168:                assertEquals(0, crr.getArtifactsNumber());
3169:            }
3170:
3171:            public void testIVY56() throws Exception {
3172:                Ivy ivy = new Ivy();
3173:                ivy.configure(new File(
3174:                        "test/repositories/bugIVY-56/ivysettings.xml"));
3175:
3176:                try {
3177:                    ResolveReport report = ivy.resolve(ResolveTest.class
3178:                            .getResource("ivy-56.xml"),
3179:                            getResolveOptions(new String[] { "default" }));
3180:                    assertNotNull(report);
3181:                } finally {
3182:                    FileUtil.forceDelete(ivy.getSettings().getDefaultCache());
3183:                }
3184:            }
3185:
3186:            public void testIVY214() throws Exception {
3187:                ResolveReport report = ivy.resolve(ResolveTest.class
3188:                        .getResource("ivy-214.xml"),
3189:                        getResolveOptions(new String[] { "compile" }));
3190:
3191:                assertNotNull(report);
3192:                assertFalse(report.hasError());
3193:
3194:                assertEquals("Number of artifacts not correct", 1, report
3195:                        .getConfigurationReport("compile").getArtifactsNumber());
3196:            }
3197:
3198:            public void testIVY218() throws Exception {
3199:                ResolveReport report = ivy.resolve(ResolveTest.class
3200:                        .getResource("ivy-218.xml"),
3201:                        getResolveOptions(new String[] { "test" }));
3202:
3203:                assertNotNull(report);
3204:                assertFalse(report.hasError());
3205:
3206:                assertEquals("Number of artifacts not correct", 3, report
3207:                        .getConfigurationReport("test").getArtifactsNumber());
3208:            }
3209:
3210:            public void testIVY729() throws Exception {
3211:                Ivy ivy = new Ivy();
3212:                ivy.configure(new File(
3213:                        "test/repositories/IVY-729/ivysettings.xml"));
3214:
3215:                ResolveReport report = ivy.resolve(new File(
3216:                        "test/repositories/IVY-729/ivy.xml").toURL(),
3217:                        getResolveOptions(new String[] { "*" }));
3218:                assertFalse(report.hasError());
3219:            }
3220:
3221:            public void testCircular() throws Exception {
3222:                // mod6.3 depends on mod6.2, which itself depends on mod6.3
3223:
3224:                ResolveReport report = ivy.resolve(new File(
3225:                        "test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
3226:                        getResolveOptions(new String[] { "default" }));
3227:                assertFalse(report.hasError());
3228:
3229:                settings
3230:                        .setCircularDependencyStrategy(IgnoreCircularDependencyStrategy
3231:                                .getInstance());
3232:                report = ivy.resolve(new File(
3233:                        "test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
3234:                        getResolveOptions(new String[] { "default" }));
3235:                assertFalse(report.hasError());
3236:
3237:                settings
3238:                        .setCircularDependencyStrategy(WarnCircularDependencyStrategy
3239:                                .getInstance());
3240:                report = ivy.resolve(new File(
3241:                        "test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
3242:                        getResolveOptions(new String[] { "default" }));
3243:                assertFalse(report.hasError());
3244:
3245:                settings
3246:                        .setCircularDependencyStrategy(ErrorCircularDependencyStrategy
3247:                                .getInstance());
3248:                try {
3249:                    ivy.resolve(new File(
3250:                            "test/repositories/2/mod6.3/ivy-1.0.xml").toURL(),
3251:                            getResolveOptions(new String[] { "default" }));
3252:                    fail("no exception with circular dependency strategy set to error");
3253:                } catch (CircularDependencyException ex) {
3254:                    assertEquals(
3255:                            "org6#mod6.3;1.0->org6#mod6.2;1.0->org6#mod6.3;latest.integration",
3256:                            ex.getMessage());
3257:                }
3258:            }
3259:
3260:            public void testCircular2() throws Exception {
3261:                // mod 9.1 (no revision) depends on mod9.2, which depends on mod9.1 2.+
3262:
3263:                ResolveReport report = ivy.resolve(new File(
3264:                        "test/repositories/circular/ivy.xml").toURL(),
3265:                        getResolveOptions(new String[] { "*" }));
3266:                assertFalse(report.hasError());
3267:
3268:                settings
3269:                        .setCircularDependencyStrategy(ErrorCircularDependencyStrategy
3270:                                .getInstance());
3271:                try {
3272:                    ivy.resolve(new File("test/repositories/circular/ivy.xml")
3273:                            .toURL(), getResolveOptions(new String[] { "*" }));
3274:                    fail("no exception with circular dependency strategy set to error");
3275:                } catch (CircularDependencyException ex) {
3276:                    // ok
3277:                    assertEquals(
3278:                            "org8#mod8.5;NONE->org8#mod8.6;2.+->org8#mod8.5;2.+",
3279:                            ex.getMessage());
3280:                }
3281:            }
3282:
3283:            public void testCircular3() throws Exception {
3284:                // test case for IVY-400
3285:                // mod6.3 depends on mod6.2, which itself depends on mod6.3,
3286:                // in both configuration default and test
3287:
3288:                ResolveReport report = ivy.resolve(new File(
3289:                        "test/repositories/2/mod6.3/ivy-1.2.xml").toURL(),
3290:                        getResolveOptions(new String[] { "default", "test" }));
3291:                assertFalse(report.hasError());
3292:                // we should have mod 6.2 artifact in both configurations
3293:                assertEquals(1, report.getConfigurationReport("default")
3294:                        .getArtifactsNumber());
3295:                assertEquals(1, report.getConfigurationReport("test")
3296:                        .getArtifactsNumber());
3297:
3298:                settings
3299:                        .setCircularDependencyStrategy(IgnoreCircularDependencyStrategy
3300:                                .getInstance());
3301:                report = ivy.resolve(new File(
3302:                        "test/repositories/2/mod6.3/ivy-1.2.xml").toURL(),
3303:                        getResolveOptions(new String[] { "default", "test" }));
3304:                assertFalse(report.hasError());
3305:                assertEquals(1, report.getConfigurationReport("default")
3306:                        .getArtifactsNumber());
3307:                assertEquals(1, report.getConfigurationReport("test")
3308:                        .getArtifactsNumber());
3309:
3310:                settings
3311:                        .setCircularDependencyStrategy(WarnCircularDependencyStrategy
3312:                                .getInstance());
3313:                report = ivy.resolve(new File(
3314:                        "test/repositories/2/mod6.3/ivy-1.2.xml").toURL(),
3315:                        getResolveOptions(new String[] { "default", "test" }));
3316:                assertFalse(report.hasError());
3317:                assertEquals(1, report.getConfigurationReport("default")
3318:                        .getArtifactsNumber());
3319:                assertEquals(1, report.getConfigurationReport("test")
3320:                        .getArtifactsNumber());
3321:
3322:                settings
3323:                        .setCircularDependencyStrategy(ErrorCircularDependencyStrategy
3324:                                .getInstance());
3325:                try {
3326:                    ivy
3327:                            .resolve(new File(
3328:                                    "test/repositories/2/mod6.3/ivy-1.2.xml")
3329:                                    .toURL(), getResolveOptions(new String[] {
3330:                                    "default", "test" }));
3331:                    fail("no exception with circular dependency strategy set to error");
3332:                } catch (CircularDependencyException ex) {
3333:                    assertEquals("org6#mod6.3;1.2->org6#mod6.2;1.1->...", ex
3334:                            .getMessage());
3335:                }
3336:            }
3337:
3338:            public void testRegularCircular() throws Exception {
3339:                // mod11.1 depends on mod11.2 but excludes itself
3340:                // mod11.2 depends on mod11.1
3341:                settings
3342:                        .setCircularDependencyStrategy(ErrorCircularDependencyStrategy
3343:                                .getInstance());
3344:                ResolveReport report = ivy.resolve(new File(
3345:                        "test/repositories/2/mod11.1/ivy-1.0.xml").toURL(),
3346:                        getResolveOptions(new String[] { "test" }));
3347:
3348:                assertNotNull(report);
3349:                assertFalse(report.hasError());
3350:
3351:                assertTrue(getIvyFileInCache(
3352:                        ModuleRevisionId.newInstance("org11", "mod11.2", "1.0"))
3353:                        .exists());
3354:                assertTrue(getArchiveFileInCache("org11", "mod11.2", "1.0",
3355:                        "mod11.2", "jar", "jar").exists());
3356:
3357:                assertFalse(getIvyFileInCache(
3358:                        ModuleRevisionId.newInstance("org11", "mod11.1", "1.0"))
3359:                        .exists());
3360:                assertFalse(getArchiveFileInCache("org11", "mod11.1", "1.0",
3361:                        "mod11.1", "jar", "jar").exists());
3362:            }
3363:
3364:            public void testResolveDualChain() throws Exception {
3365:                Ivy ivy = new Ivy();
3366:                ivy.configure(ResolveTest.class
3367:                        .getResource("dualchainresolverconf.xml"));
3368:
3369:                DependencyResolver resolver = ivy.getSettings().getResolver(
3370:                        "default");
3371:                assertNotNull(resolver);
3372:                assertTrue(resolver instanceof  DualResolver);
3373:
3374:                // first without cache
3375:                ivy.resolve(ResolveTest.class
3376:                        .getResource("ivy-dualchainresolver.xml"),
3377:                        getResolveOptions(new String[] { "default" }));
3378:
3379:                assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml")
3380:                        .exists());
3381:                assertTrue(new File(
3382:                        "build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar")
3383:                        .exists());
3384:                assertTrue(new File(
3385:                        "build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar")
3386:                        .exists());
3387:
3388:                // second with cache for ivy file only
3389:                new File(
3390:                        "build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar")
3391:                        .delete();
3392:                new File("build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar")
3393:                        .delete();
3394:                assertFalse(new File(
3395:                        "build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar")
3396:                        .exists());
3397:                assertFalse(new File(
3398:                        "build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar")
3399:                        .exists());
3400:                ivy.resolve(ResolveTest.class
3401:                        .getResource("ivy-dualchainresolver.xml"),
3402:                        getResolveOptions(new String[] { "default" }));
3403:
3404:                assertTrue(new File("build/cache/xerces/xerces/ivy-2.6.2.xml")
3405:                        .exists());
3406:                assertTrue(new File(
3407:                        "build/cache/xerces/xerces/jars/xmlParserAPIs-2.6.2.jar")
3408:                        .exists());
3409:                assertTrue(new File(
3410:                        "build/cache/xerces/xerces/jars/xercesImpl-2.6.2.jar")
3411:                        .exists());
3412:            }
3413:
3414:            public void testBug148() throws Exception {
3415:                Ivy ivy = new Ivy();
3416:                ivy.configure(new File(
3417:                        "test/repositories/bug148/ivysettings.xml"));
3418:                ivy.getSettings().setDefaultCache(cache);
3419:
3420:                ivy.resolve(ResolveTest.class.getResource("ivy-148.xml"),
3421:                        getResolveOptions(new String[] { "*" }));
3422:
3423:                assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml")
3424:                        .exists());
3425:                assertTrue(new File(
3426:                        "build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar")
3427:                        .exists());
3428:                assertTrue(new File(
3429:                        "build/cache/idautomation/barcode/ivy-4.10.xml")
3430:                        .exists());
3431:                assertTrue(new File(
3432:                        "build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar")
3433:                        .exists());
3434:            }
3435:
3436:            public void testBug148b() throws Exception {
3437:                Ivy ivy = new Ivy();
3438:                ivy.configure(new File(
3439:                        "test/repositories/bug148/ivysettings.xml"));
3440:                ivy.getSettings().setDefaultCache(cache);
3441:
3442:                ivy.resolve(ResolveTest.class.getResource("ivy-148b.xml"),
3443:                        getResolveOptions(new String[] { "*" }));
3444:
3445:                assertTrue(new File("build/cache/jtv-foo/bar/ivy-1.1.0.0.xml")
3446:                        .exists());
3447:                assertTrue(new File(
3448:                        "build/cache/jtv-foo/bar/jars/bar-1.1.0.0.jar")
3449:                        .exists());
3450:                assertTrue(new File(
3451:                        "build/cache/idautomation/barcode/ivy-4.10.xml")
3452:                        .exists());
3453:                assertTrue(new File(
3454:                        "build/cache/idautomation/barcode/jars/LinearBarCode-4.10.jar")
3455:                        .exists());
3456:            }
3457:
3458:            public void testBadFiles() throws Exception {
3459:                Ivy ivy = new Ivy();
3460:                ivy.configure(new File(
3461:                        "test/repositories/badfile/ivysettings.xml"));
3462:
3463:                try {
3464:                    ivy.resolve(new File(
3465:                            "test/repositories/badfile/ivys/ivy-badorg.xml")
3466:                            .toURL(), getResolveOptions(new String[] { "*" }));
3467:                    fail("bad org should have raised an exception !");
3468:                } catch (Exception ex) {
3469:                    // OK, it raised an exception
3470:                }
3471:                try {
3472:                    ivy.resolve(new File(
3473:                            "test/repositories/badfile/ivys/ivy-badmodule.xml")
3474:                            .toURL(), getResolveOptions(new String[] { "*" }));
3475:                    fail("bad module should have raised an exception !");
3476:                } catch (Exception ex) {
3477:                    // OK, it raised an exception
3478:                }
3479:                try {
3480:                    ivy
3481:                            .resolve(
3482:                                    new File(
3483:                                            "test/repositories/badfile/ivys/ivy-badrevision.xml")
3484:                                            .toURL(),
3485:                                    getResolveOptions(new String[] { "*" }));
3486:                    fail("bad revision should have raised an exception !");
3487:                } catch (Exception ex) {
3488:                    // OK, it raised an exception
3489:                }
3490:            }
3491:
3492:            public void testTransitiveSetting() throws Exception {
3493:                // mod2.4 depends on mod1.1 with transitive set to false
3494:                // mod1.1 depends on mod1.2, which should not be resolved because of the transitive setting
3495:                ResolveReport report = ivy.resolve(new File(
3496:                        "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml")
3497:                        .toURL(), getResolveOptions(new String[] { "*" }));
3498:                assertNotNull(report);
3499:                ModuleDescriptor md = report.getModuleDescriptor();
3500:                assertNotNull(md);
3501:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
3502:                        "mod2.4", "0.3");
3503:                assertEquals(mrid, md.getModuleRevisionId());
3504:
3505:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
3506:
3507:                // dependencies
3508:                assertTrue(getIvyFileInCache(
3509:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
3510:                        .exists());
3511:                assertTrue(getArchiveFileInCache("org1", "mod1.1", "1.0",
3512:                        "mod1.1", "jar", "jar").exists());
3513:
3514:                assertTrue(!getIvyFileInCache(
3515:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
3516:                        .exists());
3517:                assertTrue(!getArchiveFileInCache("org1", "mod1.2", "2.0",
3518:                        "mod1.2", "jar", "jar").exists());
3519:            }
3520:
3521:            public void testResolverDirectlyUsingCache() throws Exception {
3522:                Ivy ivy = new Ivy();
3523:                ivy
3524:                        .configure(ResolveTest.class
3525:                                .getResource("badcacheconf.xml"));
3526:                File depIvyFileInCache = getIvyFileInCache(ModuleRevisionId
3527:                        .newInstance("org1", "mod1.1", "1.0"));
3528:                FileUtil.copy(File.createTempFile("test", "xml"),
3529:                        depIvyFileInCache, null); // creates a
3530:                // fake
3531:                // dependency
3532:                // file in cache
3533:                ResolveReport report = ivy.resolve(new File(
3534:                        "test/repositories/1/org2/mod2.4/ivys/ivy-0.3.xml")
3535:                        .toURL(), getResolveOptions(new String[] { "*" }));
3536:
3537:                assertNotNull(report);
3538:                ModuleDescriptor md = report.getModuleDescriptor();
3539:                assertNotNull(md);
3540:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
3541:                        "mod2.4", "0.3");
3542:                assertEquals(mrid, md.getModuleRevisionId());
3543:
3544:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
3545:
3546:                // dependencies
3547:                assertTrue(depIvyFileInCache.exists());
3548:                assertTrue(!getArchiveFileInCache(ivy, "org1", "mod1.1", "1.0",
3549:                        "mod1.1", "jar", "jar").exists());
3550:            }
3551:
3552:            public void testVisibility1() throws Exception {
3553:                ivy.resolve(new File("test/repositories/2/mod8.2/ivy-1.0.xml")
3554:                        .toURL(), getResolveOptions(new String[] { "*" }));
3555:
3556:                assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0",
3557:                        "a-private", "txt", "txt").exists());
3558:            }
3559:
3560:            public void testVisibility2() throws Exception {
3561:                ivy
3562:                        .resolve(new File(
3563:                                "test/repositories/2/mod8.3/ivy-1.0.xml")
3564:                                .toURL(),
3565:                                getResolveOptions(new String[] { "private" }));
3566:
3567:                assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0",
3568:                        "a-private", "txt", "txt").exists());
3569:                assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a",
3570:                        "txt", "txt").exists());
3571:            }
3572:
3573:            public void testVisibility3() throws Exception {
3574:                ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.0.xml")
3575:                        .toURL(), getResolveOptions(new String[] { "*" }));
3576:
3577:                assertFalse(getArchiveFileInCache("org8", "mod8.1", "1.0",
3578:                        "a-private", "txt", "txt").exists());
3579:                assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.0", "a",
3580:                        "txt", "txt").exists());
3581:            }
3582:
3583:            public void testVisibility4() throws Exception {
3584:                ivy.resolve(new File("test/repositories/2/mod8.4/ivy-1.1.xml")
3585:                        .toURL(), getResolveOptions(new String[] { "*" }));
3586:
3587:                assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1",
3588:                        "a-private", "txt", "txt").exists());
3589:                assertTrue(getArchiveFileInCache("org8", "mod8.1", "1.1", "a",
3590:                        "txt", "txt").exists());
3591:            }
3592:
3593:            // /////////////////////////////////////////////////////////
3594:            // here comes a series of test provided by Chris Rudd
3595:            // about configuration mapping and eviction
3596:            // /////////////////////////////////////////////////////////
3597:
3598:            public void testConfigurationMapping1() throws Exception {
3599:                Ivy ivy = new Ivy();
3600:                ivy.configure(new File(
3601:                        "test/repositories/IVY-84/ivysettings.xml"));
3602:                ResolveReport report = ivy.resolve(new File(
3603:                        "test/repositories/IVY-84/tests/1/ivy.xml").toURL(),
3604:                        getResolveOptions(new String[] { "*" }));
3605:
3606:                ConfigurationResolveReport conf = report
3607:                        .getConfigurationReport("default");
3608:
3609:                assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt",
3610:                        conf);
3611:                assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt",
3612:                        "txt", "txt", conf);
3613:                assertContainsArtifact("test", "b", "1.0.2", "b", "txt", "txt",
3614:                        conf);
3615:                assertDoesntContainArtifact("test", "b", "1.0.2", "b-bt",
3616:                        "txt", "txt", conf);
3617:                assertContainsArtifact("test", "c", "1.0.2", "c", "txt", "txt",
3618:                        conf);
3619:                assertDoesntContainArtifact("test", "c", "1.0.2", "c-bt",
3620:                        "txt", "txt", conf);
3621:            }
3622:
3623:            public void testConfigurationMapping2() throws Exception {
3624:                Ivy ivy = new Ivy();
3625:                ivy.configure(new File(
3626:                        "test/repositories/IVY-84/ivysettings.xml"));
3627:                ResolveReport report = ivy.resolve(new File(
3628:                        "test/repositories/IVY-84/tests/2/ivy.xml").toURL(),
3629:                        getResolveOptions(new String[] { "*" }));
3630:
3631:                ConfigurationResolveReport conf = report
3632:                        .getConfigurationReport("default");
3633:
3634:                assertContainsArtifact("test", "a", "1.0.1", "a", "txt", "txt",
3635:                        conf);
3636:                assertDoesntContainArtifact("test", "a", "1.0.1", "a-bt",
3637:                        "txt", "txt", conf);
3638:                assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt",
3639:                        conf);
3640:                assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt",
3641:                        "txt", "txt", conf);
3642:                assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt",
3643:                        conf);
3644:                assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt",
3645:                        "txt", "txt", conf);
3646:            }
3647:
3648:            public void testConfigurationMapping3() throws Exception {
3649:                Ivy ivy = new Ivy();
3650:                ivy.configure(new File(
3651:                        "test/repositories/IVY-84/ivysettings.xml"));
3652:                ResolveReport report = ivy.resolve(new File(
3653:                        "test/repositories/IVY-84/tests/3/ivy.xml").toURL(),
3654:                        getResolveOptions(new String[] { "buildtime" }));
3655:
3656:                ConfigurationResolveReport conf = report
3657:                        .getConfigurationReport("buildtime");
3658:
3659:                assertContainsArtifact("test", "a", "1.0.2", "a-bt", "txt",
3660:                        "txt", conf);
3661:                assertDoesntContainArtifact("test", "a", "1.0.2", "a", "txt",
3662:                        "txt", conf);
3663:                assertContainsArtifact("test", "b", "1.0.1", "b-bt", "txt",
3664:                        "txt", conf);
3665:                assertDoesntContainArtifact("test", "b", "1.0.1", "b", "txt",
3666:                        "txt", conf);
3667:                assertContainsArtifact("test", "c", "1.0.1", "c-bt", "txt",
3668:                        "txt", conf);
3669:                assertDoesntContainArtifact("test", "c", "1.0.1", "c", "txt",
3670:                        "txt", conf);
3671:            }
3672:
3673:            public void testConfigurationMapping4() throws Exception {
3674:                Ivy ivy = new Ivy();
3675:                ivy.configure(new File(
3676:                        "test/repositories/IVY-84/ivysettings.xml"));
3677:                ResolveReport report = ivy.resolve(new File(
3678:                        "test/repositories/IVY-84/tests/4/ivy.xml").toURL(),
3679:                        getResolveOptions(new String[] { "default" }));
3680:
3681:                ConfigurationResolveReport conf = report
3682:                        .getConfigurationReport("default");
3683:
3684:                assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt",
3685:                        conf);
3686:                assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt",
3687:                        "txt", "txt", conf);
3688:                assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt",
3689:                        conf);
3690:                assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt",
3691:                        "txt", "txt", conf);
3692:                assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt",
3693:                        conf);
3694:                assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt",
3695:                        "txt", "txt", conf);
3696:            }
3697:
3698:            public void testConfigurationMapping5() throws Exception {
3699:                Ivy ivy = new Ivy();
3700:                ivy.configure(new File(
3701:                        "test/repositories/IVY-84/ivysettings.xml"));
3702:                ResolveReport report = ivy.resolve(new File(
3703:                        "test/repositories/IVY-84/tests/5/ivy.xml").toURL(),
3704:                        getResolveOptions(new String[] { "*" }));
3705:
3706:                ConfigurationResolveReport conf = report
3707:                        .getConfigurationReport("default");
3708:
3709:                assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt",
3710:                        conf);
3711:                assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt",
3712:                        "txt", "txt", conf);
3713:                assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt",
3714:                        conf);
3715:                assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt",
3716:                        "txt", "txt", conf);
3717:                assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt",
3718:                        conf);
3719:                assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt",
3720:                        "txt", "txt", conf);
3721:            }
3722:
3723:            public void testConfigurationMapping6() throws Exception {
3724:                Ivy ivy = new Ivy();
3725:                ivy.configure(new File(
3726:                        "test/repositories/IVY-84/ivysettings.xml"));
3727:                ResolveReport report = ivy
3728:                        .resolve(new File(
3729:                                "test/repositories/IVY-84/tests/6/ivy.xml")
3730:                                .toURL(), getResolveOptions(new String[] {
3731:                                "default", "buildtime" }));
3732:
3733:                ConfigurationResolveReport conf = report
3734:                        .getConfigurationReport("default");
3735:
3736:                assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt",
3737:                        conf);
3738:                assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt",
3739:                        "txt", "txt", conf);
3740:                assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt",
3741:                        conf);
3742:                assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt",
3743:                        "txt", "txt", conf);
3744:                assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt",
3745:                        conf);
3746:                assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt",
3747:                        "txt", "txt", conf);
3748:            }
3749:
3750:            public void testConfigurationMapping7() throws Exception {
3751:                Ivy ivy = new Ivy();
3752:                ivy.configure(new File(
3753:                        "test/repositories/IVY-84/ivysettings.xml"));
3754:                ResolveReport report = ivy
3755:                        .resolve(new File(
3756:                                "test/repositories/IVY-84/tests/7/ivy.xml")
3757:                                .toURL(), getResolveOptions(new String[] {
3758:                                "buildtime", "default" }));
3759:
3760:                ConfigurationResolveReport conf = report
3761:                        .getConfigurationReport("default");
3762:
3763:                assertContainsArtifact("test", "a", "1.0.2", "a", "txt", "txt",
3764:                        conf);
3765:                assertDoesntContainArtifact("test", "a", "1.0.2", "a-bt",
3766:                        "txt", "txt", conf);
3767:                assertContainsArtifact("test", "b", "1.0.1", "b", "txt", "txt",
3768:                        conf);
3769:                assertDoesntContainArtifact("test", "b", "1.0.1", "b-bt",
3770:                        "txt", "txt", conf);
3771:                assertContainsArtifact("test", "c", "1.0.1", "c", "txt", "txt",
3772:                        conf);
3773:                assertDoesntContainArtifact("test", "c", "1.0.1", "c-bt",
3774:                        "txt", "txt", conf);
3775:            }
3776:
3777:            public void testIVY97() throws Exception {
3778:                // mod9.2 depends on mod9.1 and mod1.2
3779:                // mod9.1 depends on mod1.2
3780:                ResolveReport report = ivy.resolve(new File(
3781:                        "test/repositories/1/org9/mod9.2/ivys/ivy-1.0.xml")
3782:                        .toURL(), getResolveOptions(new String[] { "*" }));
3783:                assertNotNull(report);
3784:                ModuleDescriptor md = report.getModuleDescriptor();
3785:                assertNotNull(md);
3786:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org9",
3787:                        "mod9.2", "1.0");
3788:                assertEquals(mrid, md.getModuleRevisionId());
3789:
3790:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
3791:
3792:                // dependencies
3793:                assertTrue(getIvyFileInCache(
3794:                        ModuleRevisionId.newInstance("org9", "mod9.1", "1.0"))
3795:                        .exists());
3796:                assertTrue(getArchiveFileInCache("org9", "mod9.1", "1.0",
3797:                        "mod9.1", "jar", "jar").exists());
3798:
3799:                assertTrue(getIvyFileInCache(
3800:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
3801:                        .exists());
3802:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
3803:                        "mod1.2", "jar", "jar").exists());
3804:            }
3805:
3806:            public void testResolveTransitiveExcludesSimple() throws Exception {
3807:                // mod2.5 depends on mod2.3 and excludes one artifact from mod2.1
3808:                // mod2.3 depends on mod2.1
3809:                ResolveReport report = ivy.resolve(new File(
3810:                        "test/repositories/1/org2/mod2.5/ivys/ivy-0.6.xml")
3811:                        .toURL(), getResolveOptions(new String[] { "*" }));
3812:                assertNotNull(report);
3813:                ModuleDescriptor md = report.getModuleDescriptor();
3814:                assertNotNull(md);
3815:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org2",
3816:                        "mod2.5", "0.6");
3817:                assertEquals(mrid, md.getModuleRevisionId());
3818:
3819:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
3820:
3821:                assertTrue(getIvyFileInCache(
3822:                        ModuleRevisionId.newInstance("org2", "mod2.3", "0.7"))
3823:                        .exists());
3824:                assertTrue(getArchiveFileInCache("org2", "mod2.3", "0.7",
3825:                        "mod2.3", "jar", "jar").exists());
3826:
3827:                assertTrue(getIvyFileInCache(
3828:                        ModuleRevisionId.newInstance("org2", "mod2.1", "0.3"))
3829:                        .exists());
3830:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3831:                        "art21A", "jar", "jar").exists());
3832:                assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3",
3833:                        "art21B", "jar", "jar").exists());
3834:            }
3835:
3836:            public void testResolveTransitiveExcludesDiamond1()
3837:                    throws Exception {
3838:                // mod2.6 depends on mod2.3 and mod2.5
3839:                // mod2.3 depends on mod2.1 and excludes art21B
3840:                // mod2.5 depends on mod2.1 and excludes art21A
3841:                ivy.resolve(new File(
3842:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.6.xml")
3843:                        .toURL(), getResolveOptions(new String[] { "*" }));
3844:
3845:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3846:                        "art21A", "jar", "jar").exists());
3847:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3848:                        "art21B", "jar", "jar").exists());
3849:            }
3850:
3851:            public void testResolveTransitiveExcludesDiamond2()
3852:                    throws Exception {
3853:                // mod2.6 depends on mod2.3 and mod2.5
3854:                // mod2.3 depends on mod2.1 and excludes art21B
3855:                // mod2.5 depends on mod2.1 and excludes art21B
3856:                ivy.resolve(new File(
3857:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.7.xml")
3858:                        .toURL(), getResolveOptions(new String[] { "*" }));
3859:
3860:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3861:                        "art21A", "jar", "jar").exists());
3862:                assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3",
3863:                        "art21B", "jar", "jar").exists());
3864:            }
3865:
3866:            public void testResolveTransitiveExcludesDiamond3()
3867:                    throws Exception {
3868:                // mod2.6 depends on mod2.3 and mod2.5 and on mod2.1 for which it excludes art21A
3869:                // mod2.3 depends on mod2.1 and excludes art21B
3870:                // mod2.5 depends on mod2.1 and excludes art21B
3871:                ivy.resolve(new File(
3872:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.8.xml")
3873:                        .toURL(), getResolveOptions(new String[] { "*" }));
3874:
3875:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3876:                        "art21A", "jar", "jar").exists());
3877:                assertTrue(getArchiveFileInCache("org2", "mod2.1", "0.3",
3878:                        "art21B", "jar", "jar").exists());
3879:            }
3880:
3881:            public void testResolveTransitiveExcludes2() throws Exception {
3882:                // mod2.6 depends on mod2.3 for which it excludes art21A
3883:                // mod2.3 depends on mod2.1 and excludes art21B
3884:                ResolveReport report = ivy.resolve(new File(
3885:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.9.xml")
3886:                        .toURL(), getResolveOptions(new String[] { "*" }));
3887:                ModuleDescriptor md = report.getModuleDescriptor();
3888:                assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6",
3889:                        "0.9"), md.getModuleRevisionId());
3890:
3891:                assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3",
3892:                        "art21A", "jar", "jar").exists());
3893:                assertFalse(getArchiveFileInCache("org2", "mod2.1", "0.3",
3894:                        "art21B", "jar", "jar").exists());
3895:            }
3896:
3897:            public void testResolveExcludesModule() throws Exception {
3898:                // mod2.6 depends on mod2.1 and excludes mod1.1
3899:                // mod2.1 depends on mod1.1 which depends on mod1.2
3900:                ResolveReport report = ivy.resolve(new File(
3901:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.10.xml")
3902:                        .toURL(), getResolveOptions(new String[] { "*" }));
3903:                ModuleDescriptor md = report.getModuleDescriptor();
3904:                assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6",
3905:                        "0.10"), md.getModuleRevisionId());
3906:
3907:                assertFalse(getIvyFileInCache(
3908:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
3909:                        .exists());
3910:                assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0",
3911:                        "mod1.1", "jar", "jar").exists());
3912:                assertFalse(getIvyFileInCache(
3913:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
3914:                        .exists());
3915:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
3916:                        "mod1.2", "jar", "jar").exists());
3917:            }
3918:
3919:            public void testResolveExcludesModuleWide() throws Exception {
3920:                // mod2.6 depends on mod2.1 and excludes mod1.1 module wide
3921:                // mod2.1 depends on mod1.1 which depends on mod1.2
3922:                ResolveReport report = ivy.resolve(new File(
3923:                        "test/repositories/1/org2/mod2.6/ivys/ivy-0.11.xml")
3924:                        .toURL(), getResolveOptions(new String[] { "*" }));
3925:                ModuleDescriptor md = report.getModuleDescriptor();
3926:                assertEquals(ModuleRevisionId.newInstance("org2", "mod2.6",
3927:                        "0.11"), md.getModuleRevisionId());
3928:
3929:                assertFalse(getIvyFileInCache(
3930:                        ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"))
3931:                        .exists());
3932:                assertFalse(getArchiveFileInCache("org1", "mod1.1", "1.0",
3933:                        "mod1.1", "jar", "jar").exists());
3934:                assertFalse(getIvyFileInCache(
3935:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
3936:                        .exists());
3937:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
3938:                        "mod1.2", "jar", "jar").exists());
3939:            }
3940:
3941:            public void testResolveExceptConfiguration() throws Exception {
3942:                // mod10.2 depends on mod5.1 conf *, !A
3943:                ivy.resolve(new File("test/repositories/2/mod10.2/ivy-2.0.xml")
3944:                        .toURL(), getResolveOptions(new String[] { "*" }));
3945:
3946:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.1",
3947:                        "art51A", "jar", "jar").exists());
3948:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.1",
3949:                        "art51B", "jar", "jar").exists());
3950:            }
3951:
3952:            public void testResolveFallbackConfiguration() throws Exception {
3953:                // mod10.2 depends on mod5.1 conf runtime(default)
3954:                ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.0.xml")
3955:                        .toURL(), getResolveOptions(new String[] { "*" }));
3956:
3957:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
3958:                        "art51A", "jar", "jar").exists());
3959:            }
3960:
3961:            public void testResolveFallbackConfiguration2() throws Exception {
3962:                // mod10.2 depends on mod5.1 conf runtime(*)
3963:                ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.1.xml")
3964:                        .toURL(), getResolveOptions(new String[] { "*" }));
3965:
3966:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
3967:                        "art51A", "jar", "jar").exists());
3968:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
3969:                        "art51B", "jar", "jar").exists());
3970:            }
3971:
3972:            public void testResolveFallbackConfiguration3() throws Exception {
3973:                // mod10.2 depends on mod5.1 conf runtime(*),compile(*)
3974:                ivy.resolve(new File("test/repositories/2/mod10.2/ivy-1.2.xml")
3975:                        .toURL(), getResolveOptions(new String[] { "*" }));
3976:
3977:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
3978:                        "art51A", "jar", "jar").exists());
3979:                assertTrue(getArchiveFileInCache("org5", "mod5.1", "4.0",
3980:                        "art51B", "jar", "jar").exists());
3981:            }
3982:
3983:            public void testResolveFallbackConfiguration4() throws Exception {
3984:                // mod10.2 depends on mod5.1 conf runtime()
3985:                ResolveReport report = ivy.resolve(new File(
3986:                        "test/repositories/2/mod10.2/ivy-1.3.xml").toURL(),
3987:                        getResolveOptions(new String[] { "*" }));
3988:                assertFalse(report.hasError());
3989:
3990:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
3991:                        "art51A", "jar", "jar").exists());
3992:                assertFalse(getArchiveFileInCache("org5", "mod5.1", "4.0",
3993:                        "art51B", "jar", "jar").exists());
3994:            }
3995:
3996:            public void testResolveMaven2() throws Exception {
3997:                // test3 depends on test2 which depends on test
3998:                Ivy ivy = new Ivy();
3999:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4000:                ResolveReport report = ivy
4001:                        .resolve(
4002:                                new File(
4003:                                        "test/repositories/m2/org/apache/test3/1.0/test3-1.0.pom")
4004:                                        .toURL(),
4005:                                getResolveOptions(new String[] { "test" }));
4006:                assertNotNull(report);
4007:                ModuleDescriptor md = report.getModuleDescriptor();
4008:                assertNotNull(md);
4009:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
4010:                        "org.apache", "test3", "1.0");
4011:                assertEquals(mrid, md.getModuleRevisionId());
4012:
4013:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4014:
4015:                // dependencies
4016:                assertTrue(getIvyFileInCache(
4017:                        ModuleRevisionId.newInstance("org.apache", "test2",
4018:                                "1.0")).exists());
4019:                assertTrue(getArchiveFileInCache(ivy, "org.apache", "test2",
4020:                        "1.0", "test2", "jar", "jar").exists());
4021:
4022:                assertTrue(getIvyFileInCache(
4023:                        ModuleRevisionId.newInstance("org.apache", "test",
4024:                                "1.0")).exists());
4025:                assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4026:                        "1.0", "test", "jar", "jar").exists());
4027:            }
4028:
4029:            public void testResolveMaven2RelocationOfGroupId() throws Exception {
4030:                //Same as testResolveMaven2 but with a relocated module pointing to the module
4031:                //used in testResolveMaven2.
4032:                ivy = new Ivy();
4033:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4034:                ivy.pushContext();
4035:                try {
4036:                    ResolveReport report = ivy
4037:                            .resolve(
4038:                                    new File(
4039:                                            "test/repositories/m2/org/relocated/test3/1.0/test3-1.0.pom")
4040:                                            .toURL(),
4041:                                    getResolveOptions(new String[] { "*" }));
4042:                    assertNotNull(report);
4043:
4044:                    // dependencies
4045:                    assertTrue(getIvyFileInCache(
4046:                            ModuleRevisionId.newInstance("org.apache", "test2",
4047:                                    "1.0")).exists());
4048:                    assertTrue(getArchiveFileInCache(ivy, "org.apache",
4049:                            "test2", "1.0", "test2", "jar", "jar").exists());
4050:
4051:                    assertTrue(getIvyFileInCache(
4052:                            ModuleRevisionId.newInstance("org.apache", "test",
4053:                                    "1.0")).exists());
4054:                    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4055:                            "1.0", "test", "jar", "jar").exists());
4056:                } finally {
4057:                    ivy.popContext();
4058:                }
4059:            }
4060:
4061:            public void testResolveMaven2FullRelocation() throws Exception {
4062:                //Same as testResolveMaven2 but with a relocated module pointing to the module
4063:                //used in testResolveMaven2.
4064:                ivy = new Ivy();
4065:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4066:                ivy.pushContext();
4067:                try {
4068:                    ResolveReport report = ivy
4069:                            .resolve(
4070:                                    new File(
4071:                                            "test/repositories/m2/org/relocated/test3full/1.1/test3full-1.1.pom")
4072:                                            .toURL(),
4073:                                    getResolveOptions(new String[] { "*" }));
4074:                    assertNotNull(report);
4075:
4076:                    // dependencies
4077:                    assertTrue(getIvyFileInCache(
4078:                            ModuleRevisionId.newInstance("org.apache", "test2",
4079:                                    "1.0")).exists());
4080:                    assertTrue(getArchiveFileInCache(ivy, "org.apache",
4081:                            "test2", "1.0", "test2", "jar", "jar").exists());
4082:
4083:                    assertTrue(getIvyFileInCache(
4084:                            ModuleRevisionId.newInstance("org.apache", "test",
4085:                                    "1.0")).exists());
4086:                    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4087:                            "1.0", "test", "jar", "jar").exists());
4088:                } finally {
4089:                    ivy.popContext();
4090:                }
4091:            }
4092:
4093:            public void testResolveVesionRelocationChainedWithGroupRelocation()
4094:                    throws Exception {
4095:                ivy = new Ivy();
4096:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4097:                ivy.pushContext();
4098:                try {
4099:                    ResolveReport report = ivy
4100:                            .resolve(
4101:                                    new File(
4102:                                            "test/repositories/m2/org/relocated/test3/1.1/test3-1.1.pom")
4103:                                            .toURL(),
4104:                                    getResolveOptions(new String[] { "*" }));
4105:                    assertNotNull(report);
4106:
4107:                    // dependencies
4108:                    assertTrue(getIvyFileInCache(
4109:                            ModuleRevisionId.newInstance("org.apache", "test2",
4110:                                    "1.0")).exists());
4111:                    assertTrue(getArchiveFileInCache(ivy, "org.apache",
4112:                            "test2", "1.0", "test2", "jar", "jar").exists());
4113:
4114:                    assertTrue(getIvyFileInCache(
4115:                            ModuleRevisionId.newInstance("org.apache", "test",
4116:                                    "1.0")).exists());
4117:                    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4118:                            "1.0", "test", "jar", "jar").exists());
4119:                } finally {
4120:                    ivy.popContext();
4121:                }
4122:            }
4123:
4124:            public void testResolveTransitivelyToRelocatedPom()
4125:                    throws Exception {
4126:                ivy = new Ivy();
4127:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4128:                ivy.pushContext();
4129:                try {
4130:                    ResolveReport report = ivy.resolve(new File(
4131:                            "test/repositories/m2/org/relocated/testRelocationUser/1.0/"
4132:                                    + "testRelocationUser-1.0.pom").toURL(),
4133:                            getResolveOptions(new String[] { "compile" }));
4134:                    assertNotNull(report);
4135:                    assertFalse(report.hasError());
4136:                    // dependencies
4137:                    assertTrue(getIvyFileInCache(
4138:                            ModuleRevisionId.newInstance("org.apache", "test2",
4139:                                    "1.0")).exists());
4140:                    assertTrue(getArchiveFileInCache(ivy, "org.apache",
4141:                            "test2", "1.0", "test2", "jar", "jar").exists());
4142:
4143:                    assertTrue(getIvyFileInCache(
4144:                            ModuleRevisionId.newInstance("org.apache", "test",
4145:                                    "1.0")).exists());
4146:                    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4147:                            "1.0", "test", "jar", "jar").exists());
4148:                } finally {
4149:                    ivy.popContext();
4150:                }
4151:            }
4152:
4153:            public void testResolveTransitivelyToPomRelocatedToNewVersion()
4154:                    throws Exception {
4155:                ivy = new Ivy();
4156:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4157:                ivy.pushContext();
4158:                try {
4159:                    ResolveReport report = ivy.resolve(new File(
4160:                            "test/repositories/m2/org/relocated/testRelocationUser/1.1/"
4161:                                    + "testRelocationUser-1.1.pom").toURL(),
4162:                            getResolveOptions(new String[] { "compile" }));
4163:                    assertNotNull(report);
4164:                    assertFalse(report.hasError());
4165:                    // dependencies
4166:                    assertTrue(getIvyFileInCache(
4167:                            ModuleRevisionId.newInstance("org.apache", "test2",
4168:                                    "1.0")).exists());
4169:                    assertTrue(getArchiveFileInCache(ivy, "org.apache",
4170:                            "test2", "1.0", "test2", "jar", "jar").exists());
4171:
4172:                    assertTrue(getIvyFileInCache(
4173:                            ModuleRevisionId.newInstance("org.apache", "test",
4174:                                    "1.0")).exists());
4175:                    assertTrue(getArchiveFileInCache(ivy, "org.apache", "test",
4176:                            "1.0", "test", "jar", "jar").exists());
4177:                } finally {
4178:                    ivy.popContext();
4179:                }
4180:            }
4181:
4182:            public void testResolveMaven2Classifiers() throws Exception {
4183:                // test case for IVY-418
4184:                // test-classifier depends on test-classified with classifier asl
4185:                Ivy ivy = new Ivy();
4186:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4187:                ResolveReport report = ivy
4188:                        .resolve(
4189:                                new File(
4190:                                        "test/repositories/m2/org/apache/test-classifier/1.0/test-classifier-1.0.pom")
4191:                                        .toURL(),
4192:                                getResolveOptions(new String[] { "*" }));
4193:                assertNotNull(report);
4194:                ModuleDescriptor md = report.getModuleDescriptor();
4195:                assertNotNull(md);
4196:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
4197:                        "org.apache", "test-classifier", "1.0");
4198:                assertEquals(mrid, md.getModuleRevisionId());
4199:
4200:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4201:
4202:                // dependencies
4203:                assertTrue(getIvyFileInCache(
4204:                        ModuleRevisionId.newInstance("org.apache",
4205:                                "test-classified", "1.0")).exists());
4206:                assertTrue(getArchiveFileInCache(ivy, "org.apache",
4207:                        "test-classified", "1.0", "test-classified", "jar",
4208:                        "jar").exists());
4209:            }
4210:
4211:            public void testResolveMaven2WithVersionProperty() throws Exception {
4212:                Ivy ivy = new Ivy();
4213:                ivy.configure(new File("test/repositories/m2/ivysettings.xml"));
4214:                ResolveReport report = ivy
4215:                        .resolve(
4216:                                new File(
4217:                                        "test/repositories/m2/org/apache/test-version/1.0/test-version-1.0.pom")
4218:                                        .toURL(),
4219:                                getResolveOptions(new String[] { "*" }));
4220:                assertNotNull(report);
4221:                ModuleDescriptor md = report.getModuleDescriptor();
4222:                assertNotNull(md);
4223:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
4224:                        "org.apache", "test-version", "1.0");
4225:                assertEquals(mrid, md.getModuleRevisionId());
4226:
4227:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4228:
4229:                // dependencies
4230:                assertTrue(getIvyFileInCache(
4231:                        ModuleRevisionId.newInstance("org.apache",
4232:                                "test-classifier", "1.0")).exists());
4233:                assertTrue(getArchiveFileInCache(ivy, "org.apache",
4234:                        "test-classifier", "1.0", "test-classifier", "jar",
4235:                        "jar").exists());
4236:            }
4237:
4238:            public void testResolveMaven2ParentPomChainResolver()
4239:                    throws Exception {
4240:                // test has a dependency on test2 but there is no version listed. test has a parent of parent(2.0) 
4241:                // then parent2. Both parents have a dependencyManagement element for test2, and each list the version as
4242:                // ${pom.version}. The parent version should take precidence over parent2, 
4243:                // so the version should be test2 version 2.0. Test3 is also a dependency of parent, and it's version is listed
4244:                // as 1.0 in parent2 (dependencies inherited from parent comes after).
4245:                Ivy ivy = new Ivy();
4246:                ivy.configure(new File(
4247:                        "test/repositories/parentPom/ivysettings.xml"));
4248:                ivy.getSettings().setDefaultResolver("parentChain");
4249:
4250:                ResolveReport report = ivy
4251:                        .resolve(
4252:                                new File(
4253:                                        "test/repositories/parentPom/org/apache/dm/test/1.0/test-1.0.pom")
4254:                                        .toURL(),
4255:                                getResolveOptions(new String[] { "*" }));
4256:                assertNotNull(report);
4257:                ModuleDescriptor md = report.getModuleDescriptor();
4258:                assertNotNull(md);
4259:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
4260:                        "org.apache.dm", "test", "1.0");
4261:                assertEquals(mrid, md.getModuleRevisionId());
4262:
4263:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4264:
4265:                //test the report to make sure the right dependencies are listed
4266:                List dependencies = report.getDependencies();
4267:                assertEquals(2, dependencies.size());
4268:
4269:                IvyNode ivyNode;
4270:                ivyNode = (IvyNode) dependencies.get(0);
4271:                assertNotNull(ivyNode);
4272:                mrid = ModuleRevisionId.newInstance("org.apache.dm", "test2",
4273:                        "2.0");
4274:                assertEquals(mrid, ivyNode.getId());
4275:                // dependencies
4276:                assertTrue(getIvyFileInCache(
4277:                        ModuleRevisionId.newInstance("org.apache.dm", "test2",
4278:                                "2.0")).exists());
4279:                assertTrue(getArchiveFileInCache(ivy, "org.apache.dm", "test2",
4280:                        "2.0", "test2", "jar", "jar").exists());
4281:
4282:                ivyNode = (IvyNode) dependencies.get(1);
4283:                assertNotNull(ivyNode);
4284:                mrid = ModuleRevisionId.newInstance("org.apache.dm", "test3",
4285:                        "1.0");
4286:                assertEquals(mrid, ivyNode.getId());
4287:                // dependencies
4288:                assertTrue(getIvyFileInCache(
4289:                        ModuleRevisionId.newInstance("org.apache.dm", "test3",
4290:                                "1.0")).exists());
4291:                assertTrue(getArchiveFileInCache(ivy, "org.apache.dm", "test3",
4292:                        "1.0", "test3", "jar", "jar").exists());
4293:            }
4294:
4295:            public void testResolveMaven2ParentPomDualResolver()
4296:                    throws Exception {
4297:                // test has a dependency on test2 but there is no version listed. test has a parent of parent(2.0) 
4298:                // then parent2. Both parents have a dependencyManagement element for test2, and each list the version as
4299:                // ${pom.version}. The parent version should take precidence over parent2, 
4300:                // so the version should be test2 version 2.0. Test3 is also a dependency of parent, and it's version is listed
4301:                // as 1.0 in parent2. (dependencies inherited from parent comes after)
4302:
4303:                // now run tests with dual resolver
4304:                Ivy ivy = new Ivy();
4305:                ivy.configure(new File(
4306:                        "test/repositories/parentPom/ivysettings.xml"));
4307:                ivy.getSettings().setDefaultResolver("parentDual");
4308:
4309:                ResolveReport report = ivy
4310:                        .resolve(
4311:                                new File(
4312:                                        "test/repositories/parentPom/org/apache/dm/test/1.0/test-1.0.pom")
4313:                                        .toURL(),
4314:                                getResolveOptions(new String[] { "*" }));
4315:                assertNotNull(report);
4316:                ModuleDescriptor md = report.getModuleDescriptor();
4317:                assertNotNull(md);
4318:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
4319:                        "org.apache.dm", "test", "1.0");
4320:                assertEquals(mrid, md.getModuleRevisionId());
4321:
4322:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4323:
4324:                //test the report to make sure the right dependencies are listed
4325:                List dependencies = report.getDependencies();
4326:                assertEquals(2, dependencies.size());
4327:
4328:                IvyNode ivyNode;
4329:                ivyNode = (IvyNode) dependencies.get(0);
4330:                assertNotNull(ivyNode);
4331:                mrid = ModuleRevisionId.newInstance("org.apache.dm", "test2",
4332:                        "2.0");
4333:                assertEquals(mrid, ivyNode.getId());
4334:                // dependencies
4335:                assertTrue(getIvyFileInCache(
4336:                        ModuleRevisionId.newInstance("org.apache.dm", "test2",
4337:                                "2.0")).exists());
4338:                assertTrue(getArchiveFileInCache(ivy, "org.apache.dm", "test2",
4339:                        "2.0", "test2", "jar", "jar").exists());
4340:
4341:                ivyNode = (IvyNode) dependencies.get(1);
4342:                assertNotNull(ivyNode);
4343:                mrid = ModuleRevisionId.newInstance("org.apache.dm", "test3",
4344:                        "1.0");
4345:                assertEquals(mrid, ivyNode.getId());
4346:                // dependencies
4347:                assertTrue(getIvyFileInCache(
4348:                        ModuleRevisionId.newInstance("org.apache.dm", "test3",
4349:                                "1.0")).exists());
4350:                assertTrue(getArchiveFileInCache(ivy, "org.apache.dm", "test3",
4351:                        "1.0", "test3", "jar", "jar").exists());
4352:            }
4353:
4354:            public void testNamespaceMapping() throws Exception {
4355:                // the dependency is in another namespace
4356:                Ivy ivy = new Ivy();
4357:                ivy.configure(new File(
4358:                        "test/repositories/namespace/ivysettings.xml"));
4359:                ResolveReport report = ivy.resolve(ResolveTest.class
4360:                        .getResource("ivy-namespace.xml"),
4361:                        getResolveOptions(new String[] { "*" }));
4362:                assertNotNull(report);
4363:                ModuleDescriptor md = report.getModuleDescriptor();
4364:                assertNotNull(md);
4365:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
4366:                        "namespace", "1.0");
4367:                assertEquals(mrid, md.getModuleRevisionId());
4368:
4369:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4370:
4371:                // ivy file
4372:                File ivyFile = getIvyFileInCache(ModuleRevisionId.newInstance(
4373:                        "systemorg", "systemmod", "1.0"));
4374:                assertTrue(ivyFile.exists());
4375:                ModuleDescriptor parsedMD = XmlModuleDescriptorParser
4376:                        .getInstance().parseDescriptor(ivy.getSettings(),
4377:                                ivyFile.toURL(), true);
4378:                assertEquals("systemorg", parsedMD.getModuleRevisionId()
4379:                        .getOrganisation());
4380:                assertEquals("systemmod", parsedMD.getModuleRevisionId()
4381:                        .getName());
4382:
4383:                // dependencies
4384:                assertTrue(getArchiveFileInCache(ivy, "systemorg", "systemmod",
4385:                        "1.0", "A", "jar", "jar").exists());
4386:            }
4387:
4388:            public void testNamespaceMapping2() throws Exception {
4389:                // the dependency is in another namespace and has itself a dependency on a module available
4390:                // in the same namespace
4391:                Ivy ivy = new Ivy();
4392:                ivy.configure(new File(
4393:                        "test/repositories/namespace/ivysettings.xml"));
4394:                ResolveReport report = ivy.resolve(ResolveTest.class
4395:                        .getResource("ivy-namespace2.xml"),
4396:                        getResolveOptions(new String[] { "*" }));
4397:                assertNotNull(report);
4398:                ModuleDescriptor md = report.getModuleDescriptor();
4399:                assertNotNull(md);
4400:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
4401:                        "namespace", "2.0");
4402:                assertEquals(mrid, md.getModuleRevisionId());
4403:
4404:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4405:
4406:                // dependencies
4407:                assertTrue(getIvyFileInCache(
4408:                        ModuleRevisionId.newInstance("systemorg", "systemmod2",
4409:                                "1.0")).exists());
4410:                assertTrue(getArchiveFileInCache(ivy, "systemorg",
4411:                        "systemmod2", "1.0", "B", "jar", "jar").exists());
4412:
4413:                assertTrue(getIvyFileInCache(
4414:                        ModuleRevisionId.newInstance("systemorg", "systemmod",
4415:                                "1.0")).exists());
4416:                assertTrue(getArchiveFileInCache(ivy, "systemorg", "systemmod",
4417:                        "1.0", "A", "jar", "jar").exists());
4418:            }
4419:
4420:            public void testNamespaceMapping3() throws Exception {
4421:                // same as 2 but with poms
4422:                Ivy ivy = new Ivy();
4423:                ivy.configure(new File(
4424:                        "test/repositories/namespace/ivysettings.xml"));
4425:                ResolveReport report = ivy.resolve(ResolveTest.class
4426:                        .getResource("ivy-namespace3.xml"),
4427:                        getResolveOptions(new String[] { "*" }));
4428:                assertNotNull(report);
4429:                ModuleDescriptor md = report.getModuleDescriptor();
4430:                assertNotNull(md);
4431:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
4432:                        "namespace", "3.0");
4433:                assertEquals(mrid, md.getModuleRevisionId());
4434:
4435:                assertTrue(getResolvedIvyFileInCache(mrid).exists());
4436:
4437:                // dependencies
4438:                assertTrue(getIvyFileInCache(
4439:                        ModuleRevisionId.newInstance("systemorg2", "system-2",
4440:                                "1.0")).exists());
4441:                assertTrue(getArchiveFileInCache(ivy, "systemorg2", "system-2",
4442:                        "1.0", "2", "jar", "jar").exists());
4443:
4444:                assertTrue(getIvyFileInCache(
4445:                        ModuleRevisionId.newInstance("systemorg2", "system-1",
4446:                                "1.0")).exists());
4447:                assertTrue(getArchiveFileInCache(ivy, "systemorg2", "system-1",
4448:                        "1.0", "1", "jar", "jar").exists());
4449:            }
4450:
4451:            public void testNamespaceMapping4() throws Exception {
4452:                // same as 2 but with incorrect dependency asked: the first ivy file asks for a dependency
4453:                // in the resolver namespace and not the system one: this should fail
4454:                Ivy ivy = new Ivy();
4455:                ivy.configure(new File(
4456:                        "test/repositories/namespace/ivysettings.xml"));
4457:                ResolveReport report = ivy.resolve(ResolveTest.class
4458:                        .getResource("ivy-namespace4.xml"),
4459:                        getResolveOptions(new String[] { "*" }));
4460:                assertNotNull(report);
4461:                ModuleDescriptor md = report.getModuleDescriptor();
4462:                assertNotNull(md);
4463:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
4464:                        "namespace", "4.0");
4465:                assertEquals(mrid, md.getModuleRevisionId());
4466:
4467:                assertTrue(report.hasError());
4468:            }
4469:
4470:            public void testIVY151() throws Exception {
4471:                Ivy ivy = new Ivy();
4472:                ivy.configure(new File(
4473:                        "test/repositories/multirevisions/ivysettings.xml"));
4474:                ResolveReport report = ivy.resolve(new File(
4475:                        "test/repositories/multirevisions/ivy.xml").toURL(),
4476:                        getResolveOptions(new String[] { "compile", "test" }));
4477:
4478:                assertNotNull(report);
4479:                assertNotNull(report.getUnresolvedDependencies());
4480:                assertEquals("Number of unresolved dependencies not correct",
4481:                        0, report.getUnresolvedDependencies().length);
4482:            }
4483:
4484:            public void testCheckRevision() throws Exception {
4485:                // mod12.2 depends on mod12.1 1.0 which depends on mod1.2
4486:                // mod12.1 doesn't have revision in its ivy file
4487:                ResolveReport report = ivy.resolve(new File(
4488:                        "test/repositories/2/mod12.2/ivy-1.0.xml").toURL(),
4489:                        getResolveOptions(new String[] { "*" }));
4490:
4491:                assertTrue(report.hasError());
4492:
4493:                assertFalse(getIvyFileInCache(
4494:                        ModuleRevisionId.newInstance("org12", "mod12.1", "1.0"))
4495:                        .exists());
4496:                assertFalse(getArchiveFileInCache("org12", "mod12.1", "1.0",
4497:                        "mod12.1", "jar", "jar").exists());
4498:
4499:                assertFalse(getIvyFileInCache(
4500:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
4501:                        .exists());
4502:                assertFalse(getArchiveFileInCache("org1", "mod1.2", "2.0",
4503:                        "mod1.2", "jar", "jar").exists());
4504:            }
4505:
4506:            public void testTrustRevision() throws Exception {
4507:                // mod12.2 depends on mod12.1 1.0 which depends on mod1.2
4508:                // mod12.1 doesn't have revision in its ivy file
4509:
4510:                ((BasicResolver) settings.getResolver("2-ivy"))
4511:                        .setCheckconsistency(false);
4512:
4513:                ResolveReport report = ivy.resolve(new File(
4514:                        "test/repositories/2/mod12.2/ivy-1.0.xml").toURL(),
4515:                        getResolveOptions(new String[] { "*" }));
4516:
4517:                assertFalse(report.hasError());
4518:
4519:                assertTrue(getIvyFileInCache(
4520:                        ModuleRevisionId.newInstance("org12", "mod12.1", "1.0"))
4521:                        .exists());
4522:                assertTrue(getArchiveFileInCache("org12", "mod12.1", "1.0",
4523:                        "mod12.1", "jar", "jar").exists());
4524:
4525:                assertTrue(getIvyFileInCache(
4526:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
4527:                        .exists());
4528:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
4529:                        "mod1.2", "jar", "jar").exists());
4530:            }
4531:
4532:            public void testTransitiveConfMapping() throws Exception {
4533:                // IVY-168
4534:                // mod13.3 depends on mod13.2 which depends on mod13.1
4535:                // each module has two confs: j2ee and compile
4536:                // each module only publishes one artifact in conf compile
4537:                // each module has the following conf mapping on its dependencies: *->@
4538:                // moreover, mod13.1 depends on mod1.2 in with the following conf mapping: compile->default
4539:                // thus conf j2ee should be empty for each modules
4540:
4541:                ResolveReport report = ivy.resolve(new File(
4542:                        "test/repositories/2/mod13.3/ivy-1.0.xml").toURL(),
4543:                        getResolveOptions(new String[] { "*" }));
4544:
4545:                assertFalse(report.hasError());
4546:
4547:                assertEquals(3, report.getConfigurationReport("compile")
4548:                        .getArtifactsNumber());
4549:                assertEquals(0, report.getConfigurationReport("j2ee")
4550:                        .getArtifactsNumber());
4551:            }
4552:
4553:            public void testExtraAttributes() throws Exception {
4554:                Ivy ivy = new Ivy();
4555:                ivy.configure(new File(
4556:                        "test/repositories/extra-attributes/ivysettings.xml"));
4557:                ivy.getSettings().setDefaultCache(cache);
4558:
4559:                ResolveReport report = ivy.resolve(ResolveTest.class
4560:                        .getResource("ivy-extra-att.xml"), getResolveOptions(
4561:                        ivy.getSettings(), new String[] { "*" }).setValidate(
4562:                        false));
4563:                assertFalse(report.hasError());
4564:
4565:                assertTrue(new File(cache, "apache/mymodule/task1/1854/ivy.xml")
4566:                        .exists());
4567:                assertTrue(new File(cache,
4568:                        "apache/mymodule/task1/1854/mymodule-windows.jar")
4569:                        .exists());
4570:                assertTrue(new File(cache,
4571:                        "apache/mymodule/task1/1854/mymodule-linux.jar")
4572:                        .exists());
4573:            }
4574:
4575:            public void testNamespaceExtraAttributes() throws Exception {
4576:                Ivy ivy = new Ivy();
4577:                ivy.configure(new File(
4578:                        "test/repositories/extra-attributes/ivysettings.xml"));
4579:                ivy.getSettings().setDefaultCache(cache);
4580:
4581:                ResolveReport report = ivy.resolve(ResolveTest.class
4582:                        .getResource("ivy-extra-att-ns.xml"),
4583:                        getResolveOptions(ivy.getSettings(),
4584:                                new String[] { "*" }).setValidate(true));
4585:                assertFalse(report.hasError());
4586:
4587:                assertTrue(new File(cache, "apache/mymodule/task1/1855/ivy.xml")
4588:                        .exists());
4589:                assertTrue(new File(cache,
4590:                        "apache/mymodule/task1/1855/mymodule-windows.jar")
4591:                        .exists());
4592:                assertTrue(new File(cache,
4593:                        "apache/mymodule/task1/1855/mymodule-linux.jar")
4594:                        .exists());
4595:            }
4596:
4597:            public void testBranches1() throws Exception {
4598:                Ivy ivy = new Ivy();
4599:                ivy.configure(new File(
4600:                        "test/repositories/branches/ivysettings.xml"));
4601:
4602:                ResolveReport report = ivy.resolve(new File(
4603:                        "test/repositories/branches/bar/bar1/trunk/1/ivy.xml")
4604:                        .toURL(), getResolveOptions(new String[] { "*" })
4605:                        .setValidate(false));
4606:                assertFalse(report.hasError());
4607:
4608:                assertTrue(getArchiveFileInCache(ivy, "foo", "foo1", "3",
4609:                        "foo1", "jar", "jar").exists());
4610:            }
4611:
4612:            public void testBranches2() throws Exception {
4613:                Ivy ivy = new Ivy();
4614:                ivy.configure(new File(
4615:                        "test/repositories/branches/ivysettings.xml"));
4616:
4617:                ResolveReport report = ivy.resolve(new File(
4618:                        "test/repositories/branches/bar/bar1/trunk/2/ivy.xml")
4619:                        .toURL(), getResolveOptions(new String[] { "*" })
4620:                        .setValidate(false));
4621:                assertFalse(report.hasError());
4622:
4623:                assertTrue(getArchiveFileInCache(ivy, "foo", "foo1", "4",
4624:                        "foo1", "jar", "jar").exists());
4625:            }
4626:
4627:            public void testBranches3() throws Exception {
4628:                Ivy ivy = new Ivy();
4629:                ivy
4630:                        .configure(new File(
4631:                                "test/repositories/branches/ivysettings-defaultbranch1.xml"));
4632:
4633:                ResolveReport report = ivy.resolve(new File(
4634:                        "test/repositories/branches/bar/bar1/trunk/1/ivy.xml")
4635:                        .toURL(), getResolveOptions(new String[] { "*" })
4636:                        .setValidate(false));
4637:                assertFalse(report.hasError());
4638:
4639:                assertTrue(getArchiveFileInCache(ivy, "foo", "foo1", "4",
4640:                        "foo1", "jar", "jar").exists());
4641:            }
4642:
4643:            public void testBranches4() throws Exception {
4644:                Ivy ivy = new Ivy();
4645:                ivy.configure(new File(
4646:                        "test/repositories/branches/ivysettings.xml"));
4647:
4648:                ResolveReport report = ivy.resolve(new File(
4649:                        "test/repositories/branches/bar/bar1/trunk/3/ivy.xml")
4650:                        .toURL(), getResolveOptions(new String[] { "*" })
4651:                        .setValidate(false));
4652:                assertFalse(report.hasError());
4653:
4654:                assertTrue(getArchiveFileInCache(ivy, "foo", "foo1", "3",
4655:                        "foo1", "jar", "jar").exists());
4656:                assertTrue(getArchiveFileInCache(ivy, "bar", "bar2", "2",
4657:                        "bar2", "jar", "jar").exists());
4658:            }
4659:
4660:            public void testBranches5() throws Exception {
4661:                Ivy ivy = new Ivy();
4662:                ivy
4663:                        .configure(new File(
4664:                                "test/repositories/branches/ivysettings-fooonbranch1.xml"));
4665:
4666:                ResolveReport report = ivy.resolve(new File(
4667:                        "test/repositories/branches/bar/bar1/trunk/3/ivy.xml")
4668:                        .toURL(), getResolveOptions(new String[] { "*" })
4669:                        .setValidate(false));
4670:                assertFalse(report.hasError());
4671:
4672:                assertTrue(getArchiveFileInCache(ivy, "foo", "foo1", "4",
4673:                        "foo1", "jar", "jar").exists());
4674:                assertTrue(getArchiveFileInCache(ivy, "bar", "bar2", "2",
4675:                        "bar2", "jar", "jar").exists());
4676:            }
4677:
4678:            public void testExternalArtifacts() throws Exception {
4679:                Ivy ivy = Ivy.newInstance();
4680:                ivy.getSettings().setVariable(
4681:                        "test.base.url",
4682:                        new File("test/repositories/external-artifacts")
4683:                                .toURL().toString());
4684:                ivy
4685:                        .configure(new File(
4686:                                "test/repositories/external-artifacts/ivysettings.xml"));
4687:
4688:                ResolveReport report = ivy
4689:                        .resolve(new File(
4690:                                "test/repositories/external-artifacts/ivy.xml")
4691:                                .toURL(), getResolveOptions(ivy.getSettings(),
4692:                                new String[] { "*" }).setValidate(false));
4693:                assertFalse(report.hasError());
4694:
4695:                assertTrue(getArchiveFileInCache(ivy, "apache", "A", "1.0",
4696:                        "a", "jar", "jar").exists());
4697:                assertTrue(getArchiveFileInCache(ivy, "apache", "B", "2.0",
4698:                        "b", "jar", "jar").exists());
4699:                assertTrue(getArchiveFileInCache(ivy, "apache", "C", "3.0",
4700:                        "C", "jar", "jar").exists());
4701:            }
4702:
4703:            public void testResolveWithMultipleIvyPatterns() throws Exception {
4704:                Ivy ivy = new Ivy();
4705:                ivy.configure(new File(
4706:                        "test/repositories/multi-ivypattern/ivysettings.xml"));
4707:
4708:                ModuleRevisionId module = ModuleRevisionId.newInstance("org1",
4709:                        "mod1.1", "1.+");
4710:
4711:                // use non-default options and settings
4712:                ivy.getSettings().setDefaultUseOrigin(true);
4713:                ResolveOptions options = getResolveOptions(ivy.getSettings(),
4714:                        new String[] { "*" });
4715:                options.setTransitive(false);
4716:                options.setDownload(false);
4717:                ResolveReport report = ivy.getResolveEngine().resolve(module,
4718:                        options, false);
4719:
4720:                List dependencies = report.getDependencies();
4721:                assertNotNull(dependencies);
4722:                assertEquals(1, dependencies.size());
4723:                IvyNode dependency = (IvyNode) dependencies.get(0);
4724:                assertEquals("1.1", dependency.getResolvedId().getRevision());
4725:            }
4726:
4727:            public void testPrivateConfigurationTransferWhenConflict()
4728:                    throws Exception {
4729:                ResolveReport report = ivy
4730:                        .resolve(
4731:                                new File(
4732:                                        "test/repositories/1/orgConflictAndPrivateConf/root/ivys/ivy-1.0.xml")
4733:                                        .toURL(),
4734:                                getResolveOptions(new String[] { "assembly" }));
4735:                assertFalse(report.hasError());
4736:            }
4737:
4738:            // //////////////////////////////////////////////////////////
4739:            // helper methods to ease the tests
4740:            // //////////////////////////////////////////////////////////
4741:
4742:            private void assertContainsArtifact(String org, String module,
4743:                    String rev, String artName, String type, String ext,
4744:                    ConfigurationResolveReport conf) {
4745:                Artifact art = getArtifact(org, module, rev, artName, type, ext);
4746:                if (!containsArtifact(art, conf.getDownloadedArtifactsReports())) {
4747:                    fail("artifact " + art + " should be part of "
4748:                            + conf.getConfiguration() + " from "
4749:                            + conf.getModuleDescriptor().getModuleRevisionId());
4750:                }
4751:            }
4752:
4753:            private void assertDoesntContainArtifact(String org, String module,
4754:                    String rev, String artName, String type, String ext,
4755:                    ConfigurationResolveReport conf) {
4756:                Artifact art = getArtifact(org, module, rev, artName, type, ext);
4757:                if (containsArtifact(art, conf.getDownloadedArtifactsReports())) {
4758:                    fail("artifact " + art + " should NOT be part of "
4759:                            + conf.getConfiguration() + " from "
4760:                            + conf.getModuleDescriptor().getModuleRevisionId());
4761:                }
4762:            }
4763:
4764:            private Artifact getArtifact(String org, String module, String rev,
4765:                    String artName, String type, String ext) {
4766:                return new DefaultArtifact(ModuleRevisionId.newInstance(org,
4767:                        module, rev), new Date(), artName, type, ext);
4768:            }
4769:
4770:            private boolean containsArtifact(Artifact art,
4771:                    ArtifactDownloadReport[] adr) {
4772:                for (int i = 0; i < adr.length; i++) {
4773:                    Artifact artifact = adr[i].getArtifact();
4774:                    if (artifact.getModuleRevisionId().equals(
4775:                            art.getModuleRevisionId())
4776:                            && artifact.getName().equals(art.getName())
4777:                            && artifact.getType().equals(art.getType())
4778:                            && artifact.getExt().equals(art.getExt())) {
4779:                        return true;
4780:                    }
4781:                }
4782:                return false;
4783:            }
4784:
4785:            private String getArchivePathInCache(Artifact artifact) {
4786:                return getRepositoryCacheManager(artifact.getModuleRevisionId())
4787:                        .getArchivePathInCache(artifact);
4788:            }
4789:
4790:            private String getArchivePathInCache(Artifact artifact,
4791:                    ArtifactOrigin origin) {
4792:                return getRepositoryCacheManager(artifact.getModuleRevisionId())
4793:                        .getArchivePathInCache(artifact, origin);
4794:            }
4795:
4796:            private File getArchiveFileInCache(Artifact artifact) {
4797:                return getRepositoryCacheManager(artifact.getModuleRevisionId())
4798:                        .getArchiveFileInCache(artifact);
4799:            }
4800:
4801:            private ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
4802:                return getRepositoryCacheManager(artifact.getModuleRevisionId())
4803:                        .getSavedArtifactOrigin(artifact);
4804:            }
4805:
4806:            private File getIvyFileInCache(ModuleRevisionId id) {
4807:                return getRepositoryCacheManager(id).getIvyFileInCache(id);
4808:            }
4809:
4810:            private File getIvyFileInCache(Ivy ivy, ModuleRevisionId id) {
4811:                return TestHelper.getRepositoryCacheManager(ivy, id)
4812:                        .getIvyFileInCache(id);
4813:            }
4814:
4815:            private DefaultRepositoryCacheManager getRepositoryCacheManager(
4816:                    ModuleRevisionId id) {
4817:                return TestHelper.getRepositoryCacheManager(ivy, id);
4818:            }
4819:
4820:            private File getResolvedIvyFileInCache(ModuleRevisionId mrid) {
4821:                return ivy.getResolutionCacheManager()
4822:                        .getResolvedIvyFileInCache(mrid);
4823:            }
4824:
4825:            private File getResolvedIvyFileInCache(Ivy ivy,
4826:                    ModuleRevisionId mrid) {
4827:                return ivy.getResolutionCacheManager()
4828:                        .getResolvedIvyFileInCache(mrid);
4829:            }
4830:
4831:            private File getConfigurationResolveReportInCache(String resolveId,
4832:                    String conf) {
4833:                return ivy.getResolutionCacheManager()
4834:                        .getConfigurationResolveReportInCache(resolveId, conf);
4835:            }
4836:
4837:            private File getConfigurationResolveReportInCache(Ivy ivy,
4838:                    String resolveId, String conf) {
4839:                return ivy.getResolutionCacheManager()
4840:                        .getConfigurationResolveReportInCache(resolveId, conf);
4841:            }
4842:
4843:            private File getArchiveFileInCache(String organisation,
4844:                    String module, String revision, String artifactName,
4845:                    String type, String ext) {
4846:                return getArchiveFileInCache(ivy, organisation, module,
4847:                        revision, artifactName, type, ext);
4848:            }
4849:
4850:            private File getArchiveFileInCache(Ivy ivy, String organisation,
4851:                    String module, String revision, String artifactName,
4852:                    String type, String ext) {
4853:                return TestHelper.getArchiveFileInCache(ivy, organisation,
4854:                        module, revision, artifactName, type, ext);
4855:            }
4856:
4857:            private ResolveOptions getResolveOptions(String[] confs) {
4858:                return getResolveOptions(ivy.getSettings(), confs);
4859:            }
4860:
4861:            private ResolveOptions getResolveOptions(IvySettings settings,
4862:                    String[] confs) {
4863:                return new ResolveOptions().setConfs(confs);
4864:            }
4865:
4866:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.