Search in sources :

Example 11 with Configuration

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

the class IvyNode method handleConfiguration.

private boolean handleConfiguration(boolean loaded, String rootModuleConf, IvyNode parent, String parentConf, String conf, boolean shouldBePublic, IvyNodeUsage usage) {
    if (md != null) {
        String[] confs = getRealConfs(conf);
        addRootModuleConfigurations(usage, rootModuleConf, confs);
        for (String realConf : confs) {
            Configuration c = md.getConfiguration(realConf);
            if (c == null) {
                confsToFetch.remove(conf);
                if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) {
                    Message.verbose("configuration required by evicted revision is not available in " + "selected revision. skipping " + conf + " in " + this);
                } else if (!conf.equals(realConf)) {
                    problem = new RuntimeException("configuration not found in " + this + ": '" + conf + "'. Missing configuration: '" + realConf + "'. It was required from " + parent + " " + parentConf);
                } else {
                    problem = new RuntimeException("configuration not found in " + this + ": '" + realConf + "'. It was required from " + parent + " " + parentConf);
                }
                return false;
            }
            if (shouldBePublic && !isRoot() && !PUBLIC.equals(c.getVisibility())) {
                confsToFetch.remove(conf);
                if (isConfRequiredByMergedUsageOnly(rootModuleConf, conf)) {
                    Message.verbose("configuration required by evicted revision is not visible in " + "selected revision. skipping " + conf + " in " + this);
                } else {
                    problem = new RuntimeException("configuration not public in " + this + ": '" + c + "'. It was required from " + parent + " " + parentConf);
                }
                return false;
            }
        }
        if (loaded) {
            fetchedConfigurations.add(conf);
            confsToFetch.removeAll(Arrays.asList(confs));
            confsToFetch.remove(conf);
        }
    }
    return true;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration)

Example 12 with Configuration

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

the class IvyNode method getConfiguration.

public Configuration getConfiguration(String conf) {
    if (md == null) {
        throw new IllegalStateException("impossible to get configuration when data has not been loaded");
    }
    String defaultConf = getDefaultConf(conf);
    conf = getMainConf(conf);
    Configuration configuration = md.getConfiguration(conf);
    if (configuration == null) {
        configuration = md.getConfiguration(defaultConf);
    }
    return configuration;
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration)

Example 13 with Configuration

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

the class ResolveEngine method doFetchDependencies.

private void doFetchDependencies(VisitNode node, String conf) {
    Configuration c = node.getConfiguration(conf);
    if (c == null) {
        if (!node.isConfRequiredByMergedUsageOnly(conf)) {
            Message.warn("configuration not found '" + conf + "' in " + node.getResolvedId() + ": ignoring");
            if (node.getParent() != null) {
                Message.warn("it was required from " + node.getParent().getResolvedId());
            }
        }
        return;
    }
    // we handle the case where the asked configuration extends others:
    // we have to first fetch the extended configurations
    // first we check if this is the actual requested conf (not an extended one)
    boolean requestedConfSet = false;
    if (node.getRequestedConf() == null) {
        node.setRequestedConf(conf);
        requestedConfSet = true;
    }
    // now let's recurse in extended confs
    String[] extendedConfs = c.getExtends();
    if (extendedConfs.length > 0) {
        node.updateConfsToFetch(Arrays.asList(extendedConfs));
    }
    for (String extendedConf : extendedConfs) {
        fetchDependencies(node, extendedConf, false);
    }
    // now we can actually resolve this configuration dependencies
    if (!isDependenciesFetched(node.getNode(), conf) && node.isTransitive()) {
        for (VisitNode dep : node.getDependencies(conf)) {
            // the node may have been resolved to another real one while
            dep.useRealNode();
            // resolving other deps
            for (String rconf : dep.getRequiredConfigurations(node, conf)) {
                fetchDependencies(dep, rconf, true);
            }
            if (!dep.isEvicted() && !dep.hasProblem()) {
                // been updated when evicting another module), we fetch them now
                for (String fconf : dep.getConfsToFetch()) {
                    // shouldBeFixed=false to because some of those dependencies might
                    // be private when they were actually extending public conf.
                    // Should we keep two list of confs to fetch (private&public)?
                    // I don't think, visibility is already checked, and a change in the
                    // configuration between version might anyway have worse problems.
                    fetchDependencies(dep, fconf, false);
                }
            }
        }
        markDependenciesFetched(node.getNode(), conf);
    }
    // we can clean it now
    if (requestedConfSet) {
        node.setRequestedConf(null);
    }
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration)

Example 14 with Configuration

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

the class VisitNode method isParentConfTransitive.

/**
 * Checks if the current node's parent configuration is transitive.
 *
 * @return true if the node's parent configuration is transitive
 */
protected boolean isParentConfTransitive() {
    String conf = getParent().getRequestedConf();
    if (conf == null) {
        return true;
    }
    Configuration parentConf = getParentNode().getConfiguration(conf);
    return parentConf.isTransitive();
}
Also used : Configuration(org.apache.ivy.core.module.descriptor.Configuration)

Example 15 with Configuration

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

the class XmlModuleDescriptorParserTest method testExtendsAbsoluteLocation.

/**
 * Tests that when the <code>location</code> attribute of the <code>extends</code> element of
 * a module descriptor file, includes an {@link File#isAbsolute() absolute path} with
 * characters that {@link java.net.URI} considers as encoded characters (for example,
 * <code>%2F</code>) then the module descriptor and the location of the parent descriptor
 * are resolved and parsed correctly.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-1562">IVY-1562</a>
 */
@Test
public void testExtendsAbsoluteLocation() throws Exception {
    final URL ivyXML = this.getClass().getResource("foo%2Fbar/hello/test-ivy-extends-absolute.xml");
    assertNotNull("Ivy xml file is missing", ivyXML);
    final URL parentIvyXML = this.getClass().getResource("foo%2Fbar/parent-ivy.xml");
    assertNotNull("Parent Ivy xml file is missing", parentIvyXML);
    // the ivy xml references a parent ivy xml via extends "location" and expects the parent
    // ivy to be present at a location under java.io.tmpdir, so we copy over the parent ivy
    // file over there
    final Path targetDir = Paths.get(System.getProperty("java.io.tmpdir"), "foo%2Fbar");
    Files.createDirectories(targetDir);
    final Path parentIvyXMLPath = Paths.get(targetDir.toString(), "parent-ivy.xml");
    try (final InputStream is = parentIvyXML.openStream()) {
        Files.copy(is, parentIvyXMLPath, StandardCopyOption.REPLACE_EXISTING);
    }
    assertTrue("Parent ivy xml file wasn't copied", Files.isRegularFile(parentIvyXMLPath));
    try {
        // now start parsing the Ivy xml
        final ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(settings, ivyXML, true);
        assertNotNull("Parsed module descriptor is null", md);
        assertEquals("Unexpected org for the parsed module descriptor", "myorg", md.getModuleRevisionId().getOrganisation());
        assertEquals("Unexpected module name for the parsed module descriptor", "mymodule", md.getModuleRevisionId().getName());
        assertEquals("Unexpected revision for the parsed module descriptor", "1.0.0", md.getModuleRevisionId().getRevision());
        final Configuration[] confs = md.getConfigurations();
        assertNotNull("No configurations found in module descriptor", confs);
        assertEquals("Unexpected number of configurations found in module descriptor", 3, confs.length);
        final Set<String> expectedConfs = new HashSet<>(Arrays.asList("parent-conf1", "parent-conf2", "conf2"));
        for (final Configuration conf : confs) {
            assertNotNull("One of the configurations was null in module descriptor", conf);
            assertTrue("Unexpected configuration " + conf.getName() + " found in parsed module descriptor", expectedConfs.remove(conf.getName()));
        }
        assertTrue("Missing configurations " + expectedConfs + " from the parsed module descriptor", expectedConfs.isEmpty());
    } finally {
        // clean up the copied over file
        Files.delete(parentIvyXMLPath);
    }
}
Also used : Path(java.nio.file.Path) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) Configuration(org.apache.ivy.core.module.descriptor.Configuration) InputStream(java.io.InputStream) URL(java.net.URL) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Configuration (org.apache.ivy.core.module.descriptor.Configuration)45 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)30 Test (org.junit.Test)29 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)17 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)16 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)10 Date (java.util.Date)9 URL (java.net.URL)7 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IvySettings (org.apache.ivy.core.settings.IvySettings)6 BasicResource (org.apache.ivy.plugins.repository.BasicResource)6 File (java.io.File)5 Map (java.util.Map)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 GregorianCalendar (java.util.GregorianCalendar)3 License (org.apache.ivy.core.module.descriptor.License)3 IOException (java.io.IOException)2