aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-dbcleaner-plugin
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-01-26 18:14:17 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-01-26 18:14:17 +0100
commit9ef0ec8571badea96052ffdddbcad5c09137e5fe (patch)
tree9536215a7073fec34eb6629aa8df906799ca60b9 /plugins/sonar-dbcleaner-plugin
parent1be37880a5ecfb86bd9fb326d42bbb5c5bfeaac6 (diff)
downloadsonarqube-9ef0ec8571badea96052ffdddbcad5c09137e5fe.tar.gz
sonarqube-9ef0ec8571badea96052ffdddbcad5c09137e5fe.zip
SONAR-1960 DBCleaner properties should be expressed in weeks instead of months
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java18
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java11
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java13
3 files changed, 19 insertions, 23 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
index a14b64b1f30..e039a1ff189 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
@@ -30,17 +30,17 @@ import java.util.Arrays;
import java.util.List;
@Properties({
- @Property(key = DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK, defaultValue = DbCleanerConstants.ONE_MONTH,
- name = "Number of months before starting to keep only one snapshot by week",
- description = "After this number of months, if there are several snapshots during the same week, "
+ @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",
+ 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.", global = true, project = true),
- @Property(key = DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH, defaultValue = DbCleanerConstants.ONE_YEAR,
- name = "Number of months before starting to keep only one snapshot by month",
- description = "After this number of months, if there are several snapshots during the same month, "
+ @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",
+ 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.", global = true, project = true),
- @Property(key = DbCleanerConstants.MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS, defaultValue = DbCleanerConstants.FIVE_YEARS,
- name = "Number of months before starting to delete all remaining snapshots",
- description = "After this number of months, all snapshots are fully deleted.", global = true, project = true),
+ @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),
@Property(key = "sonar.purge.minimumPeriodInHours", defaultValue = "12",
name = "Maximum duration of code inspections, in hours",
description = "Sonar has an embedded purge mechanism which is fairly powerful to avoid keeping useless data. This mechanism is using a minimum period during which a " +
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java
index a1e4bd8aabb..0dcca8e9424 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java
@@ -24,10 +24,9 @@ public interface DbCleanerConstants {
String PLUGIN_KEY = "dbcleaner";
String PLUGIN_NAME = "DbCleaner";
String PROPERTY_CLEAN_DIRECTORY = "sonar.dbcleaner.cleanDirectory";
- String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByWeek";
- String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByMonth";
- String MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS = "sonar.dbcleaner.monthsBeforeDeletingAllSnapshots";
- String ONE_MONTH = "1";
- String ONE_YEAR = "12";
- String FIVE_YEARS = "60";
+
+ 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";
+
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java
index f89db209adf..3b599513860 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Filters.java
@@ -26,16 +26,15 @@ import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
import java.util.Calendar;
import java.util.Date;
-import java.util.GregorianCalendar;
import java.util.List;
class Filters {
private final List<Filter> filters = Lists.newArrayList();
Filters(Settings settings) {
- Date dateToStartKeepingOneSnapshotByWeek = getDate(settings, DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK);
- Date dateToStartKeepingOneSnapshotByMonth = getDate(settings, DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH);
- Date dateToStartDeletingAllSnapshots = getDate(settings, DbCleanerConstants.MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS);
+ 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);
filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByWeek, new Date(), Calendar.DAY_OF_YEAR, "day"));
filters.add(new KeepOneFilter(dateToStartKeepingOneSnapshotByMonth, dateToStartKeepingOneSnapshotByWeek, Calendar.WEEK_OF_YEAR, "week"));
@@ -48,9 +47,7 @@ class Filters {
}
static Date getDate(Settings settings, String propertyKey) {
- int months = settings.getInt(propertyKey);
- GregorianCalendar calendar = new GregorianCalendar();
- calendar.add(GregorianCalendar.MONTH, -months);
- return calendar.getTime();
+ int weeks = settings.getInt(propertyKey);
+ return DateUtils.addWeeks(new Date(), -weeks);
}
}