Search in sources :

Example 41 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testMergedUpdateWithExtendsAndExcludes.

/**
 * Test case for IVY-1356.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1356">IVY-1356</a>
 */
@Test
public void testMergedUpdateWithExtendsAndExcludes() throws Exception {
    URL url = XmlModuleUpdaterTest.class.getResource("test-extends-dependencies-exclude.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);
    DependencyDescriptor[] deps = updatedMd.getDependencies();
    assertNotNull("Dependencies shouldn't be null", deps);
    assertEquals("Number of dependencies is incorrect", 2, deps.length);
    // test indentation
    String updatedXml = buffer.toString();
    System.out.println(updatedXml);
    assertTrue(updatedXml.contains(XmlModuleDescriptorUpdater.LINE_SEPARATOR + "\t\t<dependency org=\"myorg\" name=\"mymodule1\" rev=\"1.0\" conf=\"default->default\"/>" + XmlModuleDescriptorUpdater.LINE_SEPARATOR));
}
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) URL(java.net.URL) Test(org.junit.Test)

Example 42 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations1.

@Test
public void testUpdateWithExcludeConfigurations1() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs1.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);
    // test the number of configurations
    Configuration[] configs = updatedMd.getConfigurations();
    assertNotNull("Configurations shouldn't be null", configs);
    assertEquals("Number of configurations incorrect", 3, configs.length);
    // test that the correct configuration has been removed
    assertNull("myconf2 hasn't been removed", updatedMd.getConfiguration("myconf2"));
    // test that the other configurations aren't removed
    assertNotNull("myconf1 has been removed", updatedMd.getConfiguration("myconf1"));
    assertNotNull("myconf3 has been removed", updatedMd.getConfiguration("myconf3"));
    assertNotNull("myconf4 has been removed", updatedMd.getConfiguration("myconf4"));
}
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) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 43 with ModuleDescriptor

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

the class XmlModuleUpdaterTest method testUpdateWithExcludeConfigurations4.

@Test
public void testUpdateWithExcludeConfigurations4() throws Exception {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    URL settingsUrl = new File("test/java/org/apache/ivy/plugins/parser/xml/" + "test-update-excludedconfs4.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);
    // test the number of configurations
    Artifact[] artifacts = updatedMd.getAllArtifacts();
    assertNotNull("Published artifacts shouldn't be null", artifacts);
    assertEquals("Number of published artifacts incorrect", 4, artifacts.length);
    // test that the correct configuration has been removed
    for (Artifact current : artifacts) {
        List<String> currentConfs = Arrays.asList(current.getConfigurations());
        assertTrue("myconf2 hasn't been removed for artifact " + current.getName(), !currentConfs.contains("myconf2"));
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) 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) Artifact(org.apache.ivy.core.module.descriptor.Artifact) Test(org.junit.Test)

Example 44 with ModuleDescriptor

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

the class RepositoryManagementEngine method getDependency.

private ModuleRevisionId getDependency(DependencyDescriptor dd) {
    ModuleRevisionId askedMrid = dd.getDependencyRevisionId();
    VersionMatcher vmatcher = settings.getVersionMatcher();
    if (vmatcher.isDynamic(askedMrid)) {
        ModuleRevisionId mrid = cache.get(askedMrid);
        if (mrid == null) {
            for (ModuleDescriptor md : getAllRevisions(askedMrid)) {
                if (vmatcher.needModuleDescriptor(askedMrid, md.getResolvedModuleRevisionId())) {
                    if (vmatcher.accept(askedMrid, md)) {
                        mrid = md.getResolvedModuleRevisionId();
                        break;
                    }
                } else {
                    if (vmatcher.accept(askedMrid, md.getResolvedModuleRevisionId())) {
                        mrid = md.getResolvedModuleRevisionId();
                        break;
                    }
                }
            }
            if (mrid == null) {
                return null;
            } else {
                cache.put(askedMrid, mrid);
            }
        }
        return mrid;
    } else {
        return askedMrid;
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

Example 45 with ModuleDescriptor

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

the class RepositoryManagementEngine method analyze.

/**
 * Analyze data in the repository.
 * <p>
 * This method may take a long time to proceed. It should never be called from event dispatch
 * thread in a GUI.
 * </p>
 *
 * @throws IllegalStateException
 *             if the repository has not been loaded yet
 * @see #load()
 */
public void analyze() {
    ensureLoaded();
    Message.info("\nanalyzing dependencies...");
    for (ModuleDescriptor md : revisions.values()) {
        for (DependencyDescriptor dd : md.getDependencies()) {
            ModuleRevisionId dep = getDependency(dd);
            if (dep == null) {
                Message.warn("inconsistent repository: declared dependency not found: " + dd);
            } else {
                getDependers(dep).add(md.getModuleRevisionId());
            }
        }
        Message.progress();
    }
    analyzed = true;
}
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) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId)

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