Search in sources :

Example 1 with LatestTimeStrategy

use of org.apache.ivy.plugins.latest.LatestTimeStrategy in project ant-ivy by apache.

the class FileSystemResolverTest method testFormattedLatestTime.

@Test
public void testFormattedLatestTime() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/" + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setLatestStrategy(new LatestTimeStrategy());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.1");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", "mod1.1", "1+"), false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Date(java.util.Date) Test(org.junit.Test)

Example 2 with LatestTimeStrategy

use of org.apache.ivy.plugins.latest.LatestTimeStrategy in project ant-ivy by apache.

the class ChainResolverTest method testLatestTimeResolve.

@Test
public void testLatestTimeResolve() throws Exception {
    ChainResolver chain = new ChainResolver();
    chain.setName("chain");
    chain.setSettings(settings);
    settings.setDefaultLatestStrategy(new LatestTimeStrategy());
    MockResolver[] resolvers = new MockResolver[] { MockResolver.buildMockResolver(settings, "1", true, new GregorianCalendar(2005, 1, 20).getTime()), MockResolver.buildMockResolver(settings, "2", false, null), MockResolver.buildMockResolver(settings, "3", true, new GregorianCalendar(2005, 1, 25).getTime()), // younger -> should the one kept
    MockResolver.buildMockResolver(settings, "4", false, null), MockResolver.buildMockResolver(settings, "5", true, new GregorianCalendar(2005, 1, 22).getTime()), MockResolver.buildMockResolver(settings, "6", true, new GregorianCalendar(2005, 1, 18).getTime()), MockResolver.buildMockResolver(settings, "7", false, null) };
    for (MockResolver resolver : resolvers) {
        chain.add(resolver);
    }
    assertResolversSizeAndNames(chain, resolvers.length);
    DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org", "mod", "latest.integration"), false);
    ResolvedModuleRevision rmr = chain.getDependency(dd, data);
    assertNotNull(rmr);
    assertEquals("3", rmr.getResolver().getName());
    List<DependencyDescriptor> ddAsList = Collections.<DependencyDescriptor>singletonList(dd);
    for (MockResolver resolver : resolvers) {
        assertEquals(ddAsList, resolver.askedDeps);
    }
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) GregorianCalendar(java.util.GregorianCalendar) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 3 with LatestTimeStrategy

use of org.apache.ivy.plugins.latest.LatestTimeStrategy in project ant-ivy by apache.

the class XmlSettingsParserTest method test.

@Test
public void test() throws Exception {
    IvySettings settings = new IvySettings();
    XmlSettingsParser parser = new XmlSettingsParser(settings);
    parser.parse(XmlSettingsParserTest.class.getResource("ivysettings-test.xml"));
    File defaultCache = settings.getDefaultCache();
    assertNotNull(defaultCache);
    assertEquals("mycache", defaultCache.getName());
    assertFalse(settings.isCheckUpToDate());
    assertFalse(settings.doValidate());
    assertEquals("[module]/ivys/ivy-[revision].xml", settings.getDefaultCacheIvyPattern());
    assertEquals("[module]/[type]s/[artifact]-[revision].[ext]", settings.getDefaultCacheArtifactPattern());
    LatestStrategy latest = settings.getLatestStrategy("mylatest-revision");
    assertNotNull(latest);
    assertTrue(latest instanceof LatestRevisionStrategy);
    LatestRevisionStrategy l = (LatestRevisionStrategy) latest;
    assertEquals(new Integer(-2), l.getSpecialMeanings().get("pre"));
    assertEquals(new Integer(4), l.getSpecialMeanings().get("qa"));
    DependencyResolver defaultResolver = settings.getDefaultResolver();
    assertNotNull(defaultResolver);
    assertEquals("libraries", defaultResolver.getName());
    assertTrue(defaultResolver instanceof FileSystemResolver);
    FileSystemResolver fsres = (FileSystemResolver) defaultResolver;
    List<String> ivyPatterns = fsres.getIvyPatterns();
    assertNotNull(ivyPatterns);
    assertEquals(1, ivyPatterns.size());
    assertLocationEquals("lib/[organisation]/[module]/ivys/ivy-[revision].xml", ivyPatterns.get(0));
    LatestStrategy strategy = fsres.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestRevisionStrategy);
    DependencyResolver internal = settings.getResolver("internal");
    assertNotNull(internal);
    assertTrue(internal instanceof ChainResolver);
    ChainResolver chain = (ChainResolver) internal;
    List<DependencyResolver> subresolvers = chain.getResolvers();
    assertNotNull(subresolvers);
    assertEquals(2, subresolvers.size());
    FileSystemResolver fsInt1 = (FileSystemResolver) subresolvers.get(0);
    assertEquals("int1", fsInt1.getName());
    assertEquals(1, fsInt1.getIvyPatterns().size());
    assertLocationEquals("sharedrep/[organisation]/[module]/ivys/ivy-[revision].xml", fsInt1.getIvyPatterns().get(0));
    assertEquals("int2", subresolvers.get(1).getName());
    strategy = fsInt1.getLatestStrategy();
    assertNotNull(strategy);
    assertTrue(strategy instanceof LatestTimeStrategy);
    assertEquals("libraries", settings.getResolver(ModuleRevisionId.newInstance("unknown", "lib", "1.0")).getName());
    assertEquals("internal", settings.getResolver(ModuleRevisionId.newInstance("apache", "ant", "1.0")).getName());
    assertEquals("int2", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "2.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivy", "1.0")).getName());
    assertEquals("int1", settings.getResolver(ModuleRevisionId.newInstance("apache", "ivyde", "1.0")).getName());
}
Also used : ChainResolver(org.apache.ivy.plugins.resolver.ChainResolver) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) File(java.io.File) FileSystemResolver(org.apache.ivy.plugins.resolver.FileSystemResolver) Test(org.junit.Test) ModuleDescriptorParserRegistryTest(org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)

Example 4 with LatestTimeStrategy

use of org.apache.ivy.plugins.latest.LatestTimeStrategy in project ant-ivy by apache.

the class FileSystemResolverTest method testLatestTime.

@Test
public void testLatestTime() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(IVY_PATTERN);
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/" + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
    resolver.setLatestStrategy(new LatestTimeStrategy());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "2.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(ModuleRevisionId.newInstance("org1", "mod1.1", "latest.integration"), false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) LatestTimeStrategy(org.apache.ivy.plugins.latest.LatestTimeStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LatestTimeStrategy (org.apache.ivy.plugins.latest.LatestTimeStrategy)4 Test (org.junit.Test)4 GregorianCalendar (java.util.GregorianCalendar)3 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)3 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)3 Date (java.util.Date)2 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 File (java.io.File)1 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)1 LatestRevisionStrategy (org.apache.ivy.plugins.latest.LatestRevisionStrategy)1 LatestStrategy (org.apache.ivy.plugins.latest.LatestStrategy)1 ModuleDescriptorParserRegistryTest (org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistryTest)1 ChainResolver (org.apache.ivy.plugins.resolver.ChainResolver)1 DependencyResolver (org.apache.ivy.plugins.resolver.DependencyResolver)1 FileSystemResolver (org.apache.ivy.plugins.resolver.FileSystemResolver)1