Search in sources :

Example 36 with ModuleDescriptor

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

the class AbstractOSGiResolver method findNames.

@Override
protected Collection<String> findNames(Map<String, String> tokenValues, String token) {
    if (IvyPatternHelper.ORGANISATION_KEY.equals(token)) {
        return getRepoDescriptor().getCapabilities();
    }
    String osgiType = tokenValues.get(IvyPatternHelper.ORGANISATION_KEY);
    if (isNullOrEmpty(osgiType)) {
        return Collections.emptyList();
    }
    if (IvyPatternHelper.MODULE_KEY.equals(token)) {
        return getRepoDescriptor().getCapabilityValues(osgiType);
    }
    if (IvyPatternHelper.REVISION_KEY.equals(token)) {
        String name = tokenValues.get(IvyPatternHelper.MODULE_KEY);
        List<String> versions = new ArrayList<>();
        Set<ModuleDescriptorWrapper> mds = getRepoDescriptor().findModules(osgiType, name);
        if (mds != null) {
            for (ModuleDescriptorWrapper md : mds) {
                versions.add(md.getBundleInfo().getVersion().toString());
            }
        }
        return versions;
    }
    if (IvyPatternHelper.CONF_KEY.equals(token)) {
        String name = tokenValues.get(IvyPatternHelper.MODULE_KEY);
        if (name == null) {
            return Collections.emptyList();
        }
        if (osgiType.equals(BundleInfo.PACKAGE_TYPE)) {
            return Collections.singletonList(BundleInfoAdapter.CONF_USE_PREFIX + name);
        }
        Collection<ModuleDescriptor> mds = ModuleDescriptorWrapper.unwrap(getRepoDescriptor().findModules(osgiType, name));
        if (mds == null) {
            return Collections.emptyList();
        }
        String version = tokenValues.get(IvyPatternHelper.REVISION_KEY);
        if (version == null) {
            return Collections.emptyList();
        }
        ModuleDescriptor found = null;
        for (ModuleDescriptor md : mds) {
            if (md.getRevision().equals(version)) {
                found = md;
            }
        }
        if (found == null) {
            return Collections.emptyList();
        }
        return Arrays.asList(found.getConfigurationsNames());
    }
    return Collections.emptyList();
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ArrayList(java.util.ArrayList)

Example 37 with ModuleDescriptor

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

the class IBiblioMavenSnapshotsResolutionTest method testSnapshotResolution.

/**
 * Tests that an Ivy module that depends on regular and timestamped snapshots of Maven
 * artifacts, when resolved using a {@link IBiblioResolver} and with
 * {@link MavenTimedSnapshotVersionMatcher} configured in {@link IvySettings}, is resolved
 * correctly for such snapshot dependencies.
 *
 * @throws Exception
 *             if something goes wrong
 */
@Test
public void testSnapshotResolution() throws Exception {
    final IvySettings settings = this.ivy.getSettings();
    assertNotNull("Maven timestamped snapshot revision version matcher is absent", settings.getVersionMatcher(new MavenTimedSnapshotVersionMatcher().getName()));
    final ResolveOptions resolveOptions = new ResolveOptions();
    resolveOptions.setConfs(new String[] { "default" });
    final ResolveReport report = ivy.resolve(new File("test/repositories/2/maven-snapshot-deps-test/ivy-with-maven-snapshot-deps.xml"), resolveOptions);
    assertNotNull("Resolution report was null", report);
    assertFalse("Resolution report has error(s)", report.hasError());
    final ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull("Module descriptor in resolution report was null", md);
    final ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache.ivy", "maven-snapshot-deps-test", "1.2.3");
    assertEquals("Unexpected module resolved", mrid, md.getModuleRevisionId());
    final ConfigurationResolveReport crr = report.getConfigurationReport("default");
    final ModuleRevisionId exactRevision = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "exact-revision", "2.3.4");
    final ArtifactDownloadReport[] dr1 = crr.getDownloadReports(exactRevision);
    assertNotNull("Artifact download report missing for dependency " + exactRevision, dr1);
    assertEquals("Unexpected number of artifact download report for dependency " + exactRevision, dr1.length, 1);
    final ArtifactDownloadReport exactRevDownloadReport = dr1[0];
    assertEquals("Unexpected download status for dependency " + exactRevision, exactRevDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
    final ModuleRevisionId regularSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "regular-snapshot", "1.2.3-SNAPSHOT");
    final ArtifactDownloadReport[] dr2 = crr.getDownloadReports(regularSnapshot);
    assertNotNull("Artifact download report missing for dependency " + regularSnapshot, dr2);
    assertEquals("Unexpected number of artifact download report for dependency " + regularSnapshot, dr2.length, 1);
    final ArtifactDownloadReport regularSnapshotDownloadReport = dr2[0];
    assertEquals("Unexpected download status for dependency " + regularSnapshot, regularSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
    final ModuleRevisionId timestampedSnapshot = ModuleRevisionId.newInstance("org.apache.ivy.maven-snapshot-test", "timestamped-snapshot", "5.6.7-20170911.130943-1");
    final ArtifactDownloadReport[] dr3 = crr.getDownloadReports(timestampedSnapshot);
    assertNotNull("Artifact download report missing for dependency " + timestampedSnapshot, dr3);
    assertEquals("Unexpected number of artifact download report for dependency " + timestampedSnapshot, dr3.length, 1);
    final ArtifactDownloadReport timestampedSnapshotDownloadReport = dr3[0];
    assertEquals("Unexpected download status for dependency " + timestampedSnapshot, timestampedSnapshotDownloadReport.getDownloadStatus(), DownloadStatus.SUCCESSFUL);
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) MavenTimedSnapshotVersionMatcher(org.apache.ivy.plugins.version.MavenTimedSnapshotVersionMatcher) ResolveOptions(org.apache.ivy.core.resolve.ResolveOptions) File(java.io.File) Test(org.junit.Test)

Example 38 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndConfigurationsInheritance.

/**
 * Test case for IVY-1437.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1437">IVY-1437</a>
 */
@Test
public void testMergedUpdateWithExtendsAndConfigurationsInheritance() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-configurations-inherit.xml");
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    Configuration[] configurations = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configurations);
    assertEquals("Number of configurations is incorrect", 2, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("configurations defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
    assertTrue(updatedXml.contains("dependencies defaultconf=\"compile\" defaultconfmapping=\"*->default\""));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) URL(java.net.URL) Test(org.junit.Test)

Example 39 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testMergedUpdateWithInclude.

/**
 * Test case for IVY-1315.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1315">IVY-1315</a>
 */
@Test
public void testMergedUpdateWithInclude() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-update-excludedconfs6.xml");
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor md = parser.parseDescriptor(new IvySettings(), url, true);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    XmlModuleDescriptorUpdater.update(url, buffer, getUpdateOptions("release", "mynewrev").setMerge(true).setMergedDescriptor(md));
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    Configuration[] configurations = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configurations);
    assertEquals("Number of configurations is incorrect", 6, configurations.length);
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains("dependencies defaultconf=\"conf1->default\""));
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) URL(java.net.URL) Test(org.junit.Test)

Example 40 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations5.

@Test
public void testUpdateWithExcludeConfigurations5() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs5.xml").toURI().toURL();
    XmlModuleDescriptorUpdater.update(settingsUrl, buffer, getUpdateOptions("release", "mynewrev").setConfsToExclude(new String[] { "myconf2" }));
    XmlModuleDescriptorParser parser = XmlModuleDescriptorParser.getInstance();
    ModuleDescriptor updatedMd = parser.parseDescriptor(new IvySettings(), new ByteArrayInputStream(buffer.toByteArray()), new BasicResource("test", false, 0, 0, false), true);
    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 8, deps.length);
    // check that none of the dependencies contains myconf2
    for (DependencyDescriptor dep : deps) {
        String name = dep.getDependencyId().getName();
        assertFalse("Dependency " + name + " shouldn't have myconf2 as module configuration", Arrays.asList(dep.getModuleConfigurations()).contains("myconf2"));
        assertEquals("Dependency " + name + " shouldn't have a dependency artifact for configuration myconf2", 0, dep.getDependencyArtifacts("myconf2").length);
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvySettings(org.apache.ivy.core.settings.IvySettings) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BasicResource(org.apache.ivy.plugins.repository.BasicResource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)284 Test (org.junit.Test)233 File (java.io.File)143 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)114 ResolveReport (org.apache.ivy.core.report.ResolveReport)94 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)80 JarFile (java.util.jar.JarFile)76 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)76 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)69 IvySettings (org.apache.ivy.core.settings.IvySettings)60 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)44 Configuration (org.apache.ivy.core.module.descriptor.Configuration)30 Artifact (org.apache.ivy.core.module.descriptor.Artifact)28 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)27 IOException (java.io.IOException)24 ParseException (java.text.ParseException)23 Ivy (org.apache.ivy.Ivy)23 BufferedReader (java.io.BufferedReader)19 FileReader (java.io.FileReader)19 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)17