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),
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";
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));
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);
+ }
}