]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3378 Add new DB Cleaner parameter
authorFabrice Bellingard <bellingard@gmail.com>
Wed, 23 May 2012 16:08:05 +0000 (18:08 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Wed, 23 May 2012 16:10:25 +0000 (18:10 +0200)
=> Make configurable the number of hours before keeping only one
   snapshot per day

plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java

index 6b2921e61a4962b53c09fcc13ac40d5474f82510..ea37994b99073beef7b636ce65662b72faa553d5 100644 (file)
@@ -31,17 +31,24 @@ import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
 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 delete 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 by week",
+    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 first one and fully delete the other ones.",
+      + "the DbCleaner keeps the most recent one and fully delete 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 by month",
+    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 first one and fully delete the other ones.",
+      + "the DbCleaner keeps the most recent one and fully delete the other ones.",
     global = true,
     project = true,
     type = PropertyType.INTEGER),
index 0dcca8e94248938b3711871b21c1d7791b3ba888..655b9b0b6410567c3b039418e9dc6d03ed6923bf 100644 (file)
@@ -25,6 +25,7 @@ public interface DbCleanerConstants {
   String PLUGIN_NAME = "DbCleaner";
   String PROPERTY_CLEAN_DIRECTORY = "sonar.dbcleaner.cleanDirectory";
 
+  String HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY = "sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay";
   String WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK = "sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByWeek";
   String WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH = "sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByMonth";
   String WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS = "sonar.dbcleaner.weeksBeforeDeletingAllSnapshots";
index 3b59951386023067040889f609276f7beecedf60..8edac58daa67fcb1cbc86c95b32c2f17505d6d73 100644 (file)
@@ -32,11 +32,12 @@ class Filters {
   private final List<Filter> filters = Lists.newArrayList();
 
   Filters(Settings settings) {
-    Date dateToStartKeepingOneSnapshotByWeek = getDate(settings, DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK);
-    Date dateToStartKeepingOneSnapshotByMonth = getDate(settings, DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
-    Date dateToStartDeletingAllSnapshots = getDate(settings, DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS);
+    Date dateToStartKeepingOneSnapshotByDay = getDateFromHours(settings, DbCleanerConstants.HOURS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_DAY);
+    Date dateToStartKeepingOneSnapshotByWeek = getDateFromWeeks(settings, DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK);
+    Date dateToStartKeepingOneSnapshotByMonth = getDateFromWeeks(settings, DbCleanerConstants.WEEKS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
+    Date dateToStartDeletingAllSnapshots = getDateFromWeeks(settings, DbCleanerConstants.WEEKS_BEFORE_DELETING_ALL_SNAPSHOTS);
 
-    filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, new Date(), Calendar.DAY_OF_YEAR, "day"));
+    filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, dateToStartKeepingOneSnapshotByDay, Calendar.DAY_OF_YEAR, "day"));
     filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByMonth, dateToStartKeepingOneSnapshotByWeek, Calendar.WEEK_OF_YEAR, "week"));
     filters.add(new KeepOneFilter(dateToStartDeletingAllSnapshots, dateToStartKeepingOneSnapshotByMonth, Calendar.MONTH, "month"));
     filters.add(new DeleteAllFilter(dateToStartDeletingAllSnapshots));
@@ -46,8 +47,13 @@ class Filters {
     return filters;
   }
 
-  static Date getDate(Settings settings, String propertyKey) {
+  static Date getDateFromWeeks(Settings settings, String propertyKey) {
     int weeks = settings.getInt(propertyKey);
     return DateUtils.addWeeks(new Date(), -weeks);
   }
+
+  static Date getDateFromHours(Settings settings, String propertyKey) {
+    int hours = settings.getInt(propertyKey);
+    return DateUtils.addHours(new Date(), -hours);
+  }
 }