Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2021-01-15 16:49:08 +0000
committerThomas Watson2021-01-15 16:49:08 +0000
commitbf36b48391737e1d37a4e0aca0f0b1f7832fc103 (patch)
treec12a8ff11dc8bca2738d80e594de897c4e1c9745
parent6680e6f0ddc3682fd79a1b2558c81202778ba3a8 (diff)
downloadrt.equinox.framework-bf36b48391737e1d37a4e0aca0f0b1f7832fc103.tar.gz
rt.equinox.framework-bf36b48391737e1d37a4e0aca0f0b1f7832fc103.tar.xz
rt.equinox.framework-bf36b48391737e1d37a4e0aca0f0b1f7832fc103.zip
Bug 570394 - Remove usage of deprecated PackageAdmin/StartLevel services
Change-Id: Ie6ed4f11fe82f0b69117c0144bbfe7149fed112b Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java30
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java26
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java170
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/StartLevelImpl.java34
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java5
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java83
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java11
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java27
8 files changed, 181 insertions, 205 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
index 04f680981..b77577cb6 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
@@ -19,6 +19,7 @@ import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -36,8 +37,6 @@ import org.eclipse.osgi.framework.log.FrameworkLogEntry;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.connect.ConnectBundleFile;
import org.eclipse.osgi.internal.debug.Debug;
-import org.eclipse.osgi.internal.framework.legacy.PackageAdminImpl;
-import org.eclipse.osgi.internal.framework.legacy.StartLevelImpl;
import org.eclipse.osgi.internal.hookregistry.ClassLoaderHook;
import org.eclipse.osgi.internal.hookregistry.HookRegistry;
import org.eclipse.osgi.internal.location.EquinoxLocations;
@@ -55,14 +54,12 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.connect.ConnectContent;
import org.osgi.framework.connect.ConnectModule;
import org.osgi.framework.connect.ModuleConnector;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
-@SuppressWarnings("deprecation")
public class EquinoxContainer implements ThreadFactory, Runnable {
public static final String NAME = "org.eclipse.osgi"; //$NON-NLS-1$
static final SecureAction secureAction = AccessController.doPrivileged(SecureAction.createSecureAction());
@@ -71,8 +68,6 @@ public class EquinoxContainer implements ThreadFactory, Runnable {
private final EquinoxConfiguration equinoxConfig;
private final EquinoxLogServices logServices;
private final Storage storage;
- private final PackageAdmin packageAdmin;
- private final StartLevel startLevel;
private final Set<String> bootDelegation;
private final String[] bootDelegationStems;
private final boolean bootDelegateAll;
@@ -114,8 +109,7 @@ public class EquinoxContainer implements ThreadFactory, Runnable {
} catch (IOException | BundleException e) {
throw new RuntimeException("Error initializing storage.", e); //$NON-NLS-1$
}
- this.packageAdmin = new PackageAdminImpl(storage.getModuleContainer());
- this.startLevel = new StartLevelImpl(storage.getModuleContainer());
+
this.eventPublisher = new EquinoxEventPublisher(this);
// set the boot delegation according to the osgi boot delegation property
@@ -179,12 +173,18 @@ public class EquinoxContainer implements ThreadFactory, Runnable {
return logServices;
}
- public PackageAdmin getPackageAdmin() {
- return packageAdmin;
- }
-
- public StartLevel getStartLevel() {
- return startLevel;
+ public Bundle getBundle(Class<?> clazz) {
+ Bundle b = FrameworkUtil.getBundle(clazz);
+ if (b != null) {
+ return b;
+ }
+ // check if it is the system bundle
+ return AccessController.doPrivileged((PrivilegedAction<Bundle>) () -> {
+ if (clazz.getClassLoader() == EquinoxContainer.class.getClassLoader()) {
+ return getStorage().getModuleContainer().getModule(0).getBundle();
+ }
+ return null;
+ });
}
public SignedContentFactory getSignedContentFactory() {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
index 44e488c18..d689d2610 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java
@@ -22,6 +22,8 @@ import org.apache.felix.resolver.Logger;
import org.apache.felix.resolver.ResolverImpl;
import org.eclipse.osgi.internal.debug.Debug;
import org.eclipse.osgi.internal.debug.FrameworkDebugOptions;
+import org.eclipse.osgi.internal.framework.legacy.PackageAdminImpl;
+import org.eclipse.osgi.internal.framework.legacy.StartLevelImpl;
import org.eclipse.osgi.internal.location.EquinoxLocations;
import org.eclipse.osgi.internal.permadmin.EquinoxSecurityManager;
import org.eclipse.osgi.internal.permadmin.SecurityAdmin;
@@ -61,14 +63,15 @@ public class SystemBundleActivator implements BundleActivator {
public void start(BundleContext bc) throws Exception {
registrations.clear();
EquinoxBundle bundle = (EquinoxBundle) bc.getBundle();
+ EquinoxContainer equinoxContainer = bundle.getEquinoxContainer();
- bundle.getEquinoxContainer().systemStart(bc);
+ equinoxContainer.systemStart(bc);
EquinoxConfiguration configuration = bundle.getEquinoxContainer().getConfiguration();
installSecurityManager(configuration);
- bundle.getEquinoxContainer().getLogServices().start(bc);
+ equinoxContainer.getLogServices().start(bc);
- urlFactoryManager = new EquinoxFactoryManager(bundle.getEquinoxContainer());
+ urlFactoryManager = new EquinoxFactoryManager(equinoxContainer);
urlFactoryManager.installHandlerFactories(bc);
FrameworkDebugOptions dbgOptions = (FrameworkDebugOptions) configuration.getDebugOptions();
@@ -79,14 +82,16 @@ public class SystemBundleActivator implements BundleActivator {
props.put(Condition.CONDITION_ID, Condition.CONDITION_ID_TRUE);
register(bc, Condition.class, Condition.INSTANCE, false, props);
- SecurityAdmin sa = bundle.getEquinoxContainer().getStorage().getSecurityAdmin();
- ClassLoader tccl = bundle.getEquinoxContainer().getContextFinder();
-
- registerLocations(bc, bundle.getEquinoxContainer().getLocations());
- register(bc, EnvironmentInfo.class, bundle.getEquinoxContainer().getConfiguration(), null);
- register(bc, PackageAdmin.class, bundle.getEquinoxContainer().getPackageAdmin(), null);
- register(bc, StartLevel.class, bundle.getEquinoxContainer().getStartLevel(), null);
+ registerLocations(bc, equinoxContainer.getLocations());
+ register(bc, EnvironmentInfo.class, equinoxContainer.getConfiguration(), null);
+ PackageAdmin packageAdmin = new PackageAdminImpl(equinoxContainer,
+ equinoxContainer.getStorage().getModuleContainer().getFrameworkWiring());
+ register(bc, PackageAdmin.class, packageAdmin, null);
+ StartLevel startLevel = new StartLevelImpl(
+ equinoxContainer.getStorage().getModuleContainer().getFrameworkStartLevel());
+ register(bc, StartLevel.class, startLevel, null);
+ SecurityAdmin sa = equinoxContainer.getStorage().getSecurityAdmin();
register(bc, PermissionAdmin.class, sa, null);
register(bc, ConditionalPermissionAdmin.class, sa, null);
@@ -97,6 +102,7 @@ public class SystemBundleActivator implements BundleActivator {
register(bc, DebugOptions.class, dbgOptions, null);
+ ClassLoader tccl = equinoxContainer.getContextFinder();
if (tccl != null) {
props.clear();
props.put("equinox.classloader.type", "contextClassLoader"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
index c6fe2c7e3..eb6f31ce8 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/PackageAdminImpl.java
@@ -14,8 +14,6 @@
package org.eclipse.osgi.internal.framework.legacy;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -25,18 +23,14 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.eclipse.osgi.container.Module;
-import org.eclipse.osgi.container.ModuleCapability;
import org.eclipse.osgi.container.ModuleContainer;
-import org.eclipse.osgi.container.ModuleRevision;
-import org.eclipse.osgi.container.ModuleWire;
import org.eclipse.osgi.container.ModuleWiring;
import org.eclipse.osgi.internal.container.Capabilities;
import org.eclipse.osgi.internal.container.InternalUtils;
import org.eclipse.osgi.internal.framework.EquinoxContainer;
+//import org.eclipse.osgi.internal.framework.EquinoxContainer;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;
import org.osgi.framework.namespace.BundleNamespace;
@@ -45,50 +39,24 @@ import org.osgi.framework.namespace.IdentityNamespace;
import org.osgi.framework.namespace.PackageNamespace;
import org.osgi.framework.wiring.BundleCapability;
import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleRevisions;
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.framework.wiring.FrameworkWiring;
import org.osgi.resource.Namespace;
import org.osgi.resource.Requirement;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.packageadmin.RequiredBundle;
-@Deprecated
+@SuppressWarnings("deprecation")
public class PackageAdminImpl implements PackageAdmin {
- private final ModuleContainer container;
-
- /*
- * We need to make sure that the GetBundleAction class loads early to prevent a ClassCircularityError when checking permissions.
- * See bug 161561
- */
- static {
- Class<?> c;
- c = GetBundleAction.class;
- c.getName(); // to prevent compiler warnings
- }
-
- static class GetBundleAction implements PrivilegedAction<Bundle> {
- private Class<?> clazz;
- private PackageAdminImpl impl;
-
- public GetBundleAction(PackageAdminImpl impl, Class<?> clazz) {
- this.impl = impl;
- this.clazz = clazz;
- }
+ private final FrameworkWiring frameworkWiring;
+ private final EquinoxContainer equinoxContainer;
- @Override
- public Bundle run() {
- return impl.getBundlePriv(clazz);
- }
- }
-
- /**
- * Constructor.
- *
- * @param container the container
- */
- public PackageAdminImpl(ModuleContainer container) {
- this.container = container;
+ public PackageAdminImpl(EquinoxContainer equinoxContainer, FrameworkWiring frameworkWiring) {
+ this.equinoxContainer = equinoxContainer;
+ this.frameworkWiring = frameworkWiring;
}
@Override
@@ -96,16 +64,16 @@ public class PackageAdminImpl implements PackageAdmin {
if (bundle == null) {
return getExportedPackages((String) null);
}
- Module module = StartLevelImpl.getModule(bundle);
- Collection<ModuleRevision> revisions = module == null ? Collections.<ModuleRevision> emptyList() : module.getRevisions().getModuleRevisions();
+
+ Collection<BundleRevision> revisions = bundle.adapt(BundleRevisions.class).getRevisions();
Collection<ExportedPackage> allExports = new ArrayList<>();
- for (ModuleRevision revision : revisions) {
- ModuleWiring wiring = revision.getWiring();
+ for (BundleRevision revision : revisions) {
+ BundleWiring wiring = revision.getWiring();
if (wiring != null) {
- List<ModuleCapability> providedPackages = wiring.getModuleCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
+ List<BundleCapability> providedPackages = wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
if (providedPackages != null) {
- for (ModuleCapability providedPackage : providedPackages) {
+ for (BundleCapability providedPackage : providedPackages) {
allExports.add(new ExportedPackageImpl(providedPackage, wiring));
}
}
@@ -142,20 +110,20 @@ public class PackageAdminImpl implements PackageAdmin {
Map<String, String> directives = Collections.<String, String> singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
Map<String, Boolean> attributes = Collections.singletonMap(Capabilities.SYNTHETIC_REQUIREMENT, Boolean.TRUE);
Requirement packageReq = ModuleContainer.createRequirement(PackageNamespace.PACKAGE_NAMESPACE, directives, attributes);
- Collection<BundleCapability> packageCaps = container.getFrameworkWiring().findProviders(packageReq);
+ Collection<BundleCapability> packageCaps = frameworkWiring.findProviders(packageReq);
InternalUtils.filterCapabilityPermissions(packageCaps);
List<ExportedPackage> result = new ArrayList<>();
for (BundleCapability capability : packageCaps) {
- ModuleWiring wiring = (ModuleWiring) capability.getRevision().getWiring();
+ BundleWiring wiring = capability.getRevision().getWiring();
if (wiring != null) {
- Collection<ModuleWiring> wirings = Collections.emptyList();
+ Collection<BundleWiring> wirings = Collections.emptyList();
if ((capability.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
// This is a fragment, just get all the host wirings
- List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
+ List<BundleWire> hostWires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);
if (hostWires != null && !hostWires.isEmpty()) {
wirings = new ArrayList<>(hostWires.size());
- for (ModuleWire hostWire : hostWires) {
- ModuleWiring hostWiring = hostWire.getProviderWiring();
+ for (BundleWire hostWire : hostWires) {
+ BundleWiring hostWiring = hostWire.getProviderWiring();
if (hostWiring != null) {
wirings.add(hostWiring);
}
@@ -165,9 +133,11 @@ public class PackageAdminImpl implements PackageAdmin {
// just a single host wiring
wirings = Collections.singletonList(wiring);
}
- for (ModuleWiring moduleWiring : wirings) {
- if (!moduleWiring.getSubstitutedNames().contains(capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
- result.add(new ExportedPackageImpl((ModuleCapability) capability, moduleWiring));
+ for (BundleWiring moduleWiring : wirings) {
+ Object pkgName = capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+ if (pkgName instanceof String
+ && !((ModuleWiring) moduleWiring).isSubstitutedPackage((String) pkgName)) {
+ result.add(new ExportedPackageImpl(capability, moduleWiring));
}
}
}
@@ -177,12 +147,12 @@ public class PackageAdminImpl implements PackageAdmin {
@Override
public void refreshPackages(Bundle[] input) {
- container.getFrameworkWiring().refreshBundles(input == null ? null : Arrays.asList(input));
+ frameworkWiring.refreshBundles(input == null ? null : Arrays.asList(input));
}
@Override
public boolean resolveBundles(Bundle[] input) {
- return container.getFrameworkWiring().resolveBundles(input == null ? null : Arrays.asList(input));
+ return frameworkWiring.resolveBundles(input == null ? null : Arrays.asList(input));
}
@Override
@@ -191,7 +161,7 @@ public class PackageAdminImpl implements PackageAdmin {
Map<String, String> directives = Collections.<String, String> singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
Map<String, Boolean> attributes = Collections.singletonMap(Capabilities.SYNTHETIC_REQUIREMENT, Boolean.TRUE);
Requirement bundleReq = ModuleContainer.createRequirement(BundleNamespace.BUNDLE_NAMESPACE, directives, attributes);
- Collection<BundleCapability> bundleCaps = container.getFrameworkWiring().findProviders(bundleReq);
+ Collection<BundleCapability> bundleCaps = frameworkWiring.findProviders(bundleReq);
InternalUtils.filterCapabilityPermissions(bundleCaps);
Collection<RequiredBundle> result = new ArrayList<>();
for (BundleCapability capability : bundleCaps) {
@@ -215,7 +185,7 @@ public class PackageAdminImpl implements PackageAdmin {
VersionRange range = versionRange == null ? null : new VersionRange(versionRange);
String filter = (range != null ? "(&" : "") + "(" + IdentityNamespace.IDENTITY_NAMESPACE + "=" + symbolicName + ")" + (range != null ? range.toFilterString(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE) + ")" : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
Requirement identityReq = ModuleContainer.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, Collections.<String, String> singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter), Collections.<String, Object> emptyMap());
- Collection<BundleCapability> identityCaps = container.getFrameworkWiring().findProviders(identityReq);
+ Collection<BundleCapability> identityCaps = frameworkWiring.findProviders(identityReq);
if (identityCaps.isEmpty()) {
return null;
@@ -244,17 +214,17 @@ public class PackageAdminImpl implements PackageAdmin {
@Override
public Bundle[] getFragments(Bundle bundle) {
- ModuleWiring wiring = getWiring(bundle);
+ BundleWiring wiring = getWiring(bundle);
if (wiring == null) {
return null;
}
- List<ModuleWire> hostWires = wiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
+ List<BundleWire> hostWires = wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE);
if (hostWires == null) {
// we don't hold locks while checking the graph, just return if no longer valid
return null;
}
Collection<Bundle> fragments = new ArrayList<>(hostWires.size());
- for (ModuleWire wire : hostWires) {
+ for (BundleWire wire : hostWires) {
Bundle fragment = wire.getRequirer().getBundle();
if (fragment != null) {
fragments.add(fragment);
@@ -265,17 +235,17 @@ public class PackageAdminImpl implements PackageAdmin {
@Override
public Bundle[] getHosts(Bundle bundle) {
- ModuleWiring wiring = getWiring(bundle);
+ BundleWiring wiring = getWiring(bundle);
if (wiring == null) {
return null;
}
- List<ModuleWire> hostWires = wiring.getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
+ List<BundleWire> hostWires = wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE);
if (hostWires == null) {
// we don't hold locks while checking the graph, just return if no longer valid
return null;
}
Collection<Bundle> hosts = new ArrayList<>(hostWires.size());
- for (ModuleWire wire : hostWires) {
+ for (BundleWire wire : hostWires) {
Bundle host = wire.getProvider().getBundle();
if (host != null) {
hosts.add(host);
@@ -284,62 +254,42 @@ public class PackageAdminImpl implements PackageAdmin {
return hosts.isEmpty() ? null : hosts.toArray(new Bundle[hosts.size()]);
}
- private ModuleWiring getWiring(Bundle bundle) {
- Module module = StartLevelImpl.getModule(bundle);
- if (module == null) {
- return null;
- }
-
- List<ModuleRevision> revisions = module.getRevisions().getModuleRevisions();
- if (revisions.isEmpty()) {
+ private BundleWiring getWiring(Bundle bundle) {
+ BundleRevision current = bundle.adapt(BundleRevision.class);
+ if (current == null) {
return null;
}
-
- return revisions.get(0).getWiring();
- }
-
- Bundle getBundlePriv(Class<?> clazz) {
- Bundle b = FrameworkUtil.getBundle(clazz);
- if (b == null && clazz.getClassLoader() == getClass().getClassLoader()) {
- return container.getModule(0).getBundle();
- }
- return b;
+ return current.getWiring();
}
@Override
public Bundle getBundle(final Class<?> clazz) {
- if (System.getSecurityManager() == null)
- return getBundlePriv(clazz);
- return AccessController.doPrivileged(new GetBundleAction(this, clazz));
+ return equinoxContainer.getBundle(clazz);
}
@Override
public int getBundleType(Bundle bundle) {
- Module module = StartLevelImpl.getModule(bundle);
- if (module == null) {
+ BundleRevision current = bundle.adapt(BundleRevision.class);
+ if (current == null) {
return 0;
}
- List<BundleRevision> revisions = module.getRevisions().getRevisions();
- if (revisions.isEmpty()) {
- return 0;
- }
- return (revisions.get(0).getTypes() & BundleRevision.TYPE_FRAGMENT) != 0 ? PackageAdmin.BUNDLE_TYPE_FRAGMENT : 0;
+ return (current.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0 ? PackageAdmin.BUNDLE_TYPE_FRAGMENT : 0;
}
public Collection<Bundle> getRemovalPendingBundles() {
- return container.getFrameworkWiring().getRemovalPendingBundles();
+ return frameworkWiring.getRemovalPendingBundles();
}
public Collection<Bundle> getDependencyClosure(Collection<Bundle> bundles) {
- return container.getFrameworkWiring().getDependencyClosure(bundles);
+ return frameworkWiring.getDependencyClosure(bundles);
}
static class ExportedPackageImpl implements ExportedPackage {
- private final ModuleCapability packageCapability;
- private final ModuleWiring providerWiring;
+ private final BundleCapability packageCapability;
+ private final BundleWiring providerWiring;
- public ExportedPackageImpl(ModuleCapability packageCapability, ModuleWiring providerWiring) {
+ public ExportedPackageImpl(BundleCapability packageCapability, BundleWiring providerWiring) {
this.packageCapability = packageCapability;
this.providerWiring = providerWiring;
}
@@ -366,15 +316,15 @@ public class PackageAdminImpl implements PackageAdmin {
String packageName = getName();
addRequirers(importing, providerWiring, packageName);
- List<ModuleWire> providedPackages = providerWiring.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
+ List<BundleWire> providedPackages = providerWiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE);
if (providedPackages == null) {
// we don't hold locks while checking the graph, just return if no longer valid
return null;
}
- for (ModuleWire packageWire : providedPackages) {
+ for (BundleWire packageWire : providedPackages) {
if (packageCapability.equals(packageWire.getCapability())) {
importing.add(packageWire.getRequirer().getBundle());
- if (packageWire.getRequirerWiring().isSubstitutedPackage(packageName)) {
+ if (((ModuleWiring) packageWire.getRequirerWiring()).isSubstitutedPackage(packageName)) {
addRequirers(importing, packageWire.getRequirerWiring(), packageName);
}
}
@@ -382,13 +332,13 @@ public class PackageAdminImpl implements PackageAdmin {
return importing.toArray(new Bundle[importing.size()]);
}
- private static void addRequirers(Set<Bundle> importing, ModuleWiring wiring, String packageName) {
- List<ModuleWire> requirerWires = wiring.getProvidedModuleWires(BundleNamespace.BUNDLE_NAMESPACE);
+ private static void addRequirers(Set<Bundle> importing, BundleWiring wiring, String packageName) {
+ List<BundleWire> requirerWires = wiring.getProvidedWires(BundleNamespace.BUNDLE_NAMESPACE);
if (requirerWires == null) {
// we don't hold locks while checking the graph, just return if no longer isInUse
return;
}
- for (ModuleWire requireBundleWire : requirerWires) {
+ for (BundleWire requireBundleWire : requirerWires) {
Bundle requirer = requireBundleWire.getRequirer().getBundle();
if (importing.contains(requirer)) {
continue;
@@ -397,18 +347,19 @@ public class PackageAdminImpl implements PackageAdmin {
// if reexported then need to add any requirers of the reexporter
String reExport = requireBundleWire.getRequirement().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
- ModuleWiring requirerWiring = requireBundleWire.getRequirerWiring();
+ BundleWiring requirerWiring = requireBundleWire.getRequirerWiring();
if (BundleNamespace.VISIBILITY_REEXPORT.equals(reExport)) {
addRequirers(importing, requirerWiring, packageName);
}
// also need to add any importers of the same package as the wiring exports; case of aggregations
if (!requirerWiring.equals(wiring)) {
- List<ModuleWire> providedPackages = requirerWiring.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
+ List<BundleWire> providedPackages = requirerWiring.getProvidedWires(PackageNamespace.PACKAGE_NAMESPACE);
if (providedPackages != null) {
- for (ModuleWire packageWire : providedPackages) {
+ for (BundleWire packageWire : providedPackages) {
if (packageName.equals(packageWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
importing.add(packageWire.getRequirer().getBundle());
- if (packageWire.getRequirerWiring().isSubstitutedPackage(packageName)) {
+ if (((ModuleWiring) packageWire.getRequirerWiring())
+ .isSubstitutedPackage(packageName)) {
addRequirers(importing, packageWire.getRequirerWiring(), packageName);
}
}
@@ -418,6 +369,7 @@ public class PackageAdminImpl implements PackageAdmin {
}
}
+
/**
* @deprecated
*/
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/StartLevelImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/StartLevelImpl.java
index 45e272d10..9aa9b6337 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/StartLevelImpl.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/legacy/StartLevelImpl.java
@@ -13,65 +13,57 @@
*******************************************************************************/
package org.eclipse.osgi.internal.framework.legacy;
-import org.eclipse.osgi.container.Module;
-import org.eclipse.osgi.container.ModuleContainer;
-import org.eclipse.osgi.internal.framework.EquinoxBundle;
import org.osgi.framework.Bundle;
+import org.osgi.framework.startlevel.BundleStartLevel;
+import org.osgi.framework.startlevel.FrameworkStartLevel;
import org.osgi.service.startlevel.StartLevel;
@SuppressWarnings("deprecation")
public class StartLevelImpl implements StartLevel {
- private final ModuleContainer container;
+ private final FrameworkStartLevel frameworkStartLevel;
- public StartLevelImpl(ModuleContainer container) {
- this.container = container;
+ public StartLevelImpl(FrameworkStartLevel frameworkStartLevel) {
+ this.frameworkStartLevel = frameworkStartLevel;
}
@Override
public int getStartLevel() {
- return container.getFrameworkStartLevel().getStartLevel();
+ return frameworkStartLevel.getStartLevel();
}
@Override
public void setStartLevel(int startlevel) {
- container.getFrameworkStartLevel().setStartLevel(startlevel);
+ frameworkStartLevel.setStartLevel(startlevel);
}
@Override
public int getBundleStartLevel(Bundle bundle) {
- return getModule(bundle).getStartLevel();
+ return bundle.adapt(BundleStartLevel.class).getStartLevel();
}
@Override
public void setBundleStartLevel(Bundle bundle, int startlevel) {
- getModule(bundle).setStartLevel(startlevel);
+ bundle.adapt(BundleStartLevel.class).setStartLevel(startlevel);
}
@Override
public int getInitialBundleStartLevel() {
- return container.getFrameworkStartLevel().getInitialBundleStartLevel();
+ return frameworkStartLevel.getInitialBundleStartLevel();
}
@Override
public void setInitialBundleStartLevel(int startlevel) {
- container.getFrameworkStartLevel().setInitialBundleStartLevel(startlevel);
+ frameworkStartLevel.setInitialBundleStartLevel(startlevel);
}
@Override
public boolean isBundlePersistentlyStarted(Bundle bundle) {
- return getModule(bundle).isPersistentlyStarted();
+ return bundle.adapt(BundleStartLevel.class).isPersistentlyStarted();
}
@Override
public boolean isBundleActivationPolicyUsed(Bundle bundle) {
- return getModule(bundle).isActivationPolicyUsed();
- }
-
- static Module getModule(Bundle bundle) {
- if (bundle instanceof EquinoxBundle) {
- return ((EquinoxBundle) bundle).getModule();
- }
- throw new IllegalArgumentException("Bundle is not from an equinox framework: " + bundle.getClass()); //$NON-NLS-1$
+ return bundle.adapt(BundleStartLevel.class).isActivationPolicyUsed();
}
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
index 886b0f248..af785f6d4 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoader.java
@@ -189,7 +189,10 @@ public class BundleLoader extends ModuleLoader {
List<ModuleCapability> moduleDatas = wiring.getRevision().getModuleCapabilities(EquinoxModuleDataNamespace.MODULE_DATA_NAMESPACE);
@SuppressWarnings("unchecked")
List<String> buddyList = (List<String>) (moduleDatas.isEmpty() ? null : moduleDatas.get(0).getAttributes().get(EquinoxModuleDataNamespace.CAPABILITY_BUDDY_POLICY));
- policy = buddyList != null ? new PolicyHandler(this, buddyList, container.getPackageAdmin(), container.getBootLoader()) : null;
+ policy = buddyList != null
+ ? new PolicyHandler(this, buddyList, container.getStorage().getModuleContainer().getFrameworkWiring(),
+ container.getBootLoader())
+ : null;
if (policy != null) {
Module systemModule = container.getStorage().getModuleContainer().getModule(0);
Bundle systemBundle = systemModule.getBundle();
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
index 15e44183b..ac0a44670 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/GlobalPolicy.java
@@ -15,10 +15,23 @@ package org.eclipse.osgi.internal.loader.buddy;
import java.io.IOException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
+import java.util.Map;
+import org.eclipse.osgi.container.ModuleContainer;
+import org.eclipse.osgi.internal.container.Capabilities;
import org.eclipse.osgi.internal.loader.BundleLoader;
-import org.osgi.service.packageadmin.ExportedPackage;
-import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.namespace.HostNamespace;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
+import org.osgi.framework.wiring.FrameworkWiring;
+import org.osgi.resource.Namespace;
/**
* Global policy is an implementation of a buddy policy. It is responsible
@@ -26,52 +39,66 @@ import org.osgi.service.packageadmin.PackageAdmin;
* version of the same package are exported in the system, the exported package
* with the highest version will be returned.
*/
-@SuppressWarnings("deprecation")
public class GlobalPolicy implements IBuddyPolicy {
- private PackageAdmin admin;
+ private FrameworkWiring frameworkWiring;
- public GlobalPolicy(PackageAdmin admin) {
- this.admin = admin;
+ public GlobalPolicy(FrameworkWiring frameworkWiring) {
+ this.frameworkWiring = frameworkWiring;
}
@Override
public Class<?> loadClass(String name) {
- ExportedPackage pkg = admin.getExportedPackage(BundleLoader.getPackageName(name));
- if (pkg == null)
- return null;
- try {
- return pkg.getExportingBundle().loadClass(name);
- } catch (ClassNotFoundException e) {
- return null;
- }
+ return getExportingBundles(BundleLoader.getPackageName(name)) //
+ .stream().findFirst().map(b -> {
+ try {
+ return b.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ return null;
+ }
+ }).orElseGet(null);
}
@Override
public URL loadResource(String name) {
- //get all exported packages that match the resource's package
- ExportedPackage pkg = admin.getExportedPackage(BundleLoader.getResourcePackageName(name));
- if (pkg == null)
- return null;
- return pkg.getExportingBundle().getResource(name);
+ return getExportingBundles(BundleLoader.getResourcePackageName(name)) //
+ .stream().findFirst().map(b -> {
+ return b.getResource(name);
+ }).orElseGet(null);
}
@Override
public Enumeration<URL> loadResources(String name) {
- //get all exported packages that match the resource's package
- ExportedPackage[] pkgs = admin.getExportedPackages(BundleLoader.getResourcePackageName(name));
- if (pkgs == null || pkgs.length == 0)
- return null;
-
- //get all matching resources for each package
Enumeration<URL> results = null;
- for (ExportedPackage pkg : pkgs) {
+ Collection<Bundle> exporters = getExportingBundles(name);
+ for (Bundle exporter : exporters) {
try {
- results = BundleLoader.compoundEnumerations(results, pkg.getExportingBundle().getResources(name));
+ results = BundleLoader.compoundEnumerations(results, exporter.getResources(name));
}catch (IOException e) {
//ignore IO problems and try next package
}
}
-
return results;
}
+
+ private Collection<Bundle> getExportingBundles(String pkgName) {
+ Collection<Bundle> result = new ArrayList<>();
+ String filter = "(" + PackageNamespace.PACKAGE_NAMESPACE + "=" + pkgName + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Map<String, String> directives = Collections
+ .<String, String>singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
+ Map<String, Boolean> attributes = Collections.singletonMap(Capabilities.SYNTHETIC_REQUIREMENT, Boolean.TRUE);
+ Collection<BundleCapability> packages = frameworkWiring.findProviders(
+ ModuleContainer.createRequirement(PackageNamespace.PACKAGE_NAMESPACE, directives, attributes));
+ for (BundleCapability pkg : packages) {
+ if ((pkg.getRevision().getTypes() & BundleRevision.TYPE_FRAGMENT) != 0) {
+ // use the hosts
+ BundleWiring wiring = pkg.getRevision().getWiring();
+ for (BundleWire hostWire : wiring.getRequiredWires(HostNamespace.HOST_NAMESPACE)) {
+ result.add(hostWire.getProvider().getBundle());
+ }
+ } else {
+ result.add(pkg.getRevision().getBundle());
+ }
+ }
+ return result;
+ }
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java
index 190ca9c31..b70d3a1ca 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/buddy/PolicyHandler.java
@@ -27,7 +27,7 @@ import org.eclipse.osgi.internal.loader.BundleLoader;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.framework.wiring.FrameworkWiring;
public class PolicyHandler implements SynchronousBundleListener {
//Key for the framework buddies
@@ -47,15 +47,16 @@ public class PolicyHandler implements SynchronousBundleListener {
//Support to cut class / resource loading cycles in the context of one thread. The contained object is a set of classname
private final ThreadLocal<Set<String>> beingLoaded;
- private final PackageAdmin packageAdmin;
+ private final FrameworkWiring frameworkWiring;
private final ClassLoader bootLoader;
- public PolicyHandler(BundleLoader loader, List<String> buddyList, PackageAdmin packageAdmin, ClassLoader bootLoader) {
+ public PolicyHandler(BundleLoader loader, List<String> buddyList, FrameworkWiring frameworkWiring,
+ ClassLoader bootLoader) {
policedLoader = loader;
this.originalBuddyList = buddyList;
policies = buddyList.toArray();
beingLoaded = new ThreadLocal<>();
- this.packageAdmin = packageAdmin;
+ this.frameworkWiring = frameworkWiring;
this.bootLoader = bootLoader;
}
@@ -100,7 +101,7 @@ public class PolicyHandler implements SynchronousBundleListener {
return (IBuddyPolicy) policiesSnapshot[policyOrder];
}
if (GLOBAL_POLICY.equals(buddyName)) {
- policiesSnapshot[policyOrder] = new GlobalPolicy(packageAdmin);
+ policiesSnapshot[policyOrder] = new GlobalPolicy(frameworkWiring);
return (IBuddyPolicy) policiesSnapshot[policyOrder];
}
if (PARENT_POLICY.equals(buddyName)) {
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
index 358100f71..ef8d94848 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/sources/PackageSource.java
@@ -24,7 +24,6 @@ import org.eclipse.osgi.internal.framework.EquinoxContainer;
import org.eclipse.osgi.internal.loader.BundleLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceFactory;
-import org.osgi.service.packageadmin.PackageAdmin;
public abstract class PackageSource {
protected final String id;
@@ -134,7 +133,7 @@ public abstract class PackageSource {
}
// 3) for the specified bundle, find the wiring for the package. If no wiring is found return true
PackageSource consumerSource = getSourceFromLoader(consumerBL, pkgName, className, checkInternal,
- container.getPackageAdmin());
+ container);
if (consumerSource == null) {
// confirmed no source for consumer
return true;
@@ -146,12 +145,11 @@ public abstract class PackageSource {
// 4) For the registrant bundle, find the wiring for the package.
PackageSource producerSource = getSourceFromLoader(producerBL, pkgName, className, checkInternal,
- container.getPackageAdmin());
+ container);
if (producerSource == null) {
// confirmed no local class either; now check service object
if (serviceClass != null && ServiceFactory.class.isAssignableFrom(serviceClass)) {
- @SuppressWarnings("deprecation")
- Bundle bundle = container.getPackageAdmin().getBundle(serviceClass);
+ Bundle bundle = container.getBundle(serviceClass);
if (bundle != null && bundle != registrant) {
// in this case we have a wacky ServiceFactory that is doing something we cannot
// verify if it is correct. Instead of failing we allow the assignment and hope
@@ -163,7 +161,7 @@ public abstract class PackageSource {
// 5) If no wiring is found for the registrant bundle then find the wiring for
// the classloader of the service object. If no wiring is found return false.
producerSource = getPackageSource(serviceClass, pkgName, className, checkInternal,
- container.getPackageAdmin());
+ container);
if (producerSource == null) {
return false;
}
@@ -173,7 +171,7 @@ public abstract class PackageSource {
}
private static PackageSource getSourceFromLoader(BundleLoader loader, String pkgName, String className,
- boolean checkInternal, @SuppressWarnings("deprecation") PackageAdmin packageAdmin) {
+ boolean checkInternal, EquinoxContainer container) {
PackageSource source = loader.getPackageSource(pkgName);
if (source != null || !checkInternal) {
return source;
@@ -182,8 +180,7 @@ public abstract class PackageSource {
Class<?> clazz = loader.findLocalClass(className);
if (clazz != null) {
// make sure it is from this actual loader
- @SuppressWarnings("deprecation")
- Bundle b = packageAdmin.getBundle(clazz);
+ Bundle b = container.getBundle(clazz);
if (b != null) {
if (loader.getWiring().getBundle() == b) {
// create a source that represents the private package
@@ -203,13 +200,11 @@ public abstract class PackageSource {
}
private static PackageSource getPackageSource(Class<?> serviceClass, String pkgName, String className,
- boolean checkInternal,
- @SuppressWarnings("deprecation") PackageAdmin packageAdmin) {
+ boolean checkInternal, EquinoxContainer container) {
if (serviceClass == null) {
return null;
}
- @SuppressWarnings("deprecation")
- Bundle serviceBundle = packageAdmin.getBundle(serviceClass);
+ Bundle serviceBundle = container.getBundle(serviceClass);
if (serviceBundle == null) {
return null;
}
@@ -217,7 +212,7 @@ public abstract class PackageSource {
if (producerBL == null) {
return null;
}
- PackageSource producerSource = getSourceFromLoader(producerBL, pkgName, className, checkInternal, packageAdmin);
+ PackageSource producerSource = getSourceFromLoader(producerBL, pkgName, className, checkInternal, container);
if (producerSource != null) {
return producerSource;
}
@@ -225,13 +220,13 @@ public abstract class PackageSource {
Class<?>[] interfaces = serviceClass.getInterfaces();
// note that getInterfaces never returns null
for (Class<?> intf : interfaces) {
- producerSource = getPackageSource(intf, pkgName, className, checkInternal, packageAdmin);
+ producerSource = getPackageSource(intf, pkgName, className, checkInternal, container);
if (producerSource != null) {
return producerSource;
}
}
// try super class
- return getPackageSource(serviceClass.getSuperclass(), pkgName, className, checkInternal, packageAdmin);
+ return getPackageSource(serviceClass.getSuperclass(), pkgName, className, checkInternal, container);
}
private static BundleLoader getBundleLoader(Bundle bundle) {

Back to the top