Skip to content

Commit 22d9d7e

Browse files
committed
Merge pull request #427 from infthi/no_upload_on_errors
Issue #284: Upload occurs even if build fails. @infthi Thanks for this. I have been looking and asking for something like this. @rlogiacco I'm accepting this. If there are false positives (I would not be surprised if it didn't) we can decide to add a flag for testing or add a dialogue which says something like "it looks as if the build has failed: do you want to upload anyway?"
2 parents 3faf68f + 035dc91 commit 22d9d7e

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/UploadProjectHandler.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import java.net.URL;
44

55
import org.eclipse.cdt.core.model.CoreModel;
6+
import org.eclipse.cdt.core.model.ICModelMarker;
67
import org.eclipse.core.commands.AbstractHandler;
78
import org.eclipse.core.commands.ExecutionEvent;
89
import org.eclipse.core.commands.ExecutionException;
10+
import org.eclipse.core.resources.IMarker;
911
import org.eclipse.core.resources.IProject;
12+
import org.eclipse.core.resources.IResource;
1013
import org.eclipse.core.resources.IncrementalProjectBuilder;
1114
import org.eclipse.core.runtime.CoreException;
1215
import org.eclipse.core.runtime.IProgressMonitor;
@@ -34,6 +37,21 @@ public UploadJobHandler(IProject buildProject) {
3437
super(Messages.ArduinoUploadProjectHandler_Upload_for_project + buildProject.getName());
3538
this.myBuildProject = buildProject;
3639
}
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+
}
3755

3856
@Override
3957
protected IStatus run(IProgressMonitor monitor) {
@@ -62,12 +80,20 @@ protected IStatus run(IProgressMonitor _monitor) {
6280
};
6381
job.setPriority(Job.DECORATE);
6482
job.schedule();
83+
if (hasBuildErrors()) {
84+
throw new CoreException(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Build completed with errors."));
85+
}
6586
} 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+
});
7197
return Status.OK_STATUS;
7298
}
7399
}

0 commit comments

Comments
 (0)