Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2015-07-07 17:34:35 -0400
committerslewis2015-07-07 17:34:35 -0400
commit4c7ecd62e0c8f413dc9f5b7a10d4ffdb21de9f30 (patch)
tree3072d34c7c1a1457ef63da23d93310809bca7996 /framework/bundles/org.eclipse.ecf.identity/src
parent912bdd66a32afb0a6d42c1e3ecb17f778a4e9883 (diff)
downloadorg.eclipse.ecf-4c7ecd62e0c8f413dc9f5b7a10d4ffdb21de9f30.tar.gz
org.eclipse.ecf-4c7ecd62e0c8f413dc9f5b7a10d4ffdb21de9f30.tar.xz
org.eclipse.ecf-4c7ecd62e0c8f413dc9f5b7a10d4ffdb21de9f30.zip
Made PlatformHelper utility class and AdapterManagerTracker class more
robust in other environments (e.g. Karaf, ServiceRegistry, etc). Change-Id: I133acec30351e253675317307dca064984cf9127
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.identity/src')
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java7
-rw-r--r--framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java65
2 files changed, 44 insertions, 28 deletions
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java
index a4346d064..53ddd5f0f 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/AdapterManagerTracker.java
@@ -8,8 +8,7 @@
******************************************************************************/
package org.eclipse.ecf.core.util;
-import org.eclipse.core.runtime.*;
-import org.eclipse.ecf.internal.core.identity.Activator;
+import org.eclipse.core.runtime.IAdapterManager;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -34,10 +33,6 @@ public class AdapterManagerTracker extends ServiceTracker {
// PlatformHelper class
if (adapterManager == null)
adapterManager = PlatformHelper.getPlatformAdapterManager();
- if (adapterManager == null)
- Activator.getDefault().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID,
- IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$
return adapterManager;
}
diff --git a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java
index 7f9431868..ce089ce02 100644
--- a/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java
+++ b/framework/bundles/org.eclipse.ecf.identity/src/org/eclipse/ecf/core/util/PlatformHelper.java
@@ -15,6 +15,7 @@ import java.lang.reflect.Method;
import org.eclipse.core.runtime.*;
import org.eclipse.ecf.internal.core.identity.Activator;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
/**
* Helper class for eliminating direct references to Platform static methods
@@ -32,23 +33,33 @@ public class PlatformHelper {
private static IExtensionRegistry extensionRegistryCache = null;
static {
- try {
- Bundle[] bundles = Activator.getDefault().getBundleContext().getBundles();
- Bundle coreRuntime = null;
- for (int i = 0; i < bundles.length; i++)
- if (bundles[i].getSymbolicName().equals("org.eclipse.core.runtime")) { //$NON-NLS-1$
- coreRuntime = bundles[i];
- platformClass = coreRuntime.loadClass("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$
- break;
- }
- } catch (Exception e) {
- // Platform not available...just leave platformClass == null and log
- // as error
+ Activator a = Activator.getDefault();
+ if (a != null) {
try {
- Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Cannot load Platform class. No adapter manager available", //$NON-NLS-1$
- e));
- } catch (Throwable t) {
- // Should never happen, if does irrecoverable
+ BundleContext c = a.getBundleContext();
+ if (c != null) {
+ Bundle[] bundles = c.getBundles();
+ Bundle coreRuntime = null;
+ for (int i = 0; i < bundles.length; i++)
+ if (bundles[i].getSymbolicName().equals(
+ "org.eclipse.core.runtime")) { //$NON-NLS-1$
+ coreRuntime = bundles[i];
+ platformClass = coreRuntime
+ .loadClass("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$
+ break;
+ }
+ }
+ } catch (Exception e) {
+ // Platform not available...just leave platformClass == null and
+ // log
+ // as error
+ try {
+ a.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ IStatus.WARNING, "Cannot load Platform class", //$NON-NLS-1$
+ e));
+ } catch (Throwable t) {
+ // Should never happen, if does irrecoverable
+ }
}
}
}
@@ -62,11 +73,16 @@ public class PlatformHelper {
return adapterManagerCache;
if (isPlatformAvailable()) {
try {
- Method m = platformClass.getMethod("getAdapterManager", (Class []) null); //$NON-NLS-1$
- adapterManagerCache = (IAdapterManager) m.invoke(null, (Object []) null);
+ Method m = platformClass.getMethod(
+ "getAdapterManager", (Class[]) null); //$NON-NLS-1$
+ adapterManagerCache = (IAdapterManager) m.invoke(null,
+ (Object[]) null);
return adapterManagerCache;
} catch (Exception e) {
- Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Exception in PlatformHelper.getPlatformAdapterManager()", e)); //$NON-NLS-1$
+ Activator.getDefault().log(
+ new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ IStatus.WARNING,
+ "Cannot get PlatformAdapterManager()", e)); //$NON-NLS-1$
return null;
}
}
@@ -78,11 +94,16 @@ public class PlatformHelper {
return extensionRegistryCache;
if (isPlatformAvailable()) {
try {
- Method m = platformClass.getMethod("getExtensionRegistry", (Class []) null); //$NON-NLS-1$
- extensionRegistryCache = (IExtensionRegistry) m.invoke(null, (Object []) null);
+ Method m = platformClass.getMethod(
+ "getExtensionRegistry", (Class[]) null); //$NON-NLS-1$
+ extensionRegistryCache = (IExtensionRegistry) m.invoke(null,
+ (Object[]) null);
return extensionRegistryCache;
} catch (Exception e) {
- Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, "Exception in PlatformHelper.getExtensionRegistry()", e)); //$NON-NLS-1$
+ Activator.getDefault().log(
+ new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ IStatus.WARNING,
+ "Cannot get PlatformExtensionRegistry()", e)); //$NON-NLS-1$
return null;
}

Back to the top