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 " +
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";
+
}
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"));
}
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);
}
}
public final static int VERSION_UNKNOWN = -1;
- public static final int LAST_VERSION = 254;
+ public static final int LAST_VERSION = 255;
public static final int VERSION_2_13 = 241;
public final static String TABLE_NAME = "schema_migrations";
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('252');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('253');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('254');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('255');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
--- /dev/null
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# Sonar is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 2.14
+#
+class RenameDbcleanerProperties < ActiveRecord::Migration
+
+ class Property < ActiveRecord::Base
+ end
+
+
+ def self.up
+ rename('sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByWeek', 'sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByWeek')
+ rename('sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByMonth', 'sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByMonth')
+ rename('sonar.dbcleaner.monthsBeforeDeletingAllSnapshots', 'sonar.dbcleaner.weeksBeforeDeletingAllSnapshots')
+ end
+
+ private
+ def self.rename(month_key, week_key)
+ Property.find(:all, :conditions => ['prop_key=? and text_value is not null', month_key]).each do |month_property|
+ Property.create(:prop_key => week_key, :resource_id => month_property.resource_id, :text_value => (month_property.text_value.to_i * 4).to_s)
+ end
+ end
+end