use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.
the class BundleResourceUninstaller method uninstall.
public void uninstall() {
removeReference();
// Always remove the bundle as a constituent of the subsystem being
// acted upon. The bundle may or may not actually be a constituent.
// This covers the case of unscoped subsystems with shared content
// where the resource may not be uninstallable.
removeConstituent(subsystem, new BundleConstituent(null, (BundleRevision) resource));
if (!isResourceUninstallable())
return;
// If the resource is uninstallable, remove it from the "provisioned to"
// subsystem in case it was a dependency. The "provisioned to" subsystem
// may be the same subsystem as the one being acted upon. This covers
// the case where a dependency of the subsystem being acted upon was
// provisioned to another subsystem but is not content of the other
// subsystem.
removeConstituent(provisionTo, new BundleConstituent(null, (BundleRevision) resource));
if (isBundleUninstallable())
uninstallBundle();
}
use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.
the class ResolveContext method addWiring.
private void addWiring(Resource resource, Map<Resource, Wiring> wirings) {
if (resource instanceof BundleConstituent) {
BundleConstituent bc = (BundleConstituent) resource;
BundleWiring wiring = bc.getWiring();
if (wiring != null) {
wirings.put(bc.getBundle().adapt(BundleRevision.class), wiring);
}
} else if (resource instanceof BundleRevision) {
BundleRevision br = (BundleRevision) resource;
BundleWiring wiring = br.getWiring();
if (wiring != null) {
wirings.put(br, wiring);
}
}
}
use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.
the class ResolveContext method installDependenciesOfRequirerIfNecessary.
private void installDependenciesOfRequirerIfNecessary(Requirement requirement) {
if (requirement == null) {
return;
}
Resource requirer = requirement.getResource();
if (resource.equals(requirer)) {
return;
}
Collection<BasicSubsystem> subsystems;
if (requirer instanceof BasicSubsystem) {
BasicSubsystem subsystem = (BasicSubsystem) requirer;
subsystems = Collections.singletonList(subsystem);
} else if (requirer instanceof BundleRevision) {
BundleRevision revision = (BundleRevision) requirer;
BundleConstituent constituent = new BundleConstituent(null, revision);
subsystems = Activator.getInstance().getSubsystems().getSubsystemsByConstituent(constituent);
} else {
return;
}
for (BasicSubsystem subsystem : subsystems) {
if (Utils.isProvisionDependenciesInstall(subsystem) || !State.INSTALLING.equals(subsystem.getState())) {
continue;
}
AccessController.doPrivileged(new StartAction(subsystem, subsystem, subsystem, Restriction.INSTALL_ONLY));
}
}
use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent in project aries by apache.
the class BundleEventHook method handleUninstalledEvent.
@SuppressWarnings("unchecked")
private void handleUninstalledEvent(BundleEvent event) {
Bundle bundle = event.getBundle();
BundleRevision revision = bundleToRevision.remove(bundle);
if (ThreadLocalSubsystem.get() != null || (revision == null ? false : // Region context bundles must be treated as explicit installations.
revision.getSymbolicName().startsWith(Constants.RegionContextBundleSymbolicNamePrefix))) {
return;
}
Collection<BasicSubsystem> subsystems;
if (revision == null) {
// The bundle was installed while the bundle event hook was unregistered.
Object[] o = activator.getSubsystems().getSubsystemsByBundle(bundle);
if (o == null)
return;
revision = (BundleRevision) o[0];
subsystems = (Collection<BasicSubsystem>) o[1];
} else {
subsystems = activator.getSubsystems().getSubsystemsByConstituent(new BundleConstituent(null, revision));
}
for (BasicSubsystem subsystem : subsystems) {
ResourceUninstaller.newInstance(revision, subsystem).uninstall();
}
}
use of org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent 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);
}
}
}
Aggregations