]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1822 Add the property 'sonar.skipTendencies' to skip calculation of measure...
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 16:31:54 +0000 (16:31 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 16:31:54 +0000 (16:31 +0000)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/TendencyDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/TendencyDecoratorTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java

index d65ededd9a48698b7ca600093267e7a0f58011ba..2fa67c2613ae9e555a90cbcebe1188831b846497 100644 (file)
@@ -66,6 +66,14 @@ import java.util.List;
         description = TendencyDecorator.PROP_DAYS_DESCRIPTION,
         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",
index dcc6c28bd3345948d29cce33e9f443aa9bef0a0e..2b85ad195c4e1d1bd2d1cab990328c0ab78d9bb3 100644 (file)
@@ -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) {
index 7f7ddc3922d0903665bb9736b1c7c7f32f9f89f3..2a2d26a13b1c497ecfe88064d07d2c4df75c6ff6 100644 (file)
@@ -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;
@@ -42,11 +43,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);
@@ -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);
   }
index 542ef3872dbcbfd9a99d86d708fca6dfb925bace..7dafa0d2085b4fce4e77da3b4eb9e99b22773b5f 100644 (file)
@@ -73,6 +73,8 @@ public interface CoreProperties {
   String SERVER_VERSION = "sonar.core.version";
   String SERVER_ID = "sonar.core.id";
   String SERVER_STARTTIME = "sonar.core.startTime";  // format is yyyy-MM-dd'T'HH:mm:ssZ
+  String SKIP_TENDENCIES_PROPERTY = "sonar.skipTendencies";
+  boolean SKIP_TENDENCIES_DEFAULT_VALUE = false;
 
   /* CPD */
   String CPD_PLUGIN = "cpd";