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);
}
}
use of org.osgi.framework.wiring.BundleRevision in project aries by apache.
the class BundleRevisionResourceTest method testNoModellerServiceRequirements.
@Test
public void testNoModellerServiceRequirements() {
BundleRevision br = EasyMock.createNiceMock(BundleRevision.class);
expect(br.getRequirements(anyObject(String.class))).andReturn(Collections.<Requirement>emptyList());
expect(br.getCapabilities(anyObject(String.class))).andReturn(Collections.<Capability>emptyList());
replay(br);
BundleRevisionResource brr = new BundleRevisionResource(br);
assertEquals(0, brr.getRequirements("osgi.service").size());
}
use of org.osgi.framework.wiring.BundleRevision in project karaf by apache.
the class Builder method resolve.
private Map<String, Integer> resolve(DownloadManager manager, Resolver resolver, Collection<Features> repositories, Collection<String> features, Collection<String> bundles, Collection<String> overrides, Collection<String> optionals) throws Exception {
BundleRevision systemBundle = getSystemBundle();
AssemblyDeployCallback callback = new AssemblyDeployCallback(manager, this, systemBundle, repositories);
Deployer deployer = new Deployer(manager, resolver, callback, callback);
// Install framework
Deployer.DeploymentRequest request = createDeploymentRequest();
// Add overrides
request.overrides.addAll(overrides);
// Add optional resources
final List<Resource> resources = new ArrayList<>();
Downloader downloader = manager.createDownloader();
for (String optional : optionals) {
downloader.download(optional, provider -> {
Resource resource = ResourceBuilder.build(provider.getUrl(), getHeaders(provider));
synchronized (resources) {
resources.add(resource);
}
});
}
downloader.await();
request.globalRepository = new BaseRepository(resources);
// Install features
for (String feature : features) {
MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, feature);
}
for (String bundle : bundles) {
MapUtils.addToMapSet(request.requirements, FeaturesService.ROOT_REGION, "bundle:" + bundle);
}
Set<String> prereqs = new HashSet<>();
while (true) {
try {
deployer.deploy(callback.getDeploymentState(), request);
break;
} catch (Deployer.PartialDeploymentException e) {
if (!prereqs.containsAll(e.getMissing())) {
prereqs.addAll(e.getMissing());
} else {
throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
}
}
}
return callback.getStartupBundles();
}
Aggregations