Search in sources :

Example 1 with ModelledBundleResource

use of org.apache.aries.application.resolver.obr.ext.ModelledBundleResource in project aries by apache.

the class OBRAriesResolver method doResolve.

private Collection<ModelledResource> doResolve(Resolver obrResolver, String appName) throws ResolverException {
    log.debug(LOG_ENTRY, "doResolve");
    Collection<ModelledResource> toReturn = new ArrayList<ModelledResource>();
    if (obrResolver.resolve()) {
        List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
        if (requiredResources == null) {
            log.debug("resolver.getRequiredResources() returned null");
        } else {
            for (Resource r : requiredResources) {
                Map<String, String> attribs = new HashMap<String, String>();
                attribs.put(Constants.VERSION_ATTRIBUTE, "[" + r.getVersion() + ',' + r.getVersion() + "]");
                ModelledResource modelledResourceForThisMatch = null;
                // list of packages available in the target runtime environment. If the resource has no symbolic name, we can ignore it
                if (r.getSymbolicName() != null) {
                    try {
                        modelledResourceForThisMatch = new ModelledBundleResource(r, modellingManager, modellingHelper);
                    } catch (InvalidAttributeException iax) {
                        ResolverException re = new ResolverException("Internal error occurred: " + iax);
                        log.debug(LOG_EXIT, "doResolve", re);
                        throw re;
                    }
                    toReturn.add(modelledResourceForThisMatch);
                }
            }
        }
        log.debug(LOG_EXIT, toReturn);
        return toReturn;
    } else {
        Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
        // let's refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied packages or other bundles
        Map<String, Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver, reasons);
        StringBuffer reqList = new StringBuffer();
        Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
        for (String reason : unsatisfiedRequirements.keySet()) {
            reqList.append('\n');
            reqList.append(reason);
        }
        ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE", new Object[] { appName, reqList }));
        re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
        log.debug(LOG_EXIT, "doResolve", re);
        throw re;
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) Set(java.util.Set) HashSet(java.util.HashSet) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 ResolverException (org.apache.aries.application.management.ResolverException)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)1 Reason (org.apache.felix.bundlerepository.Reason)1 Resource (org.apache.felix.bundlerepository.Resource)1