START_VIOLATION_TRACKING and END_OF_VIOLATION_TRACKING are used to benefit from tracking data of Violation :
- Violation#isSwitchedOff()
- Violation#getCreatedAt()
More information in Javadoc.
*/
package org.sonar.plugins.core.sensors;
-import javax.persistence.Query;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Decorator;
+import org.sonar.api.batch.DecoratorBarriers;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.DependsUpon;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.ResourcePersister;
-import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator;
+
+import javax.persistence.Query;
/**
* Decorator that currently only closes a review when its corresponding violation has been fixed.
*/
-@DependsUpon(ViolationPersisterDecorator.BARRIER)
+@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
public class CloseReviewsDecorator implements Decorator {
private static final Logger LOG = LoggerFactory.getLogger(CloseReviewsDecorator.class);
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
-import org.sonar.plugins.core.timemachine.ViolationPersisterDecorator;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-@DependsUpon(value = ViolationPersisterDecorator.BARRIER)
+@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
public class ViolationsDecorator implements Decorator {
// temporary data for current resource
import com.google.common.collect.*;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.batch.*;
import org.sonar.api.measures.*;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import java.util.*;
-/* temporary workaround - the attributes classes() should be used but it is buggy */
-@DependsUpon(ViolationPersisterDecorator.BARRIER)
+@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
public class NewViolationsDecorator implements Decorator {
private TimeMachineConfiguration timeMachineConfiguration;
*/
package org.sonar.plugins.core.timemachine;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.IdentityHashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorBarriers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.batch.*;
import org.sonar.api.database.model.RuleFailureModel;
import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.Project;
import org.sonar.batch.components.PastViolationsLoader;
import org.sonar.batch.index.ViolationPersister;
-import com.google.common.collect.LinkedHashMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
+import java.util.*;
-@DependsUpon(DecoratorBarriers.END_OF_VIOLATIONS_GENERATION)
-@DependedUpon(ViolationPersisterDecorator.BARRIER)
-/* temporary workaround - see NewViolationsDecorator */
+@DependsUpon({DecoratorBarriers.END_OF_VIOLATIONS_GENERATION, DecoratorBarriers.START_VIOLATION_TRACKING})
+@DependedUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
public class ViolationPersisterDecorator implements Decorator {
- public static final String BARRIER = "ViolationPersisterDecorator";
-
/**
* Those chars would be ignored during generation of checksums.
*/
package org.sonar.api.batch;
/**
- * Barriers are used to define the order of execution of Decorators.
- *
+ * Barriers are used to define the order of execution of Decorators. Decorators must be annotated with the following :
+ *
+ * <ul>
+ * <li{@code @DependsUpon(BARRIER)} in order to be executed after BARRIER
+ * <li{@code @DependedUpon(BARRIER)} in order to be executed before BARRIER
+ * </ul>
+ *
* @since 2.3
*/
public interface DecoratorBarriers {
* This barrier is used by a decorator in order to :
* <ul>
* <li>be executed after all the decorators which generate violations :
- * <code>@DependsUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION</code></li>
- * <li>declare that it generates violations : <code>@DependedUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION</code></li>
+ * {@code @DependsUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION}</li>
+ * <li>declare that it generates violations : {@code @DependedUpon(value=DecoratorBarriers.END_OF_VIOLATIONS_GENERATION}</li>
* </ul>
*/
String END_OF_VIOLATIONS_GENERATION = "END_OF_VIOLATIONS_GENERATION";
+ /**
+ * Extensions which call the method {@code Violation#setSwitchedOff} must be executed before this barrier
+ * ({@code @DependedUpon(value=DecoratorBarriers.VIOLATION_TRACKING})
+ *
+ * This barrier is after {@code END_OF_VIOLATIONS_GENERATION}
+ *
+ * @since 2.8
+ */
+ String START_VIOLATION_TRACKING = "START_VIOLATION_TRACKING";
+
+ /*
+ * This barrier is after {@code END_OF_VIOLATIONS_GENERATION} and {@code START_VIOLATION_TRACKING}.
+ * Decorators executed after this barrier ({@code @DependsUpon(value=DecoratorBarriers.END_OF_VIOLATION_TRACKING})
+ * can benefit from all the features of violation tracking :
+ * <ul>
+ * <li>{@code Violation#getCreatedAt()}</li>
+ * <li>{@code Violation#isSwitchedOff()}, usually to know if a violation has been flagged as false-positives in UI</li>
+ * </ul>
+ *
+ * @since 2.8
+ */
+ String END_OF_VIOLATION_TRACKING = "END_OF_VIOLATION_TRACKING";
+
/**
* Any kinds of time machine data are calculated before this barrier. Decorators executed after this barrier can use
* Measure#getVariationValue() and Measure#getTendency() methods.
- *
+ *
* @since 2.5
*/
String END_OF_TIME_MACHINE = "END_OF_TIME_MACHINE";
private Integer lineId;
private Double cost;
private Date createdAt;
- private boolean switchedOff;
+ private boolean switchedOff=false;
/**
* Creates of a violation from a rule. Will need to define the resource later on
/**
* Switches off the current violation. This is a kind of "mute", which means the violation exists but won't be counted as an active
- * violation (and thus, won't be counted in the total number of violations).
+ * violation (and thus, won't be counted in the total number of violations). It's usually used for false-positives.
+ *
+ * The extensions which call this method must be executed
*
* @since 2.8
- * @param switchedOff
+ * @param b
* if true, the violation is considered OFF
*/
- public void setSwitchedOff(boolean switchedOff) {
- this.switchedOff = switchedOff;
+ public Violation setSwitchedOff(boolean b) {
+ this.switchedOff = b;
+ return this;
}
/**