Search in sources :

Example 1 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method run.

/**
 * Launches the platform and runs a single application. The application is either identified
 * in the given arguments (e.g., -application &lt;app id&gt;) or in the <code>eclipse.application</code>
 * System property.  This convenience method starts
 * up the platform, runs the indicated application, and then shuts down the
 * platform. The platform must not be running already.
 *
 * @param args the command line-style arguments used to configure the platform
 * @param endSplashHandler the block of code to run to tear down the splash
 * 	screen or <code>null</code> if no tear down is required
 * @return the result of running the application
 * @throws Exception if anything goes wrong
 */
public static Object run(String[] args, Runnable endSplashHandler) throws Exception {
    if (running)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_ALREADY_RUNNING);
    boolean startupFailed = true;
    try {
        startup(args, endSplashHandler);
        startupFailed = false;
        if (Boolean.valueOf(getProperty(PROP_IGNOREAPP)).booleanValue() || isForcedRestart())
            return null;
        return run(null);
    } catch (Throwable e) {
        // ensure the splash screen is down
        if (endSplashHandler != null)
            endSplashHandler.run();
        // may use startupFailed to understand where the error happened
        FrameworkLogEntry logEntry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, startupFailed ? Msg.ECLIPSE_STARTUP_STARTUP_ERROR : Msg.ECLIPSE_STARTUP_APP_ERROR, 1, e, null);
        if (log != null)
            log.log(logEntry);
        else
            // TODO desperate measure - ideally, we should write this to disk (a la Main.log)
            e.printStackTrace();
    } finally {
        try {
            // it be re-started. We need to check for this and potentially override the exit code.
            if (isForcedRestart())
                // $NON-NLS-1$
                setProperty(PROP_EXITCODE, "23");
            if (!Boolean.valueOf(getProperty(PROP_NOSHUTDOWN)).booleanValue())
                shutdown();
        } catch (Throwable e) {
            FrameworkLogEntry logEntry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, Msg.ECLIPSE_STARTUP_SHUTDOWN_ERROR, 1, e, null);
            if (log != null)
                log.log(logEntry);
            else
                // TODO desperate measure - ideally, we should write this to disk (a la Main.log)
                e.printStackTrace();
        }
    }
    // we only get here if an error happened
    if (getProperty(PROP_EXITCODE) == null) {
        // $NON-NLS-1$
        setProperty(PROP_EXITCODE, "13");
        setProperty(PROP_EXITDATA, NLS.bind(Msg.ECLIPSE_STARTUP_ERROR_CHECK_LOG, log == null ? null : log.getFile().getPath()));
    }
    return null;
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 2 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseStarter method startup.

/**
 * Starts the platform and sets it up to run a single application. The application is either identified
 * in the given arguments (e.g., -application &lt;app id&gt;) or in the <code>eclipse.application</code>
 * System property.  The platform must not be running already.
 * <p>
 * The given runnable (if not <code>null</code>) is used to tear down the splash screen if required.
 * </p>
 * @param args the arguments passed to the application
 * @return BundleContext the context of the system bundle
 * @throws Exception if anything goes wrong
 */
public static BundleContext startup(String[] args, Runnable endSplashHandler) throws Exception {
    if (running)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_ALREADY_RUNNING);
    processCommandLine(args);
    framework = new Equinox(getConfiguration());
    framework.init();
    context = framework.getBundleContext();
    ServiceReference<FrameworkLog> logRef = context.getServiceReference(FrameworkLog.class);
    log = context.getService(logRef);
    ServiceReference<EnvironmentInfo> configRef = context.getServiceReference(EnvironmentInfo.class);
    equinoxConfig = (EquinoxConfiguration) context.getService(configRef);
    equinoxConfig.setAllArgs(allArgs);
    equinoxConfig.setFrameworkArgs(frameworkArgs);
    equinoxConfig.setAppArgs(appArgs);
    registerFrameworkShutdownHandlers();
    publishSplashScreen(endSplashHandler);
    consoleMgr = ConsoleManager.startConsole(context, equinoxConfig);
    Bundle[] startBundles = loadBasicBundles();
    if (startBundles == null || ("true".equals(getProperty(PROP_REFRESH_BUNDLES)) && refreshPackages(getCurrentBundles(false)))) {
        // $NON-NLS-1$
        waitForShutdown();
        // cannot continue; loadBasicBundles caused refreshPackages to shutdown the framework
        return context;
    }
    framework.start();
    if (isForcedRestart()) {
        return context;
    }
    // set the framework start level to the ultimate value.  This will actually start things
    // running if they are persistently active.
    setStartLevel(getStartLevel());
    // they should all be active by this time
    ensureBundlesActive(startBundles);
    // in the case where the built-in console is disabled we should try to start the console bundle
    try {
        consoleMgr.checkForConsoleBundle();
    } catch (BundleException e) {
        FrameworkLogEntry entry = new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, e.getMessage(), 0, e, null);
        log.log(entry);
    }
    // TODO should log unresolved bundles if in debug or dev mode
    running = true;
    return context;
}
Also used : Equinox(org.eclipse.osgi.launch.Equinox) FrameworkLog(org.eclipse.osgi.framework.log.FrameworkLog) EnvironmentInfo(org.eclipse.osgi.service.environment.EnvironmentInfo) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 3 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class HookRegistry method mergeFileHookConfigurators.

private void mergeFileHookConfigurators(List<String> configuratorList, List<FrameworkLogEntry> errors) {
    ClassLoader cl = getClass().getClassLoader();
    // get all hook configurators files in your classloader delegation
    Enumeration<URL> hookConfigurators;
    try {
        hookConfigurators = cl != null ? cl.getResources(HookRegistry.HOOK_CONFIGURATORS_FILE) : ClassLoader.getSystemResources(HookRegistry.HOOK_CONFIGURATORS_FILE);
    } catch (IOException e) {
        // $NON-NLS-1$
        errors.add(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, "getResources error on " + HookRegistry.HOOK_CONFIGURATORS_FILE, 0, e, null));
        return;
    }
    int curBuiltin = 0;
    while (hookConfigurators.hasMoreElements()) {
        URL url = hookConfigurators.nextElement();
        InputStream input = null;
        try {
            // check each file for a hook.configurators property
            Properties configuratorProps = new Properties();
            input = url.openStream();
            configuratorProps.load(input);
            String hooksValue = configuratorProps.getProperty(HOOK_CONFIGURATORS);
            if (hooksValue == null)
                continue;
            boolean builtin = Boolean.valueOf(configuratorProps.getProperty(BUILTIN_HOOKS)).booleanValue();
            // $NON-NLS-1$
            String[] configurators = ManifestElement.getArrayFromList(hooksValue, ",");
            for (int i = 0; i < configurators.length; i++) if (!configuratorList.contains(configurators[i])) {
                if (// make sure the built-in configurators are listed first (bug 170881)
                builtin)
                    configuratorList.add(curBuiltin++, configurators[i]);
                else
                    configuratorList.add(configurators[i]);
            }
        } catch (IOException e) {
            // $NON-NLS-1$
            errors.add(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, "error loading: " + url.toExternalForm(), 0, e, null));
        // ignore and continue to next URL
        } finally {
            if (input != null)
                try {
                    input.close();
                } catch (IOException e) {
                // do nothing
                }
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) URL(java.net.URL)

Example 4 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class HookRegistry method loadConfigurators.

private void loadConfigurators(List<String> configurators, List<FrameworkLogEntry> errors) {
    for (Iterator<String> iHooks = configurators.iterator(); iHooks.hasNext(); ) {
        String hookName = iHooks.next();
        try {
            Class<?> clazz = Class.forName(hookName);
            HookConfigurator configurator = (HookConfigurator) clazz.newInstance();
            configurator.addHooks(this);
        } catch (Throwable t) {
            // We expect the follow exeptions may happen; but we need to catch all here
            // ClassNotFoundException
            // IllegalAccessException
            // InstantiationException
            // ClassCastException
            // $NON-NLS-1$
            errors.add(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, "error loading hook: " + hookName, 0, t, null));
        }
    }
}
Also used : WeavingHookConfigurator(org.eclipse.osgi.internal.weaving.WeavingHookConfigurator) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry)

Example 5 with FrameworkLogEntry

use of org.eclipse.osgi.framework.log.FrameworkLogEntry in project rt.equinox.framework by eclipse.

the class EclipseAppLauncher method start.

/*
	 * Starts this application launcher on the current thread.  This method
	 * should be called by the main thread to ensure that applications are 
	 * launched in the main thread.
	 */
public Object start(Object defaultContext) throws Exception {
    // TODO this may be a bad assumption but it works for now because we register the app launcher as a service and runtime synchronously calls launch on the service
    if (failOnNoDefault && runnable == null)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_ERROR_NO_APPLICATION);
    Object result = null;
    boolean doRelaunch;
    Bundle b = context.getBundle();
    do {
        try {
            if (relaunch) {
                // need a thread to kick the main thread when the framework stops
                final Thread mainThread = Thread.currentThread();
                final BundleContext mainContext = context;
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        Framework framework = (Framework) mainContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
                        try {
                            framework.waitForStop(0);
                            // framework is done; tell the main thread to stop
                            mainThread.interrupt();
                        } catch (InterruptedException e) {
                            Thread.interrupted();
                        // just exiting now
                        }
                    }
                }, "Framework watcher").start();
            }
            result = runApplication(defaultContext);
        } catch (Exception e) {
            if (!relaunch || (b.getState() & Bundle.ACTIVE) == 0)
                throw e;
            if (log != null)
                log.log(new FrameworkLogEntry(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, 0, Msg.ECLIPSE_STARTUP_APP_ERROR, 1, e, null));
        }
        doRelaunch = (relaunch && (b.getState() & Bundle.ACTIVE) != 0);
    } while (doRelaunch);
    return result;
}
Also used : FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) Framework(org.osgi.framework.launch.Framework)

Aggregations

FrameworkLogEntry (org.eclipse.osgi.framework.log.FrameworkLogEntry)16 Logger (org.eclipse.equinox.log.Logger)2 FrameworkLog (org.eclipse.osgi.framework.log.FrameworkLog)2 WeavingHookConfigurator (org.eclipse.osgi.internal.weaving.WeavingHookConfigurator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 Module (org.eclipse.osgi.container.Module)1 DevClassLoadingHook (org.eclipse.osgi.internal.hooks.DevClassLoadingHook)1 EclipseLazyStarter (org.eclipse.osgi.internal.hooks.EclipseLazyStarter)1 SignedBundleHook (org.eclipse.osgi.internal.signedcontent.SignedBundleHook)1 Equinox (org.eclipse.osgi.launch.Equinox)1 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)1 Location (org.eclipse.osgi.service.datalocation.Location)1 EnvironmentInfo (org.eclipse.osgi.service.environment.EnvironmentInfo)1 Framework (org.osgi.framework.launch.Framework)1 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1 Resource (org.osgi.resource.Resource)1