From f86a62e3c24d2e2587b0f76988fbd9220ee4931a Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 27 Dec 2010 00:14:52 +0000 Subject: [PATCH] Move timemachine components from core plugin to batch + do not depend on Snapshot in PastSnapshotLoader components + fix NPE when calculating variations on measures that are still not persisted --- .../org/sonar/plugins/core/CorePlugin.java | 20 +++---- .../timemachine/NewViolationsDecorator.java | 3 +- .../core/timemachine/TendencyDecorator.java | 1 + .../TimeMachineConfigurationPersister.java | 2 + .../core/timemachine/VariationDecorator.java | 30 +++++----- .../ViolationPersisterDecorator.java | 1 + .../NewViolationsDecoratorTest.java | 3 +- .../timemachine/TendencyDecoratorTest.java | 1 + ...TimeMachineConfigurationPersisterTest.java | 2 + .../TimeMachineConfigurationTest.java | 19 ++++--- .../timemachine/VariationDecoratorTest.java | 5 +- .../src/main/java/org/sonar/batch/Batch.java | 7 +++ .../java/org/sonar/batch/ProjectBatch.java | 4 ++ .../batch/components}/PastMeasuresLoader.java | 2 +- .../sonar/batch/components}/PastSnapshot.java | 2 +- .../batch/components}/PastSnapshotFinder.java | 54 +++++++++--------- .../components}/PastSnapshotFinderByDate.java | 11 ++-- .../components}/PastSnapshotFinderByDays.java | 9 +-- .../PastSnapshotFinderByPreviousAnalysis.java | 12 ++-- .../PastSnapshotFinderByVersion.java | 8 +-- .../components}/PastViolationsLoader.java | 2 +- .../components}/TimeMachineConfiguration.java | 17 +++--- .../index/DefaultPersistenceManager.java | 1 - .../components}/PastMeasuresLoaderTest.java | 3 +- .../PastSnapshotFinderByDateTest.java | 10 ++-- .../PastSnapshotFinderByDaysTest.java | 15 +++-- ...tSnapshotFinderByPreviousAnalysisTest.java | 10 ++-- .../PastSnapshotFinderByVersionTest.java | 10 ++-- .../components}/PastSnapshotFinderTest.java | 57 ++++++++++--------- .../components}/PastViolationsLoaderTest.java | 2 +- .../batch/index/ViolationPersisterTest.java | 1 - .../PastMeasuresLoaderTest/shared.xml | 0 .../PastSnapshotFinderByDateTest/shared.xml | 0 .../PastSnapshotFinderByDaysTest/shared.xml | 0 .../shouldFindPreviousAnalysis.xml | 0 .../shouldNotFindPreviousAnalysis.xml | 0 .../shared.xml | 0 .../PastViolationsLoaderTest/shared.xml | 0 .../java/org/sonar/api/CoreProperties.java | 9 +++ .../org/sonar/api/utils/HttpDownloader.java | 2 +- 40 files changed, 176 insertions(+), 159 deletions(-) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastMeasuresLoader.java (98%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshot.java (98%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshotFinder.java (61%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshotFinderByDate.java (83%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshotFinderByDays.java (87%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshotFinderByPreviousAnalysis.java (78%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastSnapshotFinderByVersion.java (86%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/PastViolationsLoader.java (97%) rename {plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine => sonar-batch/src/main/java/org/sonar/batch/components}/TimeMachineConfiguration.java (82%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastMeasuresLoaderTest.java (97%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastSnapshotFinderByDateTest.java (90%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastSnapshotFinderByDaysTest.java (84%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastSnapshotFinderByPreviousAnalysisTest.java (87%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastSnapshotFinderByVersionTest.java (85%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastSnapshotFinderTest.java (66%) rename {plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine => sonar-batch/src/test/java/org/sonar/batch/components}/PastViolationsLoaderTest.java (97%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastMeasuresLoaderTest/shared.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastSnapshotFinderByDateTest/shared.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastSnapshotFinderByDaysTest/shared.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastSnapshotFinderByVersionTest/shared.xml (100%) rename {plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine => sonar-batch/src/test/resources/org/sonar/batch/components}/PastViolationsLoaderTest/shared.xml (100%) 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 5a16664dac2..8af552c5f52 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 @@ -119,7 +119,7 @@ import java.util.List; description = "Period used to compare measures and track new violations. Values are : ", project = false, global = true, - defaultValue = PastSnapshotFinder.DEFAULT_VALUE_1 + defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1 ), @Property( key = "sonar.timemachine.period2", @@ -127,7 +127,7 @@ import java.util.List; description = "See the property 'Period 1'", project = false, global = true, - defaultValue = PastSnapshotFinder.DEFAULT_VALUE_2 + defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2 ), @Property( key = "sonar.timemachine.period3", @@ -135,21 +135,23 @@ import java.util.List; description = "See the property 'Period 1'", project = false, global = true, - defaultValue = PastSnapshotFinder.DEFAULT_VALUE_3 + defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3 ), @Property( key = "sonar.timemachine.period4", name = "Period 4", description = "Period used to compare measures and track new violations. This property is specific to the project. Values are : ", project = true, - global = false + global = false, + defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4 ), @Property( key = "sonar.timemachine.period5", name = "Period 5", description = "See the property 'Period 4'", project = true, - global = false + global = false, + defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5 ) }) public class CorePlugin implements Plugin { @@ -229,15 +231,7 @@ public class CorePlugin implements Plugin { // time machine extensions.add(TendencyDecorator.class); - extensions.add(PastSnapshotFinderByDate.class); - extensions.add(PastSnapshotFinderByDays.class); - extensions.add(PastSnapshotFinderByPreviousAnalysis.class); - extensions.add(PastSnapshotFinderByVersion.class); - extensions.add(PastMeasuresLoader.class); - extensions.add(PastSnapshotFinder.class); - extensions.add(TimeMachineConfiguration.class); extensions.add(VariationDecorator.class); - extensions.add(PastViolationsLoader.class); extensions.add(ViolationPersisterDecorator.class); extensions.add(NewViolationsDecorator.class); extensions.add(TimeMachineConfigurationPersister.class); 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 c491feafdab..ec470304406 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 @@ -20,7 +20,6 @@ package org.sonar.plugins.core.timemachine; import com.google.common.collect.*; -import org.apache.commons.lang.time.DateUtils; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.DependedUpon; @@ -32,6 +31,8 @@ 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.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; import java.util.*; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java index d92ba8f1376..836d23613e8 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java @@ -30,6 +30,7 @@ import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; +import org.sonar.batch.components.TimeMachineConfiguration; import java.util.List; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 90eb28b2710..4e1bba5d7c3 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -22,6 +22,8 @@ package org.sonar.plugins.core.timemachine; import org.sonar.api.BatchExtension; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; import java.util.List; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java index 4672fdbc10f..4e6ddddf74e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java @@ -22,15 +22,15 @@ package org.sonar.plugins.core.timemachine; import com.google.common.collect.Maps; import org.sonar.api.batch.*; import org.sonar.api.database.model.MeasureModel; -import org.sonar.api.measures.Measure; -import org.sonar.api.measures.MeasuresFilters; -import org.sonar.api.measures.Metric; -import org.sonar.api.measures.RuleMeasure; +import org.sonar.api.measures.*; import org.sonar.api.qualitymodel.Characteristic; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rules.RulePriority; +import org.sonar.batch.components.PastMeasuresLoader; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; import java.util.Collection; import java.util.List; @@ -41,14 +41,17 @@ public class VariationDecorator implements Decorator { private List projectPastSnapshots; private PastMeasuresLoader pastMeasuresLoader; + private MetricFinder metricFinder; + + public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration configuration) { + this(pastMeasuresLoader, metricFinder, configuration.getProjectPastSnapshots()); - public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, TimeMachineConfiguration configuration) { - this(pastMeasuresLoader, configuration.getProjectPastSnapshots()); } - VariationDecorator(PastMeasuresLoader pastMeasuresLoader, List projectPastSnapshots) { + VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List projectPastSnapshots) { this.pastMeasuresLoader = pastMeasuresLoader; this.projectPastSnapshots = projectPastSnapshots; + this.metricFinder = metricFinder; } public boolean shouldExecuteOnProject(Project project) { @@ -87,7 +90,8 @@ public class VariationDecorator implements Decorator { // for each measure, search equivalent past measure for (Measure measure : context.getMeasures(MeasuresFilters.all())) { // compare with past measure - MeasureModel pastMeasure = pastMeasuresByKey.get(new MeasureKey(measure)); + Integer metricId = (measure.getMetric().getId()!=null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId()); + MeasureModel pastMeasure = pastMeasuresByKey.get(new MeasureKey(measure, metricId)); if (updateVariation(measure, pastMeasure, index)) { context.saveMeasure(measure); } @@ -121,14 +125,14 @@ public class VariationDecorator implements Decorator { characteristic = model.getCharacteristic(); } - MeasureKey(Measure measure) { - metricId = measure.getMetric().getId(); - characteristic = measure.getCharacteristic(); + MeasureKey(Measure measure, Integer metricId) { + this.metricId = metricId; + this.characteristic = measure.getCharacteristic(); // TODO merge RuleMeasure into Measure if (measure instanceof RuleMeasure) { RuleMeasure rm = (RuleMeasure) measure; - ruleId = (rm.getRule() == null ? null : rm.getRule().getId()); - priority = rm.getRulePriority(); + this.ruleId = (rm.getRule() == null ? null : rm.getRule().getId()); + this.priority = rm.getRulePriority(); } } 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 5290bd6b02f..9d90f3e81b2 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 @@ -20,6 +20,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.Violation; import org.sonar.api.utils.SonarException; +import org.sonar.batch.components.PastViolationsLoader; import org.sonar.batch.index.ViolationPersister; import java.io.IOException; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java index 0ac22acda20..8170bb55dfe 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java @@ -36,8 +36,9 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.Violation; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; -import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java index 05aea8b53fb..ddf68f6d428 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java @@ -29,6 +29,7 @@ import org.sonar.api.measures.Measure; import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.JavaPackage; import org.sonar.api.resources.Project; +import org.sonar.batch.components.TimeMachineConfiguration; import java.text.ParseException; import java.text.SimpleDateFormat; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java index 9f1900b8fb8..6c0477004f5 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java @@ -21,6 +21,8 @@ package org.sonar.plugins.core.timemachine; import org.junit.Test; import org.sonar.api.database.model.Snapshot; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.text.ParseException; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java index f9cbfc6cf60..4a834d65796 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java @@ -23,6 +23,9 @@ import org.apache.commons.configuration.PropertiesConfiguration; import org.junit.Test; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; +import org.sonar.batch.components.PastSnapshot; +import org.sonar.batch.components.PastSnapshotFinder; +import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.text.ParseException; @@ -49,17 +52,17 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase { } @Test - public void shouldInitVariationSnapshots() throws ParseException { + public void shouldInitPastSnapshots() throws ParseException { PropertiesConfiguration conf = new PropertiesConfiguration(); - PastSnapshotFinder snapshotReferenceFinder = mock(PastSnapshotFinder.class); - when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15"))); - when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13"))); + PastSnapshotFinder pastSnapshotFinder = mock(PastSnapshotFinder.class); + when(pastSnapshotFinder.find(null, conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15"))); + when(pastSnapshotFinder.find(null, conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13"))); - TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, snapshotReferenceFinder); + TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, pastSnapshotFinder, null); - verify(snapshotReferenceFinder).find(conf, 1); - verify(snapshotReferenceFinder).find(conf, 2); - verify(snapshotReferenceFinder).find(conf, 3); + verify(pastSnapshotFinder).find(null, conf, 1); + verify(pastSnapshotFinder).find(null, conf, 2); + verify(pastSnapshotFinder).find(null, conf, 3); assertThat(timeMachineConfiguration.getProjectPastSnapshots().size(), is(2)); } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java index 0f02f0c2268..76fddcfb7f9 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java @@ -27,7 +27,10 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.Metric; +import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.*; +import org.sonar.batch.components.PastMeasuresLoader; +import org.sonar.batch.components.PastSnapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.util.Arrays; @@ -76,7 +79,7 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase { Measure currentCoverage = newMeasure(COVERAGE, 80.0); when(context.getMeasures(Matchers.anyObject())).thenReturn(Arrays.asList(currentNcloc, currentCoverage)); - VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, Arrays.asList(pastSnapshot1, pastSnapshot3)); + VariationDecorator decorator = new VariationDecorator(pastMeasuresLoader, mock(MetricFinder.class), Arrays.asList(pastSnapshot1, pastSnapshot3)); decorator.decorate(javaPackage, context); // context updated for each variation : 2 times for ncloc and 1 time for coverage diff --git a/sonar-batch/src/main/java/org/sonar/batch/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/Batch.java index 91e981e41ac..bf5b1e348bd 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/Batch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/Batch.java @@ -33,6 +33,7 @@ import org.sonar.batch.bootstrap.BatchPluginRepository; import org.sonar.batch.bootstrap.BootstrapClassLoader; import org.sonar.batch.bootstrap.ExtensionDownloader; import org.sonar.batch.bootstrap.TempDirectories; +import org.sonar.batch.components.*; import org.sonar.batch.index.*; import org.sonar.core.components.CacheMetricFinder; import org.sonar.core.components.CacheRuleFinder; @@ -92,6 +93,12 @@ public class Batch { batchContainer.as(Characteristics.CACHE).addComponent(MeasuresDao.class); batchContainer.as(Characteristics.CACHE).addComponent(CacheRuleFinder.class); batchContainer.as(Characteristics.CACHE).addComponent(CacheMetricFinder.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastSnapshotFinderByDate.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastSnapshotFinderByDays.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastSnapshotFinderByPreviousAnalysis.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastSnapshotFinderByVersion.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastMeasuresLoader.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastSnapshotFinder.class); batchContainer.start(); ProjectTree projectTree = batchContainer.getComponent(ProjectTree.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java index afccb16fdda..6bc1ac2862c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java @@ -36,6 +36,8 @@ import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.utils.IocContainer; import org.sonar.api.utils.SonarException; import org.sonar.batch.bootstrap.BatchPluginRepository; +import org.sonar.batch.components.PastViolationsLoader; +import org.sonar.batch.components.TimeMachineConfiguration; import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.index.DefaultResourcePersister; import org.sonar.batch.phases.Phases; @@ -93,6 +95,8 @@ public class ProjectBatch { batchContainer.as(Characteristics.CACHE).addComponent(ViolationFilters.class); batchContainer.as(Characteristics.CACHE).addComponent(ResourceFilters.class); batchContainer.as(Characteristics.CACHE).addComponent(DefaultModelFinder.class); + batchContainer.as(Characteristics.CACHE).addComponent(TimeMachineConfiguration.class); + batchContainer.as(Characteristics.CACHE).addComponent(PastViolationsLoader.class); batchContainer.addAdapter(new ProfileProvider()); batchContainer.addAdapter(new CheckProfileProvider()); loadCoreComponents(batchContainer); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java similarity index 98% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastMeasuresLoader.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java index 7fc073956fc..ee3ad649957 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastMeasuresLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import com.google.common.collect.Maps; import org.apache.commons.lang.ObjectUtils; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java similarity index 98% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java index 6909cf29e5a..b55ad44d661 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.sonar.api.database.model.Snapshot; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java similarity index 61% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java index bf7d8ba5d9f..00f112a1b56 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java @@ -17,11 +17,13 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchExtension; +import org.sonar.api.CoreProperties; +import org.sonar.api.database.model.Snapshot; import org.sonar.api.utils.Logs; import java.text.ParseException; @@ -33,11 +35,6 @@ public class PastSnapshotFinder implements BatchExtension { /** * IMPORTANT : please update default values in the ruby side too. See app/helpers/FiltersHelper.rb, method period_names() */ - public static final String DEFAULT_VALUE_1 = PastSnapshotFinderByPreviousAnalysis.MODE; - public static final String DEFAULT_VALUE_2 = "5"; - public static final String DEFAULT_VALUE_3 = "30"; - public static final String PROPERTY_PREFIX = "sonar.timemachine.period"; - private PastSnapshotFinderByDays finderByDays; private PastSnapshotFinderByVersion finderByVersion; private PastSnapshotFinderByDate finderByDate; @@ -51,11 +48,11 @@ public class PastSnapshotFinder implements BatchExtension { this.finderByPreviousAnalysis = finderByPreviousAnalysis; } - public PastSnapshot find(Configuration conf, int index) { + public PastSnapshot find(Snapshot projectSnapshot, Configuration conf, int index) { String propertyValue = getPropertyValue(conf, index); - PastSnapshot pastSnapshot = find(index, propertyValue); + PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue); if (pastSnapshot==null && StringUtils.isNotBlank(propertyValue)) { - Logs.INFO.warn("The property " + PROPERTY_PREFIX + index + " has an unvalid value: " + propertyValue); + Logs.INFO.warn("The property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " has an unvalid value: " + propertyValue); } return pastSnapshot; } @@ -63,26 +60,27 @@ public class PastSnapshotFinder implements BatchExtension { static String getPropertyValue(Configuration conf, int index) { String defaultValue = null; switch (index) { - // only global settings (from 1 to 3) have default values - case 1: defaultValue = DEFAULT_VALUE_1; break; - case 2: defaultValue = DEFAULT_VALUE_2; break; - case 3: defaultValue = DEFAULT_VALUE_3; break; + case 1: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1; break; + case 2: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2; break; + case 3: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3; break; + case 4: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4; break; + case 5: defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5; break; } - return conf.getString(PROPERTY_PREFIX + index, defaultValue); + return conf.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index, defaultValue); } - public PastSnapshot find(int index, String property) { + public PastSnapshot find(Snapshot projectSnapshot, int index, String property) { if (StringUtils.isBlank(property)) { return null; } - PastSnapshot result = findByDays(property); + PastSnapshot result = findByDays(projectSnapshot, property); if (result == null) { - result = findByDate(property); + result = findByDate(projectSnapshot, property); if (result == null) { - result = findByPreviousAnalysis(property); + result = findByPreviousAnalysis(projectSnapshot, property); if (result == null) { - result = findByVersion(property); + result = findByVersion(projectSnapshot, property); } } } @@ -94,33 +92,33 @@ public class PastSnapshotFinder implements BatchExtension { return result; } - private PastSnapshot findByPreviousAnalysis(String property) { + private PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot, String property) { PastSnapshot pastSnapshot = null; - if (StringUtils.equals(PastSnapshotFinderByPreviousAnalysis.MODE, property)) { - pastSnapshot = finderByPreviousAnalysis.findByPreviousAnalysis(); + if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) { + pastSnapshot = finderByPreviousAnalysis.findByPreviousAnalysis(projectSnapshot); } return pastSnapshot; } - private PastSnapshot findByDate(String property) { + private PastSnapshot findByDate(Snapshot projectSnapshot, String property) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { Date date = format.parse(property); - return finderByDate.findByDate(date); + return finderByDate.findByDate(projectSnapshot, date); } catch (ParseException e) { return null; } } - private PastSnapshot findByVersion(String property) { - return finderByVersion.findByVersion(property); + private PastSnapshot findByVersion(Snapshot projectSnapshot, String property) { + return finderByVersion.findByVersion(projectSnapshot, property); } - private PastSnapshot findByDays(String property) { + private PastSnapshot findByDays(Snapshot projectSnapshot, String property) { try { int days = Integer.parseInt(property); - return finderByDays.findFromDays(days); + return finderByDays.findFromDays(projectSnapshot, days); } catch (NumberFormatException e) { return null; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java similarity index 83% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDate.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java index d33ead7c16b..75ef31b9084 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDate.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.sonar.api.BatchExtension; import org.sonar.api.database.DatabaseSession; @@ -27,20 +27,17 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -public class PastSnapshotFinderByDate implements BatchExtension{ +public class PastSnapshotFinderByDate implements BatchExtension { public static final String MODE = "date"; - - private Snapshot projectSnapshot; // TODO replace by PersistenceManager private DatabaseSession session; - public PastSnapshotFinderByDate(Snapshot projectSnapshot, DatabaseSession session) { - this.projectSnapshot = projectSnapshot; + public PastSnapshotFinderByDate(DatabaseSession session) { this.session = session; } - PastSnapshot findByDate(Date date) { + PastSnapshot findByDate(Snapshot projectSnapshot, Date date) { String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status order by createdAt asc"; List snapshots = session.createQuery(hql) .setParameter("date", date) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java similarity index 87% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDays.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java index 8daea1a6bd1..6894a802ec1 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDays.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.apache.commons.lang.time.DateUtils; import org.sonar.api.BatchExtension; @@ -31,16 +31,13 @@ public class PastSnapshotFinderByDays implements BatchExtension { public static final String MODE = "days"; - - private Snapshot projectSnapshot; // TODO replace by PersistenceManager private DatabaseSession session; - public PastSnapshotFinderByDays(Snapshot projectSnapshot, DatabaseSession session) { - this.projectSnapshot = projectSnapshot; + public PastSnapshotFinderByDays(DatabaseSession session) { this.session = session; } - PastSnapshot findFromDays(int days) { + PastSnapshot findFromDays(Snapshot projectSnapshot, int days) { Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days); String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt>=:from AND createdAt<:to order by createdAt asc"; List snapshots = session.createQuery(hql) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java similarity index 78% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java index e8c0432fd67..55dda549bbc 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java @@ -17,9 +17,10 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.sonar.api.BatchExtension; +import org.sonar.api.CoreProperties; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; @@ -27,17 +28,14 @@ import java.text.SimpleDateFormat; import java.util.List; public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { - public static final String MODE = "previous_analysis"; - private Snapshot projectSnapshot; // TODO replace by PersistenceManager private DatabaseSession session; - public PastSnapshotFinderByPreviousAnalysis(Snapshot projectSnapshot, DatabaseSession session) { - this.projectSnapshot = projectSnapshot; + public PastSnapshotFinderByPreviousAnalysis(DatabaseSession session) { this.session = session; } - PastSnapshot findByPreviousAnalysis() { + PastSnapshot findByPreviousAnalysis(Snapshot projectSnapshot) { String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc"; List snapshots = session.createQuery(hql) .setParameter("date", projectSnapshot.getCreatedAt()) @@ -51,7 +49,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { } Snapshot snapshot = snapshots.get(0); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(format.format(snapshot.getCreatedAt())); + return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot.getCreatedAt(), snapshot).setModeParameter(format.format(snapshot.getCreatedAt())); } } diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java similarity index 86% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java index bba16f91fad..cd360d2b125 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.sonar.api.BatchExtension; import org.sonar.api.database.DatabaseSession; @@ -29,15 +29,13 @@ public class PastSnapshotFinderByVersion implements BatchExtension { public static final String MODE = "version"; - private Snapshot projectSnapshot; // TODO replace by PersistenceManager private DatabaseSession session; - public PastSnapshotFinderByVersion(Snapshot projectSnapshot, DatabaseSession session) { - this.projectSnapshot = projectSnapshot; + public PastSnapshotFinderByVersion(DatabaseSession session) { this.session = session; } - PastSnapshot findByVersion(String version) { + PastSnapshot findByVersion(Snapshot projectSnapshot, String version) { String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status order by createdAt desc"; List snapshots = session.createQuery(hql) .setParameter("version", version) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java similarity index 97% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java rename to sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java index d8b064fbee0..5f238ee9aed 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastViolationsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastViolationsLoader.java @@ -1,4 +1,4 @@ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.sonar.api.BatchExtension; import org.sonar.api.database.DatabaseSession; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java similarity index 82% rename from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java rename to sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index 1658381f0d4..eb1977270e7 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -17,12 +17,13 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import com.google.common.collect.Lists; import org.apache.commons.configuration.Configuration; import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; +import org.sonar.api.database.model.Snapshot; import org.sonar.api.utils.Logs; import java.util.Collections; @@ -35,15 +36,15 @@ public class TimeMachineConfiguration implements BatchExtension { private final Configuration configuration; private List projectPastSnapshots; - public TimeMachineConfiguration(Configuration configuration, PastSnapshotFinder variationSnapshotFinder) { + public TimeMachineConfiguration(Configuration configuration, PastSnapshotFinder pastSnapshotFinder, Snapshot projectSnapshot) { this.configuration = configuration; - initVariationSnapshots(variationSnapshotFinder); + initPastSnapshots(pastSnapshotFinder, projectSnapshot); } - private void initVariationSnapshots(PastSnapshotFinder variationSnapshotFinder) { + private void initPastSnapshots(PastSnapshotFinder pastSnapshotFinder, Snapshot projectSnapshot) { projectPastSnapshots = Lists.newLinkedList(); for (int index = 1; index <= NUMBER_OF_VARIATION_SNAPSHOTS; index++) { - PastSnapshot variationSnapshot = variationSnapshotFinder.find(configuration, index); + PastSnapshot variationSnapshot = pastSnapshotFinder.find(projectSnapshot, configuration, index); if (variationSnapshot != null) { Logs.INFO.info("Comparison date: " + variationSnapshot.getDate()); projectPastSnapshots.add(variationSnapshot); @@ -51,11 +52,7 @@ public class TimeMachineConfiguration implements BatchExtension { } } - - /** - * for unit tests - */ - TimeMachineConfiguration(Configuration configuration) { + public TimeMachineConfiguration(Configuration configuration) { this.configuration = configuration; this.projectPastSnapshots = Collections.emptyList(); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java index c91bf3205aa..942dd3aa127 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultPersistenceManager.java @@ -26,7 +26,6 @@ import org.sonar.api.measures.Measure; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectLink; import org.sonar.api.resources.Resource; -import org.sonar.api.rules.Violation; import java.util.List; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java similarity index 97% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastMeasuresLoaderTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java index 73959db7844..1f3301424ed 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastMeasuresLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java @@ -17,12 +17,13 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.junit.Test; import org.sonar.api.database.model.MeasureModel; import org.sonar.api.database.model.Snapshot; import org.sonar.api.measures.Metric; +import org.sonar.batch.components.PastMeasuresLoader; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.util.Arrays; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java similarity index 90% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java index 5ee48a6595d..2013424d30c 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDateTest.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.junit.Test; import org.sonar.api.database.model.Snapshot; @@ -38,11 +38,11 @@ public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(projectSnapshot, getSession()); + PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession()); Date date = DATE_FORMAT.parse("2008-11-22"); - PastSnapshot pastSnapshot = finder.findByDate(date); + PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date); assertThat(pastSnapshot.getProjectSnapshotId(), is(1006)); } @@ -51,11 +51,11 @@ public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(projectSnapshot, getSession()); + PastSnapshotFinderByDate finder = new PastSnapshotFinderByDate(getSession()); Date date = DATE_FORMAT.parse("2008-11-24"); - PastSnapshot pastSnapshot = finder.findByDate(date); + PastSnapshot pastSnapshot = finder.findByDate(projectSnapshot, date); assertThat(pastSnapshot.getProjectSnapshotId(), is(1009)); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java similarity index 84% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java index 226010b327b..6db32df71c7 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java @@ -17,9 +17,8 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; -import org.hamcrest.core.IsNull; import org.junit.Test; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; @@ -37,9 +36,9 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession()); + PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - assertThat(finder.findFromDays(50).getProjectSnapshotId(), is(1000)); + assertThat(finder.findFromDays(projectSnapshot, 50).getProjectSnapshotId(), is(1000)); } @Test @@ -47,9 +46,9 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession()); + PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - assertThat(finder.findFromDays(7).getProjectSnapshotId(), is(1006)); + assertThat(finder.findFromDays(projectSnapshot, 7).getProjectSnapshotId(), is(1006)); } @Test @@ -57,9 +56,9 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16 - PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession()); + PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(getSession()); - assertThat(finder.findFromDays(1), nullValue()); + assertThat(finder.findFromDays(projectSnapshot, 1), nullValue()); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java similarity index 87% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java index 992ebc37aa6..b72947d275e 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.junit.Test; import org.sonar.api.database.model.Snapshot; @@ -36,9 +36,9 @@ public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTest setupData("shouldFindPreviousAnalysis"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession()); + PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession()); - PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(); + PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot); assertThat(pastSnapshot.getProjectSnapshotId(), is(1009)); } @@ -47,8 +47,8 @@ public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTest setupData("shouldNotFindPreviousAnalysis"); Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession()); + PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(getSession()); - assertNull(finder.findByPreviousAnalysis()); + assertNull(finder.findByPreviousAnalysis(projectSnapshot)); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java similarity index 85% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java index c051c5d4dae..6a6f084b842 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java @@ -17,7 +17,7 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.junit.Test; import org.sonar.api.database.model.Snapshot; @@ -34,9 +34,9 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession()); + PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - assertThat(finder.findByVersion("1.1").getProjectSnapshotId(), is(1009)); + assertThat(finder.findByVersion(currentProjectSnapshot, "1.1").getProjectSnapshotId(), is(1009)); } @Test @@ -44,8 +44,8 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { setupData("shared"); Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); - PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession()); + PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - assertThat(finder.findByVersion("1.0"), nullValue()); + assertThat(finder.findByVersion(currentProjectSnapshot, "1.0"), nullValue()); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java similarity index 66% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java index 127933294d9..eb59d8d4139 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java @@ -17,13 +17,14 @@ * License along with Sonar; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 */ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.apache.commons.configuration.PropertiesConfiguration; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Before; import org.junit.Test; +import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; import java.text.ParseException; @@ -57,11 +58,11 @@ public class PastSnapshotFinderTest { @Test public void shouldFindByNumberOfDays() { - when(finderByDays.findFromDays(30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30")); + when(finderByDays.findFromDays(null, 30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30")); - PastSnapshot variationSnapshot = finder.find(1, "30"); + PastSnapshot variationSnapshot = finder.find(null, 1, "30"); - verify(finderByDays).findFromDays(30); + verify(finderByDays).findFromDays(null, 30); assertNotNull(variationSnapshot); assertThat(variationSnapshot.getIndex(), is(1)); assertThat(variationSnapshot.getMode(), is("days")); @@ -70,9 +71,9 @@ public class PastSnapshotFinderTest { @Test public void shouldNotFindByNumberOfDays() { - PastSnapshot variationSnapshot = finder.find(1, "30"); + PastSnapshot variationSnapshot = finder.find(null, 1, "30"); - verify(finderByDays).findFromDays(30); + verify(finderByDays).findFromDays(null, 30); assertNull(variationSnapshot); } @@ -80,11 +81,11 @@ public class PastSnapshotFinderTest { public void shouldFindByDate() throws ParseException { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); final Date date = format.parse("2010-05-18"); - when(finderByDate.findByDate(date)).thenReturn(new PastSnapshot("date", new Snapshot())); + when(finderByDate.findByDate(null, date)).thenReturn(new PastSnapshot("date", new Snapshot())); - PastSnapshot variationSnapshot = finder.find(2, "2010-05-18"); + PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); - verify(finderByDate).findByDate(argThat(new BaseMatcher() { + verify(finderByDate).findByDate((Snapshot) anyObject(), argThat(new BaseMatcher() { public boolean matches(Object o) { return o.equals(date); } @@ -100,11 +101,11 @@ public class PastSnapshotFinderTest { @Test public void shouldNotFindByDate() throws ParseException { - when(finderByDate.findByDate((Date) anyObject())).thenReturn(null); + when(finderByDate.findByDate((Snapshot) anyObject(), (Date) anyObject())).thenReturn(null); - PastSnapshot variationSnapshot = finder.find(2, "2010-05-18"); + PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18"); - verify(finderByDate).findByDate((Date) anyObject()); + verify(finderByDate).findByDate((Snapshot) anyObject(), (Date) anyObject()); assertNull(variationSnapshot); } @@ -114,34 +115,34 @@ public class PastSnapshotFinderTest { final Date date = format.parse("2010-05-18"); Snapshot snapshot = new Snapshot(); snapshot.setCreatedAt(date); - when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, snapshot)); + when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, snapshot)); - PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE); + PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - verify(finderByPreviousAnalysis).findByPreviousAnalysis(); + verify(finderByPreviousAnalysis).findByPreviousAnalysis(null); assertThat(variationSnapshot.getIndex(), is(2)); - assertThat(variationSnapshot.getMode(), is(PastSnapshotFinderByPreviousAnalysis.MODE)); + assertThat(variationSnapshot.getMode(), is(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)); assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); } @Test public void shouldNotFindPreviousAnalysis() { - when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(null); + when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(null); - PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE); + PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - verify(finderByPreviousAnalysis).findByPreviousAnalysis(); + verify(finderByPreviousAnalysis).findByPreviousAnalysis(null); assertNull(variationSnapshot); } @Test public void shouldFindByVersion() { - when(finderByVersion.findByVersion("1.2")).thenReturn(new PastSnapshot("version", new Snapshot())); + when(finderByVersion.findByVersion(null, "1.2")).thenReturn(new PastSnapshot("version", new Snapshot())); - PastSnapshot variationSnapshot = finder.find(2, "1.2"); + PastSnapshot variationSnapshot = finder.find(null, 2, "1.2"); - verify(finderByVersion).findByVersion("1.2"); + verify(finderByVersion).findByVersion(null, "1.2"); assertThat(variationSnapshot.getIndex(), is(2)); assertThat(variationSnapshot.getMode(), is("version")); assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue())); @@ -149,18 +150,18 @@ public class PastSnapshotFinderTest { @Test public void shouldNotFindVersion() { - when(finderByVersion.findByVersion("1.2")).thenReturn(null); + when(finderByVersion.findByVersion(null, "1.2")).thenReturn(null); - PastSnapshot variationSnapshot = finder.find(2, "1.2"); + PastSnapshot variationSnapshot = finder.find(null, 2, "1.2"); - verify(finderByVersion).findByVersion("1.2"); + verify(finderByVersion).findByVersion(null, "1.2"); assertNull(variationSnapshot); } @Test public void shouldNotFailIfUnknownFormat() { - when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, new Snapshot())); // should not be called - assertNull(finder.find(2, "foooo")); + when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Snapshot())); // should not be called + assertNull(finder.find(null, 2, "foooo")); } @Test @@ -177,6 +178,6 @@ public class PastSnapshotFinderTest { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty("sonar.timemachine.period1", "5"); - assertThat(PastSnapshotFinder.getPropertyValue(conf, 2), is(PastSnapshotFinder.DEFAULT_VALUE_2)); + assertThat(PastSnapshotFinder.getPropertyValue(conf, 2), is(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2)); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastViolationsLoaderTest.java similarity index 97% rename from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java rename to sonar-batch/src/test/java/org/sonar/batch/components/PastViolationsLoaderTest.java index 341b5107c4c..bbc35b4b878 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastViolationsLoaderTest.java @@ -1,4 +1,4 @@ -package org.sonar.plugins.core.timemachine; +package org.sonar.batch.components; import org.junit.Before; import org.junit.Test; diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java index f9bd575af86..b307e8dbe67 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java @@ -51,7 +51,6 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase { Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000); ResourcePersister resourcePersister = mock(ResourcePersister.class); when(resourcePersister.saveResource((Project) anyObject(), eq(javaFile))).thenReturn(snapshot); - when(resourcePersister.getLastSnapshot(snapshot, true)).thenReturn(snapshot); when(resourcePersister.getSnapshot(javaFile)).thenReturn(snapshot); violationPersister = new ViolationPersister(getSession(), resourcePersister, new DefaultRuleFinder(getSessionFactory())); } diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastMeasuresLoaderTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastMeasuresLoaderTest/shared.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest/shared.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest/shared.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest/shared.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastViolationsLoaderTest/shared.xml similarity index 100% rename from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastViolationsLoaderTest/shared.xml rename to sonar-batch/src/test/resources/org/sonar/batch/components/PastViolationsLoaderTest/shared.xml diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 2e52aa374a3..d1455f00aec 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -115,4 +115,13 @@ public interface CoreProperties { /* Surefire */ String SUREFIRE_PLUGIN = "surefire"; String SUREFIRE_REPORTS_PATH_PROPERTY = "sonar.surefire.reportsPath"; + + /* Time machine periods */ + String TIMEMACHINE_PERIOD_PREFIX = "sonar.timemachine.period"; + String TIMEMACHINE_MODE_PREVIOUS_ANALYSIS = "previous_analysis"; + String TIMEMACHINE_DEFAULT_PERIOD_1 = TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; + String TIMEMACHINE_DEFAULT_PERIOD_2 = "5"; + String TIMEMACHINE_DEFAULT_PERIOD_3 = "30"; + String TIMEMACHINE_DEFAULT_PERIOD_4 = ""; + String TIMEMACHINE_DEFAULT_PERIOD_5 = ""; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java index 71ea6f72ff6..923e1606e10 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java @@ -170,7 +170,7 @@ public class HttpDownloader implements BatchComponent, ServerComponent { } private HttpURLConnection newHttpConnection(URI uri) throws IOException { - LoggerFactory.getLogger(getClass()).info("Download: " + uri + " (" + getProxySynthesis(uri) + ")"); + LoggerFactory.getLogger(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri) + ")"); HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setConnectTimeout(TIMEOUT_MILLISECONDS); connection.setReadTimeout(TIMEOUT_MILLISECONDS); -- 2.39.5