Search in sources :

Example 1 with MDResolvedResource

use of org.apache.ivy.plugins.resolver.util.MDResolvedResource 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 MDResolvedResource

use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.

the class BasicResolver method getDependency.

public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
    IvyContext context = IvyContext.pushNewCopyContext();
    try {
        ResolvedModuleRevision mr = data.getCurrentResolvedModuleRevision();
        if (mr != null && shouldReturnResolvedModule(dd, mr)) {
            return mr;
        }
        if (isForce()) {
            dd = dd.clone(ModuleRevisionId.newInstance(dd.getDependencyRevisionId(), "latest.integration"));
        }
        DependencyDescriptor systemDd = dd;
        DependencyDescriptor nsDd = fromSystem(dd);
        context.setDependencyDescriptor(systemDd);
        context.setResolveData(data);
        clearIvyAttempts();
        clearArtifactAttempts();
        ModuleRevisionId systemMrid = systemDd.getDependencyRevisionId();
        ModuleRevisionId nsMrid = nsDd.getDependencyRevisionId();
        checkRevision(systemMrid);
        boolean isDynamic = getAndCheckIsDynamic(systemMrid);
        // we first search for the dependency in cache
        ResolvedModuleRevision rmr = findModuleInCache(systemDd, data);
        if (rmr != null) {
            if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
                Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but it's a default one, maybe we can find a better one");
            } else if (isForce() && rmr.getResolver() != this) {
                Message.verbose("\t" + getName() + ": found revision in cache: " + systemMrid + " (resolved by " + rmr.getResolver().getName() + "): but we are in force mode, let's try to find one ourselves");
            } else {
                Message.verbose("\t" + getName() + ": revision in cache: " + systemMrid);
                return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
            }
        }
        if (data.getOptions().isUseCacheOnly()) {
            throw new UnresolvedDependencyException("\t" + getName() + " (useCacheOnly) : no ivy file found for " + systemMrid, false);
        }
        checkInterrupted();
        ResolvedResource ivyRef = findIvyFileRef(nsDd, data);
        checkInterrupted();
        // get module descriptor
        ModuleDescriptor nsMd;
        ModuleDescriptor systemMd = null;
        if (ivyRef == null) {
            if (!isAllownomd()) {
                throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file found for " + systemMrid, false);
            }
            nsMd = DefaultModuleDescriptor.newDefaultInstance(nsMrid, nsDd.getAllDependencyArtifacts());
            ResolvedResource artifactRef = findFirstArtifactRef(nsMd, nsDd, data);
            checkInterrupted();
            if (artifactRef == null) {
                throw new UnresolvedDependencyException("\t" + getName() + ": no ivy file nor artifact found for " + systemMrid, false);
            }
            long lastModified = artifactRef.getLastModified();
            if (lastModified != 0 && nsMd instanceof DefaultModuleDescriptor) {
                ((DefaultModuleDescriptor) nsMd).setLastModified(lastModified);
            }
            Message.verbose("\t" + getName() + ": no ivy file found for " + systemMrid + ": using default data");
            if (isDynamic) {
                nsMd.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(nsMrid, artifactRef.getRevision()));
            }
            systemMd = toSystem(nsMd);
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(systemMd.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            rmr = new ResolvedModuleRevision(this, this, systemMd, madr, isForce());
            getRepositoryCacheManager().cacheModuleDescriptor(this, artifactRef, toSystem(dd), systemMd.getAllArtifacts()[0], null, getCacheOptions(data));
        } else {
            if (ivyRef instanceof MDResolvedResource) {
                rmr = ((MDResolvedResource) ivyRef).getResolvedModuleRevision();
            }
            if (rmr == null) {
                rmr = parse(ivyRef, systemDd, data);
                if (rmr == null) {
                    throw new UnresolvedDependencyException();
                }
            }
            if (!rmr.getReport().isDownloaded() && rmr.getReport().getLocalFile() != null) {
                return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
            }
            nsMd = rmr.getDescriptor();
            // check descriptor data is in sync with resource revision and names
            systemMd = toSystem(nsMd);
            if (isCheckconsistency()) {
                checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
                checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
            } else {
                if (systemMd instanceof DefaultModuleDescriptor) {
                    DefaultModuleDescriptor defaultMd = (DefaultModuleDescriptor) systemMd;
                    ModuleRevisionId revision = getRevision(ivyRef, systemMrid, systemMd);
                    defaultMd.setModuleRevisionId(revision);
                    defaultMd.setResolvedModuleRevisionId(revision);
                } else {
                    Message.warn("consistency disabled with instance of non DefaultModuleDescriptor... module info can't be updated, so consistency check will be done");
                    checkDescriptorConsistency(nsMrid, nsMd, ivyRef);
                    checkDescriptorConsistency(systemMrid, systemMd, ivyRef);
                }
            }
            rmr = new ResolvedModuleRevision(this, this, systemMd, toSystem(rmr.getReport()), isForce());
        }
        resolveAndCheckRevision(systemMd, systemMrid, ivyRef, isDynamic);
        resolveAndCheckPublicationDate(systemDd, systemMd, systemMrid, data);
        checkNotConvertedExclusionRule(systemMd, ivyRef, data);
        if (ivyRef == null || ivyRef.getResource() != null) {
            cacheModuleDescriptor(systemMd, systemMrid, ivyRef, rmr);
        }
        return checkLatest(systemDd, checkForcedResolvedModuleRevision(rmr), data);
    } catch (UnresolvedDependencyException ex) {
        if (!ex.getMessage().isEmpty()) {
            if (ex.isError()) {
                Message.error(ex.getMessage());
            } else {
                Message.verbose(ex.getMessage());
            }
        }
        return data.getCurrentResolvedModuleRevision();
    } finally {
        IvyContext.popContext();
    }
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) IvyContext(org.apache.ivy.core.IvyContext) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 3 with MDResolvedResource

use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.

the class BasicResolver method getDefaultRMDParser.

protected ResourceMDParser getDefaultRMDParser(final ModuleId mid) {
    return new ResourceMDParser() {

        public MDResolvedResource parse(Resource resource, String rev) {
            DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(new ModuleRevisionId(mid, rev));
            MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(md.getMetadataArtifact());
            madr.setDownloadStatus(DownloadStatus.NO);
            madr.setSearched(true);
            return new MDResolvedResource(resource, rev, new ResolvedModuleRevision(BasicResolver.this, BasicResolver.this, md, madr, isForce()));
        }
    };
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResourceMDParser(org.apache.ivy.plugins.resolver.util.ResourceMDParser) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) Resource(org.apache.ivy.plugins.repository.Resource) FileResource(org.apache.ivy.plugins.repository.file.FileResource) URLResource(org.apache.ivy.plugins.repository.url.URLResource) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 4 with MDResolvedResource

use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.

the class AbstractOSGiResolver method buildResolvedCapabilityMd.

private MDResolvedResource buildResolvedCapabilityMd(DependencyDescriptor dd, ModuleDescriptor md) {
    String org = dd.getDependencyRevisionId().getOrganisation();
    String name = dd.getDependencyRevisionId().getName();
    String rev = md.getExtraInfoContentByTagName(BundleInfoAdapter.EXTRA_INFO_EXPORT_PREFIX + name);
    ModuleRevisionId capabilityRev = ModuleRevisionId.newInstance(org, name, rev, Collections.singletonMap(CAPABILITY_EXTRA_ATTR, md.getModuleRevisionId().toString()));
    DefaultModuleDescriptor capabilityMd = new DefaultModuleDescriptor(capabilityRev, getSettings().getStatusManager().getDefaultStatus(), new Date());
    String useConf = BundleInfoAdapter.CONF_USE_PREFIX + dd.getDependencyRevisionId().getName();
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_DEFAULT);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_OPTIONAL);
    capabilityMd.addConfiguration(BundleInfoAdapter.CONF_TRANSITIVE_OPTIONAL);
    capabilityMd.addConfiguration(new Configuration(useConf));
    DefaultDependencyDescriptor capabilityDD = new DefaultDependencyDescriptor(md.getModuleRevisionId(), false);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_DEFAULT, BundleInfoAdapter.CONF_NAME_DEFAULT);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_OPTIONAL, BundleInfoAdapter.CONF_NAME_OPTIONAL);
    capabilityDD.addDependencyConfiguration(BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL, BundleInfoAdapter.CONF_NAME_TRANSITIVE_OPTIONAL);
    capabilityDD.addDependencyConfiguration(useConf, useConf);
    capabilityMd.addDependency(capabilityDD);
    MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
    report.setDownloadStatus(DownloadStatus.NO);
    report.setSearched(true);
    ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, capabilityMd, report);
    return new MDResolvedResource(null, capabilityMd.getRevision(), rmr);
}
Also used : MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) Configuration(org.apache.ivy.core.module.descriptor.Configuration) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) DefaultDependencyDescriptor(org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) Date(java.util.Date) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Example 5 with MDResolvedResource

use of org.apache.ivy.plugins.resolver.util.MDResolvedResource in project ant-ivy by apache.

the class AbstractOSGiResolver method findBundle.

public ResolvedResource[] findBundle(DependencyDescriptor dd, ResolveData data, Collection<ModuleDescriptor> mds) {
    ResolvedResource[] ret = new ResolvedResource[mds.size()];
    int i = 0;
    for (ModuleDescriptor md : mds) {
        MetadataArtifactDownloadReport report = new MetadataArtifactDownloadReport(null);
        report.setDownloadStatus(DownloadStatus.NO);
        report.setSearched(true);
        ResolvedModuleRevision rmr = new ResolvedModuleRevision(this, this, md, report);
        MDResolvedResource mdrr = new MDResolvedResource(null, md.getRevision(), rmr);
        ret[i++] = mdrr;
    }
    return ret;
}
Also used : DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) MetadataArtifactDownloadReport(org.apache.ivy.core.report.MetadataArtifactDownloadReport) ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource)

Aggregations

MDResolvedResource (org.apache.ivy.plugins.resolver.util.MDResolvedResource)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)5 ResolvedResource (org.apache.ivy.plugins.resolver.util.ResolvedResource)5 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)4 MetadataArtifactDownloadReport (org.apache.ivy.core.report.MetadataArtifactDownloadReport)4 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)4 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)3 ArrayList (java.util.ArrayList)2 IvyContext (org.apache.ivy.core.IvyContext)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Configuration (org.apache.ivy.core.module.descriptor.Configuration)1 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)1 IvyNode (org.apache.ivy.core.resolve.IvyNode)1 ResolveData (org.apache.ivy.core.resolve.ResolveData)1 ConflictManager (org.apache.ivy.plugins.conflict.ConflictManager)1 ArtifactInfo (org.apache.ivy.plugins.latest.ArtifactInfo)1