Search in sources :

Example 1 with ResolveData

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;
}
Also used : DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ArrayList(java.util.ArrayList) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolveData(org.apache.ivy.core.resolve.ResolveData) 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) ArtifactInfo(org.apache.ivy.plugins.latest.ArtifactInfo) VersionMatcher(org.apache.ivy.plugins.version.VersionMatcher) IvyContext(org.apache.ivy.core.IvyContext) ConflictManager(org.apache.ivy.plugins.conflict.ConflictManager) IvyNode(org.apache.ivy.core.resolve.IvyNode)

Example 2 with ResolveData

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);
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) ArrayList(java.util.ArrayList) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) HasLatestStrategy(org.apache.ivy.plugins.resolver.util.HasLatestStrategy) LatestStrategy(org.apache.ivy.plugins.latest.LatestStrategy) ParseException(java.text.ParseException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 3 with ResolveData

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());
    }
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision)

Example 4 with ResolveData

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());
    }
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) IvyNodeBlacklist(org.apache.ivy.core.resolve.IvyNodeBlacklist) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IvyNode(org.apache.ivy.core.resolve.IvyNode) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with ResolveData

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);
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData)

Aggregations

ResolveData (org.apache.ivy.core.resolve.ResolveData)33 ResolveOptions (org.apache.ivy.core.resolve.ResolveOptions)19 IvySettings (org.apache.ivy.core.settings.IvySettings)18 Before (org.junit.Before)16 ResolveEngine (org.apache.ivy.core.resolve.ResolveEngine)14 EventManager (org.apache.ivy.core.event.EventManager)13 SortEngine (org.apache.ivy.core.sort.SortEngine)13 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)11 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)11 File (java.io.File)10 IOException (java.io.IOException)10 ParseException (java.text.ParseException)10 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)10 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)9 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)8 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)8 Test (org.junit.Test)8 Ivy (org.apache.ivy.Ivy)5 RepositoryCacheManager (org.apache.ivy.core.cache.RepositoryCacheManager)5 ArrayList (java.util.ArrayList)2