aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-28 16:31:54 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-28 16:31:54 +0000
commitb2e835b4eae846a5e978a8020f8bf77bef0ba0b6 (patch)
treed9ce212c2dd5e55fbbffff255c82bb2794f0bfe5 /plugins
parenta5b432905bee26cc250726f0174ba9ba9410b82f (diff)
downloadsonarqube-b2e835b4eae846a5e978a8020f8bf77bef0ba0b6.tar.gz
sonarqube-b2e835b4eae846a5e978a8020f8bf77bef0ba0b6.zip
SONAR-1822 Add the property 'sonar.skipTendencies' to skip calculation of measure tendencies
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java8
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java10
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java27
3 files changed, 34 insertions, 11 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index d65ededd9a4..2fa67c2613a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -67,6 +67,14 @@ import java.util.List;
project = false,
global = true),
@Property(
+ key = CoreProperties.SKIP_TENDENCIES_PROPERTY,
+ defaultValue = "" + CoreProperties.SKIP_TENDENCIES_DEFAULT_VALUE,
+ name = "Skip tendencies",
+ description = "Skip calculation of measure tendencies",
+ project = true,
+ module = false,
+ global = true),
+ @Property(
key = CoreProperties.CORE_SKIPPED_MODULES_PROPERTY,
name = "Exclude modules",
description = "Maven artifact ids of modules to exclude (comma-separated).",
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java
index dcc6c28bd33..2b85ad195c4 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java
@@ -20,6 +20,7 @@
package org.sonar.plugins.core.sensors;
import com.google.common.collect.ArrayListMultimap;
+import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.time.DateUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.*;
@@ -42,17 +43,20 @@ public class TendencyDecorator implements Decorator {
private TimeMachine timeMachine;
private TimeMachineQuery query;
private TendencyAnalyser analyser;
+ private Configuration configuration;
- public TendencyDecorator(TimeMachine timeMachine, MeasuresDao measuresDao) {
+ public TendencyDecorator(TimeMachine timeMachine, MeasuresDao measuresDao, Configuration configuration) {
this.timeMachine = timeMachine;
this.measuresDao = measuresDao;
this.analyser = new TendencyAnalyser();
+ this.configuration = configuration;
}
- protected TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser) {
+ protected TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser, Configuration configuration) {
this.timeMachine = timeMachine;
this.query = query;
this.analyser = analyser;
+ this.configuration = configuration;
}
protected TimeMachineQuery initQuery(Project project) {
@@ -81,7 +85,7 @@ public class TendencyDecorator implements Decorator {
}
public boolean shouldExecuteOnProject(Project project) {
- return true;
+ return !configuration.getBoolean(CoreProperties.SKIP_TENDENCIES_PROPERTY, CoreProperties.SKIP_TENDENCIES_DEFAULT_VALUE);
}
public void decorate(Resource resource, DecoratorContext context) {
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java
index 7f7ddc3922d..2a2d26a13b1 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.sensors;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.TimeMachine;
import org.sonar.api.batch.TimeMachineQuery;
@@ -43,11 +44,6 @@ import static org.mockito.Mockito.*;
public class TendencyDecoratorTest {
@Test
- public void shouldExecuteOnAllProjects() {
- assertThat(new TendencyDecorator(null, null, null).shouldExecuteOnProject(null), is(true));
- }
-
- @Test
public void initQuery() throws ParseException {
Project project = mock(Project.class);
when(project.getAnalysisDate()).thenReturn(date("2009-12-25"));
@@ -56,7 +52,7 @@ public class TendencyDecoratorTest {
MeasuresDao dao = mock(MeasuresDao.class);
when(dao.getMetrics()).thenReturn(Arrays.asList(CoreMetrics.LINES, CoreMetrics.COVERAGE, CoreMetrics.COVERAGE_LINE_HITS_DATA, CoreMetrics.PROFILE));
- TendencyDecorator decorator = new TendencyDecorator(null, dao);
+ TendencyDecorator decorator = new TendencyDecorator(null, dao, new PropertiesConfiguration());
TimeMachineQuery query = decorator.initQuery(project);
assertThat(query.getMetrics().size(), is(2));
@@ -83,7 +79,7 @@ public class TendencyDecoratorTest {
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, new PropertiesConfiguration());
decorator.decorate(new JavaPackage("org.foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
@@ -102,12 +98,27 @@ public class TendencyDecoratorTest {
));
DecoratorContext context = mock(DecoratorContext.class);
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, new PropertiesConfiguration());
decorator.decorate(new JavaPackage("org.foo"), context);
verify(analyser, never()).analyseLevel(anyList());
}
+ @Test
+ public void shouldSkipExecution() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(CoreProperties.SKIP_TENDENCIES_PROPERTY, true);
+ TendencyDecorator decorator = new TendencyDecorator(null, null, null, conf);
+ assertThat(decorator.shouldExecuteOnProject(null), is(false));
+ }
+
+ @Test
+ public void shouldNotSkipExecutionByDefault() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ TendencyDecorator decorator = new TendencyDecorator(null, null, null, conf);
+ assertThat(decorator.shouldExecuteOnProject(null), is(true));
+ }
+
private Date date(String date) throws ParseException {
return new SimpleDateFormat("yyyy-MM-dd").parse(date);
}