diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-04 09:50:42 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-04 09:50:57 +0200 |
commit | b8ae0c40bc4d6dca25a745b01d1d93cbf8430264 (patch) | |
tree | daaa443339fbe187cc04c9b9582c8db497be0f33 | |
parent | 0d2522a308bbee1d35aed6303d7ce9e4bcfea13b (diff) | |
download | sonarqube-b8ae0c40bc4d6dca25a745b01d1d93cbf8430264.tar.gz sonarqube-b8ae0c40bc4d6dca25a745b01d1d93cbf8430264.zip |
SONAR-2627 False-positive flags disappear after second analysis run
5 files changed, 31 insertions, 14 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java index bec5499851f..f49b4edd8c9 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java @@ -104,7 +104,7 @@ public class CloseReviewsDecorator implements Decorator { * Reopen reviews that had been set to resolved but for which the violation is still here. */ protected int reopenReviews(Resource resource, int resourceId) { - String conditions = " WHERE status='RESOLVED' AND resource_id=" + resourceId; + String conditions = " WHERE status='RESOLVED' AND resolution<>'FALSE-POSITIVE' AND resource_id=" + resourceId; List<Review> reviews = databaseSession.getEntityManager().createNativeQuery("SELECT * FROM reviews " + conditions, Review.class).getResultList(); for (Review review : reviews) { notifyReopened(resource, review); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java index 43f7887ca33..9a7b0f2c434 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java @@ -28,6 +28,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.Violation; +import org.sonar.api.violations.ViolationQuery; import org.sonar.batch.index.ResourcePersister; import org.sonar.core.NotDryRun; @@ -59,7 +60,7 @@ public class ViolationPersisterDecorator implements Decorator { } public void decorate(Resource resource, DecoratorContext context) { - saveViolations(context.getProject(), context.getViolations()); + saveViolations(context.getProject(), context.getViolations(ViolationQuery.create().forResource(resource).setSwitchMode(ViolationQuery.SwitchMode.BOTH))); } void saveViolations(Project project, List<Violation> violations) { diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java index 68aaa853f08..81e93fe6f1b 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java @@ -23,7 +23,6 @@ import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.*; @@ -31,9 +30,9 @@ import org.sonar.api.database.model.RuleFailureModel; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.rules.Violation; +import org.sonar.api.violations.ViolationQuery; import java.util.Collection; -import java.util.IdentityHashMap; import java.util.List; import java.util.Map; @@ -58,7 +57,8 @@ public class ViolationTrackingDecorator implements Decorator { public void decorate(Resource resource, DecoratorContext context) { referenceViolationsMap.clear(); - if (!context.getViolations().isEmpty()) { + ViolationQuery violationQuery = ViolationQuery.create().forResource(resource).setSwitchMode(ViolationQuery.SwitchMode.BOTH); + if (!context.getViolations(violationQuery).isEmpty()) { // Load new violations List<Violation> newViolations = prepareNewViolations(context); @@ -175,6 +175,7 @@ public class ViolationTrackingDecorator implements Decorator { newViolation.setNew(false); pastViolationsByRule.remove(newViolation.getRule().getId(), pastViolation); violationMap.put(newViolation, pastViolation); + } else { newViolation.setNew(true); newViolation.setCreatedAt(project.getAnalysisDate()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 5aeac943af9..ffa330334eb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -313,9 +313,11 @@ public class DefaultIndex extends SonarIndex { return Collections.emptyList(); } List<Violation> filteredViolations = Lists.newArrayList(); - boolean isSwitchedOff = violationQuery.isSwitchedOff(); + ViolationQuery.SwitchMode mode = violationQuery.getSwitchMode(); for (Violation violation : bucket.getViolations()) { - if ( violation.isSwitchedOff() == isSwitchedOff) { + if (mode== ViolationQuery.SwitchMode.BOTH || + (mode== ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff()) || + (mode== ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff())) { filteredViolations.add(violation); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/violations/ViolationQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/violations/ViolationQuery.java index 28b9082693c..24c717f181a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/violations/ViolationQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/violations/ViolationQuery.java @@ -28,7 +28,11 @@ import org.sonar.api.resources.Resource; */ public final class ViolationQuery { - private boolean isSwitchedOff; + public static enum SwitchMode { + OFF, ON, BOTH + } + + private SwitchMode switchMode = SwitchMode.ON; private Resource resource; /** @@ -47,24 +51,33 @@ public final class ViolationQuery { } /** - * Specifies if the query should returned switched-off violations or not. + * Specifies if the query should return only switched-off violations. * - * @param ignore + * @param b * if true, the query will return only switched-off violations. if false, it will return only active violations. * @return the current violation query */ - public ViolationQuery setSwitchedOff(boolean ignore) { - this.isSwitchedOff = ignore; + public ViolationQuery setSwitchedOff(boolean b) { + this.switchMode = (b ? SwitchMode.OFF : SwitchMode.ON); return this; } /** - * Tells if the query should returned switched-off violations or active violations. + * Tells if the query should return only switched-off violations. * * @return */ public boolean isSwitchedOff() { - return isSwitchedOff; + return switchMode == SwitchMode.OFF; + } + + public SwitchMode getSwitchMode() { + return switchMode; + } + + public ViolationQuery setSwitchMode(SwitchMode s) { + this.switchMode = s; + return this; } /** |