diff options
3 files changed, 20 insertions, 8 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java index ada9ecacf7f..cb4eacd5957 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java @@ -19,6 +19,8 @@ */ package org.sonar.batch; +import org.sonar.core.measure.MeasurementFilters; + import java.util.Collection; import java.util.Date; import java.util.List; @@ -43,16 +45,19 @@ public class DefaultDecoratorContext implements DecoratorContext { private static final String SAVE_MEASURE_METHOD = "saveMeasure"; private SonarIndex index; private Resource resource; + private MeasurementFilters measurementFilters; private boolean readOnly = false; private List<DecoratorContext> childrenContexts; public DefaultDecoratorContext(Resource resource, SonarIndex index, - List<DecoratorContext> childrenContexts) { + List<DecoratorContext> childrenContexts, + MeasurementFilters measurementFilters) { this.index = index; this.resource = resource; this.childrenContexts = childrenContexts; + this.measurementFilters = measurementFilters; } public DefaultDecoratorContext setReadOnly(boolean b) { @@ -109,13 +114,15 @@ public class DefaultDecoratorContext implements DecoratorContext { public DecoratorContext saveMeasure(Measure measure) { checkReadOnly(SAVE_MEASURE_METHOD); - index.addMeasure(resource, measure); + if(measurementFilters.accept(resource, measure)) { + index.addMeasure(resource, measure); + } return this; } public DecoratorContext saveMeasure(Metric metric, Double value) { checkReadOnly(SAVE_MEASURE_METHOD); - index.addMeasure(resource, new Measure(metric, value)); + saveMeasure(new Measure(metric, value)); return this; } @@ -125,7 +132,7 @@ public class DefaultDecoratorContext implements DecoratorContext { public List<Violation> getViolations(ViolationQuery violationQuery) { return index.getViolations(violationQuery); } - + /** * {@inheritDoc} */ diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java index 75b6cd54be0..fea48d45502 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.phases; +import org.sonar.core.measure.MeasurementFilters; + import com.google.common.collect.Lists; import org.sonar.api.BatchComponent; import org.sonar.api.batch.BatchExtensionDictionnary; @@ -42,13 +44,15 @@ public class DecoratorsExecutor implements BatchComponent { private SonarIndex index; private EventBus eventBus; private Project project; + private MeasurementFilters measurementFilters; public DecoratorsExecutor(BatchExtensionDictionnary batchExtDictionnary, - Project project, SonarIndex index, EventBus eventBus) { + Project project, SonarIndex index, EventBus eventBus, MeasurementFilters measurementFilters) { this.decoratorsSelector = new DecoratorsSelector(batchExtDictionnary); this.index = index; this.eventBus = eventBus; this.project = project; + this.measurementFilters = measurementFilters; } public void execute() { @@ -66,7 +70,7 @@ public class DecoratorsExecutor implements BatchComponent { childrenContexts.add(childContext.setReadOnly(true)); } - DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts); + DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts, measurementFilters); if (executeDecorators) { for (Decorator decorator : decorators) { executeDecorator(decorator, context, resource); diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java index 7d7a132aa30..6330c25c828 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.phases; +import org.sonar.core.measure.MeasurementFilters; + import org.junit.Test; import org.sonar.api.batch.BatchExtensionDictionnary; import org.sonar.api.batch.Decorator; @@ -30,7 +32,6 @@ import org.sonar.api.resources.Resource; import org.sonar.api.utils.SonarException; import org.sonar.batch.DefaultDecoratorContext; import org.sonar.batch.events.EventBus; - import static org.hamcrest.number.OrderingComparisons.greaterThanOrEqualTo; import static org.hamcrest.number.OrderingComparisons.lessThan; import static org.junit.Assert.assertThat; @@ -66,7 +67,7 @@ public class DecoratorsExecutorTest { doThrow(new SonarException()).when(decorator).decorate(any(Resource.class), any(DecoratorContext.class)); DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), new Project("key"), mock(SonarIndex.class), - mock(EventBus.class)); + mock(EventBus.class), mock(MeasurementFilters.class)); try { executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), new File("org/foo/Bar.java")); fail("Exception has not been thrown"); |