Build for Eclipse 3.5 and CDT 6.0.
authorryall
Mon, 03 Aug 2009 17:19:13 -0500
changeset 47 4c12a1ced0aa
parent 46 a77f821427fa
child 48 b1ed4ce3cbe4
Build for Eclipse 3.5 and CDT 6.0.
cdt/cdt_6_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java
cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java
cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java
--- a/cdt/cdt_6_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java	Fri Jul 31 15:55:52 2009 -0500
+++ b/cdt/cdt_6_0_x/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/ICDTLaunchConfigurationConstants.java	Mon Aug 03 17:19:13 2009 -0500
@@ -50,6 +50,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_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java	Fri Jul 31 15:55:52 2009 -0500
+++ b/cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/AbstractCLaunchDelegate.java	Mon Aug 03 17:19:13 2009 -0500
@@ -136,6 +136,10 @@
 	private List orderedProjects;
 	private String preLaunchBuildConfiguration;
 
+	/**
+	 * 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;
 
@@ -591,11 +595,24 @@
 	 * @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
 	 */
 	@Override
 	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;
@@ -666,6 +683,26 @@
 	 */
 	@Override
 	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;
@@ -770,6 +807,8 @@
 			monitor = new NullProgressMonitor();
 		}
 
+		buildForLaunchCalled = false;
+
 		int scale = 1000;
 		int totalWork = 2 * scale;
 		
--- a/cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java	Fri Jul 31 15:55:52 2009 -0500
+++ b/cdt/cdt_6_0_x/org.eclipse.cdt.launch/src/org/eclipse/cdt/launch/ui/CMainTab.java	Mon Aug 03 17:19:13 2009 -0500
@@ -66,9 +66,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;
 
 /**
@@ -114,6 +117,11 @@
 	 * @since 6.0
 	 */
 	protected Combo fBuildConfigCombo;
+	// Build option UI widgets
+	protected Button fDisableBuildButton;
+	protected Button fEnableBuildButton;
+	protected Button fWorkspaceSettingsButton;
+	protected Link fWorkpsaceSettingsLink;
 
 	private final boolean fWantsTerminalOption;
 	protected Button fTerminalButton;
@@ -320,6 +328,65 @@
 		});
 	}
 
+	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();
+			}
+		});
+	}
 	/** @since 6.0 */
 	protected void createCoreFileGroup(Composite parent, int colSpan) {
 		Composite coreComp = new Composite(parent, SWT.NONE);
@@ -395,6 +462,7 @@
 		updateProjectFromConfig(config);
 		updateProgramFromConfig(config);
 		updateCoreFromConfig(config);
+		updateBuildOptionFromConfig(config);
 		updateTerminalFromConfig(config);
 	}
 
@@ -442,10 +510,23 @@
 			} catch (CoreException ce) {
 				LaunchUIPlugin.log(ce);
 			}
-			fCoreText.setText(coreName);
+			fProgText.setText(coreName);
 		}
 	}
-	
+
+	protected void updateBuildOptionFromConfig(ILaunchConfiguration config) {
+		int buildBeforeLaunchValue = ICDTLaunchConfigurationConstants.BUILD_BEFORE_LAUNCH_USE_WORKSPACE_SETTING;
+		try {
+			buildBeforeLaunchValue = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_BUILD_BEFORE_LAUNCH, buildBeforeLaunchValue);
+		} catch (CoreException e) {
+			LaunchUIPlugin.log(e);
+		}
+
+		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);
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -472,6 +553,16 @@
 		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);
+		}
 	}
 
 	/**