Search in sources :

Example 6 with MDResolvedResource

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

the class AbstractOSGiResolver method findResource.

@Override
public ResolvedResource findResource(ResolvedResource[] rress, ResourceMDParser rmdparser, ModuleRevisionId mrid, Date date) {
    ResolvedResource found = super.findResource(rress, rmdparser, mrid, date);
    if (found == null) {
        return null;
    }
    String osgiType = mrid.getOrganisation();
    // for non bundle requirement : log the selected bundle
    if (!BundleInfo.BUNDLE_TYPE.equals(osgiType)) {
        // several candidates with different symbolic name : make an warning about the ambiguity
        if (rress.length != 1) {
            // several candidates with different symbolic name ?
            Map<String, List<MDResolvedResource>> matching = new HashMap<>();
            for (ResolvedResource rres : rress) {
                String name = ((MDResolvedResource) rres).getResolvedModuleRevision().getDescriptor().getExtraAttribute(CAPABILITY_EXTRA_ATTR);
                List<MDResolvedResource> list = matching.get(name);
                if (list == null) {
                    list = new ArrayList<>();
                    matching.put(name, list);
                }
                list.add((MDResolvedResource) rres);
            }
            if (matching.keySet().size() != 1) {
                if (requirementStrategy == RequirementStrategy.first) {
                    Message.warn("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
                    for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
                        Message.warn("\t" + entry.getKey());
                        for (MDResolvedResource c : entry.getValue()) {
                            Message.warn("\t\t" + c.getRevision() + (found == c ? " (selected)" : ""));
                        }
                    }
                } else if (requirementStrategy == RequirementStrategy.noambiguity) {
                    Message.error("Ambiguity for the '" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision());
                    for (Map.Entry<String, List<MDResolvedResource>> entry : matching.entrySet()) {
                        Message.error("\t" + entry.getKey());
                        for (MDResolvedResource c : entry.getValue()) {
                            Message.error("\t\t" + c.getRevision() + (found == c ? " (best match)" : ""));
                        }
                    }
                    return null;
                }
            }
        }
        Message.info("'" + osgiType + "' requirement " + mrid.getName() + ";version=" + mrid.getRevision() + " satisfied by " + ((MDResolvedResource) found).getResolvedModuleRevision().getId().getName() + ";" + found.getRevision());
    }
    return found;
}
Also used : ResolvedResource(org.apache.ivy.plugins.resolver.util.ResolvedResource) MDResolvedResource(org.apache.ivy.plugins.resolver.util.MDResolvedResource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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