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.*;
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) {
}
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) {
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;
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);
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));
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));
));
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);
}