use of org.apache.ivy.core.resolve.ResolveData 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.ResolveData in project ant-ivy by apache.
the class ChainResolver method getDependency.
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
data = new ResolveData(data, doValidate(data));
List<Exception> errors = new ArrayList<>();
ResolvedModuleRevision resolved = data.getCurrentResolvedModuleRevision();
ResolvedModuleRevision mr = resolved;
if (mr == null) {
Message.verbose(getName() + ": Checking cache for: " + dd);
mr = findModuleInCache(dd, data, true);
if (mr != null) {
Message.verbose(getName() + ": module revision found in cache: " + mr.getId());
mr = forcedRevision(mr);
}
}
for (DependencyResolver resolver : chain) {
LatestStrategy oldLatest = setLatestIfRequired(resolver, getLatestStrategy());
try {
ResolvedModuleRevision previouslyResolved = mr;
data.setCurrentResolvedModuleRevision(previouslyResolved);
mr = resolver.getDependency(dd, data);
if (mr != previouslyResolved && isReturnFirst()) {
mr = forcedRevision(mr);
}
} catch (Exception ex) {
Message.verbose("problem occurred while resolving " + dd + " with " + resolver, ex);
errors.add(ex);
} finally {
if (oldLatest != null) {
setLatest(resolver, oldLatest);
}
}
checkInterrupted();
}
if (mr == null && !errors.isEmpty()) {
if (errors.size() == 1) {
Exception ex = errors.get(0);
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else if (ex instanceof ParseException) {
throw (ParseException) ex;
} else {
throw new RuntimeException(ex.toString(), ex);
}
} else {
StringBuilder err = new StringBuilder();
for (Exception ex : errors) {
err.append("\t").append(StringUtils.getErrorMessage(ex)).append("\n");
}
err.setLength(err.length() - 1);
throw new RuntimeException("several problems occurred while resolving " + dd + ":\n" + err);
}
}
if (resolved == mr) {
// nothing has actually been resolved here, we don't need to touch the returned rmr
return resolved;
}
return resolvedRevision(mr);
}
use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class DualResolver method getDependency.
public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
if (ivyResolver == null || artifactResolver == null) {
throw new IllegalStateException("exactly two resolvers must be added: ivy(1) and artifact(2) one");
}
ResolvedModuleRevision resolved = data.getCurrentResolvedModuleRevision();
data = new ResolveData(data, doValidate(data));
final ResolvedModuleRevision mr = ivyResolver.getDependency(dd, data);
if (mr == null) {
checkInterrupted();
if (isAllownomd()) {
Message.verbose("ivy resolver didn't find " + dd + ": trying with artifact resolver");
return artifactResolver.getDependency(dd, data);
} else {
return null;
}
} else {
if (mr == resolved) {
// nothing has actually been resolved here, we don't need to touch the returned rmr
return mr;
}
return new ResolvedModuleRevision(mr.getResolver(), this, mr.getDescriptor(), mr.getReport(), mr.isForce());
}
}
use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class LatestCompatibleConflictManager method handleAllBlacklistedRevisions.
@Override
public void handleAllBlacklistedRevisions(DependencyDescriptor dd, Collection<ModuleRevisionId> foundBlacklisted) {
ResolveData resolveData = IvyContext.getContext().getResolveData();
Collection<IvyNode> blacklisted = new HashSet<>();
for (ModuleRevisionId mrid : foundBlacklisted) {
blacklisted.add(resolveData.getNode(mrid));
}
for (IvyNode node : blacklisted) {
IvyNodeBlacklist bdata = node.getBlacklistData(resolveData.getReport().getConfiguration());
handleUnsolvableConflict(bdata.getConflictParent(), Arrays.asList(bdata.getEvictedNode(), bdata.getSelectedNode()), bdata.getEvictedNode(), bdata.getSelectedNode());
}
}
use of org.apache.ivy.core.resolve.ResolveData in project ant-ivy by apache.
the class AbstractLogCircularDependencyStrategy method getCircularDependencyId.
protected String getCircularDependencyId(ModuleRevisionId[] mrids) {
String contextPrefix = "";
ResolveData data = IvyContext.getContext().getResolveData();
if (data != null) {
contextPrefix = data.getOptions().getResolveId() + " ";
}
return contextPrefix + Arrays.asList(mrids);
}
Aggregations