Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Recoskie2008-06-03 23:24:47 +0000
committerChris Recoskie2008-06-03 23:24:47 +0000
commitbed01751016215d724f984b9c72dc5771ed35018 (patch)
treea0cff9bdf07585206e4be853552d535abdff36b2 /build/org.eclipse.cdt.managedbuilder.ui
parente97f7113f8df5cb96bf0101bc82a297b17d28d94 (diff)
downloadorg.eclipse.cdt-bed01751016215d724f984b9c72dc5771ed35018.tar.gz
org.eclipse.cdt-bed01751016215d724f984b9c72dc5771ed35018.tar.xz
org.eclipse.cdt-bed01751016215d724f984b9c72dc5771ed35018.zip
RESOLVED - bug 230159: "Build selected files" does not save changed files
https://bugs.eclipse.org/bugs/show_bug.cgi?id=230159
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.ui')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildFilesAction.java58
1 files changed, 57 insertions, 1 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildFilesAction.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildFilesAction.java
index cddc1854b26..df15b5c123d 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildFilesAction.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/actions/BuildFilesAction.java
@@ -14,7 +14,9 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
@@ -28,6 +30,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.GeneratedMakefileBuilder;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -37,6 +40,7 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.actions.ActionDelegate;
+import org.eclipse.ui.internal.ide.actions.BuildUtilities;
/**
* @author crecoskie
@@ -209,7 +213,7 @@ public class BuildFilesAction extends ActionDelegate implements
boolean isFirstFile = true;
while (iterator.hasNext()) {
- IFile file = (IFile) iterator.next();
+ IFile file = iterator.next();
IManagedBuildInfo buildInfo = ManagedBuildManager
.getBuildInfo(file.getProject());
@@ -255,6 +259,12 @@ public class BuildFilesAction extends ActionDelegate implements
Job buildFilesJob = new BuildFilesJob(selectedFiles);
+ List<IProject> projects = getProjectsToBuild(selectedFiles);
+ if (projects != null && !projects.isEmpty()) {
+ // Save all resources prior to doing build
+ BuildUtilities.saveEditors(projects);
+ }
+
buildFilesJob.schedule();
}
@@ -355,5 +365,51 @@ public class BuildFilesAction extends ActionDelegate implements
// update state
update();
}
+
+
+ /*
+ * Returns the projects to build.
+ * This contains the set of projects which have builders, across all selected resources.
+ */
+ private List<IProject> getProjectsToBuild(List<IFile> selectedFiles) {
+ List<IProject> projectsToBuild = new LinkedList<IProject>();
+ for (Iterator<IFile> i = selectedFiles.iterator(); i.hasNext();) {
+ IFile file = i.next();
+ IProject project = file.getProject();
+ if (project != null) {
+ if (!projectsToBuild.contains(project)) {
+ if (hasBuilder(project)) {
+ projectsToBuild.add(project);
+ }
+ }
+ }
+ }
+
+ return projectsToBuild;
+ }
+
+ /*
+ * Returns whether there are builders configured on the given project.
+ *
+ * @return <code>true</code> if it has builders,
+ * <code>false</code> if not, or if this couldn't be determined
+ */
+ private boolean hasBuilder(IProject project) {
+ if (!project.isAccessible())
+ return false;
+ try {
+ ICommand[] commands = project.getDescription().getBuildSpec();
+ if (commands.length > 0) {
+ return true;
+ }
+ } catch (CoreException e) {
+ // this method is called when selection changes, so
+ // just fall through if it fails.
+ // this shouldn't happen anyway, since the list of selected resources
+ // has already been checked for accessibility before this is called
+ }
+ return false;
+ }
+
}

Back to the top