Class LaunchConfigurationDelegate

  • All Implemented Interfaces:
    ILaunchConfigurationDelegate, ILaunchConfigurationDelegate2

    public abstract class LaunchConfigurationDelegate
    extends Object
    implements ILaunchConfigurationDelegate2
    Default implementation of a launch configuration delegate. Provides convenience methods for computing the build order of projects, building projects, and searching for errors in the workspace. The default pre-launch check prompts the user to launch in debug mode if breakpoints are present in the workspace.

    Clients implementing launch configuration delegates should subclass this class.

    Since:
    3.0
    • Field Detail

      • promptStatus

        protected static final IStatus promptStatus
        Status code for which a UI prompter is registered.
      • switchToDebugPromptStatus

        protected static final IStatus switchToDebugPromptStatus
        Status code for which a prompter is registered to ask the user if they want to launch in debug mode when breakpoints are present.
      • complileErrorPromptStatus

        protected static final IStatus complileErrorPromptStatus
        Status code for which a prompter is registered to ask the user if the want to continue launch despite existing compile errors
      • saveScopedDirtyEditors

        protected static final IStatus saveScopedDirtyEditors
        Status code for which a prompter will ask the user to save any/all of the dirty editors which have only to do with this launch (scoping them to the current launch/build)
        Since:
        3.2
      • complileErrorProjectPromptStatus

        protected static final IStatus complileErrorProjectPromptStatus
        Status code for which a prompter is registered to ask the user if the want to continue launch despite existing compile errors in specific projects. This enhances the 'compileErrorPromptStatus' by specifying which projects the errors exist in.
        Since:
        3.1
    • Constructor Detail

      • LaunchConfigurationDelegate

        public LaunchConfigurationDelegate()
    • Method Detail

      • getLaunch

        public ILaunch getLaunch​(ILaunchConfiguration configuration,
                                 String mode)
                          throws CoreException
        Description copied from interface: ILaunchConfigurationDelegate2
        Returns a launch object to use when launching the given launch configuration in the given mode, or null if a new default launch object should be created by the debug platform. If a launch object is returned, its launch mode must match that of the mode specified in this method call.
        Specified by:
        getLaunch in interface ILaunchConfigurationDelegate2
        Parameters:
        configuration - the configuration being launched
        mode - the mode the configuration is being launched in
        Returns:
        a launch object or null
        Throws:
        CoreException - if unable to launch
      • buildForLaunch

        public boolean buildForLaunch​(ILaunchConfiguration configuration,
                                      String mode,
                                      IProgressMonitor monitor)
                               throws CoreException
        Description copied from interface: ILaunchConfigurationDelegate2
        Optionally performs any required building before launching the given configuration in the specified mode, and returns whether the debug platform should perform an incremental workspace build before the launch continues. If false is returned the launch will proceed without further building, and if true is returned an incremental build will be performed on the workspace before launching.

        This method is only called if the launch is invoked with flag indicating building should take place before the launch. This is done via the method ILaunchConfiguration.launch(String mode, IProgressMonitor monitor, boolean build).

        Specified by:
        buildForLaunch in interface ILaunchConfigurationDelegate2
        Parameters:
        configuration - the configuration being launched
        mode - the mode the configuration is being launched in
        monitor - progress monitor, or null. A cancelable progress monitor is provided by the Job framework. It should be noted that the setCanceled(boolean) method should never be called on the provided monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
        Returns:
        whether the debug platform should perform an incremental workspace build before the launch
        Throws:
        CoreException - if an exception occurs while building
      • getBuildOrder

        protected IProject[] getBuildOrder​(ILaunchConfiguration configuration,
                                           String mode)
                                    throws CoreException
        Returns the projects to build before launching the given launch configuration or null if the entire workspace should be built incrementally. Subclasses should override as required.
        Parameters:
        configuration - the configuration being launched
        mode - launch mode
        Returns:
        projects to build, in build order, or null
        Throws:
        CoreException - if an exception occurs
      • getProjectsForProblemSearch

        protected IProject[] getProjectsForProblemSearch​(ILaunchConfiguration configuration,
                                                         String mode)
                                                  throws CoreException
        Returns the set of projects to use when searching for errors or null if no search is to be done.
        Parameters:
        configuration - the configuration being launched
        mode - launch mode
        Returns:
        a list of projects or null
        Throws:
        CoreException - if an exception occurs
      • finalLaunchCheck

        public boolean finalLaunchCheck​(ILaunchConfiguration configuration,
                                        String mode,
                                        IProgressMonitor monitor)
                                 throws CoreException
        Description copied from interface: ILaunchConfigurationDelegate2
        Returns whether a launch should proceed. This method is called after preLaunchCheck() and buildForLaunch() providing a final chance for this launch delegate to abort a launch if required. For example, a delegate could cancel a launch if it discovered compilation errors that would prevent the launch from succeeding.
        Specified by:
        finalLaunchCheck in interface ILaunchConfigurationDelegate2
        Parameters:
        configuration - the configuration being launched
        mode - launch mode
        monitor - progress monitor, or null. A cancelable progress monitor is provided by the Job framework. It should be noted that the setCanceled(boolean) method should never be called on the provided monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
        Returns:
        whether the launch should proceed
        Throws:
        CoreException - if an exception occurs during final checks
      • preLaunchCheck

        public boolean preLaunchCheck​(ILaunchConfiguration configuration,
                                      String mode,
                                      IProgressMonitor monitor)
                               throws CoreException
        Description copied from interface: ILaunchConfigurationDelegate2
        Returns whether a launch should proceed. This method is called first in the launch sequence providing an opportunity for this launch delegate to abort the launch.
        Specified by:
        preLaunchCheck in interface ILaunchConfigurationDelegate2
        Parameters:
        configuration - configuration being launched
        mode - launch mode
        monitor - progress monitor, or null. A cancelable progress monitor is provided by the Job framework. It should be noted that the setCanceled(boolean) method should never be called on the provided monitor or the monitor passed to any delegates from this method; due to a limitation in the progress monitor framework using the setCanceled method can cause entire workspace batch jobs to be canceled, as the canceled flag is propagated up the top-level parent monitor. The provided monitor is not guaranteed to have been started.
        Returns:
        whether the launch should proceed
        Throws:
        CoreException - if an exception occurs while performing pre-launch checks
      • saveBeforeLaunch

        protected boolean saveBeforeLaunch​(ILaunchConfiguration configuration,
                                           String mode,
                                           IProgressMonitor monitor)
                                    throws CoreException
        Performs the scoped saving of resources before launching and returns whether the launch should continue. By default, only resources contained within the projects which are part of the build scope are considered.

        Subclasses may override this method if required.

        Parameters:
        configuration - the configuration being launched
        mode - the launch mode
        monitor - progress monitor
        Returns:
        whether the launch should continue
        Throws:
        CoreException - if an exception occurs during the save
        Since:
        3.2
      • getBreakpoints

        protected IBreakpoint[] getBreakpoints​(ILaunchConfiguration configuration)
        Returns the breakpoint collection that is relevant for this launch delegate. By default this is all the breakpoints registered with the Debug breakpoint manager.
        Parameters:
        configuration - the configuration to get associated breakpoints for
        Returns:
        the breakpoints that are relevant for this launch delegate
        Since:
        3.1
      • computeReferencedBuildOrder

        protected IProject[] computeReferencedBuildOrder​(IProject[] baseProjects)
                                                  throws CoreException
        Returns an array of projects in their suggested build order containing all of the projects specified by baseProjects and all of their referenced projects.
        Parameters:
        baseProjects - a collection of projects
        Returns:
        an array of projects in their suggested build order containing all of the projects specified by baseProjects
        Throws:
        CoreException - if an error occurs while computing referenced projects
      • addReferencedProjects

        protected void addReferencedProjects​(IProject project,
                                             Set<IProject> references)
                                      throws CoreException
        Adds all projects referenced by project to the given set.
        Parameters:
        project - project
        references - set to which referenced projects are added
        Throws:
        CoreException - if an error occurs while computing referenced projects
      • computeBuildOrder

        protected IProject[] computeBuildOrder​(IProject[] projects)
        Returns a list of projects in their suggested build order from the given unordered list of projects.
        Parameters:
        projects - the list of projects to sort into build order
        Returns:
        a new array containing all projects from projects sorted according to their build order.
      • existsProblems

        protected boolean existsProblems​(IProject proj)
                                  throws CoreException
        Returns whether the given project contains any problem markers of the specified severity.
        Parameters:
        proj - the project to search
        Returns:
        whether the given project contains any problems that should stop it from launching
        Throws:
        CoreException - if an error occurs while searching for problem markers
      • isLaunchProblem

        protected boolean isLaunchProblem​(IMarker problemMarker)
                                   throws CoreException
        Returns whether the given problem should potentially abort the launch. By default if the problem has an error severity, the problem is considered a potential launch problem. Subclasses may override to specialize error detection.
        Parameters:
        problemMarker - candidate problem
        Returns:
        whether the given problem should potentially abort the launch
        Throws:
        CoreException - if any exceptions occur while accessing marker attributes
      • buildProjects

        protected void buildProjects​(IProject[] projects,
                                     IProgressMonitor monitor)
                              throws CoreException
        Performs an incremental build on each of the given projects.
        Parameters:
        projects - projects to build
        monitor - progress monitor
        Throws:
        CoreException - if an exception occurs while building