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());
}
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());
}
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();
}
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());
}
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();
}
Aggregations