use of org.apache.ivy.core.resolve.IvyNode in project lucene-solr by apache.
the class IvyNodeElementAdapter method adapt.
/**
* Adapt all dependencies and evictions from the ResolveReport.
* @return the root node adapted from the ResolveReport
*/
public static IvyNodeElement adapt(ResolveReport report) {
Map<ModuleRevisionId, IvyNodeElement> resolvedNodes = new HashMap<>();
IvyNodeElement root = new IvyNodeElement();
root.setModuleRevisionId(report.getModuleDescriptor().getModuleRevisionId());
resolvedNodes.put(report.getModuleDescriptor().getModuleRevisionId(), root);
@SuppressWarnings("unchecked") List<IvyNode> dependencies = report.getDependencies();
// First pass - build the map of resolved nodes by revision id
for (Iterator<IvyNode> iter = dependencies.iterator(); iter.hasNext(); ) {
IvyNode node = iter.next();
if (node.getAllEvictingNodes() != null) {
// We map them as evictions rather than dependencies.
continue;
}
IvyNodeElement nodeElement = new IvyNodeElement();
nodeElement.setModuleRevisionId(node.getResolvedId());
resolvedNodes.put(node.getResolvedId(), nodeElement);
}
// Second pass - establish relationships between the resolved nodes
for (Iterator<IvyNode> iter = dependencies.iterator(); iter.hasNext(); ) {
IvyNode node = iter.next();
if (node.getAllEvictingNodes() != null) {
// see note above
continue;
}
IvyNodeElement nodeElement = resolvedNodes.get(node.getResolvedId());
IvyNodeCallers.Caller[] callers = node.getAllRealCallers();
for (int i = 0; i < callers.length; i++) {
IvyNodeElement caller = resolvedNodes.get(callers[i].getModuleRevisionId());
if (caller != null) {
nodeElement.addCaller(caller);
nodeElement.setCallerConfigurations(caller, callers[i].getCallerConfigurations());
}
}
}
IvyNode[] evictions = report.getEvictedNodes();
for (int i = 0; i < evictions.length; i++) {
IvyNode eviction = evictions[i];
IvyNodeElement evictionElement = new IvyNodeElement();
evictionElement.setModuleRevisionId(eviction.getResolvedId());
evictionElement.setEvicted(true);
IvyNodeCallers.Caller[] callers = eviction.getAllCallers();
for (int j = 0; j < callers.length; j++) {
IvyNodeElement caller = resolvedNodes.get(callers[j].getModuleRevisionId());
if (caller != null) {
evictionElement.addCaller(caller);
evictionElement.setCallerConfigurations(caller, callers[j].getCallerConfigurations());
}
}
}
// Recursively set depth starting at root
root.setDepth(0);
findConflictsBeneathNode(root);
return root;
}
use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.
the class BasicResolver method findResource.
/**
* When the resolver has many choices, this function helps choosing one
*
* @param rress
* the list of resolved resource which the resolver found to fit the requirement
* @param rmdparser
* the parser of module descriptor
* @param mrid
* the module being resolved
* @param date
* the current date
* @return the selected resource
*/
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
String name = getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ResolvedResource found = null;
List<ArtifactInfo> sorted = getLatestStrategy().sort(rress);
List<String> rejected = new ArrayList<>();
List<ModuleRevisionId> foundBlacklisted = new ArrayList<>();
IvyContext context = IvyContext.getContext();
ListIterator<ArtifactInfo> iter = sorted.listIterator(sorted.size());
while (iter.hasPrevious()) {
ResolvedResource rres = (ResolvedResource) iter.previous();
// name, blacklisting and first level version matching
if (filterNames(new ArrayList<>(Collections.singleton(rres.getRevision()))).isEmpty()) {
Message.debug("\t" + name + ": filtered by name: " + rres);
continue;
}
ModuleRevisionId foundMrid = ModuleRevisionId.newInstance(mrid, rres.getRevision());
ResolveData data = context.getResolveData();
if (data != null && data.getReport() != null && data.isBlacklisted(data.getReport().getConfiguration(), foundMrid)) {
Message.debug("\t" + name + ": blacklisted: " + rres);
rejected.add(rres.getRevision() + " (blacklisted)");
foundBlacklisted.add(foundMrid);
continue;
}
if (!versionMatcher.accept(mrid, foundMrid)) {
Message.debug("\t" + name + ": rejected by version matcher: " + rres);
rejected.add(rres.getRevision());
continue;
}
if (rres.getResource() != null && !rres.getResource().exists()) {
Message.debug("\t" + name + ": unreachable: " + rres + "; res=" + rres.getResource());
rejected.add(rres.getRevision() + " (unreachable)");
continue;
}
if (date != null && rres.getLastModified() > date.getTime()) {
Message.verbose("\t" + name + ": too young: " + rres);
rejected.add(rres.getRevision() + " (" + rres.getLastModified() + ")");
continue;
}
if (versionMatcher.needModuleDescriptor(mrid, foundMrid)) {
ResolvedResource r = rmdparser.parse(rres.getResource(), rres.getRevision());
if (r == null) {
Message.debug("\t" + name + ": impossible to get module descriptor resource: " + rres);
rejected.add(rres.getRevision() + " (no or bad MD)");
continue;
}
ModuleDescriptor md = ((MDResolvedResource) r).getResolvedModuleRevision().getDescriptor();
if (md.isDefault()) {
Message.debug("\t" + name + ": default md rejected by version matcher" + "requiring module descriptor: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
if (!versionMatcher.accept(mrid, md)) {
Message.debug("\t" + name + ": md rejected by version matcher: " + rres);
rejected.add(rres.getRevision() + " (MD)");
continue;
}
found = r;
} else {
found = rres;
}
if (found != null) {
break;
}
}
if (found == null && !rejected.isEmpty()) {
logAttempt(rejected.toString());
}
if (found == null && !foundBlacklisted.isEmpty()) {
// all acceptable versions have been blacklisted, this means that an unsolvable conflict
// has been found
DependencyDescriptor dd = context.getDependencyDescriptor();
IvyNode parentNode = context.getResolveData().getNode(dd.getParentRevisionId());
ConflictManager cm = parentNode.getConflictManager(mrid.getModuleId());
cm.handleAllBlacklistedRevisions(dd, foundBlacklisted);
}
return found;
}
use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.
the class XmlReportWriter method outputEvictionInformation.
private void outputEvictionInformation(ConfigurationResolveReport report, PrintWriter out, IvyNode dep) {
if (dep.isEvicted(report.getConfiguration())) {
EvictionData ed = dep.getEvictedData(report.getConfiguration());
Collection<IvyNode> selected = ed.getSelected();
if (selected != null) {
for (IvyNode sel : selected) {
out.println("\t\t\t\t<evicted-by rev=\"" + XMLHelper.escape(sel.getResolvedId().getRevision()) + "\"/>");
}
}
}
}
use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.
the class IvyDependencyTree method printDependencies.
private void printDependencies(final ModuleRevisionId mrid, final List<IvyNode> dependencyList, final int indent, final Set<ModuleRevisionId> ancestors) {
for (IvyNode dependency : dependencyList) {
final Set<ModuleRevisionId> ancestorsForCurrentDep = new HashSet<>(ancestors);
// previous ancestors plus the module to whom these dependencies belong to
ancestorsForCurrentDep.add(mrid);
final boolean evicted = dependency.isEvicted(getConf());
if (evicted && !showEvicted) {
continue;
}
final boolean isLastDependency = dependencyList.indexOf(dependency) == dependencyList.size() - 1;
final StringBuilder sb = new StringBuilder();
final ModuleRevisionId dependencyMrid = dependency.getId();
final boolean circular = ancestorsForCurrentDep.contains(dependencyMrid);
if (indent > 0) {
for (int i = 0; i < indent; i++) {
if (i == indent - 1 && isLastDependency && !hasDependencies(dependency)) {
sb.append(" ");
} else {
sb.append("| ");
}
}
}
sb.append(isLastDependency ? "\\- " : "+- ");
if (!evicted && circular) {
// log and skip processing the (transitive) dependencies of this dependency
sb.append("(circularly depends on) ").append(dependencyMrid);
log(sb.toString());
continue;
} else {
sb.append(dependencyMrid.toString());
}
if (evicted && showEvicted) {
EvictionData evictedData = dependency.getEvictedData(getConf());
if (evictedData.isTransitivelyEvicted()) {
sb.append(" transitively");
} else {
sb.append(" evicted by ");
sb.append(evictedData.getSelected());
sb.append(" in ").append(evictedData.getParent());
if (evictedData.getDetail() != null) {
sb.append(" ").append(evictedData.getDetail());
}
}
}
log(sb.toString());
printDependencies(dependencyMrid, dependencies.get(dependencyMrid), indent + 1, ancestorsForCurrentDep);
}
}
use of org.apache.ivy.core.resolve.IvyNode in project ant-ivy by apache.
the class InstallEngine method install.
public ResolveReport install(ModuleRevisionId mrid, String from, String to, InstallOptions options) throws IOException {
DependencyResolver fromResolver = settings.getResolver(from);
DependencyResolver toResolver = settings.getResolver(to);
if (fromResolver == null) {
throw new IllegalArgumentException("unknown resolver " + from + ". Available resolvers are: " + settings.getResolverNames());
}
if (toResolver == null) {
throw new IllegalArgumentException("unknown resolver " + to + ". Available resolvers are: " + settings.getResolverNames());
}
PatternMatcher matcher = settings.getMatcher(options.getMatcherName());
if (matcher == null) {
throw new IllegalArgumentException("unknown matcher " + options.getMatcherName() + ". Available matchers are: " + settings.getMatcherNames());
}
// build module file declaring the dependency
Message.info(":: installing " + mrid + " ::");
DependencyResolver oldDictator = resolveEngine.getDictatorResolver();
boolean log = settings.logNotConvertedExclusionRule();
try {
settings.setLogNotConvertedExclusionRule(true);
resolveEngine.setDictatorResolver(fromResolver);
DefaultModuleDescriptor md = new DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", "1.0"), settings.getStatusManager().getDefaultStatus(), new Date());
String resolveId = ResolveOptions.getDefaultResolveId(md);
md.addConfiguration(new Configuration("default"));
md.addConflictManager(new ModuleId(ExactPatternMatcher.ANY_EXPRESSION, ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new NoConflictManager());
for (String dc : options.getConfs()) {
final String depConf = dc.trim();
if (MatcherHelper.isExact(matcher, mrid)) {
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, mrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
} else {
for (ModuleRevisionId imrid : searchEngine.listModules(fromResolver, mrid, matcher)) {
Message.info("\tfound " + imrid + " to install: adding to the list");
DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, imrid, false, false, options.isTransitive());
dd.addDependencyConfiguration("default", depConf);
md.addDependency(dd);
}
}
}
// resolve using appropriate resolver
ResolveReport report = new ResolveReport(md, resolveId);
Message.info(":: resolving dependencies ::");
ResolveOptions resolveOptions = new ResolveOptions().setResolveId(resolveId).setConfs(new String[] { "default" }).setValidate(options.isValidate());
IvyNode[] dependencies = resolveEngine.getDependencies(md, resolveOptions, report);
report.setDependencies(Arrays.asList(dependencies), options.getArtifactFilter());
Message.info(":: downloading artifacts to cache ::");
resolveEngine.downloadArtifacts(report, options.getArtifactFilter(), new DownloadOptions());
// now that everything is in cache, we can publish all these modules
Message.info(":: installing in " + to + " ::");
for (IvyNode dependency : dependencies) {
ModuleDescriptor depmd = dependency.getDescriptor();
if (depmd != null) {
ModuleRevisionId depMrid = depmd.getModuleRevisionId();
Message.verbose("installing " + depMrid);
boolean successfullyPublished = false;
try {
toResolver.beginPublishTransaction(depMrid, options.isOverwrite());
// publish artifacts
for (ArtifactDownloadReport artifact : report.getArtifactsReports(depMrid)) {
if (artifact.getLocalFile() != null) {
toResolver.publish(artifact.getArtifact(), artifact.getLocalFile(), options.isOverwrite());
}
}
// publish metadata
MetadataArtifactDownloadReport artifactDownloadReport = dependency.getModuleRevision().getReport();
File localIvyFile = artifactDownloadReport.getLocalFile();
toResolver.publish(depmd.getMetadataArtifact(), localIvyFile, options.isOverwrite());
if (options.isInstallOriginalMetadata()) {
if (artifactDownloadReport.getArtifactOrigin() != null && artifactDownloadReport.getArtifactOrigin().isExists() && !ArtifactOrigin.isUnknown(artifactDownloadReport.getArtifactOrigin()) && artifactDownloadReport.getArtifactOrigin().getArtifact() != null && artifactDownloadReport.getArtifactOrigin().getArtifact().getType().endsWith(".original") && !artifactDownloadReport.getArtifactOrigin().getArtifact().getType().equals(depmd.getMetadataArtifact().getType() + ".original")) {
// publish original metadata artifact, too, as it has a different
// type
toResolver.publish(artifactDownloadReport.getArtifactOrigin().getArtifact(), artifactDownloadReport.getOriginalLocalFile(), options.isOverwrite());
}
}
// end module publish
toResolver.commitPublishTransaction();
successfullyPublished = true;
} finally {
if (!successfullyPublished) {
toResolver.abortPublishTransaction();
}
}
}
}
Message.info(":: install resolution report ::");
// output report
resolveEngine.outputReport(report, settings.getResolutionCacheManager(), resolveOptions);
return report;
} finally {
// IVY-834: log the problems if there were any...
Message.sumupProblems();
resolveEngine.setDictatorResolver(oldDictator);
settings.setLogNotConvertedExclusionRule(log);
}
}
Aggregations