|
Lines 10-18
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.internal.ui.cview; |
11 |
package org.eclipse.cdt.internal.ui.cview; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.Arrays; |
| 14 |
import java.util.Collection; |
| 15 |
import java.util.HashSet; |
| 13 |
import java.util.Iterator; |
16 |
import java.util.Iterator; |
|
|
17 |
import java.util.List; |
| 18 |
import java.util.Set; |
| 14 |
|
19 |
|
| 15 |
import org.eclipse.core.resources.ICommand; |
20 |
import org.eclipse.core.resources.ICommand; |
|
|
21 |
import org.eclipse.core.resources.IFile; |
| 16 |
import org.eclipse.core.resources.IProject; |
22 |
import org.eclipse.core.resources.IProject; |
| 17 |
import org.eclipse.core.resources.IResource; |
23 |
import org.eclipse.core.resources.IResource; |
| 18 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
24 |
import org.eclipse.core.resources.IncrementalProjectBuilder; |
|
Lines 25-33
Link Here
|
| 25 |
import org.eclipse.jface.window.IShellProvider; |
31 |
import org.eclipse.jface.window.IShellProvider; |
| 26 |
import org.eclipse.swt.events.KeyEvent; |
32 |
import org.eclipse.swt.events.KeyEvent; |
| 27 |
import org.eclipse.ui.IActionBars; |
33 |
import org.eclipse.ui.IActionBars; |
|
|
34 |
import org.eclipse.ui.IEditorPart; |
| 35 |
import org.eclipse.ui.IWorkbenchPage; |
| 28 |
import org.eclipse.ui.IWorkbenchPartSite; |
36 |
import org.eclipse.ui.IWorkbenchPartSite; |
|
|
37 |
import org.eclipse.ui.IWorkbenchWindow; |
| 38 |
import org.eclipse.ui.PlatformUI; |
| 29 |
import org.eclipse.ui.actions.BuildAction; |
39 |
import org.eclipse.ui.actions.BuildAction; |
| 30 |
import org.eclipse.ui.ide.IDEActionFactory; |
40 |
import org.eclipse.ui.ide.IDEActionFactory; |
|
|
41 |
import org.eclipse.ui.ide.ResourceUtil; |
| 31 |
|
42 |
|
| 32 |
import org.eclipse.cdt.core.CCorePlugin; |
43 |
import org.eclipse.cdt.core.CCorePlugin; |
| 33 |
|
44 |
|
|
Lines 38-44
Link Here
|
| 38 |
|
49 |
|
| 39 |
/** |
50 |
/** |
| 40 |
* An internal class which overrides the 'shouldPerformResourcePruning' |
51 |
* An internal class which overrides the 'shouldPerformResourcePruning' |
| 41 |
* method so that referenced projects aren't build twice |
52 |
* method so that referenced projects aren't build twice . (The CDT |
|
|
53 |
* managedbuild builds CDT reference project configuration as part of |
| 54 |
* building the top-level project). |
| 55 |
* |
| 56 |
* Also ensure that files in referenced projects are saved automatically |
| 57 |
* before build. |
| 42 |
*/ |
58 |
*/ |
| 43 |
public static class CDTBuildAction extends BuildAction { |
59 |
public static class CDTBuildAction extends BuildAction { |
| 44 |
public CDTBuildAction(IShellProvider shell, int kind) { |
60 |
public CDTBuildAction(IShellProvider shell, int kind) { |
|
Lines 47-58
Link Here
|
| 47 |
@Override |
63 |
@Override |
| 48 |
protected boolean shouldPerformResourcePruning() { |
64 |
protected boolean shouldPerformResourcePruning() { |
| 49 |
// If the selected resources aren't new-style CDT projects, then |
65 |
// If the selected resources aren't new-style CDT projects, then |
| 50 |
// fall-back to parent behaviour |
66 |
// fall-back to parent behaviour. |
|
|
67 |
// For CDT projects, we only want 'build' to be called on the top-level |
| 68 |
// selected project(s) |
| 51 |
for (Object res : getSelectedResources()) |
69 |
for (Object res : getSelectedResources()) |
| 52 |
if (!(res instanceof IProject) || !CCorePlugin.getDefault().isNewStyleProject((IProject)res)) |
70 |
if (!(res instanceof IProject) || !CCorePlugin.getDefault().isNewStyleProject((IProject)res)) |
| 53 |
return super.shouldPerformResourcePruning(); |
71 |
return super.shouldPerformResourcePruning(); |
| 54 |
return false; |
72 |
return false; |
| 55 |
} |
73 |
} |
|
|
74 |
@Override |
| 75 |
@SuppressWarnings("unchecked") |
| 76 |
public void run() { |
| 77 |
// Ensure we correctly save files in all referenced projects before build |
| 78 |
Set<IProject> prjs = new HashSet<IProject>(); |
| 79 |
for (IResource resource : (List<IResource>)getSelectedResources()) { |
| 80 |
IProject project = resource.getProject(); |
| 81 |
if (project != null) { |
| 82 |
prjs.add(project); |
| 83 |
try { |
| 84 |
prjs.addAll(Arrays.asList(project.getReferencedProjects())); |
| 85 |
} catch (CoreException e) { |
| 86 |
// Project not accessible or not open |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
saveEditors(prjs); |
| 91 |
|
| 92 |
// Now delegate to the parent |
| 93 |
super.run(); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Taken from inaccessible o.e.ui.ide.BuildUtilities.java |
| 98 |
* |
| 99 |
* Causes all editors to save any modified resources in the provided collection |
| 100 |
* of projects depending on the user's preference. |
| 101 |
* @param projects The projects in which to save editors, or <code>null</code> |
| 102 |
* to save editors in all projects. |
| 103 |
*/ |
| 104 |
private static void saveEditors(Collection<IProject> projects) { |
| 105 |
if (!BuildAction.isSaveAllSet()) { |
| 106 |
return; |
| 107 |
} |
| 108 |
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); |
| 109 |
for (int i = 0; i < windows.length; i++) { |
| 110 |
IWorkbenchPage[] pages = windows[i].getPages(); |
| 111 |
for (int j = 0; j < pages.length; j++) { |
| 112 |
IWorkbenchPage page = pages[j]; |
| 113 |
if (projects == null) { |
| 114 |
page.saveAllEditors(false); |
| 115 |
} else { |
| 116 |
IEditorPart[] editors = page.getDirtyEditors(); |
| 117 |
for (int k = 0; k < editors.length; k++) { |
| 118 |
IEditorPart editor = editors[k]; |
| 119 |
IFile inputFile = ResourceUtil.getFile(editor.getEditorInput()); |
| 120 |
if (inputFile != null) { |
| 121 |
if (projects.contains(inputFile.getProject())) { |
| 122 |
page.saveEditor(editor, false); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 56 |
} |
130 |
} |
| 57 |
|
131 |
|
| 58 |
private static class RebuildAction extends CDTBuildAction { |
132 |
private static class RebuildAction extends CDTBuildAction { |