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;
}
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()]);
}
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;
}
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;
}
}
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);
}
}
Aggregations