* 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);
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;
}
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) {
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.*;
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;
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);
newViolation.setNew(false);
pastViolationsByRule.remove(newViolation.getRule().getId(), pastViolation);
violationMap.put(newViolation, pastViolation);
+
} else {
newViolation.setNew(true);
newViolation.setCreatedAt(project.getAnalysisDate());
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);
}
}
*/
public final class ViolationQuery {
- private boolean isSwitchedOff;
+ public static enum SwitchMode {
+ OFF, ON, BOTH
+ }
+
+ private SwitchMode switchMode = SwitchMode.ON;
private Resource resource;
/**
}
/**
- * 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;
}
/**