Search in sources :

Example 96 with Artifact

use of org.apache.ivy.core.module.descriptor.Artifact 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 97 with Artifact

use of org.apache.ivy.core.module.descriptor.Artifact 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)

Example 98 with Artifact

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

the class FileSystemResolverTest method testAbortTransaction.

@Test
public void testAbortTransaction() throws Exception {
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    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]");
    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.abortPublishTransaction();
    assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/ivy.xml").exists());
    assertFalse(new File("test/repositories/1/myorg/mymodule/myrevision/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 99 with Artifact

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

the class FileSystemResolverTest method testUnsupportedTransaction.

/**
 * Publishing with transaction=true and an unsupported pattern must fail.
 *
 * @throws Exception if something goes wrong
 */
@Test
public void testUnsupportedTransaction() throws Exception {
    expExc.expect(IllegalStateException.class);
    expExc.expectMessage("transactional");
    FileSystemResolver resolver = new FileSystemResolver();
    resolver.setName("test");
    resolver.setSettings(settings);
    resolver.setTransactional("true");
    resolver.addArtifactPattern(// this pattern is not supported for transaction publish
    settings.getBaseDir() + "/test/repositories/1/[organisation]/[module]/[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");
    resolver.beginPublishTransaction(mrid, 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 100 with Artifact

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

the class IvyRepResolverTest method testIvyRepWithLocalURL.

@Test
public void testIvyRepWithLocalURL() throws Exception {
    IvyRepResolver resolver = new IvyRepResolver();
    String rootpath = new File("test/repositories/1").getAbsolutePath();
    resolver.setName("testLocal");
    resolver.setIvyroot("file:" + rootpath);
    resolver.setIvypattern("[organisation]/[module]/ivys/ivy-[revision].xml");
    resolver.setArtroot("file:" + rootpath);
    resolver.setArtpattern("[organisation]/[module]/jars/[artifact]-[revision].[ext]");
    resolver.setSettings(settings);
    ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1", "mod1.1", "1.0");
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    DefaultArtifact artifact = new DefaultArtifact(mrid, rmr.getPublicationDate(), "mod1.1", "jar", "jar");
    DownloadReport report = resolver.download(new Artifact[] { artifact }, downloadOptions());
    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 }, downloadOptions());
    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) 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) File(java.io.File) 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

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