Search in sources :

Example 16 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class SortEngine method sortNodes.

/**
 * Same as {@link #sortModuleDescriptors(Collection, SortOptions)} but for <code>IvyNode</code>
 * s.
 *
 * @param nodes
 *            a Collection of nodes to sort
 * @param options
 *            Options to use to sort the nodes.
 * @return a List of sorted IvyNode
 * @throws CircularDependencyException
 *             if a circular dependency exists and circular dependency strategy decide to throw
 *             an exception
 */
public List<IvyNode> sortNodes(Collection<IvyNode> nodes, SortOptions options) {
    /*
         * here we want to use the sort algorithm which work on module descriptors : so we first put
         * dependencies on a map from descriptors to dependency, then we sort the keySet (i.e. a
         * collection of descriptors), then we replace in the sorted list each descriptor by the
         * corresponding dependency
         */
    Map<ModuleDescriptor, List<IvyNode>> dependenciesMap = new LinkedHashMap<>();
    List<IvyNode> nulls = new ArrayList<>();
    for (IvyNode node : nodes) {
        if (node.getDescriptor() == null) {
            nulls.add(node);
        } else {
            List<IvyNode> n = dependenciesMap.get(node.getDescriptor());
            if (n == null) {
                n = new ArrayList<>();
                dependenciesMap.put(node.getDescriptor(), n);
            }
            n.add(node);
        }
    }
    List<ModuleDescriptor> list = sortModuleDescriptors(dependenciesMap.keySet(), options);
    final double adjustFactor = 1.3;
    List<IvyNode> ret = new ArrayList<>((int) (list.size() * adjustFactor + nulls.size()));
    // attempt to adjust the size to avoid too much list resizing
    for (ModuleDescriptor md : list) {
        List<IvyNode> n = dependenciesMap.get(md);
        ret.addAll(n);
    }
    ret.addAll(0, nulls);
    return ret;
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IvyNode(org.apache.ivy.core.resolve.IvyNode) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class AbstractOSGiResolver method findCapability.

public ResolvedResource[] findCapability(DependencyDescriptor dd, ResolveData data, Collection<ModuleDescriptor> mds) {
    List<ResolvedResource> ret = new ArrayList<>(mds.size());
    for (ModuleDescriptor md : mds) {
        IvyNode node = data.getNode(md.getModuleRevisionId());
        if (node != null && node.getDescriptor() != null) {
            // already resolved import, no need to go further
            return new ResolvedResource[] { buildResolvedCapabilityMd(dd, node.getDescriptor()) };
        }
        ret.add(buildResolvedCapabilityMd(dd, md));
    }
    return ret.toArray(new ResolvedResource[mds.size()]);
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ArrayList(java.util.ArrayList) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 18 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class LatestCompatibleConflictManager method blackListIncompatibleCaller.

/**
 * Tries to blacklist exactly one version for all callers paths.
 *
 * @param versionMatcher
 *            the version matcher to use to interpret versions
 * @param conflictParent
 *            the node in which the conflict is occurring
 * @param selectedNode
 *            the node in favor of which the conflict is resolved
 * @param evictedNode
 *            the node which will be evicted if we are able to blacklist all paths
 * @param callerStack
 *            ditto
 * @return the collection of blacklisting to do, null if a blacklist is not possible in at least
 *         one caller path
 */
private Collection<IvyNodeBlacklist> blackListIncompatibleCaller(VersionMatcher versionMatcher, IvyNode conflictParent, IvyNode selectedNode, IvyNode evictedNode, Stack<IvyNode> callerStack) {
    Collection<IvyNodeBlacklist> blacklisted = new ArrayList<>();
    IvyNode node = callerStack.peek();
    String rootModuleConf = conflictParent.getData().getReport().getConfiguration();
    for (Caller caller : node.getCallers(rootModuleConf)) {
        IvyNode callerNode = node.findNode(caller.getModuleRevisionId());
        if (callerNode.isBlacklisted(rootModuleConf)) {
            continue;
        }
        if (versionMatcher.isDynamic(caller.getAskedDependencyId())) {
            blacklisted.add(new IvyNodeBlacklist(conflictParent, selectedNode, evictedNode, node, rootModuleConf));
            if (node.isEvicted(rootModuleConf) && !handleIncompatibleCaller(callerStack, node, callerNode, conflictParent, selectedNode, evictedNode, blacklisted, versionMatcher)) {
                return null;
            }
        } else if (!handleIncompatibleCaller(callerStack, node, callerNode, conflictParent, selectedNode, evictedNode, blacklisted, versionMatcher)) {
            return null;
        }
    }
    if (blacklisted.isEmpty() && !callerStack.subList(0, callerStack.size() - 1).contains(node)) {
        return null;
    }
    return blacklisted;
}
Also used : Caller(org.apache.ivy.core.resolve.IvyNodeCallers.Caller) IvyNodeBlacklist(org.apache.ivy.core.resolve.IvyNodeBlacklist) ArrayList(java.util.ArrayList) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 19 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class LatestCompatibleConflictManager method handleIncompatibleConflict.

/**
 * Handles an incompatible conflict
 * <p>
 * An incompatible conflicts is handled with this pseudo algorithm:
 *
 * <pre>
 * take latest among two nodes in conflict
 *   for all callers
 *      if dependency is a version constraint (dynamic)
 *         blacklist the mapped version
 *      else
 *         recurse for all callers
 *   if a version constraint has been found
 *     restart resolve
 *   else
 *     throw strict conflict exception
 * </pre>
 *
 * </p>
 *
 * @param parent
 *            the parent node of nodes in conflict
 * @param conflicts
 *            all the nodes in conflict
 * @param node
 *            one of the two incompatible nodes
 * @param other
 *            the other incompatible node
 * @return true if the incompatible conflict has been handled, false otherwise (in which case
 *         resolveConflicts should return null)
 */
private boolean handleIncompatibleConflict(IvyNode parent, Collection<IvyNode> conflicts, IvyNode node, IvyNode other) {
    // but returning a boolean make the calling code cleaner
    try {
        IvyNodeArtifactInfo latest = (IvyNodeArtifactInfo) getStrategy().findLatest(toArtifactInfo(Arrays.asList(node, other)), null);
        if (latest != null) {
            IvyNode latestNode = latest.getNode();
            IvyNode oldestNode = latestNode == node ? other : node;
            blackListIncompatibleCallerAndRestartResolveIfPossible(getSettings(), parent, oldestNode, latestNode);
            // if we arrive here, we haven't managed to blacklist all paths to the latest
            // node, we try with the oldest
            blackListIncompatibleCallerAndRestartResolveIfPossible(getSettings(), parent, latestNode, oldestNode);
            // still not possible, we aren't able to find a solution to the incompatibility
            handleUnsolvableConflict(parent, conflicts, node, other);
            // never actually reached
            return true;
        } else {
            return false;
        }
    } catch (NoConflictResolvedYetException ex) {
        // according to the resolveConflicts contract, resolveConflicts must return null
        return false;
    }
}
Also used : IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 20 with IvyNode

use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.

the class IvyArtifactReport method generateXml.

private void generateXml(IvyNode[] dependencies, Map<ModuleRevisionId, Set<ArtifactDownloadReport>> moduleRevToArtifactsMap, Map<ArtifactDownloadReport, Set<String>> artifactsToCopy) {
    try {
        try (FileOutputStream fileOutputStream = new FileOutputStream(tofile)) {
            TransformerHandler saxHandler = createTransformerHandler(fileOutputStream);
            saxHandler.startDocument();
            saxHandler.startElement(null, "modules", "modules", new AttributesImpl());
            for (IvyNode dependency : dependencies) {
                if (dependency.getModuleRevision() == null || dependency.isCompletelyEvicted()) {
                    continue;
                }
                startModule(saxHandler, dependency);
                Set<ArtifactDownloadReport> artifactsOfModuleRev = moduleRevToArtifactsMap.get(dependency.getModuleRevision().getId());
                if (artifactsOfModuleRev != null) {
                    for (ArtifactDownloadReport artifact : artifactsOfModuleRev) {
                        RepositoryCacheManager cache = dependency.getModuleRevision().getArtifactResolver().getRepositoryCacheManager();
                        startArtifact(saxHandler, artifact.getArtifact());
                        writeOriginLocationIfPresent(cache, saxHandler, artifact);
                        writeCacheLocationIfPresent(cache, saxHandler, artifact);
                        for (String artifactDestPath : artifactsToCopy.get(artifact)) {
                            writeRetrieveLocation(saxHandler, artifactDestPath);
                        }
                        saxHandler.endElement(null, "artifact", "artifact");
                    }
                }
                saxHandler.endElement(null, "module", "module");
            }
            saxHandler.endElement(null, "modules", "modules");
            saxHandler.endDocument();
        }
    } catch (SAXException | IOException | TransformerConfigurationException e) {
        throw new BuildException("impossible to generate report", e);
    }
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) RepositoryCacheManager(org.apache.ivy.core.cache.RepositoryCacheManager) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ArtifactDownloadReport(org.apache.ivy.core.report.ArtifactDownloadReport) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) AttributesImpl(org.xml.sax.helpers.AttributesImpl) FileOutputStream(java.io.FileOutputStream) BuildException(org.apache.tools.ant.BuildException) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Aggregations

IvyNode (org.apache.ivy.core.resolve.IvyNode)26 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)12 ArrayList (java.util.ArrayList)7 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)5 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)4 ModuleId (org.apache.ivy.core.module.id.ModuleId)4 ArtifactDownloadReport (org.apache.ivy.core.report.ArtifactDownloadReport)4 EvictionData (org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData)4 HashSet (java.util.HashSet)3 ResolveReport (org.apache.ivy.core.report.ResolveReport)3 IvyNodeBlacklist (org.apache.ivy.core.resolve.IvyNodeBlacklist)3 VersionMatcher (org.apache.ivy.plugins.version.VersionMatcher)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Artifact (org.apache.ivy.core.module.descriptor.Artifact)2 Configuration (org.apache.ivy.core.module.descriptor.Configuration)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2