aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2013-07-23 14:55:21 (EDT)
committerJeff Johnston2013-07-25 16:32:19 (EDT)
commit18a2434af4445fba1ae6a95cbd2c9a01d6be2980 (patch)
tree8af3c471977e60d4cca75b23e446e33b72dc26db
parenta1577a80fa0110ddfad45ee5aea3fb618a68accc (diff)
downloadorg.eclipse.linuxtools-18a2434af4445fba1ae6a95cbd2c9a01d6be2980.zip
org.eclipse.linuxtools-18a2434af4445fba1ae6a95cbd2c9a01d6be2980.tar.gz
org.eclipse.linuxtools-18a2434af4445fba1ae6a95cbd2c9a01d6be2980.tar.bz2
Valgrind: Clear custom error markers after a build.refs/changes/50/14850/4
* Implement IResourceChangeListener keeping track of post-build events. * Skip auto-build events as they lead to unpredictable marker erasure. Change-Id: I4cda1a87ba1e2cf6cb1727b7d691f7a3969841da Reviewed-on: https://git.eclipse.org/r/14850 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> IP-Clean: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ProjectBuildListener.java114
-rw-r--r--valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java8
2 files changed, 121 insertions, 1 deletions
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ProjectBuildListener.java b/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ProjectBuildListener.java
new file mode 100644
index 0000000..f41bb14
--- /dev/null
+++ b/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ProjectBuildListener.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.valgrind.launch;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.valgrind.ui.ValgrindUIPlugin;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Implementation of {@link IResourceChangeListener} that listens for project
+ * specific post-build events
+ */
+public class ProjectBuildListener implements IResourceChangeListener {
+
+ // project to keep track of
+ private IProject project;
+
+ public ProjectBuildListener(IProject targetProject) {
+ project = targetProject;
+ }
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (project != null && isPostBuildEvent(event)) {
+
+ // find the project from event delta and delete its markers
+ IResourceDelta delta = event.getDelta();
+ IResourceDelta[] childrenDelta = delta.getAffectedChildren(IResourceDelta.CHANGED);
+ for (IResourceDelta childDelta : childrenDelta) {
+ if (isProjectDelta(childDelta, project)) {
+
+ // clear markers and de-register this listener
+ clearProjectMarkers(project);
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ }
+ }
+ }
+ }
+
+ /**
+ * Check if {@link IResourceDelta} represents a change in the specified {@link IProject}..
+ *
+ * @param delta IResourceDelta resource delta to check
+ * @param project IProject project to compare against
+ * @return boolean true if IResourceDelta is a project and equals the
+ */
+ public boolean isProjectDelta(IResourceDelta delta, IProject project){
+ if(delta != null){
+ IResource resource = delta.getResource();
+ return delta.getKind() == IResourceDelta.CHANGED
+ && resource != null
+ && resource.getType() == IResource.PROJECT
+ && resource.equals(project);
+ }
+ return false;
+ }
+
+ /**
+ * Check if {@link IResourceChangeEvent} is a post-build event.
+ *
+ * @param event IResourceChangeEvent event to check
+ * @return boolean true if IResourceChangeEvent is a post-build event, false
+ * otherwise
+ */
+ public boolean isPostBuildEvent(IResourceChangeEvent event) {
+ if(event != null){
+ int buildKind = event.getBuildKind();
+ return event.getType() == IResourceChangeEvent.POST_BUILD
+ && (buildKind == IncrementalProjectBuilder.FULL_BUILD
+ || buildKind == IncrementalProjectBuilder.INCREMENTAL_BUILD
+ || buildKind == IncrementalProjectBuilder.CLEAN_BUILD);
+ }
+ return false;
+ }
+
+ /**
+ * Clear markers of specified project.
+ *
+ * @param project IProject project to clear markers from
+ */
+ protected void clearProjectMarkers(IProject project) {
+ try {
+
+ // remove project markers
+ project.deleteMarkers(ValgrindLaunchPlugin.MARKER_TYPE, true,IResource.DEPTH_INFINITE);
+
+ // clear valgrind error view
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ ValgrindUIPlugin.getDefault().resetView();
+ }
+ });
+ } catch (CoreException e) {
+ Status status = new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, e.getMessage());
+ ValgrindLaunchPlugin.getDefault().getLog().log(status);
+ }
+ }
+} \ No newline at end of file
diff --git a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java b/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java
index 517c5a1..297987a 100644
--- a/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java
+++ b/valgrind/org.eclipse.linuxtools.valgrind.launch/src/org/eclipse/linuxtools/internal/valgrind/launch/ValgrindLaunchConfigurationDelegate.java
@@ -27,6 +27,8 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -188,6 +190,11 @@ public class ValgrindLaunchConfigurationDelegate extends ProfileLaunchConfigurat
// show view
ValgrindUIPlugin.getDefault().showView();
+
+ // set up resource listener for post-build events.
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(
+ new ProjectBuildListener(project), IResourceChangeEvent.POST_BUILD);
+
monitor.worked(1);
} catch (IOException e) {
abort(Messages.getString("ValgrindLaunchConfigurationDelegate.Error_starting_process"), e, ICDTLaunchConfigurationConstants.ERR_INTERNAL_ERROR); //$NON-NLS-1$
@@ -381,5 +388,4 @@ public class ValgrindLaunchConfigurationDelegate extends ProfileLaunchConfigurat
root.deleteMarkers(ValgrindLaunchPlugin.MARKER_TYPE, true, IResource.DEPTH_INFINITE); //$NON-NLS-1$
return super.finalLaunchCheck(configuration, mode, monitor);
}
-
}