use of org.osgi.framework.wiring.BundleRevision in project karaf by apache.
the class BundleInfoImpl method populateFragementInfos.
private void populateFragementInfos(Bundle bundle) {
this.isFragment = bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
this.fragments = new ArrayList<>();
this.fragmentHosts = new ArrayList<>();
BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
if (revisions == null) {
return;
}
for (BundleRevision revision : revisions.getRevisions()) {
if (revision.getWiring() != null) {
getFragments(revision);
getFragmentHosts(revision);
}
}
}
use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class SubsystemResource method findContent.
private Resource findContent(Requirement requirement) throws BundleException, IOException, InvalidSyntaxException, URISyntaxException {
Map<Requirement, Collection<Capability>> map;
// the case of a persisted subsystem.
if (isUnscoped()) {
map = Activator.getInstance().getSystemRepository().findProviders(Collections.singleton(requirement));
if (map.containsKey(requirement)) {
Collection<Capability> capabilities = map.get(requirement);
for (Capability capability : capabilities) {
Resource provider = capability.getResource();
if (provider instanceof BundleRevision) {
if (getRegion().contains(((BundleRevision) provider).getBundle())) {
return provider;
}
} else if (provider instanceof BasicSubsystem) {
if (getRegion().equals(((BasicSubsystem) provider).getRegion())) {
return provider;
}
}
}
}
}
// First search the local repository.
map = resource.getLocalRepository().findProviders(Collections.singleton(requirement));
Collection<Capability> capabilities = map.get(requirement);
if (capabilities.isEmpty()) {
// Nothing found in the local repository so search the repository services.
capabilities = new RepositoryServiceRepository().findProviders(requirement);
}
if (capabilities.isEmpty()) {
// Nothing found period.
return null;
}
for (Capability capability : capabilities) {
if (!IdentityNamespace.TYPE_FRAGMENT.equals(capability.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE))) {
// See ARIES-1425.
return capability.getResource();
}
}
// Nothing here but fragment bundles. Return the first one.
return capabilities.iterator().next().getResource();
}
use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class WovenClassListener method modified.
@Override
public void modified(WovenClass wovenClass) {
if (wovenClass.getState() != WovenClass.TRANSFORMED) {
// the defined state is reached.
return;
}
List<String> dynamicImports = wovenClass.getDynamicImports();
if (dynamicImports.isEmpty()) {
// Nothing to do if there are no dynamic imports.
return;
}
BundleWiring wiring = wovenClass.getBundleWiring();
Bundle bundle = wiring.getBundle();
BundleRevision revision = bundle.adapt(BundleRevision.class);
BundleConstituent constituent = new BundleConstituent(null, revision);
Collection<BasicSubsystem> basicSubsystems = subsystems.getSubsystemsByConstituent(constituent);
BasicSubsystem subsystem = basicSubsystems.iterator().next();
// Find the scoped subsystem in the region.
subsystem = scopedSubsystem(subsystem);
if (subsystem.getSubsystemId() == 0) {
// The root subsystem needs no sharing policy.
return;
}
if (EnumSet.of(Subsystem.State.INSTALLING, Subsystem.State.INSTALLED).contains(subsystem.getState())) {
// The scoped subsystem must be resolved before adding dynamic
// package imports to the sharing policy in order to minimize
// unpredictable wirings. Resolving the scoped subsystem will also
// resolve all of the unscoped subsystems in the region.
AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.RESOLVE_ONLY));
}
Bundle systemBundle = context.getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
// The following map tracks all of the necessary updates as each dynamic
// import is processed. The key is the tail region of the connection
// whose filter needs updating.
Map<Region, RegionUpdaterInfo> updates = new HashMap<Region, RegionUpdaterInfo>();
for (String dynamicImport : dynamicImports) {
// For each dynamic import, collect the necessary update information.
DynamicImportPackageHeader header = new DynamicImportPackageHeader(dynamicImport);
List<DynamicImportPackageRequirement> requirements = header.toRequirements(revision);
for (DynamicImportPackageRequirement requirement : requirements) {
Collection<BundleCapability> providers = frameworkWiring.findProviders(requirement);
if (providers.isEmpty()) {
// import, no updates are made.
continue;
}
addSharingPolicyUpdates(requirement, subsystem, providers, updates);
}
}
// Now update each sharing policy only once.
for (RegionUpdaterInfo update : updates.values()) {
RegionUpdater updater = new RegionUpdater(update.tail(), update.head());
try {
updater.addRequirements(update.requirements());
} catch (IllegalStateException e) {
// Something outside of the subsystems implementation has
// deleted the edge between the parent and child subsystems.
// Assume the dynamic import sharing policy is being handled
// elsewhere. See ARIES-1429.
} catch (Exception e) {
throw new SubsystemException(e);
}
}
}
use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class SystemRepository method addingBundle.
@Override
public AtomicReference<BundleRevisionResource> addingBundle(Bundle bundle, BundleEvent event) {
// The state mask must guarantee this will only be called when the bundle is in the INSTALLED state.
BundleRevision revision = bundle.adapt(BundleRevision.class);
BundleRevisionResource resource = new BundleRevisionResource(revision);
if (ThreadLocalSubsystem.get() == null) {
// This is an explicitly installed bundle. It must be prevented
// from resolving as part of adding it to the repository. Searching
// for service requirements and capabilities will result in a call
// to findEntries which will cause the framework to attempt a
// resolution.
ThreadLocalBundleRevision.set(revision);
try {
repository.addResource(resource);
} finally {
ThreadLocalBundleRevision.remove();
}
} else {
// If this is a bundle being installed as part of a subsystem
// installation, it is already protected.
repository.addResource(resource);
}
return new AtomicReference<BundleRevisionResource>(resource);
}
use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class SystemRepository method modifiedBundle.
@Override
public void modifiedBundle(Bundle bundle, BundleEvent event, AtomicReference<BundleRevisionResource> object) {
if (BundleEvent.UPDATED == event.getType()) {
BundleRevision revision = bundle.adapt(BundleRevision.class);
BundleRevisionResource resource = new BundleRevisionResource(revision);
repository.removeResource(object.getAndSet(resource));
repository.addResource(resource);
}
}
Aggregations