|
3 | 3 | import java.net.URL; |
4 | 4 |
|
5 | 5 | import org.eclipse.cdt.core.model.CoreModel; |
| 6 | +import org.eclipse.cdt.core.model.ICModelMarker; |
6 | 7 | import org.eclipse.core.commands.AbstractHandler; |
7 | 8 | import org.eclipse.core.commands.ExecutionEvent; |
8 | 9 | import org.eclipse.core.commands.ExecutionException; |
| 10 | +import org.eclipse.core.resources.IMarker; |
9 | 11 | import org.eclipse.core.resources.IProject; |
| 12 | +import org.eclipse.core.resources.IResource; |
10 | 13 | import org.eclipse.core.resources.IncrementalProjectBuilder; |
11 | 14 | import org.eclipse.core.runtime.CoreException; |
12 | 15 | import org.eclipse.core.runtime.IProgressMonitor; |
@@ -34,6 +37,21 @@ public UploadJobHandler(IProject buildProject) { |
34 | 37 | super(Messages.ArduinoUploadProjectHandler_Upload_for_project + buildProject.getName()); |
35 | 38 | this.myBuildProject = buildProject; |
36 | 39 | } |
| 40 | + |
| 41 | + /** |
| 42 | + * Checks if build completed successfully. |
| 43 | + * @return true iff project was not built successfully last time. |
| 44 | + * @throws CoreException if current project does not exist or is not open. |
| 45 | + */ |
| 46 | + private boolean hasBuildErrors() throws CoreException { |
| 47 | + IMarker[] markers = this.myBuildProject.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); |
| 48 | + for (IMarker marker: markers) { |
| 49 | + if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) { |
| 50 | + return true; |
| 51 | + } |
| 52 | + } |
| 53 | + return false; |
| 54 | + } |
37 | 55 |
|
38 | 56 | @Override |
39 | 57 | protected IStatus run(IProgressMonitor monitor) { |
@@ -62,12 +80,20 @@ protected IStatus run(IProgressMonitor _monitor) { |
62 | 80 | }; |
63 | 81 | job.setPriority(Job.DECORATE); |
64 | 82 | job.schedule(); |
| 83 | + if (hasBuildErrors()) { |
| 84 | + throw new CoreException(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Build completed with errors.")); |
| 85 | + } |
65 | 86 | } catch (CoreException e) { |
66 | | - Shell theShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
67 | | - MessageBox dialog = new MessageBox(theShell, SWT.ICON_QUESTION | SWT.OK); |
68 | | - dialog.setText(Messages.ArduinoUploadProjectHandler_Build_failed); |
69 | | - dialog.setMessage(Messages.ArduinoUploadProjectHandler_Build_failed_so_no_upload); |
70 | | - dialog.open(); |
| 87 | + Display.getDefault().asyncExec(new Runnable() { |
| 88 | + @Override |
| 89 | + public void run() { |
| 90 | + Shell theShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
| 91 | + MessageBox dialog = new MessageBox(theShell, SWT.ICON_QUESTION | SWT.OK); |
| 92 | + dialog.setText(Messages.ArduinoUploadProjectHandler_Build_failed); |
| 93 | + dialog.setMessage(Messages.ArduinoUploadProjectHandler_Build_failed_so_no_upload); |
| 94 | + dialog.open(); |
| 95 | + } |
| 96 | + }); |
71 | 97 | return Status.OK_STATUS; |
72 | 98 | } |
73 | 99 | } |
|
0 commit comments