Search in sources :

Example 11 with DefaultRepositoryCacheManager

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());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) Ivy(org.apache.ivy.Ivy) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 12 with DefaultRepositoryCacheManager

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());
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ArtifactOrigin(org.apache.ivy.core.cache.ArtifactOrigin) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 13 with DefaultRepositoryCacheManager

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());
}
Also used : File(java.io.File) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 14 with DefaultRepositoryCacheManager

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());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Date(java.util.Date) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 15 with DefaultRepositoryCacheManager

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());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) Date(java.util.Date) DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)16 File (java.io.File)13 Test (org.junit.Test)11 JarFile (java.util.jar.JarFile)7 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)7 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)6 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)6 Ivy (org.apache.ivy.Ivy)5 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)5 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 Date (java.util.Date)2 GregorianCalendar (java.util.GregorianCalendar)2 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2 DownloadReport (org.apache.ivy.core.report.DownloadReport)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)2 FileNotFoundException (java.io.FileNotFoundException)1