]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2627 False-positive flags disappear after second analysis run
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 4 Aug 2011 07:50:42 +0000 (09:50 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 4 Aug 2011 07:50:57 +0000 (09:50 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CloseReviewsDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationPersisterDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java
sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
sonar-plugin-api/src/main/java/org/sonar/api/violations/ViolationQuery.java

index bec5499851f3b59594359954737d948a755cf9a5..f49b4edd8c97de959cf180f85431d36447489302 100644 (file)
@@ -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);
index 43f7887ca33a9ca9b97a30a1bb47e5c62cb2c1d3..9a7b0f2c434f3c619e8cb032fdfdc3ba76ebf4bc 100644 (file)
@@ -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) {
index 68aaa853f080fe142ec7a7f4048df18ad2950308..81e93fe6f1be8a1fc2fad8524a9b1cdac763750c 100644 (file)
@@ -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());
index 5aeac943af956506007e9fb0c52e5f180120f6a0..ffa330334eb95d65468e70b2ed6acfbc03c968d8 100644 (file)
@@ -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);
       }
     }
index 28b9082693c7c04fbb0a97546d132af160ec1302..24c717f181a2eaa9d322b83da8067b34ade4e3d5 100644 (file)
@@ -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;
   }
 
   /**