Bugfix for issue mentioned here:

http://sourceforge.net/p/pmd/discussion/188192/thread/888425ac
This commit is contained in:
hooperbloob committed 2012-10-31 23:35:36 -07:00
1 parent 09e0aaf335
commit d6c2e505ab
2 files changed
+15 -2

No files matched your search

@@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.Set;
import name.herlin.command.CommandException;
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
import net.sourceforge.pmd.eclipse.runtime.cmd.ReviewCodeCmd;
import org.eclipse.core.resources.IFile;
@@ -11,6 +12,7 @@ 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.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -79,10 +81,11 @@ public class FileChangeReviewer implements IResourceChangeListener {
if (itemsChanged.isEmpty()) return;
ReviewCodeCmd cmd = new ReviewCodeCmd(); // separate one for each thread
cmd.clearExistingMarkersBeforeApplying(true);
cmd.reset();
for (ResourceChange chg : itemsChanged) cmd.addResource(chg.file);
try {
cmd.performExecute();
} catch (CommandException e) {
@@ -49,6 +49,7 @@ import net.sourceforge.pmd.Rule;
import net.sourceforge.pmd.RuleSet;
import net.sourceforge.pmd.eclipse.plugin.PMDPlugin;
import net.sourceforge.pmd.eclipse.runtime.PMDRuntimeConstants;
import net.sourceforge.pmd.eclipse.runtime.builder.MarkerUtil;
import net.sourceforge.pmd.eclipse.runtime.preferences.IPreferences;
import net.sourceforge.pmd.eclipse.runtime.properties.IProjectProperties;
import net.sourceforge.pmd.eclipse.runtime.properties.PropertiesException;
@@ -99,6 +100,7 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
private int ruleCount;
private int fileCount;
private long pmdDuration;
private boolean clearExistingMarkersBeforeApplying;
private String onErrorIssue = null;
private static final long serialVersionUID = 1L;
@@ -116,6 +118,10 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
setTerminated(false);
}
public void clearExistingMarkersBeforeApplying(boolean flag) {
clearExistingMarkersBeforeApplying = flag;
}
public Set<IFile> markedFiles() {
return markersByFile.keySet();
}
@@ -523,7 +529,11 @@ public class ReviewCodeCmd extends AbstractDefaultCommand {
currentFile = file.getName();
Set<MarkerInfo2> markerInfoSet = markersByFile.get(file);
// MarkerUtil.deleteAllMarkersIn(file);
if (clearExistingMarkersBeforeApplying) {
MarkerUtil.deleteAllMarkersIn(file);
}
for (MarkerInfo2 markerInfo : markerInfoSet) {
markerInfo.addAsMarkerTo(file);
violationCount++;