Search in sources :

Example 6 with IStatusHandler

use of org.eclipse.debug.core.IStatusHandler in project bndtools by bndtools.

the class NativeBndLaunchDelegate method isAlreadyRunning.

/**
 * Check if we already have a configuration running
 */
public boolean isAlreadyRunning(ILaunchConfiguration configuration) throws CoreException {
    // Check for existing launches of same resource
    BndPreferences prefs = new BndPreferences();
    if (prefs.getWarnExistingLaunches()) {
        IResource launchResource = LaunchUtils.getTargetResource(configuration);
        if (launchResource == null)
            return false;
        int processCount = 0;
        for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
            // ... is it the same launch resource?
            ILaunchConfiguration launchConfig = l.getLaunchConfiguration();
            if (launchConfig == null) {
                continue;
            }
            if (launchResource.equals(LaunchUtils.getTargetResource(launchConfig))) {
                // Iterate existing processes
                for (IProcess process : l.getProcesses()) {
                    if (!process.isTerminated())
                        processCount++;
                }
            }
        }
        // Warn if existing processes running
        if (processCount > 0) {
            Status status = new Status(IStatus.WARNING, Plugin.PLUGIN_ID, 0, "One or more OSGi Frameworks have already been launched for this configuration. Additional framework instances may interfere with each other due to the shared storage directory.", null);
            IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
            if (prompter != null) {
                boolean okay = (Boolean) prompter.handleStatus(status, launchResource);
                return !okay;
            }
        }
    }
    return false;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) BndPreferences(bndtools.preferences.BndPreferences) IStatusHandler(org.eclipse.debug.core.IStatusHandler) ILaunch(org.eclipse.debug.core.ILaunch) IProcess(org.eclipse.debug.core.model.IProcess) IResource(org.eclipse.core.resources.IResource)

Aggregations

IStatusHandler (org.eclipse.debug.core.IStatusHandler)6 Status (org.eclipse.core.runtime.Status)5 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 IResource (org.eclipse.core.resources.IResource)3 BndPreferences (bndtools.preferences.BndPreferences)2 ILaunch (org.eclipse.debug.core.ILaunch)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)2 IProcess (org.eclipse.debug.core.model.IProcess)2 Project (aQute.bnd.build.Project)1 ProjectLauncher (aQute.bnd.build.ProjectLauncher)1 Run (aQute.bnd.build.Run)1 RunSession (aQute.bnd.build.RunSession)1 Processor (aQute.bnd.osgi.Processor)1 LaunchStatusHandler (bndtools.launch.ui.internal.LaunchStatusHandler)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1