1 6 package fr.jayasoft.ivy; 7 8 import java.io.File ; 9 10 import org.apache.tools.ant.Project; 11 import org.apache.tools.ant.taskdefs.Delete; 12 13 import fr.jayasoft.ivy.report.ResolveReport; 14 import fr.jayasoft.ivy.util.IvyPatternHelper; 15 16 import junit.framework.TestCase; 17 18 public class RetrieveTest extends TestCase { 19 private final Ivy _ivy; 20 private File _cache; 21 22 public RetrieveTest() throws Exception { 23 _ivy = new Ivy(); 24 _ivy.configure(new File ("test/repositories/ivyconf.xml")); 25 } 26 27 protected void setUp() throws Exception { 28 createCache(); 29 } 30 31 private void createCache() { 32 _cache = new File ("build/cache"); 33 _cache.mkdirs(); 34 } 35 36 protected void tearDown() throws Exception { 37 cleanCache(); 38 Delete del = new Delete(); 39 del.setProject(new Project()); 40 del.setDir(new File ("build/test/retrieve")); 41 del.execute(); 42 } 43 44 private void cleanCache() { 45 Delete del = new Delete(); 46 del.setProject(new Project()); 47 del.setDir(_cache); 48 del.execute(); 49 } 50 51 public void testRetrieveSimple() throws Exception { 52 ResolveReport report = _ivy.resolve(new File ("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), 54 null, new String [] {"*"}, _cache, null, true); 55 assertNotNull(report); 56 ModuleDescriptor md = report.getModuleDescriptor(); 57 assertNotNull(md); 58 59 String pattern = "build/test/retrieve/[module]/[conf]/[artifact]-[revision].[ext]"; 60 _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(), _cache, pattern); 61 assertTrue(new File (IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")).exists()); 62 63 pattern = "build/test/retrieve/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; 64 _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(), _cache, pattern); 65 assertTrue(new File (IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")).exists()); 66 } 67 68 public void testRetrieveWithVariable() throws Exception { 69 _ivy.setVariable("retrieve.dir", "retrieve"); 71 ResolveReport report = _ivy.resolve(new File ("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(), 72 null, new String [] {"*"}, _cache, null, true); 73 assertNotNull(report); 74 ModuleDescriptor md = report.getModuleDescriptor(); 75 assertNotNull(md); 76 77 String pattern = "build/test/${retrieve.dir}/[module]/[conf]/[artifact]-[revision].[ext]"; 78 _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(), _cache, pattern); 79 pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); 80 assertTrue(new File (IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")).exists()); 81 82 pattern = "build/test/${retrieve.dir}/[module]/[conf]/[type]s/[artifact]-[revision].[ext]"; 83 _ivy.retrieve(md.getModuleRevisionId().getModuleId(), md.getConfigurationsNames(), _cache, pattern); 84 pattern = IvyPatternHelper.substituteVariable(pattern, "retrieve.dir", "retrieve"); 85 assertTrue(new File (IvyPatternHelper.substitute(pattern, "org1", "mod1.2", "2.0", "mod1.2", "jar", "jar", "default")).exists()); 86 } 87 88 89 } 90 | Popular Tags |