Search in sources :

Example 41 with DependencyDescriptor

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

the class ResolveEngine method fetchDependencies.

private void fetchDependencies(VisitNode node, String conf, boolean shouldBePublic) {
    checkInterrupted();
    long start = System.currentTimeMillis();
    if (node.getParent() != null) {
        Message.verbose("== resolving dependencies " + node.getParent().getId() + "->" + node.getId() + " [" + node.getParentConf() + "->" + conf + "]");
    } else {
        Message.verbose("== resolving dependencies for " + node.getId() + " [" + conf + "]");
    }
    ResolveData data = node.getNode().getData();
    VisitNode parentVisitNode = data.getCurrentVisitNode();
    data.setCurrentVisitNode(node);
    DependencyDescriptor dd = node.getDependencyDescriptor();
    VersionMatcher versionMatcher = node.getNode().getData().getSettings().getVersionMatcher();
    if (dd != null && !(node.getRoot() == node.getParent() && versionMatcher.isDynamic(dd.getDependencyRevisionId()))) {
        /*
             * we don't resolve conflicts before loading data for direct dependencies on dynamic
             * revisions, so that direct dynamic revisions are always resolved, which is mandatory
             * for proper replacement of dynamic revisions during 'deliver'
             */
        resolveConflict(node, conf);
    }
    if (node.loadData(conf, shouldBePublic)) {
        // we resolve conflict again now that we have all information loaded
        // indeed in some cases conflict manager need more information than just asked
        // dependency to take the decision
        resolveConflict(node, conf);
        if (!node.isEvicted() && !node.isCircular()) {
            for (String rconf : node.getRealConfs(conf)) {
                doFetchDependencies(node, rconf);
            }
        }
    } else if (!node.hasProblem()) {
        // => we just have to update its dependencies data
        if (!node.isEvicted() && !node.isCircular()) {
            for (String rconf : node.getRealConfs(conf)) {
                doFetchDependencies(node, rconf);
            }
        }
    }
    if (node.isEvicted()) {
        // update selected nodes with confs asked in evicted one
        EvictionData ed = node.getEvictedData();
        if (ed.getSelected() != null) {
            for (IvyNode selected : ed.getSelected()) {
                if (!selected.isLoaded()) {
                    // the node is not yet loaded, we can simply update its set of
                    // configurations to fetch
                    selected.updateConfsToFetch(Collections.singleton(conf));
                } else {
                    // the node has already been loaded, we must fetch its dependencies in the
                    // required conf
                    fetchDependencies(node.gotoNode(selected), conf, true);
                }
            }
        }
    }
    if (settings.debugConflictResolution()) {
        Message.debug(node.getId() + " => dependencies resolved in " + conf + " (" + (System.currentTimeMillis() - start) + "ms)");
    }
    data.setCurrentVisitNode(parentVisitNode);
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) EvictionData(org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData)

Example 42 with DependencyDescriptor

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

the class IvyNode method getDependencies.

/**
 * Load the dependencies of the current node
 * <p>
 * The resulting collection of nodes may have some configuration to load
 *
 * @param rootModuleConf
 *            the requested configuration of the root module
 * @param conf
 *            the configuration to load of this node
 * @param requestedConf
 *            the actual node conf requested, possibly extending the <code>conf</code> one.
 * @return {@link Collection} of {@link IvyNode}
 */
public Collection<IvyNode> getDependencies(String rootModuleConf, String conf, String requestedConf) {
    if (md == null) {
        throw new IllegalStateException("impossible to get dependencies when data has not been loaded");
    }
    // it's important to respect order => LinkedHashMap
    Map<ModuleRevisionId, IvyNode> dependencies = new LinkedHashMap<>();
    for (DependencyDescriptor dependencyDescriptor : md.getDependencies()) {
        DependencyDescriptor dd = data.mediate(dependencyDescriptor);
        String[] dependencyConfigurations = dd.getDependencyConfigurations(conf, requestedConf);
        if (dependencyConfigurations.length == 0) {
            // it is exactly the same as if there was no dependency at all on it
            continue;
        }
        ModuleRevisionId requestedDependencyRevisionId = dd.getDependencyRevisionId();
        if (isDependencyModuleExcluded(dd, rootModuleConf, requestedDependencyRevisionId, conf)) {
            // the whole module is excluded, it is considered as not being part of dependencies
            // at all
            Message.verbose("excluding " + dd + " in " + conf);
            continue;
        }
        // check if not already loaded here
        IvyNode depNode = dependencies.get(requestedDependencyRevisionId);
        if (depNode == null) {
            // check if not already loaded during the resolve session
            depNode = data.getNode(requestedDependencyRevisionId);
        }
        if (depNode == null) {
            depNode = new IvyNode(data, this, dd);
        } else {
            depNode.addDependencyDescriptor(this, dd);
            if (depNode.hasProblem()) {
            // dependency already tried to be resolved, but unsuccessfully
            // nothing special to do
            }
        }
        String[] confsArray = depNode.resolveSpecialConfigurations(dependencyConfigurations);
        Collection<String> confs = Arrays.asList(confsArray);
        depNode.updateConfsToFetch(confs);
        depNode.addRootModuleConfigurations(depNode.usage, rootModuleConf, confsArray);
        depNode.usage.setRequiredConfs(this, conf, confs);
        depNode.addCaller(rootModuleConf, this, conf, requestedConf, dependencyConfigurations, dd);
        dependencies.put(requestedDependencyRevisionId, depNode);
    }
    return dependencies.values();
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with DependencyDescriptor

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

the class IvyNode method loadData.

/**
 * After the call node may be discarded. To avoid using discarded node, make sure to get the
 * real node after the call
 * <code>IvyNode node = ... node.loadData(); node = node.getRealNode(); ...</code>
 *
 * @param rootModuleConf String
 * @param parent IvyNode
 * @param parentConf String
 * @param conf String
 * @param shouldBePublic boolean
 * @param usage IvyNodeUsage
 * @return boolean
 */
public boolean loadData(String rootModuleConf, IvyNode parent, String parentConf, String conf, boolean shouldBePublic, IvyNodeUsage usage) {
    Message.debug("loadData of " + this.toString() + " of rootConf=" + rootModuleConf);
    if (!isRoot() && (data.getReport() != null)) {
        data.getReport().addDependency(this);
    }
    boolean loaded = false;
    if (hasProblem()) {
        Message.debug("Node has problem.  Skip loading");
    } else if (isEvicted(rootModuleConf)) {
        Message.debug(rootModuleConf + " is evicted.  Skip loading");
    } else if (!hasConfigurationsToLoad() && isRootModuleConfLoaded(rootModuleConf)) {
        Message.debug(rootModuleConf + " is loaded and no conf to load.  Skip loading");
    } else {
        markRootModuleConfLoaded(rootModuleConf);
        if (md == null) {
            DependencyResolver resolver = data.getSettings().getResolver(getId());
            if (resolver == null) {
                Message.error("no resolver found for " + getModuleId() + ": check your configuration");
                problem = new RuntimeException("no resolver found for " + getModuleId() + ": check your configuration");
                return false;
            }
            try {
                Message.debug("\tusing " + resolver + " to resolve " + getId());
                DependencyDescriptor dependencyDescriptor = getDependencyDescriptor(parent);
                long start = System.currentTimeMillis();
                ModuleRevisionId requestedRevisionId = dependencyDescriptor.getDependencyRevisionId();
                data.getEventManager().fireIvyEvent(new StartResolveDependencyEvent(resolver, dependencyDescriptor, requestedRevisionId));
                module = resolver.getDependency(dependencyDescriptor, data);
                data.getEventManager().fireIvyEvent(new EndResolveDependencyEvent(resolver, dependencyDescriptor, requestedRevisionId, module, System.currentTimeMillis() - start));
                if (module != null) {
                    module.getResolver().getRepositoryCacheManager().saveResolvers(module.getDescriptor(), module.getResolver().getName(), module.getArtifactResolver().getName());
                    if (settings.logModuleWhenFound() && LogOptions.LOG_DEFAULT.equals(getData().getOptions().getLog())) {
                        Message.info("\tfound " + module.getId() + " in " + module.getResolver().getName());
                    } else {
                        Message.verbose("\tfound " + module.getId() + " in " + module.getResolver().getName());
                    }
                    // IVY-56: check if revision has actually been resolved
                    if (settings.getVersionMatcher().isDynamic(getId()) && settings.getVersionMatcher().isDynamic(module.getId())) {
                        Message.error("impossible to resolve dynamic revision for " + getId() + ": check your configuration and make sure revision is part of your pattern");
                        problem = new RuntimeException("impossible to resolve dynamic revision");
                        return false;
                    }
                    if (!getId().equals(module.getId())) {
                        IvyNode resolved = data.getNode(module.getId());
                        if (resolved != null) {
                            // found revision has already been resolved
                            // => update it and discard this node
                            // needed for handleConfiguration
                            md = module.getDescriptor();
                            if (!handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic, usage)) {
                                return false;
                            }
                            moveToRealNode(rootModuleConf, parent, parentConf, conf, shouldBePublic, resolved);
                            return true;
                        }
                        String log = "\t[" + module.getId().getRevision() + "] " + getId();
                        if (!settings.getVersionMatcher().isDynamic(getId())) {
                            log += " (forced)";
                        }
                        if (settings.logResolvedRevision() && LogOptions.LOG_DEFAULT.equals(getData().getOptions().getLog())) {
                            Message.info(log);
                        } else {
                            Message.verbose(log);
                        }
                    }
                    downloaded = module.getReport().isDownloaded();
                    searched = module.getReport().isSearched();
                    loaded = true;
                    md = module.getDescriptor();
                    confsToFetch.remove("*");
                    updateConfsToFetch(Arrays.asList(resolveSpecialConfigurations(getRequiredConfigurations(parent, parentConf))));
                } else {
                    Message.warn("\tmodule not found: " + getId());
                    resolver.reportFailure();
                    problem = new RuntimeException("not found");
                    return false;
                }
            } catch (ResolveProcessException e) {
                throw e;
            } catch (Exception e) {
                problem = e;
                Message.debug("Unexpected error: " + problem.getMessage(), problem);
                return false;
            }
        } else {
            loaded = true;
        }
    }
    handleConfiguration(loaded, rootModuleConf, parent, parentConf, conf, shouldBePublic, usage);
    if (hasProblem()) {
        Message.debug("problem : " + problem.getMessage());
        return false;
    }
    DependencyDescriptor dd = getDependencyDescriptor(parent);
    if (dd != null) {
        usage.addUsage(rootModuleConf, dd, parentConf);
    }
    return loaded;
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) StartResolveDependencyEvent(org.apache.ivy.core.event.resolve.StartResolveDependencyEvent) EndResolveDependencyEvent(org.apache.ivy.core.event.resolve.EndResolveDependencyEvent) DependencyResolver(org.apache.ivy.plugins.resolver.DependencyResolver)

Example 44 with DependencyDescriptor

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

the class ModuleDescriptorSorter method sortModuleDescriptorsHelp.

/**
 * If current module has already been added to list, returns, Otherwise invokes
 * sortModuleDescriptorsHelp for all dependencies contained within set of moduleDescriptors.
 * Then finally adds self to list of sorted.<br/>
 * When a loop is detected by a recursive call, the moduleDescriptors are not added immediately
 * added to the sorted list. They are added as loop dependencies of the root, and will be added
 * to the sorted list only when the root itself will be added.
 *
 * @param current
 *            Current module to add to sorted list.
 * @throws CircularDependencyException somehow
 */
private void sortModuleDescriptorsHelp(ModuleInSort current, ModuleInSort caller) throws CircularDependencyException {
    // if already sorted return
    if (current.isProcessed()) {
        return;
    }
    if (current.checkLoop(caller, circularDepStrategy)) {
        return;
    }
    DependencyDescriptor[] descriptors = current.getDependencies();
    Message.debug("Sort dependencies of : " + current.toString() + " / Number of dependencies = " + descriptors.length);
    current.setCaller(caller);
    for (DependencyDescriptor descriptor : descriptors) {
        ModuleInSort child = moduleDescriptors.getModuleDescriptorDependency(descriptor);
        if (child != null) {
            sortModuleDescriptorsHelp(child, current);
        }
    }
    current.endOfCall();
    Message.debug("Sort done for : " + current.toString());
    current.addToSortedListIfRequired(sorted);
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor)

Example 45 with DependencyDescriptor

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

the class ResolveTest method testNoAttributesForcedDependencies.

@Test
public void testNoAttributesForcedDependencies() throws Exception {
    Ivy ivy = new Ivy();
    ivy.configure(new File("test/repositories/extra-attributes-forceddependencies/ivysettings-filerepo-noattribs.xml"));
    ivy.getSettings().setDefaultCache(cache);
    ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-attrib-forced-dependencies.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }).setValidate(false));
    assertFalse(report.hasError());
    ivy.deliver("1.0.0", deliverDir.getAbsolutePath() + "/ivy-1.0.0.xml", new DeliverOptions().setResolveId(report.getResolveId()).setValidate(false).setPubdate(new Date()));
    File deliveredIvyFile = new File(deliverDir, "ivy-1.0.0.xml");
    assertTrue(deliveredIvyFile.exists());
    ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(ivy.getSettings(), deliveredIvyFile.toURI().toURL(), false);
    DependencyDescriptor[] dds = md.getDependencies();
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("CAE-Visualization-Components", "SGL", "MAIN", "6.2.34.7"), dds[1].getDependencyRevisionId());
}
Also used : DeliverOptions(org.apache.ivy.core.deliver.DeliverOptions) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)101 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)80 Test (org.junit.Test)75 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)35 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)33 File (java.io.File)26 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)25 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)18 IvySettings (org.apache.ivy.core.settings.IvySettings)17 Configuration (org.apache.ivy.core.module.descriptor.Configuration)15 Artifact (org.apache.ivy.core.module.descriptor.Artifact)13 ParseException (java.text.ParseException)12 IOException (java.io.IOException)11 ResolveData (org.apache.ivy.core.resolve.ResolveData)11 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)9 JarFile (java.util.jar.JarFile)7 GregorianCalendar (java.util.GregorianCalendar)6 ModuleId (org.apache.ivy.core.module.id.ModuleId)6 ResolveReport (org.apache.ivy.core.report.ResolveReport)6