use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testDynamicFromCacheWithTTL.
@Test
public void testDynamicFromCacheWithTTL() throws Exception {
// mod1.4;1.0.2 depends on mod1.2;[1.0,2.0[
Ivy ivy = ivyTestCache();
ivy.getSettings().setVariable("ivy.cache.ttl.default", "10s", true);
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).addTTL(ModuleRevisionId.newInstance("org1", "*", "*").getAttributes(), ExactPatternMatcher.INSTANCE, 500);
// set up repository
FileUtil.forceDelete(new File("build/testCache2"));
FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File("build/testCache2/mod1.2-1.5.jar"), null);
// we first do a simple resolve so that module is in cache
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
assertFalse(report.hasError());
// now we update the repository
FileUtil.copy(new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar"), new File("build/testCache2/mod1.2-1.6.jar"), null);
// now do a new resolve: it should use cached data
report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
assertFalse(report.hasError());
assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.5")), report.getConfigurationReport("default").getModuleRevisionIds());
// wait for org1 TTL to expire
Thread.sleep(700);
// now do a new resolve: it should resolve the dynamic revision again
report = ivy.resolve(new File("test/repositories/1/org1/mod1.4/ivys/ivy-1.0.2.xml"), getResolveOptions(new String[] { "*" }));
assertFalse(report.hasError());
assertEquals(Collections.singleton(ModuleRevisionId.newInstance("org1", "mod1.2", "1.6")), report.getConfigurationReport("default").getModuleRevisionIds());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class ResolveTest method testUseOrigin.
@Test
public void testUseOrigin() throws Exception {
((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setUseOrigin(true);
ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(new String[] { "default" }));
assertNotNull(report);
ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"));
assertNotNull(dReports);
assertEquals("number of downloaded artifacts not correct.", 1, dReports.length);
assertEquals("download status not correct: should not download the artifact in useOrigin mode.", DownloadStatus.NO, dReports[0].getDownloadStatus());
Artifact artifact = dReports[0].getArtifact();
assertNotNull(artifact);
String expectedLocation = new File("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath();
ArtifactOrigin origin = getSavedArtifactOrigin(artifact);
File artInCache = new File(cache, getArchivePathInCache(artifact, origin));
assertFalse("should not download artifact in useOrigin mode.", artInCache.exists());
assertEquals("location for artifact not correct.", expectedLocation, getArchiveFileInCache(artifact).getAbsolutePath());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class XmlSettingsParserTest method testCache.
@Test
public void testCache() throws Exception {
IvySettings settings = new IvySettings();
XmlSettingsParser parser = new XmlSettingsParser(settings);
parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-cache.xml"));
assertEquals(new File("repository").getCanonicalFile(), settings.getDefaultRepositoryCacheBasedir().getCanonicalFile());
assertEquals(new File("resolution").getCanonicalFile(), settings.getDefaultResolutionCacheBasedir().getCanonicalFile());
assertEquals("artifact-lock", settings.getDefaultLockStrategy().getName());
assertEquals("[module]/ivys/ivy-[revision].xml", settings.getDefaultCacheIvyPattern());
assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings.getDefaultCacheArtifactPattern());
assertTrue(settings.isDefaultUseOrigin());
DefaultRepositoryCacheManager c = (DefaultRepositoryCacheManager) settings.getRepositoryCacheManager("mycache");
assertNotNull(c);
assertEquals("mycache", c.getName());
assertEquals(1000, c.getDefaultTTL());
assertEquals(200, c.getTTL(ModuleRevisionId.newInstance("apache", "ivy", "latest.integration")));
assertEquals(// 10m 20s
10 * 60 * 1000 + 20 * 1000, c.getTTL(ModuleRevisionId.newInstance("org1", "A", "A")));
assertEquals(// 5h
5 * 3600 * 1000, c.getTTL(ModuleRevisionId.newInstance("org2", "A", "A")));
assertEquals(// 2d 12h = 60h
60 * 3600 * 1000, c.getTTL(ModuleRevisionId.newInstance("org3", "A", "A")));
assertEquals(new File("mycache").getCanonicalFile(), c.getBasedir().getCanonicalFile());
assertFalse(c.isUseOrigin());
assertEquals("no-lock", c.getLockStrategy().getName());
assertEquals("[module]/ivy-[revision].xml", c.getIvyPattern());
assertEquals("[module]/[artifact]-[revision].[ext]", c.getArtifactPattern());
DefaultRepositoryCacheManager c2 = (DefaultRepositoryCacheManager) settings.getRepositoryCacheManager("mycache2");
assertNotNull(c2);
assertEquals("mycache2", c2.getName());
assertEquals(new File("repository").getCanonicalFile(), c2.getBasedir().getCanonicalFile());
assertEquals("artifact-lock", c2.getLockStrategy().getName());
assertEquals("[module]/ivys/ivy-[revision].xml", c2.getIvyPattern());
assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", c2.getArtifactPattern());
assertTrue(c2.isUseOrigin());
assertEquals(c2, settings.getResolver("A").getRepositoryCacheManager());
assertEquals(c, settings.getResolver("B").getRepositoryCacheManager());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class FileSystemResolverTest method testDownloadWithUseOriginIsTrue.
@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
assertEquals("test", resolver.getName());
resolver.addIvyPattern(IVY_PATTERN);
resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/" + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
assertEquals(pubdate, rmr.getPublicationDate());
// test to ask to download
DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
DownloadReport report = resolver.download(new Artifact[] { artifact }, getDownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
use of org.apache.ivy.core.cache.DefaultRepositoryCacheManager in project ant-ivy by apache.
the class URLResolverTest method testDownloadWithUseOriginIsTrue.
@Test
public void testDownloadWithUseOriginIsTrue() throws Exception {
URLResolver resolver = new URLResolver();
resolver.setSettings(settings);
String rootpath = new File("test/repositories/1").toURI().toURL().toExternalForm();
resolver.addIvyPattern(rootpath + "/[organisation]/[module]/ivys/ivy-[revision].xml");
resolver.addArtifactPattern(rootpath + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
resolver.setName("test");
((DefaultRepositoryCacheManager) resolver.getRepositoryCacheManager()).setUseOrigin(true);
assertEquals("test", resolver.getName());
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(mrid, rmr.getId());
Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
assertEquals(pubdate, rmr.getPublicationDate());
// test to ask to download
DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
DownloadReport report = resolver.download(new Artifact[] { artifact }, new DownloadOptions());
assertNotNull(report);
assertEquals(1, report.getArtifactsReports().length);
ArtifactDownloadReport ar = report.getArtifactReport(artifact);
assertNotNull(ar);
assertEquals(artifact, ar.getArtifact());
assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Aggregations