1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 06:32:10 +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);
}
/*
* callback from Output Parser
*/
/*
* callback from Output Parser
*/
@Override
public void addMarker(ProblemMarkerInfo problemMarkerInfo) {
try {
IResource markerResource = problemMarkerInfo.file ;
if (markerResource==null) {
markerResource = getProject();
IProject project = getProject();
IResource markerResource = problemMarkerInfo.file;
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;
if (problemMarkerInfo.externalPath != null && ! problemMarkerInfo.externalPath.isEmpty()) {
externalLocation = problemMarkerInfo.externalPath.toOSString();
}
if ((cur != null) && (cur.length > 0)) {
for (IMarker element : cur) {
int line = ((Integer) element.getAttribute(IMarker.LINE_NUMBER)).intValue();
int sev = ((Integer) element.getAttribute(IMarker.SEVERITY)).intValue();
String mesg = (String) element.getAttribute(IMarker.MESSAGE);
String extloc = (String) element.getAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION);
if (line == problemMarkerInfo.lineNumber && sev == mapMarkerSeverity(problemMarkerInfo.severity) && mesg.equals(problemMarkerInfo.description)) {
if (extloc==externalLocation || (extloc!=null && extloc.equals(externalLocation))) {
// Try to find matching markers and don't put in duplicates
IMarker[] markers = markerResource.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_ONE);
for (IMarker m : markers) {
int line = ((Integer) m.getAttribute(IMarker.LINE_NUMBER)).intValue();
int sev = ((Integer) m.getAttribute(IMarker.SEVERITY)).intValue();
String msg = (String) m.getAttribute(IMarker.MESSAGE);
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;
}
}
@ -112,6 +116,10 @@ public abstract class ACBuilder extends IncrementalProjectBuilder implements IMa
} else if (problemMarkerInfo.lineNumber==0){
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.
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.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.utils.EFSExtensionManager;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
@ -193,10 +194,34 @@ public class BuildRunnerHelper implements Closeable {
}
try {
monitor.beginTask("", IProgressMonitor.UNKNOWN); //$NON-NLS-1$
if (rc != null) {
monitor.subTask(CCorePlugin.getFormattedString("BuildRunnerHelper.removingMarkers", rc.getFullPath().toString())); //$NON-NLS-1$
rc.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
try {
if (rc != null) {
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 {
monitor.done();
}