Search in sources :

Example 91 with Artifact

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

the class XmlModuleDescriptorParserTest method testExtraAttributes.

@Test
public void testExtraAttributes() throws Exception {
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extra-attributes.xml"), false);
    assertNotNull(md);
    assertEquals("infoextravalue", md.getAttribute("infoextra"));
    assertEquals("infoextravalue", md.getModuleRevisionId().getAttribute("infoextra"));
    assertEquals("confextravalue", md.getConfiguration("default").getAttribute("confextra"));
    Artifact[] artifacts = md.getArtifacts("default");
    assertEquals(1, artifacts.length);
    Artifact art = artifacts[0];
    assertEquals("art1", art.getName());
    assertEquals("artextravalue", art.getAttribute("artextra"));
    DependencyDescriptor[] dependencies = md.getDependencies();
    assertNotNull(dependencies);
    assertEquals(1, dependencies.length);
    DependencyDescriptor dd = getDependency(dependencies, "mymodule1");
    assertNotNull(dd);
    assertEquals("myorg", dd.getDependencyId().getOrganisation());
    assertEquals("1.0", dd.getDependencyRevisionId().getRevision());
    assertEquals("depextravalue", dd.getAttribute("depextra"));
    assertEquals("depextravalue", dd.getDependencyRevisionId().getAttribute("depextra"));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 92 with Artifact

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

the class XmlModuleDescriptorParserTest method testExtendsDescriptionWithOverride.

@Test
public void testExtendsDescriptionWithOverride() throws Exception {
    // descriptor specifies that only parent description should be included
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-extends-description-override.xml"), true);
    assertNotNull(md);
    assertEquals("myorg", md.getModuleRevisionId().getOrganisation());
    assertEquals("mymodule", md.getModuleRevisionId().getName());
    assertEquals(Ivy.getWorkingRevision(), md.getModuleRevisionId().getRevision());
    assertEquals("integration", md.getStatus());
    // child description should always be preferred, even if extendType="description"
    assertEquals("Child description overrides parent.", md.getDescription());
    // verify that the parent configurations were ignored.
    final Configuration[] expectedConfs = { new Configuration("default") };
    assertNotNull(md.getConfigurations());
    assertEquals(Arrays.asList(expectedConfs), Arrays.asList(md.getConfigurations()));
    // verify parent dependencies were ignored.
    DependencyDescriptor[] deps = md.getDependencies();
    assertNotNull(deps);
    assertEquals(1, deps.length);
    assertEquals(Collections.singletonList("default"), Arrays.asList(deps[0].getModuleConfigurations()));
    ModuleRevisionId dep = deps[0].getDependencyRevisionId();
    assertEquals("myorg", dep.getModuleId().getOrganisation());
    assertEquals("mymodule2", dep.getModuleId().getName());
    assertEquals("2.0", dep.getRevision());
    // verify only child publications are present
    Artifact[] artifacts = md.getAllArtifacts();
    assertNotNull(artifacts);
    assertEquals(1, artifacts.length);
    assertEquals("mymodule", artifacts[0].getName());
    assertEquals("jar", artifacts[0].getType());
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 93 with Artifact

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

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

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

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