Search in sources :

Example 11 with DefaultModuleDescriptor

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

the class ResolveEngine method findModule.

public ResolvedModuleRevision findModule(ModuleRevisionId id, ResolveOptions options) {
    DependencyResolver r = settings.getResolver(id);
    if (r == null) {
        throw new IllegalStateException("no resolver found for " + id.getModuleId());
    }
    DefaultModuleDescriptor md = DefaultModuleDescriptor.newCallerInstance(id, new String[] { "*" }, false, false);
    if (options.getResolveId() == null) {
        options.setResolveId(ResolveOptions.getDefaultResolveId(md));
    }
    try {
        return r.getDependency(new DefaultDependencyDescriptor(id, true), new ResolveData(this, options, new ConfigurationResolveReport(this, md, "default", null, options)));
    } catch (ParseException e) {
        throw new RuntimeException("problem while parsing repository module descriptor for " + id + ": " + e, e);
    }
}
Also used : DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ParseException(java.text.ParseException) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 12 with DefaultModuleDescriptor

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

the class PomModuleDescriptorParserTest method createIvySettingsForParentLicenseTesting.

private IvySettings createIvySettingsForParentLicenseTesting(final String parentPomFileName, final String parentOrgName, final String parentModuleName) throws Exception {
    final URL parentPomURL = this.getClass().getResource(parentPomFileName);
    assertNotNull("Could not find " + parentPomFileName, parentPomURL);
    final PomReader parentPomReader = new PomReader(parentPomURL, new URLResource(parentPomURL));
    final License[] parentLicenses = parentPomReader.getLicenses();
    assertNotNull("Missing licenses in parent pom " + parentPomFileName, parentLicenses);
    assertEquals("Unexpected number of licenses in parent pom " + parentPomFileName, 1, parentLicenses.length);
    final DependencyResolver dependencyResolver = new MockedDependencyResolver() {

        @Override
        protected ModuleDescriptor getModuleDescriptor(DependencyDescriptor dependencyDescriptor) {
            final String depOrg = dependencyDescriptor.getDependencyId().getOrganisation();
            final String depModuleName = dependencyDescriptor.getDependencyId().getName();
            if (depOrg.equals(parentOrgName) && depModuleName.equals(parentModuleName)) {
                final DefaultModuleDescriptor moduleDescriptor = DefaultModuleDescriptor.newDefaultInstance(dependencyDescriptor.getDependencyRevisionId());
                for (final License license : parentLicenses) {
                    moduleDescriptor.addLicense(license);
                }
                return moduleDescriptor;
            } else {
                return super.getModuleDescriptor(dependencyDescriptor);
            }
        }
    };
    final IvySettings ivySettings = new IvySettings();
    ivySettings.setDictatorResolver(dependencyResolver);
    return ivySettings;
}
Also used : URLResource(org.apache.ivy.plugins.repository.url.URLResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) License(org.apache.ivy.core.module.descriptor.License) IvySettings(org.apache.ivy.core.settings.IvySettings) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) URL(java.net.URL) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 13 with DefaultModuleDescriptor

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

the class XmlModuleDescriptorWriterTest method testTransitiveAttributeForNonTransitiveConfs.

/**
 * Test that the transitive attribute is written for non-transitive configurations.
 *
 * <code>&lt;conf ... transitive="false" ... /&gt;</code>
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1207">IVY-1207</a>
 */
@Test
public void testTransitiveAttributeForNonTransitiveConfs() throws Exception {
    // Given a ModuleDescriptor with a non-transitive configuration
    DefaultModuleDescriptor md = new DefaultModuleDescriptor(new ModuleRevisionId(new ModuleId("myorg", "myname"), "1.0"), "integration", new Date());
    Configuration conf = new Configuration("conf", PUBLIC, "desc", null, false, null);
    md.addConfiguration(conf);
    // When the ModuleDescriptor is written
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);
    // Then the transitive attribute must be set to false
    String output = FileUtil.readEntirely(dest);
    String writtenConf = output.substring(output.indexOf("<configurations>") + 16, output.indexOf("</configurations>")).trim();
    assertTrue("Transitive attribute not set to false: " + writtenConf, writtenConf.contains("transitive=\"false\""));
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) Test(org.junit.Test) PomModuleDescriptorParserTest(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParserTest)

Example 14 with DefaultModuleDescriptor

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

the class XmlModuleDescriptorWriterTest method testInfo.

@Test
public void testInfo() throws Exception {
    DefaultModuleDescriptor md = (DefaultModuleDescriptor) XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), XmlModuleDescriptorWriterTest.class.getResource("test-info.xml"), true);
    md.setResolvedPublicationDate(new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime());
    md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), "NONE"));
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);
    assertTrue(dest.exists());
    String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))).replaceAll("\r\n", "\n").replace('\r', '\n');
    String expected = readEntirely("test-write-info.xml").replaceAll("\r\n", "\n").replace('\r', '\n');
    assertEquals(expected, wrote);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) FileReader(java.io.FileReader) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Test(org.junit.Test) PomModuleDescriptorParserTest(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParserTest)

Example 15 with DefaultModuleDescriptor

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

the class XmlModuleDescriptorWriterTest method testSimple.

@Test
public void testSimple() throws Exception {
    DefaultModuleDescriptor md = (DefaultModuleDescriptor) XmlModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), XmlModuleDescriptorWriterTest.class.getResource("test-simple.xml"), true);
    md.setResolvedPublicationDate(new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime());
    md.setResolvedModuleRevisionId(new ModuleRevisionId(md.getModuleRevisionId().getModuleId(), "NONE"));
    XmlModuleDescriptorWriter.write(md, LICENSE, dest);
    assertTrue(dest.exists());
    String wrote = FileUtil.readEntirely(new BufferedReader(new FileReader(dest))).replaceAll("\r\n", "\n").replace('\r', '\n');
    String expected = readEntirely("test-write-simple.xml").replaceAll("\r\n", "\n").replace('\r', '\n');
    assertEquals(expected, wrote);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) IvySettings(org.apache.ivy.core.settings.IvySettings) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) FileReader(java.io.FileReader) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Test(org.junit.Test) PomModuleDescriptorParserTest(org.apache.ivy.plugins.parser.m2.PomModuleDescriptorParserTest)

Aggregations

DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)30 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)17 Date (java.util.Date)10 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)9 File (java.io.File)7 Configuration (org.apache.ivy.core.module.descriptor.Configuration)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 Test (org.junit.Test)6 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)5 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)5 ParseException (java.text.ParseException)4 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 Map (java.util.Map)3 Artifact (org.apache.ivy.core.module.descriptor.Artifact)3 ModuleId (org.apache.ivy.core.module.id.ModuleId)3