Search in sources :

Example 41 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class EclipseStarter method run.

/**
 * Runs the application for which the platform was started. The platform
 * must be running.
 * <p>
 * The given argument is passed to the application being run.  If it is <code>null</code>
 * then the command line arguments used in starting the platform, and not consumed
 * by the platform code, are passed to the application as a <code>String[]</code>.
 * </p>
 * @param argument the argument passed to the application. May be <code>null</code>
 * @return the result of running the application
 * @throws Exception if anything goes wrong
 */
public static Object run(Object argument) throws Exception {
    if (!running)
        throw new IllegalStateException(Msg.ECLIPSE_STARTUP_NOT_RUNNING);
    // if we are just initializing, do not run the application just return.
    if (initialize)
        return Integer.valueOf(0);
    try {
        if (appLauncher == null) {
            // $NON-NLS-1$
            boolean launchDefault = Boolean.valueOf(getProperty(PROP_APPLICATION_LAUNCHDEFAULT, "true")).booleanValue();
            // create the ApplicationLauncher and register it as a service
            appLauncher = new EclipseAppLauncher(context, Boolean.valueOf(getProperty(PROP_ALLOW_APPRELAUNCH)).booleanValue(), launchDefault, log, equinoxConfig);
            appLauncherRegistration = context.registerService(ApplicationLauncher.class.getName(), appLauncher, null);
            // will return only after the application has stopped.
            return appLauncher.start(argument);
        }
        return appLauncher.reStart(argument);
    } catch (Exception e) {
        if (log != null && context != null) {
            // context can be null if OSGi failed to launch (bug 151413)
            ResolutionReport report = context.getBundle().adapt(Module.class).getContainer().resolve(null, false);
            for (Resource unresolved : report.getEntries().keySet()) {
                String bsn = ((ModuleRevision) unresolved).getSymbolicName();
                FrameworkLogEntry logEntry = new FrameworkLogEntry(bsn != null ? bsn : EquinoxContainer.NAME, FrameworkLogEntry.WARNING, 0, Msg.Module_ResolveError + report.getResolutionReportMessage(unresolved), 1, null, null);
                log.log(logEntry);
            }
        }
        throw e;
    }
}
Also used : Resource(org.osgi.resource.Resource) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Module(org.eclipse.osgi.container.Module)

Example 42 with ResolutionReport

use of org.eclipse.osgi.report.resolution.ResolutionReport in project rt.equinox.framework by eclipse.

the class Module method start.

/**
 * Starts this module
 * @param options the options for starting
 * @throws BundleException if an errors occurs while starting
 */
public void start(StartOptions... options) throws BundleException {
    revisions.getContainer().checkAdminPermission(getBundle(), AdminPermission.EXECUTE);
    if (options == null) {
        options = new StartOptions[0];
    }
    ModuleEvent event;
    if (StartOptions.LAZY_TRIGGER.isContained(options)) {
        setTrigger();
        if (stateChangeLock.getHoldCount() > 0 && stateTransitionEvents.contains(ModuleEvent.STARTED)) {
            // nothing to do here; the current thread is activating the bundle.
            return;
        }
    }
    BundleException startError = null;
    boolean lockedStarted = false;
    // Indicate we are in the middle of a start.
    // This must be incremented before we acquire the STARTED lock the first time.
    inStart.incrementAndGet();
    try {
        lockStateChange(ModuleEvent.STARTED);
        lockedStarted = true;
        checkValid();
        if (StartOptions.TRANSIENT_IF_AUTO_START.isContained(options) && !settings.contains(Settings.AUTO_START)) {
            // Do nothing; this is a request to start only if the module is set for auto start
            return;
        }
        checkFragment();
        persistStartOptions(options);
        if (getStartLevel() > getRevisions().getContainer().getStartLevel()) {
            if (StartOptions.TRANSIENT.isContained(options)) {
                // it is an error to attempt to transient start a bundle without its start level met
                throw new BundleException(Msg.Module_Transient_StartError, BundleException.START_TRANSIENT_ERROR);
            }
            // Do nothing; start level is not met
            return;
        }
        if (State.ACTIVE.equals(getState()))
            return;
        if (getState().equals(State.INSTALLED)) {
            ResolutionReport report;
            // must unlock to avoid out of order locks when multiple unresolved
            // bundles are started at the same time from different threads
            unlockStateChange(ModuleEvent.STARTED);
            lockedStarted = false;
            try {
                report = getRevisions().getContainer().resolve(Arrays.asList(this), true);
            } finally {
                lockStateChange(ModuleEvent.STARTED);
                lockedStarted = true;
            }
            // need to check valid again in case someone uninstalled the bundle
            checkValid();
            ResolutionException e = report.getResolutionException();
            if (e != null) {
                if (e.getCause() instanceof BundleException) {
                    throw (BundleException) e.getCause();
                }
            }
            if (State.ACTIVE.equals(getState()))
                return;
            if (getState().equals(State.INSTALLED)) {
                String reportMessage = report.getResolutionReportMessage(getCurrentRevision());
                throw new BundleException(Msg.Module_ResolveError + reportMessage, BundleException.RESOLVE_ERROR);
            }
        }
        try {
            event = doStart(options);
        } catch (BundleException e) {
            // must return state to resolved
            setState(State.RESOLVED);
            startError = e;
            // must always publish the STOPPED event on error
            event = ModuleEvent.STOPPED;
        }
    } finally {
        if (lockedStarted) {
            unlockStateChange(ModuleEvent.STARTED);
        }
        inStart.decrementAndGet();
    }
    if (event != null) {
        if (!EnumSet.of(ModuleEvent.STARTED, ModuleEvent.LAZY_ACTIVATION, ModuleEvent.STOPPED).contains(event))
            // $NON-NLS-1$
            throw new IllegalStateException("Wrong event type: " + event);
        publishEvent(event);
    }
    if (startError != null) {
        throw startError;
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) ModuleEvent(org.eclipse.osgi.container.ModuleContainerAdaptor.ModuleEvent) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport)

Aggregations

ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)42 Module (org.eclipse.osgi.container.Module)37 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)36 Test (org.junit.Test)33 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)23 HashMap (java.util.HashMap)22 ModuleWire (org.eclipse.osgi.container.ModuleWire)13 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)6 ArrayList (java.util.ArrayList)4 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)4 BundleException (org.osgi.framework.BundleException)3 HashSet (java.util.HashSet)2 ExecutorService (java.util.concurrent.ExecutorService)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)2 DummyCollisionHook (org.eclipse.osgi.tests.container.dummys.DummyCollisionHook)2 DummyContainerEvent (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase.DummyContainerEvent)2 BundleCapability (org.osgi.framework.wiring.BundleCapability)2 ResolutionException (org.osgi.service.resolver.ResolutionException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1