Search in sources :

Example 21 with Artifact

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());
}
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 22 with Artifact

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

Example 23 with Artifact

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);
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) Test(org.junit.Test)

Example 24 with Artifact

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

Example 25 with Artifact

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());
}
Also used : ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Artifact (org.apache.ivy.core.module.descriptor.Artifact)106 Test (org.junit.Test)68 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)59 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)55 File (java.io.File)53 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)31 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)30 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)28 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)25 Date (java.util.Date)22 DownloadReport (org.apache.ivy.core.report.DownloadReport)20 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)15 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)13 Configuration (org.apache.ivy.core.module.descriptor.Configuration)10 IOException (java.io.IOException)9 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)9 ParseException (java.text.ParseException)8 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 ResolveReport (org.apache.ivy.core.report.ResolveReport)7 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)7