Search in sources :

Example 16 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision 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 17 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class FileSystemResolverTest method testLatestRevision.

@Test
public void testLatestRevision() 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 LatestRevisionStrategy());
    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) LatestRevisionStrategy(org.apache.ivy.plugins.latest.LatestRevisionStrategy) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Date(java.util.Date) Test(org.junit.Test)

Example 18 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class FileSystemResolverTest method testMaven2.

@Test
public void testMaven2() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.setM2compatible(true);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/m2/" + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/m2/" + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "test", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    mrid = ModuleRevisionId.newInstance("org.apache.unknown", "test", "1.0");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNull(rmr);
    resolver.reportFailure();
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Test(org.junit.Test)

Example 19 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class FileSystemResolverTest method testSHA512Checksum.

/**
 * Tests that <code>SHA-512</code> algorithm can be used for checksums on resolvers
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testSHA512Checksum() throws Exception {
    final FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("sha256-checksum-resolver");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[revision]/[artifact]-[revision].[ext]");
    resolver.setChecksums("SHA-512");
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "3.0");
    final ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull("Resolved module revision was null for " + mrid, rmr);
    final DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    final ArtifactDownloadReport[] successfulDownloadReports = dr.getArtifactsReports(DownloadStatus.SUCCESSFUL);
    assertNotNull("No artifacts were downloaded successfully", successfulDownloadReports);
    assertEquals("Unexpected number of successfully downloaded artifacts", 1, successfulDownloadReports.length);
    final ArtifactDownloadReport successfulDownloadReport = successfulDownloadReports[0];
    final Artifact downloadedArtifact = successfulDownloadReport.getArtifact();
    assertEquals("Unexpected organization of downloaded artifact", "test", downloadedArtifact.getModuleRevisionId().getOrganisation());
    assertEquals("Unexpected module of downloaded artifact", "allright", downloadedArtifact.getModuleRevisionId().getModuleId().getName());
    assertEquals("Unexpected revision of downloaded artifact", "3.0", downloadedArtifact.getModuleRevisionId().getRevision());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) 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) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 20 with ResolvedModuleRevision

use of org.apache.ivy.core.resolve.ResolvedModuleRevision in project ant-ivy by apache.

the class FileSystemResolverTest method testChanging.

@Test
public void testChanging() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    settings.addResolver(resolver);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "checkmodified" + FS + "ivy-[revision].xml");
    resolver.addArtifactPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "checkmodified" + FS + "[artifact]-[revision].[ext]");
    File modify = new File("test/repositories/checkmodified/ivy-1.0.xml");
    File artifact = new File("test/repositories/checkmodified/mod1.1-1.0.jar");
    // 'publish' 'before' version
    FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-before.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-before.jar"), artifact, null, true);
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    modify.setLastModified(pubdate.getTime());
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default");
    resolver.download(artifacts, getDownloadOptions());
    File archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
    assertTrue(archiveFileInCache.exists());
    BufferedReader r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("before", r.readLine());
    r.close();
    // updates ivy file and artifact in repository
    FileUtil.copy(new File("test/repositories/checkmodified/ivy-1.0-after.xml"), modify, null, true);
    FileUtil.copy(new File("test/repositories/checkmodified/mod1.1-1.0-after.jar"), artifact, null, true);
    pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
    modify.setLastModified(pubdate.getTime());
    // no need to update new artifact timestamp cause it isn't used
    // should not get the new version: checkmodified is false and dependency is not told to be a
    // changing one
    resolver.setCheckmodified(false);
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime(), rmr.getPublicationDate());
    assertTrue(archiveFileInCache.exists());
    r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("before", r.readLine());
    r.close();
    // should now get the new version cause we say it's a changing one
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false, true), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    assertEquals(pubdate, rmr.getPublicationDate());
    assertFalse(archiveFileInCache.exists());
    artifacts = rmr.getDescriptor().getArtifacts("default");
    resolver.download(artifacts, getDownloadOptions());
    assertTrue(archiveFileInCache.exists());
    r = new BufferedReader(new FileReader(archiveFileInCache));
    assertEquals("after", r.readLine());
    r.close();
}
Also used : GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) FileReader(java.io.FileReader) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) File(java.io.File) Date(java.util.Date) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)89 Test (org.junit.Test)63 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)61 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)45 Artifact (org.apache.ivy.core.module.descriptor.Artifact)25 GregorianCalendar (java.util.GregorianCalendar)24 File (java.io.File)19 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)19 Date (java.util.Date)18 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)18 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)18 DownloadReport (org.apache.ivy.core.report.DownloadReport)18 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)17 IOException (java.io.IOException)14 ParseException (java.text.ParseException)14 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)13 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)8 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)8