[
https://issues.apache.org/jira/browse/FELIX-6015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16737360#comment-16737360
]
Cristiano Gavião commented on FELIX-6015:
-----------------------------------------
The Resource I'm providing initially doesn't have a host requirement because we
don't know up front that it is a fragment. I'm using a json that the container
retrieves at startup to initiate the provisioning service in the container.
In this json file I just inform the symbolicname and version of all jars.
Maybe I'm wrong, but to me doesn't make sense to know, at this time, details as
host requirements, because we just see jars in the file system.
Following your suggestion, in the ResolveContext getMandatoryResources() I use
FrameworkWiring. findProviders() to discover whether the resource is already
installed and if it is not I just create a synthetic resource object containing
a identity capability and requirements needed to search the real resource in a
repository in findProviders().
So, after that the context will know if the resource is a bundle or fragment or
any other kind of resource.
The Resolver is doing its job properly with the info I'm passing, except for a
fragment.
The json:
{noformat}
"bundles": [
{
"symbolicName": "org.eclipse.equinox.region",
"version": "1.4.300.v20181116-1551"
},
{
"symbolicName": "org.apache.aries.subsystem.core",
"version": "2.0.10"
}
{noformat}
> IndexOutOfBoundsException due a missing HostNamespace.HOST_NAMESPACE
> --------------------------------------------------------------------
>
> Key: FELIX-6015
> URL: https://issues.apache.org/jira/browse/FELIX-6015
> Project: Felix
> Issue Type: Bug
> Components: Resolver
> Affects Versions: resolver-1.16.0
> Reporter: Cristiano Gavião
> Priority: Major
>
> When creating a custom ResolveContext we need to build a collection of
> mandatory resources using the method getMandatoryResources().
> Normally we will create such collection using a custom built Resource
> containing only a IdentityNamespace.IDENTITY_NAMESPACE capability, because it
> is enough in order to search for more details of such resource in the
> installed bundles/fragments or in the registered bundle repositories inside
> the findProviders() method.
> The error that I'm getting is due the fact that the resolver, most precisely,
> the Candidates class is using getMandatoryResources() after the
> getInitialCandidates(session) been executed and inferring that it has a
> information about fragments that it doesn't have.
> {code:java}
> public Map<Resource, Resource> getRootHosts()
> {
> Map<Resource, Resource> hosts = new LinkedHashMap<Resource,
> Resource>();
> for (Resource res : *m_session.getMandatoryResources()*)
> {
> addHost(res, hosts);
> }
> for (Resource res : m_session.getOptionalResources())
> {
> if (isPopulated(res)) {
> addHost(res, hosts);
> }
> }
> return hosts;
> }
> {code}
> {code:java}
> private void addHost(Resource res, Map<Resource, Resource> hosts) {
> if (res instanceof WrappedResource)
> {
> res = ((WrappedResource) res).getDeclaredResource();
> }
> if (!Util.isFragment(res))
> {
> hosts.put(res, getWrappedHost(res));
> } else {
> // The error is happening here:
> *Requirement hostReq =
> res.getRequirements(HostNamespace.HOST_NAMESPACE).get(0);*
> Capability hostCap = getFirstCandidate(hostReq);
> // If the resource is an already resolved fragment and can not
> // be attached to new hosts, there will be no matching host,
> // so ignore this resource
> if (hostCap != null) {
> res = getWrappedHost(hostCap.getResource());
> if (res instanceof WrappedResource) {
> hosts.put(((WrappedResource) res).getDeclaredResource(),
> res);
> }
> }
> }
> }
> {code}
> Wouldn't be possible to use the processed initial candidates resources
> instead ?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)