From b738fdefddbf88842e3a7ef22f98bfe8c5ca1e11 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 28 Apr 2011 12:55:50 +0200 Subject: [PATCH] Define new constants in DecoratorBarriers 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. --- .../core/sensors/CloseReviewsDecorator.java | 8 ++-- .../core/sensors/ViolationsDecorator.java | 3 +- .../timemachine/NewViolationsDecorator.java | 8 +--- .../ViolationPersisterDecorator.java | 26 ++++--------- .../sonar/api/batch/DecoratorBarriers.java | 38 ++++++++++++++++--- .../java/org/sonar/api/rules/Violation.java | 13 ++++--- 6 files changed, 55 insertions(+), 41 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 2d339753595..87528e5c554 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 @@ -19,11 +19,10 @@ */ 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; @@ -31,12 +30,13 @@ import org.sonar.api.database.model.Snapshot; 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); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java index de9e1a1123b..ebe4f47397f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java @@ -30,14 +30,13 @@ import org.sonar.api.resources.ResourceUtils; 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 diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java index b5fd6553251..5df64a2b139 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java @@ -21,10 +21,7 @@ package org.sonar.plugins.core.timemachine; 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; @@ -38,8 +35,7 @@ import org.sonar.batch.components.TimeMachineConfiguration; 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; 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 fe42056dea0..2d0c0fb8264 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 @@ -19,19 +19,12 @@ */ 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; @@ -40,17 +33,12 @@ import org.sonar.api.rules.Violation; 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. */ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java index 429050ecc74..526c87c6c9e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/DecoratorBarriers.java @@ -20,8 +20,13 @@ 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 : + * + *