Search in sources :

Example 61 with Artifact

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

the class ResolveTest method testResolveWithRetainingArtifactNameAndExtraAttributes.

@Test
public void testResolveWithRetainingArtifactNameAndExtraAttributes() throws Exception {
    ((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
    ResolveReport report = ivy.resolve(new File("test/repositories/2/mod15.4/ivy-1.1.xml"), getResolveOptions(new String[] { "default" }).setValidate(false));
    assertNotNull(report);
    Map<String, String> extra = new HashMap<>();
    extra.put("extra", "foo");
    ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.3", "1.1", extra));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    Artifact artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    String cachePath = getArchivePathInCache(artifact);
    assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("library.jar"));
    dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    cachePath = getArchivePathInCache(artifact);
    assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) HashMap(java.util.HashMap) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 62 with Artifact

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

the class ResolveTest method testResolveWithRetainingArtifactName.

@Test
public void testResolveWithRetainingArtifactName() throws Exception {
    ((DefaultRepositoryCacheManager) ivy.getSettings().getDefaultRepositoryCacheManager()).setArtifactPattern(ivy.substitute("[module]/[originalname].[ext]"));
    ResolveReport report = ivy.resolve(new File("test/repositories/2/mod15.2/ivy-1.1.xml"), getResolveOptions(new String[] { "default" }));
    assertNotNull(report);
    ArtifactDownloadReport[] dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org15", "mod15.1", "1.1"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    Artifact artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    String cachePath = getArchivePathInCache(artifact);
    assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("library.jar"));
    dReports = report.getConfigurationReport("default").getDownloadReports(ModuleRevisionId.newInstance("org14", "mod14.1", "1.1"));
    assertNotNull(dReports);
    assertEquals("number of downloaded artifacts not correct", 1, dReports.length);
    artifact = dReports[0].getArtifact();
    assertNotNull(artifact);
    cachePath = getArchivePathInCache(artifact);
    assertTrue("artifact name has not been retained: " + cachePath, cachePath.endsWith("mod14.1-1.1.jar"));
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultRepositoryCacheManager(org.apache.ivy.core.cache.DefaultRepositoryCacheManager) JarFile(java.util.jar.JarFile) File(java.io.File) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) Test(org.junit.Test)

Example 63 with Artifact

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

the class ResolveTest method assertDoesntContainArtifact.

private void assertDoesntContainArtifact(String org, String module, String rev, String artName, String type, String ext, ConfigurationResolveReport conf) {
    Artifact art = getArtifact(org, module, rev, artName, type, ext);
    assertFalse("artifact " + art + " should NOT be part of " + conf.getConfiguration() + " from " + conf.getModuleDescriptor().getModuleRevisionId(), containsArtifact(art, conf.getDownloadedArtifactsReports()));
}
Also used : Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact)

Example 64 with Artifact

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

the class OBRResolverTest method genericTestResolveDownload.

private void genericTestResolveDownload(DependencyResolver resolver, ModuleRevisionId mrid) throws ParseException {
    ResolvedModuleRevision rmr = resolver.getDependency(new DefaultDependencyDescriptor(mrid, false), data);
    assertNotNull(rmr);
    assertEquals(mrid, rmr.getId());
    Artifact artifact = rmr.getDescriptor().getAllArtifacts()[0];
    DownloadReport report = resolver.download(new Artifact[] { artifact }, new 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 }, new 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) DownloadOptions(org.apache.ivy.core.resolve.DownloadOptions) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact)

Example 65 with Artifact

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

the class OBRXMLWriterTest method testWriteWithSource.

@Test
public void testWriteWithSource() throws Exception {
    List<BundleInfo> bundles = new ArrayList<>();
    BundleInfo bundle = new BundleInfo(BUNDLE_1, BUNDLE_VERSION);
    bundle.addArtifact(new BundleArtifact(false, new URI("file:///test.jar"), null));
    bundle.addArtifact(new BundleArtifact(true, new URI("file:///test-sources.jar"), null));
    bundles.add(bundle);
    bundle = new BundleInfo(BUNDLE_2, BUNDLE_VERSION);
    bundle.addArtifact(new BundleArtifact(false, new URI("file:///test2.jar"), null));
    bundles.add(bundle);
    new File("build/test-files").mkdirs();
    File obrFile = new File("build/test-files/obr-sources.xml");
    try (FileOutputStream out = new FileOutputStream(obrFile)) {
        ContentHandler handler = OBRXMLWriter.newHandler(out, "UTF-8", true);
        OBRXMLWriter.writeBundles(bundles, handler);
    }
    BundleRepoDescriptor repo;
    try (FileInputStream in = new FileInputStream(obrFile)) {
        repo = OBRXMLParser.parse(new URI("file:///test"), in);
    }
    assertEquals(2, CollectionUtils.toList(repo.getModules()).size());
    ModuleDescriptorWrapper bundle1 = repo.findModule(BUNDLE_1, BUNDLE_VERSION);
    assertNotNull(bundle1);
    Artifact[] artifacts = bundle1.getModuleDescriptor().getAllArtifacts();
    assertEquals(2, artifacts.length);
    if (artifacts[0].getType().equals("jar")) {
        assertEquals("source", artifacts[1].getType());
    } else {
        assertEquals("jar", artifacts[1].getType());
        assertEquals("source", artifacts[0].getType());
    }
    ModuleDescriptorWrapper bundle2 = repo.findModule(BUNDLE_2, BUNDLE_VERSION);
    assertNotNull(bundle2);
    assertEquals(1, bundle2.getModuleDescriptor().getAllArtifacts().length);
}
Also used : ModuleDescriptorWrapper(org.apache.ivy.osgi.repo.ModuleDescriptorWrapper) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) ArrayList(java.util.ArrayList) URI(java.net.URI) ContentHandler(org.xml.sax.ContentHandler) FileInputStream(java.io.FileInputStream) BundleArtifact(org.apache.ivy.osgi.core.BundleArtifact) Artifact(org.apache.ivy.core.module.descriptor.Artifact) BundleRepoDescriptor(org.apache.ivy.osgi.repo.BundleRepoDescriptor) BundleInfo(org.apache.ivy.osgi.core.BundleInfo) FileOutputStream(java.io.FileOutputStream) File(java.io.File) 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