Fix for Bug 8513.
authorstechong
Thu, 18 Jun 2009 16:49:04 -0500
changeset 31 c647861c2c67
parent 30 7bb4feeae900
child 32 5fdb1cfe8afb
Fix for Bug 8513.
cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java
cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java
cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties
cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java
--- a/cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java	Tue Jun 16 15:36:31 2009 -0500
+++ b/cdt/cdt_5_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java	Thu Jun 18 16:49:04 2009 -0500
@@ -36,6 +36,19 @@
 	public static final String ATTR_PROJECT_NAME = CDT_LAUNCH_ID + ".PROJECT_ATTR"; //$NON-NLS-1$
 
 	/**
+	 * Launch configuration attribute value constants for build before launch.
+	 */
+	public static final int BUILD_BEFORE_LAUNCH_DISABLED = 0;
+	public static final int BUILD_BEFORE_LAUNCH_ENABLED = 1;
+	public static final int BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING = 2;
+
+	/**
+	 * Launch configuration attribute key. The value is the ID of the project's
+	 * build configuration that should be used when a build is required before launch.
+	 */
+	public static final String ATTR_BUILD_BEFORE_LAUNCH = CDT_LAUNCH_ID + ".ATTR_BUILD_BEFORE_LAUNCH_ATTR"; //$NON-NLS-1$
+
+	/**
 	 * Launch configuration attribute key. The value is the ID of the project's
 	 * build configuration that should be used when a build is required before launch.
 	 */
--- a/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java	Tue Jun 16 15:36:31 2009 -0500
+++ b/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java	Thu Jun 18 16:49:04 2009 -0500
@@ -81,7 +81,13 @@
 	 * A list of prequisite projects ordered by their build order.
 	 */
 	private List orderedProjects;
-
+	
+	/**
+	 * Used in conjunction with build before launch settings in the main tab.
+	 */
+	private boolean buildForLaunchCalled;
+	
+	
 	abstract public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
 			throws CoreException;
 
@@ -519,10 +525,23 @@
 	 * @return whether the debug platform should perform an incremental
 	 *         workspace build before the launch
 	 * @throws CoreException
-	 *             if an exception occurrs while building
+	 *             if an exception occurs while building
 	 */
 	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
-		//This matches the old code, but I don't know that it is the right behaviour.
+
+		buildForLaunchCalled = true;
+		
+		// check the build before launch setting and honor it
+		int buildBeforeLaunchValue = configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
+				ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
+
+		// we shouldn't be getting called if the workspace setting is disabled, so assume we need to
+		// build unless the user explicitly disabled it in the main tab of the launch.
+		if (buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED) {
+			return false;
+		}
+		
+		//This matches the old code, but I don't know that it is the right behavior.
 		//We should be building the local project as well, not just the ordered projects
 		if(orderedProjects == null) {		
 			return false;
@@ -591,6 +610,26 @@
 	 *             if an exception occurs while checking for compile errors.
 	 */
 	public boolean finalLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
+		
+		if (!buildForLaunchCalled) {
+			// buildForLaunch was not called which means that the workspace pref is disabled.  see if the user enabled the
+			// launch specific setting in the main tab.  if so, we do call buildBeforeLaunch here.
+			if (ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED == configuration.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH,
+					ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING)) {
+				
+				IProgressMonitor buildMonitor = new SubProgressMonitor(monitor, 10, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
+				buildMonitor.beginTask(LaunchMessages.getString("AbstractCLaunchDelegate.BuildBeforeLaunch"), 10); //$NON-NLS-1$	
+				buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingBuild")); //$NON-NLS-1$
+				if (buildForLaunch(configuration, mode, new SubProgressMonitor(buildMonitor, 7))) {
+					buildMonitor.subTask(LaunchMessages.getString("AbstractCLaunchDelegate.PerformingIncrementalBuild")); //$NON-NLS-1$
+					ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(buildMonitor, 3));				
+				}
+				else {
+					buildMonitor.worked(3); /* No incremental build required */
+				}
+			}
+		}
+
 		boolean continueLaunch = true;
 		if(orderedProjects == null) {
 			return continueLaunch;
@@ -670,6 +709,8 @@
 			monitor = new NullProgressMonitor();
 		}
 
+		buildForLaunchCalled = false;
+
 		int scale = 1000;
 		int totalWork = 2 * scale;
 		
--- a/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties	Tue Jun 16 15:36:31 2009 -0500
+++ b/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/internal/ui/LaunchMessages.properties	Thu Jun 18 16:49:04 2009 -0500
@@ -30,6 +30,9 @@
 AbstractCLaunchDelegate.searching_for_errors_in=Searching for compile errors in 
 AbstractCLaunchDelegate.20=Building prerequisite project list
 AbstractCLaunchDelegate.Program_is_not_a_recongnized_executable=Program is not a recognized executable.
+AbstractCLaunchDelegate.BuildBeforeLaunch=Build before launch - 
+AbstractCLaunchDelegate.PerformingBuild=Performing required build...
+AbstractCLaunchDelegate.PerformingIncrementalBuild=Performing incremental workspace build...
 
 LocalRunLaunchDelegate.Launching_Local_C_Application=Launching Local C/C++ Application
 LocalRunLaunchDelegate.Failed_setting_runtime_option_though_debugger=Failed to set program arguments, environment or working directory.
@@ -97,6 +100,15 @@
 CMainTab.Program_is_not_a_recongnized_executable=Program is not a recognized executable.
 #For CMainTab.Configuration_name: {0} - project name; {1} - configuration name
 CMainTab.Configuration_name={0} {1}
+CMainTab.Build_options=Build (if required) before launching
+CMainTab.Disable_build_button_label=Disable auto build
+CMainTab.Disable_build_button_tooltip=Requires manually building project before launching (this may improve launch performance)
+CMainTab.Enable_build_button_label=Enable auto build
+CMainTab.Enable_build_button_tooltip=Always build project before launching (this may impact launch performance)
+CMainTab.Workspace_settings_button_label=Use workspace settings
+CMainTab.Workspace_settings_button_tooltip=Use workspace settings
+CMainTab.Workspace_settings_link_label=<a>Configure Workspace Settings...</a>
+CMainTab.Workspace_settings_page_id=org.eclipse.debug.ui.LaunchingPreferencePage
 
 CDebuggerTab.Advanced_Options_Dialog_Title=Advanced Options
 CDebuggerTab.Stop_at_main_on_startup=Stop on startup at:
--- a/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java	Tue Jun 16 15:36:31 2009 -0500
+++ b/cdt/cdt_5_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java	Thu Jun 18 16:49:04 2009 -0500
@@ -57,9 +57,12 @@
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.PreferencesUtil;
 import org.eclipse.ui.dialogs.TwoPaneElementSelector;
 
 /**
@@ -84,6 +87,12 @@
 	protected Text fProgText;
 	protected Button fSearchButton;
 
+	// Build option UI widgets
+	protected Button fDisableBuildButton;
+	protected Button fEnableBuildButton;
+	protected Button fWorkspaceSettingsButton;
+	protected Link fWorkpsaceSettingsLink;
+
 	private final boolean fWantsTerminalOption;
 	protected Button fTerminalButton;
 
@@ -126,6 +135,7 @@
 		createVerticalSpacer(comp, 1);
 		createProjectGroup(comp, 1);
 		createExeFileGroup(comp, 1);
+		createBuildOptionGroup(comp, 1);
 		createVerticalSpacer(comp, 1);
 		if (wantsTerminalOption() /* && ProcessFactory.supportesTerminal() */) {
 			createTerminalOption(comp, 1);
@@ -212,6 +222,66 @@
 		});
 	}
 
+	protected void createBuildOptionGroup(final Composite parent, int colSpan) {
+		Group buildGroup = new Group(parent, SWT.NONE);
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.horizontalSpan = colSpan;
+		GridLayout gridLayout = new GridLayout();
+		gridLayout.numColumns = 2;
+		gridLayout.marginHeight = 5;
+		gridLayout.marginWidth = 5;
+		gridLayout.makeColumnsEqualWidth= true;
+		buildGroup.setLayoutData(gridData);
+		buildGroup.setLayout(gridLayout);
+		buildGroup.setText("Build (if required) before launching"); //$NON-NLS-1$
+
+		fDisableBuildButton = new Button(buildGroup, SWT.RADIO);
+		fDisableBuildButton.setText(LaunchMessages.getString("CMainTab.Disable_build_button_label")); //$NON-NLS-1$
+		fDisableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Disable_build_button_tooltip")); //$NON-NLS-1$
+		fDisableBuildButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+			}
+		});
+		
+		new Label(buildGroup, SWT.NONE);
+
+		fEnableBuildButton = new Button(buildGroup, SWT.RADIO);
+		fEnableBuildButton.setText(LaunchMessages.getString("CMainTab.Enable_build_button_label")); //$NON-NLS-1$
+		fEnableBuildButton.setToolTipText(LaunchMessages.getString("CMainTab.Enable_build_button_tooltip")); //$NON-NLS-1$
+		fEnableBuildButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+			}
+		});
+		
+		new Label(buildGroup, SWT.NONE);
+		
+		fWorkspaceSettingsButton = new Button(buildGroup, SWT.RADIO);
+		fWorkspaceSettingsButton.setText(LaunchMessages.getString("CMainTab.Workspace_settings_button_label")); //$NON-NLS-1$
+		fWorkspaceSettingsButton.setToolTipText(LaunchMessages.getString("CMainTab.Workspace_settings_button_tooltip")); //$NON-NLS-1$
+		fWorkspaceSettingsButton.addSelectionListener(new SelectionAdapter() {
+
+			public void widgetSelected(SelectionEvent evt) {
+				updateLaunchConfigurationDialog();
+			}
+		});
+
+		fWorkpsaceSettingsLink = new Link(buildGroup, SWT.NONE); //$NON-NLS-1$
+		fWorkpsaceSettingsLink.setText(LaunchMessages.getString("CMainTab.Workspace_settings_link_label")); //$NON-NLS-1$
+		fWorkpsaceSettingsLink.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				PreferencesUtil.createPreferenceDialogOn(
+						parent.getShell(), 
+						LaunchMessages.getString("CMainTab.Workspace_settings_page_id"), //$NON-NLS-1$
+						null, 
+						null).open();
+			}
+		});
+	}
+
 	protected boolean wantsTerminalOption() {
 		return fWantsTerminalOption;
 	}
@@ -246,6 +316,7 @@
 		filterPlatform = getPlatform(config);
 		updateProjectFromConfig(config);
 		updateProgramFromConfig(config);
+		updateBuildOptionFromConfig(config);
 		updateTerminalFromConfig(config);
 	}
 
@@ -272,13 +343,28 @@
 	}
 
 	protected void updateProgramFromConfig(ILaunchConfiguration config) {
-		String programName = EMPTY_STRING;
+		if (fProgText != null) {
+			String programName = EMPTY_STRING;
+			try {
+				programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
+			} catch (CoreException ce) {
+				LaunchUIPlugin.log(ce);
+			}
+			fProgText.setText(programName);
+		}
+	}
+
+	protected void updateBuildOptionFromConfig(ILaunchConfiguration config) {
+		int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
 		try {
-			programName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, EMPTY_STRING);
-		} catch (CoreException ce) {
-			LaunchUIPlugin.log(ce);
+			buildBeforeLaunchValue = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
+		} catch (CoreException e) {
+			LaunchUIPlugin.log(e);
 		}
-		fProgText.setText(programName);
+
+		fDisableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED);
+		fEnableBuildButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED);
+		fWorkspaceSettingsButton.setSelection(buildBeforeLaunchValue == ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING);
 	}
 
 	/*
@@ -303,11 +389,25 @@
 				}
 			} catch (CoreException e) { e.printStackTrace(); }
 		}
+		
 		config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, fProjText.getText());
-		config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText());
+		
+		if (fProgText != null) {
+			config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, fProgText.getText());
+		}
 		if (fTerminalButton != null) {
 			config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_USE_TERMINAL, fTerminalButton.getSelection());
 		}
+
+		if (fDisableBuildButton != null) {
+			int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
+			if (fDisableBuildButton.getSelection()) {
+				buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_DISABLED;
+			} else if (fEnableBuildButton.getSelection()) {
+				buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_ENABLED;
+			}
+			config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
+		}
 	}
 
 	/**