diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java index bbc23275cd0..6b22cd1e96d 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java @@ -4595,12 +4595,56 @@ public class ManagedBuildManager extends AbstractCExtension { } public static void buildConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders) throws CoreException{ + buildOrCleanConfigurations(configs, builder, monitor, allBuilders, IncrementalProjectBuilder.FULL_BUILD); + } + + /** + * Clean the specified build configurations + * @param configs + * @param monitor + * @throws CoreException + * @since 7.0 + */ + public static void cleanConfigurations(IConfiguration[] configs, IProgressMonitor monitor) throws CoreException{ + cleanConfigurations(configs, null, monitor); + } + + /** + * Clean the specified build configurations using the given builder + * @param configs + * @param builder + * @param monitor + * @throws CoreException + * @since 7.0 + */ + public static void cleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor) throws CoreException{ + cleanConfigurations(configs, builder, monitor, true); + } + + /** + * Clean the specified configurations + * @param configs + * @param builder + * @param monitor + * @param allBuilders + * @throws CoreException + * @since 7.0 + */ + public static void cleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders) throws CoreException{ + buildOrCleanConfigurations(configs, builder, monitor, allBuilders, IncrementalProjectBuilder.CLEAN_BUILD); + } + + private static void buildOrCleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders, int buildKind) throws CoreException{ Map map = sortConfigs(configs); for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){ Map.Entry entry = (Map.Entry)iter.next(); IProject proj = (IProject)entry.getKey(); IConfiguration[] cfgs = (IConfiguration[])entry.getValue(); - buildConfigurations(proj, cfgs, builder, monitor, allBuilders); + if(buildKind == IncrementalProjectBuilder.CLEAN_BUILD) { + cleanConfigurations(proj, cfgs, builder, monitor, allBuilders); + } else { + buildConfigurations(proj, cfgs, builder, monitor, allBuilders); + } } } @@ -4668,6 +4712,46 @@ public class ManagedBuildManager extends AbstractCExtension { } + private static void cleanConfigurations(final IProject project, final IConfiguration[] configs, IBuilder builder, final IProgressMonitor monitor, boolean allBuilders) throws CoreException{ + final boolean runAllBuidlers = allBuilders; + final IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project); + IConfiguration savedCfg = buildInfo.getDefaultConfiguration(); + IWorkspaceRunnable op = new IWorkspaceRunnable() { + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public void run(IProgressMonitor monitor) throws CoreException { + ICommand[] commands = project.getDescription().getBuildSpec(); + int totalWork = (runAllBuidlers) ? commands.length * configs.length : configs.length; + + // iterate through all configurations and clean them + monitor.beginTask("", totalWork); //$NON-NLS-1$ + for (IConfiguration config : configs) { + buildInfo.setDefaultConfiguration(config); + if (runAllBuidlers) { + for (int i = 0; i < commands.length; i++) { + // currently the platform doesn't accept arguments for a builder to clean a project, thus arguments are null + project.build(IncrementalProjectBuilder.CLEAN_BUILD, commands[i].getBuilderName(), null, new SubProgressMonitor(monitor, 1)); + } + } else { + project.build(IncrementalProjectBuilder.CLEAN_BUILD, CommonBuilder.BUILDER_ID, null, new SubProgressMonitor(monitor, 1)); + } + } + } + }; + try { + ResourcesPlugin.getWorkspace().run(op, monitor); + } finally { + // complete the progress monitor and restore default configuration + monitor.done(); + buildInfo.setDefaultConfiguration(savedCfg); + } + + } + public static IBuilder getInternalBuilder(){ return getExtensionBuilder(INTERNAL_BUILDER_ID); } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties index 13d9f784048..8198d290769 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.properties @@ -54,6 +54,7 @@ Environment=Environment BuildCfgMenu.label=Build configurations BuildMenu.label=Build +CleanMenu.label=Clean Build.System.Wizard=Build System Wizard Make.Project.Wizard=Make Project Wizard diff --git a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml index 7a7b3e7547e..2ca8a5094fc 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml +++ b/build/org.eclipse.cdt.managedbuilder.ui/plugin.xml @@ -95,6 +95,13 @@ objectClass="org.eclipse.core.resources.IProject" adaptable="true" id="org.eclipse.cdt.managedbuilder.ui.popupMenu.BuildAll"> + projects = null; + private ActionContributionItem it_all = null; + private ActionContributionItem it_sel = null; + + /* + * Get message strings + */ + protected abstract String getTIP_ALL(); + protected abstract String getLBL_ALL(); + protected abstract String getJOB_MSG(); + protected abstract String getERR_MSG(); + protected abstract String getLBL_SEL(); + protected abstract String getTIP_SEL(); + protected abstract String getDLG_TEXT(); + protected abstract String getDLG_TITLE(); + /** + * Perform the requested build + * @param configs + * @param monitor + * @throws CoreException + */ + protected abstract void performAction(IConfiguration[] configs, IProgressMonitor monitor) throws CoreException; + + @Override + public void selectionChanged(IAction action, ISelection selection) { + projects = null; + + if (!selection.isEmpty()) { + // case for context menu + if (selection instanceof IStructuredSelection) { + Object[] obs = ((IStructuredSelection)selection).toArray(); + if (obs.length > 0) { + for (int i=0; i 0) { + if (projects == null) projects = new ArrayList(); + projects.add(prj); + } + } + } + } + } + } + action.setEnabled(projects != null); + if (projects != null && it_sel != null) + it_sel.getAction().setEnabled(projects.size() == 1); + action.setMenuCreator(this); + } + + @Override + public void run(IAction action) {} // do nothing - show menus only + public void setActivePart(IAction action, IWorkbenchPart targetPart) {} + + // doing nothing + public void init(IWorkbenchWindow window) { } + + private final class BuildCleanFilesJob extends Job { + Object[] cfs; + + BuildCleanFilesJob(Object[] _cfs) { + super(getJOB_MSG() + ((ICConfigurationDescription)_cfs[0]).getProjectDescription().getName()); + cfs = _cfs; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + IConfiguration[] cf = new IConfiguration[cfs.length]; + for (int i=0; i it = projects.iterator(); + if (forAll) { + while(it.hasNext()) + processProject(it.next()); + } else { + if (it.hasNext()) + processProject(it.next()); + } + } + + private void processProject(IProject prj) { + ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false); + if (prjd == null) return; + Object[] cfgds = prjd.getConfigurations(); + if (!forAll) cfgds = openDialog(cfgds); + if (cfgds == null || cfgds.length == 0) return; + Job buildCleanFilesJob = new BuildCleanFilesJob(cfgds); + buildCleanFilesJob.schedule(); + } + } + + private Object[] openDialog(Object[] cfgds) { + if (cfgds == null || cfgds.length == 0) return null; + ListSelectionDialog dialog = new ListSelectionDialog( + CUIPlugin.getActiveWorkbenchShell(), + cfgds, + new IStructuredContentProvider() { + public Object[] getElements(Object inputElement) { return (Object[])inputElement; } + public void dispose() {} + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + }, + new LabelProvider() { + @Override + public String getText(Object element) { + if (element == null || !(element instanceof ICConfigurationDescription)) return null; + return ((ICConfigurationDescription)element).getName(); + } + }, + getDLG_TEXT()); + dialog.setTitle(getDLG_TITLE()); + dialog.setInitialSelections(cfgds); + return (dialog.open() == Window.OK) ? dialog.getResult() : null; + } +} diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildAllAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildAllAction.java index e1567bd21d1..c288980b4f5 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildAllAction.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildAllAction.java @@ -7,226 +7,54 @@ * * Contributors: * Intel Corporation - initial API and implementation + * LSI Corporation - added symmetric project clean action *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.actions; -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.internal.ui.actions.CommonBuildCleanAllAction; import org.eclipse.cdt.managedbuilder.ui.properties.Messages; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuCreator; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; -import org.eclipse.ui.actions.ActionDelegate; -import org.eclipse.ui.dialogs.ListSelectionDialog; /** - * Action which changes active build configuration of the current project to + * Action which changes active build configuration of the current project to * the given one. - * + * * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. */ -public class BuildAllAction extends ActionDelegate - implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate, IMenuCreator { - - private static final String TIP_ALL = Messages.getString("BuildAllAction.0");//$NON-NLS-1$ - private static final String LBL_ALL = Messages.getString("BuildAllAction.1");//$NON-NLS-1$ - private static final String JOB_MSG = Messages.getString("BuildAllAction.2");//$NON-NLS-1$ - private static final String ERR_MSG = Messages.getString("BuildAllAction.3");//$NON-NLS-1$ - private static final String LBL_SEL = Messages.getString("BuildAllAction.4");//$NON-NLS-1$ - private static final String TIP_SEL = Messages.getString("BuildAllAction.5");//$NON-NLS-1$ - private static final String DLG_TEXT = Messages.getString("BuildAllAction.6");//$NON-NLS-1$ - private static final String DLG_TITLE = Messages.getString("BuildAllAction.7");//$NON-NLS-1$ - - protected ArrayList projects = null; - private ActionContributionItem it_all = null; - private ActionContributionItem it_sel = null; - +public class BuildAllAction extends CommonBuildCleanAllAction { + /** @since 7.0 */ @Override - public void selectionChanged(IAction action, ISelection selection) { - projects = null; - - if (!selection.isEmpty()) { - // case for context menu - if (selection instanceof IStructuredSelection) { - Object[] obs = ((IStructuredSelection)selection).toArray(); - if (obs.length > 0) { - for (int i=0; i 0) { - if (projects == null) projects = new ArrayList(); - projects.add(prj); - } - } - } - } - } - } - action.setEnabled(projects != null); - if (projects != null && it_sel != null) - it_sel.getAction().setEnabled(projects.size() == 1); - action.setMenuCreator(this); - } - + protected String getTIP_ALL() { return Messages.getString("BuildAllAction.0");}//$NON-NLS-1$ + /** @since 7.0 */ @Override - public void run(IAction action) {} // do nothing - show menus only - public void setActivePart(IAction action, IWorkbenchPart targetPart) {} - - // doing nothing + protected String getLBL_ALL() { return Messages.getString("BuildAllAction.1");}//$NON-NLS-1$ + /** @since 7.0 */ @Override - public void dispose() { } - public void init(IWorkbenchWindow window) { } - - private static final class BuildFilesJob extends Job { - Object[] cfs; - - BuildFilesJob(Object[] _cfs) { - super(JOB_MSG + ((ICConfigurationDescription)_cfs[0]).getProjectDescription().getName()); - cfs = _cfs; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - protected IStatus run(IProgressMonitor monitor) { - IConfiguration[] cf = new IConfiguration[cfs.length]; - for (int i=0; i it = projects.iterator(); - if (forAll) { - while(it.hasNext()) - processProject(it.next()); - } else { - if (it.hasNext()) - processProject(it.next()); - } - } - - private void processProject(IProject prj) { - ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false); - if (prjd == null) return; - Object[] cfgds = prjd.getConfigurations(); - if (!forAll) cfgds = openDialog(cfgds); - if (cfgds == null || cfgds.length == 0) return; - Job buildFilesJob = new BuildFilesJob(cfgds); - buildFilesJob.schedule(); - } - } - - private Object[] openDialog(Object[] cfgds) { - if (cfgds == null || cfgds.length == 0) return null; - ListSelectionDialog dialog = new ListSelectionDialog( - CUIPlugin.getActiveWorkbenchShell(), - cfgds, - new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { return (Object[])inputElement; } - public void dispose() {} - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} - }, - new LabelProvider() { - @Override - public String getText(Object element) { - if (element == null || !(element instanceof ICConfigurationDescription)) return null; - return ((ICConfigurationDescription)element).getName(); - } - }, - DLG_TEXT); - dialog.setTitle(DLG_TITLE); - dialog.setInitialSelections(cfgds); - return (dialog.open() == Window.OK) ? dialog.getResult() : null; + protected String getJOB_MSG() { return Messages.getString("BuildAllAction.2");}//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected String getERR_MSG() { return Messages.getString("BuildAllAction.3");}//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected String getLBL_SEL() { return Messages.getString("BuildAllAction.4");}//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected String getTIP_SEL() { return Messages.getString("BuildAllAction.5");}//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected String getDLG_TEXT(){ return Messages.getString("BuildAllAction.6"); }//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected String getDLG_TITLE(){ return Messages.getString("BuildAllAction.7");}//$NON-NLS-1$ + /** @since 7.0 */ + @Override + protected void performAction(IConfiguration[] configs, + IProgressMonitor monitor) throws CoreException { + ManagedBuildManager.buildConfigurations(configs, monitor); } } diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/messages.properties b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/messages.properties index f3a69dccbb7..f244483c078 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/messages.properties +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/messages.properties @@ -100,6 +100,14 @@ BuildAllAction.4=Select... BuildAllAction.5=Build selected configurations in parallel BuildAllAction.6=Select configurations to build BuildAllAction.7=Build configurations +CleanAllAction.0=Clean all project configurations in parallel +CleanAllAction.1=All +CleanAllAction.2=Cleaning project +CleanAllAction.3=Clean error +CleanAllAction.4=Select... +CleanAllAction.5=Clean selected configurations in parallel +CleanAllAction.6=Select configurations to clean +CleanAllAction.7=Clean configurations PrefPage_NewCDTWizard.0=Settings will be applied to CDT new project wizard during project creation process WizardDefaultsTab.0=Show only supported toolchains, by default WizardDefaultsTab.1=Group old-style toolchains to folder