use of org.apache.ivy.core.module.descriptor.Artifact 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.module.descriptor.Artifact 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();
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class FileSystemResolverTest method testUnsupportedTransaction2.
/**
* Publishing with transaction=true and an unsupported combination of patterns must fail.
*
* @throws Exception if something goes wrong
*/
@Test
public void testUnsupportedTransaction2() throws Exception {
expExc.expect(IllegalStateException.class);
expExc.expectMessage("transactional");
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
resolver.setTransactional("true");
// the two patterns are inconsistent and thus not supported for transactions
resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]-[module]/[revision]/[artifact]-[revision].[ext]");
resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml");
Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", "myext");
File src = new File("test/repositories/ivysettings.xml");
resolver.beginPublishTransaction(mrid, false);
resolver.publish(ivyArtifact, src, false);
resolver.publish(artifact, src, false);
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class FileSystemResolverTest method testNoRevision.
@Test
public void testNoRevision() 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 + "norevision" + FS + "ivy-[module].xml");
resolver.addArtifactPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "norevision" + FS + "[artifact].[ext]");
File modify = new File("test/repositories/norevision/ivy-mod1.1.xml");
File artifact = new File("test/repositories/norevision/mod1.1.jar");
// 'publish' 'before' version
FileUtil.copy(new File("test/repositories/norevision/ivy-mod1.1-before.xml"), modify, null, true);
FileUtil.copy(new File("test/repositories/norevision/mod1.1-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", "latest.integration");
ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.0"), rmr.getId());
assertEquals(pubdate, rmr.getPublicationDate());
Artifact[] artifacts = rmr.getDescriptor().getArtifacts("default");
File archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
resolver.download(artifacts, getDownloadOptions());
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/norevision/ivy-mod1.1-after.xml"), modify, null, true);
FileUtil.copy(new File("test/repositories/norevision/mod1.1-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 get the new version even if checkModified is false, because we ask a
// latest.integration
resolver.setCheckmodified(false);
rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
assertNotNull(rmr);
assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1", "1.1"), rmr.getId());
assertEquals(pubdate, rmr.getPublicationDate());
artifacts = rmr.getDescriptor().getArtifacts("default");
archiveFileInCache = cacheManager.getArchiveFileInCache(artifacts[0]);
assertFalse(archiveFileInCache.exists());
// should download the new artifact
artifacts = rmr.getDescriptor().getArtifacts("default");
resolver.download(artifacts, getDownloadOptions());
assertTrue(archiveFileInCache.exists());
r = new BufferedReader(new FileReader(archiveFileInCache));
assertEquals("after", r.readLine());
r.close();
}
use of org.apache.ivy.core.module.descriptor.Artifact in project ant-ivy by apache.
the class FileSystemResolverTest method testPublish.
@Test
public void testPublish() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setSettings(settings);
assertEquals("test", resolver.getName());
resolver.addIvyPattern(settings.getBaseDir() + FS + "test" + FS + "repositories" + FS + "1" + FS + "[organisation]" + FS + "[module]" + FS + "[revision]" + FS + "[artifact].[ext]");
resolver.addArtifactPattern(settings.getBaseDir() + FS + "test/repositories/1/" + "[organisation]/[module]/[type]s/[artifact]-[revision].[ext]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml");
Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", "myext");
File src = new File("test/repositories/ivysettings.xml");
resolver.beginPublishTransaction(mrid, false);
resolver.publish(ivyArtifact, src, false);
resolver.publish(artifact, src, false);
resolver.commitPublishTransaction();
assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
assertTrue(new File("test/repositories/1/myorg/mymodule/mytypes/myartifact-myrevision.myext").exists());
}
Aggregations