Search in sources :

Example 26 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.

the class FileSystemResolverTest method testPublishTransactionWithSubDirectories.

@Test
public void testPublishTransactionWithSubDirectories() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[type]/[artifact].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[type]/[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);
    // files should not be available until the transaction is committed
    resolver.publish(ivyArtifact, src, false);
    assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/ivy/ivy.xml").exists());
    resolver.publish(artifact, src, false);
    assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/mytype/myartifact-myrevision.myext").exists());
    resolver.commitPublishTransaction();
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/ivy/ivy.xml").exists());
    assertTrue(new File("test/repositories/1/myorg/mymodule/myrevision/mytype/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)

Example 27 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.

the class FileSystemResolverTest method testChecksum.

@Test
public void testChecksum() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[artifact]-[revision].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/checksums/[module]/[artifact]-[revision].[ext]");
    resolver.setChecksums("sha1, md5");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("test", "allright", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    DownloadReport dr = resolver.download(rmr.getDescriptor().getAllArtifacts(), getDownloadOptions());
    assertEquals(4, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
    resolver.setChecksums("md5");
    mrid = ModuleRevisionId.newInstance("test", "badivycs", "1.0");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNull(rmr);
    resolver.setChecksums("none");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    dr = resolver.download(new Artifact[] { new DefaultArtifact(mrid, rmr.getPublicationDate(), mrid.getName(), "jar", "jar") }, getDownloadOptions());
    assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
    resolver.setChecksums("md5");
    mrid = ModuleRevisionId.newInstance("test", "badartcs", "1.0");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    dr = resolver.download(new Artifact[] { new DefaultArtifact(mrid, rmr.getPublicationDate(), mrid.getName(), "jar", "jar") }, getDownloadOptions());
    assertEquals(1, dr.getArtifactsReports(DownloadStatus.FAILED).length);
    resolver.setChecksums("");
    rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    dr = resolver.download(new Artifact[] { new DefaultArtifact(mrid, rmr.getPublicationDate(), mrid.getName(), "jar", "jar") }, getDownloadOptions());
    assertEquals(1, dr.getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
}
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) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 28 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.

the class FileSystemResolverTest method testPublishOverwrite.

@Test
public void testPublishOverwrite() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    assertEquals("test", resolver.getName());
    resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    File ivyFile = new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml");
    File artifactFile = new File("test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext");
    touch(ivyFile);
    touch(artifactFile);
    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, true);
    resolver.publish(ivyArtifact, src, true);
    resolver.publish(artifact, src, true);
    resolver.commitPublishTransaction();
    long length = src.length();
    assertEquals(length, ivyFile.length());
    assertEquals(length, artifactFile.length());
}
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 29 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.

the class FileSystemResolverTest method testUnsupportedTransaction3.

/**
 * Publishing with transaction=true and overwrite mode must fail.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testUnsupportedTransaction3() throws Exception {
    expExc.expect(IllegalStateException.class);
    expExc.expectMessage("transactional");
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.setTransactional("true");
    resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("myorg", "mymodule", "myrevision");
    Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", "myext");
    File src = new File("test/repositories/ivysettings.xml");
    // overwrite transaction not supported
    resolver.beginPublishTransaction(mrid, true);
    resolver.publish(artifact, src, true);
}
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 30 with DefaultArtifact

use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.

the class FileSystemResolverTest method testFixedRevision.

@Test
public void testFixedRevision() 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]");
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0).getTime();
    assertEquals(pubdate, rmr.getPublicationDate());
    // test to ask to download
    DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate, "mod1.1", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] { artifact }, getDownloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    ArtifactDownloadReport ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
    // test to ask to download again, should use cache
    report = resolver.download(new Artifact[] { artifact }, getDownloadOptions());
    assertNotNull(report);
    assertEquals(1, report.getArtifactsReports().length);
    ar = report.getArtifactReport(artifact);
    assertNotNull(ar);
    assertEquals(artifact, ar.getArtifact());
    assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
}
Also used : DownloadReport(org.apache.ivy.core.report.DownloadReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) GregorianCalendar(java.util.GregorianCalendar) 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) Date(java.util.Date) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Aggregations

DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)38 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)33 Test (org.junit.Test)27 Artifact (org.apache.ivy.core.module.descriptor.Artifact)25 Date (java.util.Date)24 File (java.io.File)21 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)13 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)12 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)10 DownloadReport (org.apache.ivy.core.report.DownloadReport)10 GregorianCalendar (java.util.GregorianCalendar)5 IOException (java.io.IOException)3 Locale (java.util.Locale)3 DefaultRepositoryCacheManager (org.apache.ivy.core.cache.DefaultRepositoryCacheManager)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3 PackagerResolver (org.apache.ivy.plugins.resolver.packager.PackagerResolver)3 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)3 MalformedURLException (java.net.MalformedURLException)2 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2