@Property(
key = "sonar.timemachine.variation1",
name = "Variation 1",
- description = "Period used to compare measures and track new violations. Values are : <ul><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li><li>A version, for example 1.2</li></ul>",
+ description = "Period used to compare measures and track new violations. Values are : <ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li><li>A version, for example 1.2</li></ul>",
project = false,
- global = true
+ global = true,
+ defaultValue = PastSnapshotFinder.DEFAULT_VALUE_1
),
@Property(
key = "sonar.timemachine.variation2",
name = "Variation 2",
- description = "To be defined. For the moment the number of days",
+ description = "See the property 'Variation 1'",
project = false,
- global = true
+ global = true,
+ defaultValue = PastSnapshotFinder.DEFAULT_VALUE_2
),
@Property(
key = "sonar.timemachine.variation3",
name = "Variation 3",
- description = "To be defined. For the moment the number of days",
+ description = "See the property 'Variation 1'",
project = false,
- global = true
+ global = true,
+ defaultValue = PastSnapshotFinder.DEFAULT_VALUE_3
),
@Property(
key = "sonar.timemachine.variation4",
name = "Variation 4",
- description = "To be defined. For the moment the number of days",
+ description = "Period used to compare measures and track new violations. This property is specific to the project. Values are : <ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to compare to previous analysis</li><li>A version, for example 1.2</li></ul>",
project = true,
global = false
),
@Property(
key = "sonar.timemachine.variation5",
name = "Variation 5",
- description = "To be defined. For the moment the number of days",
+ description = "See the property 'Variation 4'",
project = true,
global = false
)
import java.util.Date;
public class PastSnapshotFinder implements BatchExtension {
+
+ 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";
+
private PastSnapshotFinderByDays finderByDays;
private PastSnapshotFinderByVersion finderByVersion;
private PastSnapshotFinderByDate finderByDate;
}
public PastSnapshot find(Configuration conf, int index) {
- return find(index, conf.getString("sonar.timemachine.variation" + index));
+ String propertyValue = getPropertyValue(conf, index);
+ return find(index, propertyValue);
+ }
+
+ static String getPropertyValue(Configuration conf, int index) {
+ String defaultValue = null;
+ switch (index) {
+ case 1: defaultValue = DEFAULT_VALUE_1; break;
+ case 2: defaultValue = DEFAULT_VALUE_2; break;
+ case 3: defaultValue = DEFAULT_VALUE_3; break;
+ }
+ return conf.getString("sonar.timemachine.variation" + index, defaultValue);
}
public PastSnapshot find(int index, String property) {
public static final String MODE = "days";
+
private Snapshot projectSnapshot; // TODO replace by PersistenceManager
private DatabaseSession session;
*/
package org.sonar.plugins.core.timemachine;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
+import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, new Snapshot())); // should not be called
assertNull(finder.find(2, "foooo"));
}
+
+ @Test
+ public void shouldGetPropertyValue() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty("sonar.timemachine.variation1", "5");
+
+ assertThat(PastSnapshotFinder.getPropertyValue(conf, 1), is("5"));
+ assertThat(PastSnapshotFinder.getPropertyValue(conf, 999), nullValue());
+ }
+
+ @Test
+ public void shouldGetDefaultPropertyValue() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty("sonar.timemachine.variation1", "5");
+
+ assertThat(PastSnapshotFinder.getPropertyValue(conf, 2), is(PastSnapshotFinder.DEFAULT_VALUE_2));
+ }
}