Bug 544423 - Remove usage of deprecated PackageAdmin

Query FrameworkWiring for capabilities when looking up bundles.
Inline logic from PackageAdminImpl to refactor getFragments(Bundle) and
getHosts(Bundle).
Refactored isFragment(Bundle).
(Adopt lost changes from changeset#136868, patchset#3)

Change-Id: Ic0911001f83c39ad34fc3a55d6bc7867801991d2
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
index 2068da8..de79541 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
@@ -35,7 +35,6 @@
 import org.eclipse.osgi.framework.log.FrameworkLog;
 import org.eclipse.osgi.service.datalocation.Location;
 import org.eclipse.osgi.service.debug.DebugOptions;
-import org.eclipse.osgi.service.debug.DebugOptionsListener;
 import org.eclipse.osgi.service.environment.EnvironmentInfo;
 import org.eclipse.osgi.service.resolver.PlatformAdmin;
 import org.osgi.framework.*;
@@ -94,6 +93,7 @@
 	private Path cachedInstanceLocation; // Cache the path of the instance location
 	private ServiceTracker<Location,Location> configurationLocation = null;
 	private BundleContext context;
+	private FrameworkWiring fwkWiring;
 
 	private Map<IBundleGroupProvider,ServiceRegistration<IBundleGroupProvider>> groupProviders = new HashMap<>(3);
 	private ServiceTracker<Location,Location> installLocation = null;
@@ -108,7 +108,6 @@
 	private ServiceTracker<EnvironmentInfo,EnvironmentInfo> environmentTracker = null;
 	private ServiceTracker<FrameworkLog,FrameworkLog> logTracker = null;
 	private ServiceTracker<PlatformAdmin, PlatformAdmin> platformTracker = null;
-	private ServiceTracker<DebugOptionsListener, DebugOptionsListener> debugOptionsListenerTracker = null;
 	private ServiceTracker<DebugOptions,DebugOptions> debugTracker = null;
 	private ServiceTracker<IContentTypeManager,IContentTypeManager> contentTracker = null;
 	private ServiceTracker<IPreferencesService,IPreferencesService> preferencesTracker = null;
@@ -228,15 +227,9 @@
 	}
 
 	public Bundle[] getBundles(String symbolicName, String versionRange) {
-		ModuleContainer container = getModuleContainer();
-		if (container == null)
-			return null;
-
-		FrameworkWiring wiring = container.getFrameworkWiring();
-
 		Map<String, String> directives = Collections.singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE,
 				getRequirementFilter(symbolicName, null));
-		Collection<BundleCapability> matchingBundleCapabilities = wiring.findProviders(ModuleContainer
+		Collection<BundleCapability> matchingBundleCapabilities = fwkWiring.findProviders(ModuleContainer
 				.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, directives, Collections.emptyMap()));
 
 		if (matchingBundleCapabilities.isEmpty()) {
@@ -255,7 +248,7 @@
 		VersionRange range = versionRange == null ? null : new VersionRange(versionRange);
 		StringBuilder filter = new StringBuilder();
 		if (range != null) {
-			filter.append("(&");
+			filter.append("(&"); //$NON-NLS-1$
 		}
 		filter.append('(').append(IdentityNamespace.IDENTITY_NAMESPACE).append('=').append(symbolicName).append(')');
 
@@ -413,19 +406,6 @@
 		return platformTracker == null ? null : platformTracker.getService();
 	}
 
-	private ModuleContainer getModuleContainer() {
-		if (debugOptionsListenerTracker == null)
-			return null;
-
-		// is there a better way to retrieve the ModuleContainer?
-		for (Object service : debugOptionsListenerTracker.getServices()) {
-			if (service instanceof ModuleContainer) {
-				return (ModuleContainer) service;
-			}
-		}
-		return null;
-	}
-
 	//TODO I guess it is now time to get rid of that
 	/*
 	 * This method is retained for R1.0 compatibility because it is defined as API.
@@ -721,6 +701,7 @@
 	 */
 	public void start(BundleContext runtimeContext) {
 		this.context = runtimeContext;
+		this.fwkWiring = runtimeContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).adapt(FrameworkWiring.class);
 		openOSGiTrackers();
 		splashEnded = false;
 		processCommandLine(getEnvironmentInfoService().getNonFrameworkArgs());
@@ -799,11 +780,6 @@
 		}
 
 		if (context != null) {
-			debugOptionsListenerTracker = new ServiceTracker<>(context, DebugOptionsListener.class, null);
-			debugOptionsListenerTracker.open();
-		}
-
-		if (context != null) {
 			contentTracker = new ServiceTracker<>(context, IContentTypeManager.class, null);
 			contentTracker.open();
 		}
@@ -874,10 +850,6 @@
 			platformTracker.close();
 			platformTracker = null;
 		}
-		if (debugOptionsListenerTracker != null) {
-			debugOptionsListenerTracker.close();
-			debugOptionsListenerTracker = null;
-		}
 		if (logTracker != null) {
 			logTracker.close();
 			logTracker = null;