1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

bug 105978: [Error Parser]: Error markers that build generates on files in different projects are not removed

This commit is contained in:
Andrew Gvozdev 2013-09-26 09:53:33 -04:00
parent ee19807cb0
commit ed2bb8449b
2 changed files with 54 additions and 21 deletions

View file

@ -56,32 +56,36 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
addMarker(problemMarkerInfo); addMarker(problemMarkerInfo);
} }
/* /*
* callback from Output Parser * callback from Output Parser
*/ */
@Override @Override
public void addMarker(ProblemMarkerInfo problemMarkerInfo) { public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
try { try {
IResource markerResource = problemMarkerInfo.file ; IProject project = getProject();
if (markerResource==null) { IResource markerResource = problemMarkerInfo.file;
markerResource = getProject(); if (markerResource == null) {
markerResource = project;
} }
IMarker[] cur = markerResource.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ONE);
/*
* Try to find matching markers and don't put in duplicates
*/
String externalLocation = null; String externalLocation = null;
if (problemMarkerInfo.externalPath != null && ! problemMarkerInfo.externalPath.isEmpty()) { if (problemMarkerInfo.externalPath != null && ! problemMarkerInfo.externalPath.isEmpty()) {
externalLocation = problemMarkerInfo.externalPath.toOSString(); externalLocation = problemMarkerInfo.externalPath.toOSString();
} }
if ((cur != null) && (cur.length > 0)) {
for (IMarker element : cur) { // Try to find matching markers and don't put in duplicates
int line = ((Integer) element.getAttribute(IMarker.LINE_NUMBER)).intValue(); IMarker[] markers = markerResource.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ONE);
int sev = ((Integer) element.getAttribute(IMarker.SEVERITY)).intValue(); for (IMarker m : markers) {
String mesg = (String) element.getAttribute(IMarker.MESSAGE); int line = ((Integer) m.getAttribute(IMarker.LINE_NUMBER)).intValue();
String extloc = (String) element.getAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION); int sev = ((Integer) m.getAttribute(IMarker.SEVERITY)).intValue();
if (line == problemMarkerInfo.lineNumber && sev == mapMarkerSeverity(problemMarkerInfo.severity) && mesg.equals(problemMarkerInfo.description)) { String msg = (String) m.getAttribute(IMarker.MESSAGE);
if (extloc==externalLocation || (extloc!=null && extloc.equals(externalLocation))) { if (line == problemMarkerInfo.lineNumber && sev == mapMarkerSeverity(problemMarkerInfo.severity) && msg.equals(problemMarkerInfo.description)) {
String extloc = (String) m.getAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
if (extloc == externalLocation || (extloc != null && extloc.equals(externalLocation))) {
if (project == null || project.equals(markerResource.getProject())) {
return;
}
String source = (String) m.getAttribute(IMarker.SOURCE_ID);
if (project.getName().equals(source)) {
return; return;
} }
} }
@ -112,6 +116,10 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
} else if (problemMarkerInfo.lineNumber==0){ } else if (problemMarkerInfo.lineNumber==0){
marker.setAttribute(IMarker.LOCATION, " "); //$NON-NLS-1$ marker.setAttribute(IMarker.LOCATION, " "); //$NON-NLS-1$
} }
// Set source attribute only if the marker is being set to a file from different project
if (project != null && !project.equals(markerResource.getProject())) {
marker.setAttribute(IMarker.SOURCE_ID, project.getName());
}
// Add all other client defined attributes. // Add all other client defined attributes.
Map<String, String> attributes = problemMarkerInfo.getAttributes(); Map<String, String> attributes = problemMarkerInfo.getAttributes();

View file

@ -35,6 +35,7 @@ import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.core.resources.RefreshScopeManager; import org.eclipse.cdt.core.resources.RefreshScopeManager;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.utils.EFSExtensionManager; import org.eclipse.cdt.utils.EFSExtensionManager;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspace;
@ -193,10 +194,34 @@ public class BuildRunnerHelper implements Closeable {
} }
try { try {
monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$ monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
if (rc != null) { try {
monitor.subTask(CCorePlugin.getFormattedString("BuildRunnerHelper.removingMarkers", rc.getFullPath().toString())); //$NON-NLS-1$ if (rc != null) {
rc.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); monitor.subTask(CCorePlugin.getFormattedString("BuildRunnerHelper.removingMarkers", rc.getFullPath().toString())); //$NON-NLS-1$
rc.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
}
} catch (CoreException e) {
// ignore
} }
if (project != null) {
// Remove markers which source is this project from other projects
try {
IWorkspace workspace = project.getWorkspace();
IMarker[] markers = workspace.getRoot().findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
String projectName = project.getName();
List<IMarker> markersList = new ArrayList<IMarker>();
for (IMarker marker : markers) {
if (projectName.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
markersList.add(marker);
}
}
if (markersList.size() > 0) {
workspace.deleteMarkers(markersList.toArray(new IMarker[markersList.size()]));
}
} catch (CoreException e) {
// ignore
}
}
} finally { } finally {
monitor.done(); monitor.done();
} }