Search in sources :

Example 1 with DebugOptions

use of org.eclipse.osgi.service.debug.DebugOptions in project hale by halestudio.

the class Activator method getBooleanDebugOption.

/**
 * Return the debug value of the option if founded otherwise return
 * defaultValue.
 *
 * @param option
 * @param defaultValue
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static boolean getBooleanDebugOption(String option, boolean defaultValue) {
    // 1) search param from JVM
    String s = System.getProperty(DEBUG_PROPERTY);
    if (!Utils.isEmpty(s)) {
        return Utils.isTrue(s, defaultValue);
    }
    // 2) search param from nonosgiregistry.properties files.
    if (nonosgiregistryProps == null) {
        nonosgiregistryProps = Utils.load(Activator.class.getClassLoader());
        s = nonosgiregistryProps.getProperty(DEBUG_PROPERTY);
        if (!Utils.isEmpty(s)) {
            return Utils.isTrue(s, defaultValue);
        }
    }
    // 3) Search param from OSGi options
    Activator activator = getDefault();
    if (activator == null)
        // No OSGi context
        return defaultValue;
    BundleContext myBundleContext = activator.bundleContext;
    if (myBundleContext == null)
        return defaultValue;
    // Search the DebugOptions OSGi service
    if (getDefault().debugTracker == null) {
        getDefault().debugTracker = new ServiceTracker(getDefault().bundleContext, DebugOptions.class.getName(), null);
        getDefault().debugTracker.open();
    }
    DebugOptions options = (DebugOptions) getDefault().debugTracker.getService();
    if (options != null) {
        // get the value of the option by using OSGi service DebugOptions
        return Utils.isTrue(options.getOption(option), defaultValue);
    }
    return defaultValue;
}
Also used : BundleActivator(org.osgi.framework.BundleActivator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions) BundleContext(org.osgi.framework.BundleContext)

Example 2 with DebugOptions

use of org.eclipse.osgi.service.debug.DebugOptions in project eclipse.platform.runtime by eclipse.

the class ServiceContextTest method testServiceContextAsParent.

/**
 * Tests accessing OSGi services through a child context that is not aware of them.
 */
@Test
public void testServiceContextAsParent() {
    IEclipseContext child = context.createChild("child");
    DebugOptions service = (DebugOptions) child.get(DebugOptions.class.getName());
    assertNotNull(service);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions) Test(org.junit.Test)

Example 3 with DebugOptions

use of org.eclipse.osgi.service.debug.DebugOptions in project eclipse.platform.runtime by eclipse.

the class Plugin method isDebugging.

/**
 * Returns whether this plug-in is in debug mode.
 * By default plug-ins are not in debug mode.  A plug-in can put itself
 * into debug mode or the user can set an execution option to do so.
 * <p>
 * Note that the plug-in's debug flag is initialized when the
 * plug-in is started. The result of calling this method before the plug-in
 * has started is unspecified.
 * </p>
 *
 * @return whether this plug-in is in debug mode
 * XXX deprecate use the service and cache as needed
 */
public boolean isDebugging() {
    Bundle debugBundle = getBundle();
    if (debugBundle == null)
        return debug;
    // $NON-NLS-1$
    String key = debugBundle.getSymbolicName() + "/debug";
    // first check if platform debugging is enabled
    final DebugOptions debugOptions = getDebugOptions();
    if (debugOptions == null)
        return debug;
    // if platform debugging is enabled, check to see if this plugin is enabled for debugging
    return debugOptions.isDebugEnabled() ? InternalPlatform.getDefault().getBooleanOption(key, false) : false;
}
Also used : DebugOptions(org.eclipse.osgi.service.debug.DebugOptions)

Example 4 with DebugOptions

use of org.eclipse.osgi.service.debug.DebugOptions in project epp.mpc by eclipse.

the class MarketplaceClientCorePlugin method start.

public void start(BundleContext context) throws Exception {
    bundle = context.getBundle();
    instance = this;
    ProxyHelper.acquireProxyService();
    registerServices(context);
    serviceHelper = new ServiceHelperImpl();
    serviceHelper.startTracking(context);
    Hashtable<String, String> props = new Hashtable<String, String>(2);
    props.put(org.eclipse.osgi.service.debug.DebugOptions.LISTENER_SYMBOLICNAME, MarketplaceClientCore.BUNDLE_ID);
    context.registerService(DebugOptionsListener.class.getName(), new DebugOptionsListener() {

        public void optionsChanged(DebugOptions options) {
            DebugTrace debugTrace = null;
            boolean debug = options.getBooleanOption(MarketplaceClientCore.BUNDLE_ID + DEBUG_OPTION, false);
            boolean fakeClient = false;
            if (debug) {
                debugTrace = options.newDebugTrace(MarketplaceClientCore.BUNDLE_ID);
                fakeClient = options.getBooleanOption(MarketplaceClientCore.BUNDLE_ID + DEBUG_FAKE_CLIENT_OPTION, false);
            }
            DEBUG = debug;
            DEBUG_FAKE_CLIENT = fakeClient;
            MarketplaceClientCorePlugin.debugTrace = debugTrace;
        }
    }, props);
}
Also used : DebugTrace(org.eclipse.osgi.service.debug.DebugTrace) Hashtable(java.util.Hashtable) DebugOptionsListener(org.eclipse.osgi.service.debug.DebugOptionsListener) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions)

Example 5 with DebugOptions

use of org.eclipse.osgi.service.debug.DebugOptions in project polymap4-core by Polymap4.

the class AuthPlugin method getBooleanOption.

public boolean getBooleanOption(String option, boolean defaultValue) {
    if (debugTracker == null) {
        if (bundleContext == null)
            return defaultValue;
        debugTracker = new ServiceTracker(bundleContext, DebugOptions.class.getName(), null);
        debugTracker.open();
    }
    DebugOptions options = (DebugOptions) debugTracker.getService();
    if (options == null)
        return defaultValue;
    String value = options.getOption(option);
    if (value == null)
        return defaultValue;
    // $NON-NLS-1$
    return value.equalsIgnoreCase("true");
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) DebugOptions(org.eclipse.osgi.service.debug.DebugOptions)

Aggregations

DebugOptions (org.eclipse.osgi.service.debug.DebugOptions)14 ServiceTracker (org.osgi.util.tracker.ServiceTracker)3 Hashtable (java.util.Hashtable)2 Properties (java.util.Properties)2 DebugOptionsListener (org.eclipse.osgi.service.debug.DebugOptionsListener)2 DebugTrace (org.eclipse.osgi.service.debug.DebugTrace)2 ArrayList (java.util.ArrayList)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 Activator (org.eclipse.ecf.internal.core.identity.Activator)1 ResourceProvider (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider)1 IMarketplaceClientService (org.eclipse.epp.mpc.ui.IMarketplaceClientService)1 ICheckStateProvider (org.eclipse.jface.viewers.ICheckStateProvider)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 BundleActivator (org.osgi.framework.BundleActivator)1 BundleContext (org.osgi.framework.BundleContext)1