Search in sources :

Example 1 with FrameworkDebugOptions

use of org.eclipse.osgi.internal.debug.FrameworkDebugOptions in project rt.equinox.framework by eclipse.

the class SystemBundleActivator method stop.

public void stop(BundleContext bc) throws Exception {
    EquinoxBundle bundle = (EquinoxBundle) bc.getBundle();
    bundle.getEquinoxContainer().getStorage().getExtensionInstaller().stopExtensionActivators(bc);
    FrameworkDebugOptions dbgOptions = (FrameworkDebugOptions) bundle.getEquinoxContainer().getConfiguration().getDebugOptions();
    dbgOptions.stop(bc);
    urlFactoryManager.uninstallHandlerFactories();
    // unregister services
    for (ServiceRegistration<?> registration : registrations) registration.unregister();
    registrations.clear();
    bundle.getEquinoxContainer().getLogServices().stop(bc);
    unintallSecurityManager();
    bundle.getEquinoxContainer().systemStop(bc);
}
Also used : FrameworkDebugOptions(org.eclipse.osgi.internal.debug.FrameworkDebugOptions)

Example 2 with FrameworkDebugOptions

use of org.eclipse.osgi.internal.debug.FrameworkDebugOptions in project rt.equinox.framework by eclipse.

the class SystemBundleActivator method start.

@SuppressWarnings("deprecation")
public void start(BundleContext bc) throws Exception {
    registrations.clear();
    EquinoxBundle bundle = (EquinoxBundle) bc.getBundle();
    bundle.getEquinoxContainer().systemStart(bc);
    EquinoxConfiguration configuration = bundle.getEquinoxContainer().getConfiguration();
    installSecurityManager(configuration);
    bundle.getEquinoxContainer().getLogServices().start(bc);
    urlFactoryManager = new EquinoxFactoryManager(bundle.getEquinoxContainer());
    urlFactoryManager.installHandlerFactories(bc);
    FrameworkDebugOptions dbgOptions = (FrameworkDebugOptions) configuration.getDebugOptions();
    dbgOptions.start(bc);
    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);
    register(bc, PermissionAdmin.class, sa, null);
    register(bc, ConditionalPermissionAdmin.class, sa, null);
    Hashtable<String, Object> props = new Hashtable<>(7);
    props.clear();
    props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
    register(bc, Resolver.class, new ResolverImpl(new Logger(0), null), false, props);
    register(bc, DebugOptions.class, dbgOptions, null);
    if (tccl != null) {
        props.clear();
        // $NON-NLS-1$ //$NON-NLS-2$
        props.put("equinox.classloader.type", "contextClassLoader");
        register(bc, ClassLoader.class, tccl, props);
    }
    props.clear();
    // $NON-NLS-1$
    props.put("protocol", new String[] { BundleResourceHandler.OSGI_ENTRY_URL_PROTOCOL, BundleResourceHandler.OSGI_RESOURCE_URL_PROTOCOL });
    register(bc, URLConverter.class, new BundleURLConverter(), props);
    register(bc, BundleLocalization.class, new BundleLocalizationImpl(), null);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    boolean setTccl = "true".equals(bundle.getEquinoxContainer().getConfiguration().getConfiguration("eclipse.parsers.setTCCL", "true"));
    try {
        // $NON-NLS-1$
        register(bc, "javax.xml.parsers.SAXParserFactory", new XMLParsingServiceFactory(true, setTccl), false, null);
        // $NON-NLS-1$
        register(bc, "javax.xml.parsers.DocumentBuilderFactory", new XMLParsingServiceFactory(false, setTccl), false, null);
    } catch (NoClassDefFoundError e) {
    // ignore; on a platform with no javax.xml (Java 8 SE compact1 profile)
    }
    bundle.getEquinoxContainer().getStorage().getExtensionInstaller().startExtensionActivators(bc);
    // Add an options listener; we already read the options on initialization.
    // Here we are just allowing the options to change
    props.clear();
    props.put(DebugOptions.LISTENER_SYMBOLICNAME, EquinoxContainer.NAME);
    register(bc, DebugOptionsListener.class, bundle.getEquinoxContainer().getConfiguration().getDebug(), props);
    register(bc, DebugOptionsListener.class, bundle.getModule().getContainer(), props);
}
Also used : ResolverImpl(org.apache.felix.resolver.ResolverImpl) Logger(org.apache.felix.resolver.Logger) EquinoxFactoryManager(org.eclipse.osgi.internal.url.EquinoxFactoryManager) SecurityAdmin(org.eclipse.osgi.internal.permadmin.SecurityAdmin) BundleURLConverter(org.eclipse.osgi.storage.url.BundleURLConverter) FrameworkDebugOptions(org.eclipse.osgi.internal.debug.FrameworkDebugOptions) BundleLocalizationImpl(org.eclipse.osgi.storage.BundleLocalizationImpl)

Example 3 with FrameworkDebugOptions

use of org.eclipse.osgi.internal.debug.FrameworkDebugOptions in project rt.equinox.framework by eclipse.

the class DebugOptionsTestCase method testVerboseDebugging.

/**
 * Test all DebugTrace.trace*() API when verbose debugging is disabled
 */
public void testVerboseDebugging() {
    // TODO: Convert this back to {@link DebugOptions} once is/setVerbose becomes API
    FrameworkDebugOptions fwDebugOptions = (FrameworkDebugOptions) debugOptions;
    if (!debugOptions.isDebugEnabled()) {
        debugOptions.setDebugEnabled(true);
    }
    // create a tracing record
    // $NON-NLS-1$
    final File traceFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".trace");
    TestDebugTrace debugTrace = this.createDebugTrace(traceFile);
    TraceEntry[] traceOutput = null;
    // $NON-NLS-1$
    final String exceptionMessage1 = "An error 1";
    try {
        fwDebugOptions.setVerbose(false);
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.trace("/debug", "testing 1", new Exception(exceptionMessage1));
        fwDebugOptions.setVerbose(true);
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.trace("/debug", "testing 2");
        fwDebugOptions.setVerbose(false);
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.trace("/debug", "testing 3");
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.traceEntry("/debug");
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.traceEntry("/debug", "arg");
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        debugTrace.traceEntry("/debug", new String[] { "arg1", "arg2" });
        // $NON-NLS-1$
        debugTrace.traceExit("/debug");
        // $NON-NLS-1$ //$NON-NLS-2$
        debugTrace.traceExit("/debug", "returnValue");
        // Note: this call will also delete the trace file
        traceOutput = readTraceFile(traceFile);
    } catch (InvalidTraceEntry invalidEx) {
        // $NON-NLS-1$ //$NON-NLS-2$
        fail("Failed 'DebugTrace.trace(option, message)' test as an invalid trace entry was found.  Actual Value: '" + invalidEx.getActualValue() + "'.", invalidEx);
    }
    // make sure all 3 entries exist
    // $NON-NLS-1$
    assertEquals("Wrong number of trace entries", 8, traceOutput.length);
    // validate the trace("/debug", "testing 1", new Exception(exceptionMessage1)) call when verbose tracing is disabled
    // $NON-NLS-1$
    assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[0].getThreadName());
    // $NON-NLS-1$
    assertNull("A bundle was found when it should be null", traceOutput[0].getBundleSymbolicName());
    // $NON-NLS-1$
    assertNull("A class name was found when it should be null", traceOutput[0].getClassName());
    // $NON-NLS-1$
    assertNull("A method name was found when it should be null", traceOutput[0].getMethodName());
    // $NON-NLS-1$
    assertTrue("A line number other than -1 was read in", traceOutput[0].getLineNumber() == -1);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "testing 1", traceOutput[0].getMessage());
    // $NON-NLS-1$
    final StringBuffer expectedThrowableText1 = new StringBuffer("java.lang.Exception: ");
    expectedThrowableText1.append(exceptionMessage1);
    expectedThrowableText1.append(DebugOptionsTestCase.LINE_SEPARATOR);
    expectedThrowableText1.append(DebugOptionsTestCase.TAB_CHARACTER);
    // $NON-NLS-1$
    expectedThrowableText1.append("at org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase.testVerboseDebugging(DebugOptionsTestCase.java:");
    if (!traceOutput[0].getThrowableText().startsWith(expectedThrowableText1.toString())) {
        // $NON-NLS-1$
        final StringBuffer errorMessage = new StringBuffer("The expected throwable text does not start with the actual throwable text.");
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        // $NON-NLS-1$
        errorMessage.append("Expected");
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        // $NON-NLS-1$
        errorMessage.append("--------");
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        errorMessage.append(expectedThrowableText1.toString());
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        // $NON-NLS-1$
        errorMessage.append("Actual");
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        // $NON-NLS-1$
        errorMessage.append("--------");
        errorMessage.append(DebugOptionsTestCase.LINE_SEPARATOR);
        errorMessage.append(traceOutput[0].getThrowableText());
        fail(errorMessage.toString());
    }
    // validate the trace("/debug", "testing 2") call when verbose tracing is re-enabled
    // $NON-NLS-1$
    assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[1].getThreadName());
    // $NON-NLS-1$
    assertEquals("Bundle name is incorrect", getName(), traceOutput[1].getBundleSymbolicName());
    // $NON-NLS-1$//$NON-NLS-2$
    assertEquals("option-path value is incorrect", "/debug", traceOutput[1].getOptionPath());
    // $NON-NLS-1$
    assertEquals("class name value is incorrect", DebugOptionsTestCase.class.getName(), traceOutput[1].getClassName());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("method name value is incorrect", "testVerboseDebugging", traceOutput[1].getMethodName());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "testing 2", traceOutput[1].getMessage());
    assertNull("The throwable text was found when it should be null", traceOutput[1].getThrowableText());
    // validate the trace("/debug", "testing 3") call when verbose is disabled
    // $NON-NLS-1$
    assertEquals("Thread name is incorrect", Thread.currentThread().getName(), traceOutput[2].getThreadName());
    // $NON-NLS-1$
    assertNull("A bundle was found when it should be null", traceOutput[2].getBundleSymbolicName());
    // $NON-NLS-1$
    assertNull("A class name was found when it should be null", traceOutput[2].getClassName());
    // $NON-NLS-1$
    assertNull("A method name was found when it should be null", traceOutput[2].getMethodName());
    // $NON-NLS-1$
    assertTrue("A line number other than -1 was read in", traceOutput[2].getLineNumber() == -1);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "testing 3", traceOutput[2].getMessage());
    assertNull("The throwable text was found when it should be null", traceOutput[2].getThrowableText());
    // validate the traceEntry("/debug") call when verbose is disabled
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with no parameters", traceOutput[3].getMessage());
    // validate the traceEntry("/debug", "arg") call when verbose is disabled
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with parameters: (arg)", traceOutput[4].getMessage());
    // validate the traceEntry("/debug", new String[] {"arg1", "arg2"}) call when verbose is disabled
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "Entering method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with parameters: (arg1 arg2)", traceOutput[5].getMessage());
    // validate the traceExit("/debug") call when verbose is disabled
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "Exiting method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with a void return", traceOutput[6].getMessage());
    // validate the traceExit("/debug", "returnValue") call when verbose is disabled
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals("trace message is incorrect", "Exiting method org.eclipse.osgi.tests.debugoptions.DebugOptionsTestCase#testVerboseDebugging with result: returnValue", traceOutput[7].getMessage());
    // make sure the file is deleted
    traceFile.delete();
    // reset verbose debugging to the default (true)
    fwDebugOptions.setVerbose(true);
}
Also used : FrameworkDebugTraceEntry(org.eclipse.osgi.internal.debug.FrameworkDebugTraceEntry) FrameworkDebugOptions(org.eclipse.osgi.internal.debug.FrameworkDebugOptions) ParseException(java.text.ParseException)

Aggregations

FrameworkDebugOptions (org.eclipse.osgi.internal.debug.FrameworkDebugOptions)3 ParseException (java.text.ParseException)1 Logger (org.apache.felix.resolver.Logger)1 ResolverImpl (org.apache.felix.resolver.ResolverImpl)1 FrameworkDebugTraceEntry (org.eclipse.osgi.internal.debug.FrameworkDebugTraceEntry)1 SecurityAdmin (org.eclipse.osgi.internal.permadmin.SecurityAdmin)1 EquinoxFactoryManager (org.eclipse.osgi.internal.url.EquinoxFactoryManager)1 BundleLocalizationImpl (org.eclipse.osgi.storage.BundleLocalizationImpl)1 BundleURLConverter (org.eclipse.osgi.storage.url.BundleURLConverter)1