]> source.dussan.org Git - sonarqube.git/commitdiff
Change order of DBCleaner properties
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Jun 2013 09:05:58 +0000 (11:05 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 6 Jun 2013 09:05:58 +0000 (11:05 +0200)
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java

index 78d561c8fffac60ea28f6ef4808f8d62828bd4ee..5a0e48fb96af0d00cbcff36265020a5d55eb2656 100644 (file)
 package org.sonar.plugins.dbcleaner;
 
 import com.google.common.collect.ImmutableList;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
 import org.sonar.api.PropertyType;
 import org.sonar.api.SonarPlugin;
+import org.sonar.api.config.PropertyDefinition;
+import org.sonar.api.resources.Qualifiers;
 import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
 import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
 
+import java.util.Arrays;
 import java.util.List;
 
-@Properties({
-  @Property(key = DbCleanerConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY, defaultValue = "24",
-    name = "Number of hours before starting to keep only one snapshot per day",
-    description = "After this number of hours, if there are several snapshots during the same day, "
-      + "the DbCleaner keeps the most recent one and fully deletes the other ones.",
-    global = true,
-    project = true,
-    type = PropertyType.INTEGER),
-  @Property(key = DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK, defaultValue = "4",
-    name = "Number of weeks before starting to keep only one snapshot per week",
-    description = "After this number of weeks, if there are several snapshots during the same week, "
-      + "the DbCleaner keeps the most recent one and fully deletes the other ones.",
-    global = true,
-    project = true,
-    type = PropertyType.INTEGER),
-  @Property(key = DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH, defaultValue = "52",
-    name = "Number of weeks before starting to keep only one snapshot per month",
-    description = "After this number of weeks, if there are several snapshots during the same month, "
-      + "the DbCleaner keeps the most recent one and fully deletes the other ones.",
-    global = true,
-    project = true,
-    type = PropertyType.INTEGER),
-  @Property(key = DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS, defaultValue = "260",
-    name = "Number of weeks before starting to delete all remaining snapshots",
-    description = "After this number of weeks, all snapshots are fully deleted.",
-    global = true,
-    project = true,
-    type = PropertyType.INTEGER),
-  @Property(
-    key = DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY,
-    defaultValue = "true",
-    name = "Clean history data of directories/packages",
-    description = "If set to true, no history is kept at directory/package level. Setting this to false can cause database bloat.",
-    global = true,
-    project = true,
-    module = false,
-    type = PropertyType.BOOLEAN),
-  @Property(
-    key = DbCleanerConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES,
-    defaultValue = "30",
-    name = "Number of days before deleting closed issues",
-    description = "Issues that have been closed for more than this number of days will be deleted.",
-    global = true,
-    project = true,
-    type = PropertyType.INTEGER)
-})
 public final class DbCleanerPlugin extends SonarPlugin {
 
   public List getExtensions() {
-    return ImmutableList.of(
-      DefaultPeriodCleaner.class,
-      DefaultPurgeTask.class,
-      ProjectPurgePostJob.class);
+    return ImmutableList.builder().add(DefaultPeriodCleaner.class, DefaultPurgeTask.class, ProjectPurgePostJob.class)
+      .addAll(propertyDefinitions()).build();
+  }
+
+  static List<PropertyDefinition> propertyDefinitions() {
+    return Arrays.asList(
+      PropertyDefinition.builder(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY)
+        .defaultValue("true")
+        .name("Clean history data of directories/packages")
+        .description("If set to true, no history is kept at directory/package level. Setting this to false can cause database bloat.")
+        .type(PropertyType.BOOLEAN)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(1)
+        .build(),
+
+      PropertyDefinition.builder(DbCleanerConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES)
+        .defaultValue("30")
+        .name("Number of days before deleting closed issues")
+        .description("Issues that have been closed for more than this number of days will be deleted.")
+        .type(PropertyType.INTEGER)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(2)
+        .build(),
+
+      PropertyDefinition.builder(DbCleanerConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY)
+        .defaultValue("24")
+        .name("Number of hours before starting to keep only one snapshot per day")
+        .description("After this number of hours, if there are several snapshots during the same day, "
+          + "the DbCleaner keeps the most recent one and fully deletes the other ones.")
+        .type(PropertyType.INTEGER)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(3)
+        .build(),
+
+      PropertyDefinition.builder(DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK)
+        .defaultValue("4")
+        .name("Number of weeks before starting to keep only one snapshot per week")
+        .description("After this number of weeks, if there are several snapshots during the same week, "
+          + "the DbCleaner keeps the most recent one and fully deletes the other ones")
+        .type(PropertyType.INTEGER)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(4)
+        .build(),
+
+      PropertyDefinition.builder(DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH)
+        .defaultValue("52")
+        .name("Number of weeks before starting to keep only one snapshot per month")
+        .description("After this number of weeks, if there are several snapshots during the same month, "
+          + "the DbCleaner keeps the most recent one and fully deletes the other ones.")
+        .type(PropertyType.INTEGER)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(5)
+        .build(),
+
+      PropertyDefinition.builder(DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS)
+        .defaultValue("260")
+        .name("Number of weeks before starting to delete all remaining snapshots")
+        .description("After this number of weeks, all snapshots are fully deleted.")
+        .type(PropertyType.INTEGER)
+        .onQualifiers(Qualifiers.PROJECT)
+        .index(6)
+        .build()
+    );
   }
 }
index 651c7fb575f90a8c955754a7476b46e55dafe78b..160699524f7e076abd59c16c1c54d0455b24185c 100644 (file)
@@ -27,6 +27,6 @@ public class DbCleanerPluginTest {
 
   @Test
   public void shouldGetExtensions() {
-    assertThat(new DbCleanerPlugin().getExtensions()).hasSize(3);
+    assertThat(new DbCleanerPlugin().getExtensions()).hasSize(9);
   }
 }
index 4469ad0ac651e36d929a9aace917859a52b6fb6c..9a8a2edc1efee732250508d7e038ee0829fe59d8 100644 (file)
@@ -44,7 +44,7 @@ public class DefaultPurgeTaskTest {
   @Test
   public void shouldNotDeleteHistoricalDataOfDirectories() {
     PurgeDao purgeDao = mock(PurgeDao.class);
-    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.class));
+    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.propertyDefinitions()));
     settings.setProperty(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY, "false");
     DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class), mock(PurgeProfiler.class));
 
@@ -62,7 +62,7 @@ public class DefaultPurgeTaskTest {
   @Test
   public void shouldDeleteHistoricalDataOfDirectoriesByDefault() {
     PurgeDao purgeDao = mock(PurgeDao.class);
-    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.class));
+    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.propertyDefinitions()));
     DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class), mock(PurgeProfiler.class));
 
     task.purge(1L);
@@ -95,7 +95,7 @@ public class DefaultPurgeTaskTest {
     PurgeConfiguration conf = new PurgeConfiguration(1L, new String[0], 30);
     PurgeDao purgeDao = mock(PurgeDao.class);
     when(purgeDao.purge(conf)).thenThrow(new RuntimeException());
-    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.class));
+    Settings settings = new Settings(new PropertyDefinitions(DbCleanerPlugin.propertyDefinitions()));
     settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, true);
     PurgeProfiler profiler = mock(PurgeProfiler.class);