X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBootDiagnostics.java;fp=org.argeo.osgi.boot%2Fsrc%2Forg%2Fargeo%2Fosgi%2Fboot%2FOsgiBootDiagnostics.java;h=0000000000000000000000000000000000000000;hb=b7d8618ce593bbeca7e311d32a4d98988e27f877;hp=24a3317c6358d617368662e2c3605fa77e56de8a;hpb=25a31ea46e5de6ce0de366fdb999588c6788c540;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootDiagnostics.java b/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootDiagnostics.java deleted file mode 100644 index 24a3317c6..000000000 --- a/org.argeo.osgi.boot/src/org/argeo/osgi/boot/OsgiBootDiagnostics.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.argeo.osgi.boot; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.service.packageadmin.ExportedPackage; -import org.osgi.service.packageadmin.PackageAdmin; - -@SuppressWarnings("deprecation") -class OsgiBootDiagnostics { - private final BundleContext bundleContext; - - public OsgiBootDiagnostics(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - /* - * DIAGNOSTICS - */ - /** Check unresolved bundles */ - protected void checkUnresolved() { - // Refresh - ServiceReference packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class); - PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef); - packageAdmin.resolveBundles(null); - - Bundle[] bundles = bundleContext.getBundles(); - List unresolvedBundles = new ArrayList(); - for (int i = 0; i < bundles.length; i++) { - int bundleState = bundles[i].getState(); - if (!(bundleState == Bundle.ACTIVE || bundleState == Bundle.RESOLVED || bundleState == Bundle.STARTING)) - unresolvedBundles.add(bundles[i]); - } - - if (unresolvedBundles.size() != 0) { - OsgiBootUtils.warn("Unresolved bundles " + unresolvedBundles); - } - } - - /** List packages exported twice. */ - public Map> findPackagesExportedTwice() { - ServiceReference paSr = bundleContext.getServiceReference(PackageAdmin.class); - PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(paSr); - - // find packages exported twice - Bundle[] bundles = bundleContext.getBundles(); - Map> exportedPackages = new TreeMap>(); - for (int i = 0; i < bundles.length; i++) { - Bundle bundle = bundles[i]; - ExportedPackage[] pkgs = packageAdmin.getExportedPackages(bundle); - if (pkgs != null) - for (int j = 0; j < pkgs.length; j++) { - String pkgName = pkgs[j].getName(); - if (!exportedPackages.containsKey(pkgName)) { - exportedPackages.put(pkgName, new TreeSet()); - } - (exportedPackages.get(pkgName)).add(bundle.getSymbolicName() + "_" + bundle.getVersion()); - } - } - Map> duplicatePackages = new TreeMap>(); - Iterator it = exportedPackages.keySet().iterator(); - while (it.hasNext()) { - String pkgName = it.next().toString(); - Set bdles = exportedPackages.get(pkgName); - if (bdles.size() > 1) - duplicatePackages.put(pkgName, bdles); - } - return duplicatePackages; - } - -}