diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-18 15:34:12 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-11-18 15:34:12 +0000 |
commit | 435981a06db36de3f9f5b60220ae005699c09b2c (patch) | |
tree | c3d84604e817b36802872218faa656953b71025f /plugins/sonar-dbcleaner-plugin | |
parent | 4bfd79e52cea465f226c78abb253c2073f4c1d4c (diff) | |
download | sonarqube-435981a06db36de3f9f5b60220ae005699c09b2c.tar.gz sonarqube-435981a06db36de3f9f5b60220ae005699c09b2c.zip |
SONAR-1663 improve QA
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
18 files changed, 25 insertions, 71 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/pom.xml b/plugins/sonar-dbcleaner-plugin/pom.xml index 65b1a4fea6f..145d5a33b49 100644 --- a/plugins/sonar-dbcleaner-plugin/pom.xml +++ b/plugins/sonar-dbcleaner-plugin/pom.xml @@ -46,7 +46,7 @@ <artifactId>sonar-packaging-maven-plugin</artifactId> <extensions>true</extensions> <configuration> - <pluginName>DbCleaner</pluginName> + <pluginName>Database Cleaner</pluginName> <pluginClass>org.sonar.plugins.dbcleaner.DbCleanerPlugin</pluginClass> </configuration> </plugin> 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 fc32c8334f6..1196faab143 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 @@ -32,14 +32,14 @@ import java.util.List; @Properties({
@Property(key = DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK,
- defaultValue = DbCleanerConstants._1_MONTH, name = "Number of months before starting to keep 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, "
+ "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._12_MONTH, name = "Number of months before starting to keep 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, "
+ "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._36_MONTH,
+ @Property(key = DbCleanerConstants.MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS, defaultValue = DbCleanerConstants.THREE_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)})
public final class DbCleanerPlugin implements Plugin {
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java index 2df7a355d4c..89d9ebbed6f 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java @@ -26,7 +26,6 @@ import org.slf4j.LoggerFactory; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; -import org.sonar.api.utils.TimeProfiler; import org.sonar.plugins.dbcleaner.api.Purge; import org.sonar.plugins.dbcleaner.api.PurgeContext; import org.sonar.plugins.dbcleaner.util.DbCleanerConstants; @@ -38,12 +37,11 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.List; -public class PeriodCleaner extends Purge { +public final class PeriodCleaner extends Purge { private static final Logger LOG = LoggerFactory.getLogger(PeriodCleaner.class); private final SQLRequests sql; private final Project project; - private static final SimpleDateFormat dateFormat = new SimpleDateFormat(); Date dateToStartKeepingOneSnapshotByWeek; Date dateToStartKeepingOneSnapshotByMonth; @@ -61,14 +59,10 @@ public class PeriodCleaner extends Purge { } public void purge(int snapshotId) { - TimeProfiler profiler = new TimeProfiler().start("DbCleaner"); - List<SnapshotFilter> filters = initDbCleanerFilters(); List<Snapshot> snapshotHistory = getAllProjectSnapshots(snapshotId); applyFilters(snapshotHistory, filters); deleteSnapshotsAndAllRelatedData(snapshotHistory); - - profiler.stop(); } private List<Snapshot> getAllProjectSnapshots(int snapshotId) { @@ -104,14 +98,15 @@ public class PeriodCleaner extends Purge { } private void initMilestones() { + SimpleDateFormat dateFormat = new SimpleDateFormat(); dateToStartKeepingOneSnapshotByWeek = getDate(project.getConfiguration(), - DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK, DbCleanerConstants._1_MONTH); + DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK, DbCleanerConstants.ONE_MONTH); LOG.debug("Keep only one snapshot by week after : " + dateFormat.format(dateToStartKeepingOneSnapshotByWeek)); dateToStartKeepingOneSnapshotByMonth = getDate(project.getConfiguration(), - DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH, DbCleanerConstants._12_MONTH); + DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH, DbCleanerConstants.ONE_YEAR); LOG.debug("Keep only one snapshot by month after : " + dateFormat.format(dateToStartKeepingOneSnapshotByMonth)); dateToStartDeletingAllSnapshots = getDate(project.getConfiguration(), DbCleanerConstants.MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS, - DbCleanerConstants._36_MONTH); + DbCleanerConstants.THREE_YEARS); LOG.debug("Delete all snapshots after : " + dateFormat.format(dateToStartDeletingAllSnapshots)); } diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java index 5d944367cb3..b0e3c3991f9 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java @@ -33,7 +33,7 @@ import javax.persistence.Query; /** * @since 1.11 */ -public class PurgeDeletedResources extends Purge { +public final class PurgeDeletedResources extends Purge { public PurgeDeletedResources(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java index 2e88570e570..b3532177878 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java @@ -29,7 +29,7 @@ import org.sonar.plugins.dbcleaner.util.PurgeUtils; import javax.persistence.Query; import java.util.List; -public class PurgeDependencies extends Purge { +public final class PurgeDependencies extends Purge { public PurgeDependencies(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java index fe59d2aeb56..a08ba28718c 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java @@ -32,7 +32,7 @@ import javax.persistence.Query; /** * @since 1.11 */ -public class PurgeDeprecatedLast extends Purge { +public final class PurgeDeprecatedLast extends Purge { public PurgeDeprecatedLast(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java index 562b7c68f9c..27376509543 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java @@ -34,7 +34,7 @@ import javax.persistence.Query; /** * @since 1.11 */ -public class PurgeDisabledResources extends Purge { +public final class PurgeDisabledResources extends Purge { public PurgeDisabledResources(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java index 99952e48cf7..98415599098 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java @@ -36,7 +36,7 @@ import java.util.List; /** * @since 1.11 */ -public class PurgeEntities extends Purge { +public final class PurgeEntities extends Purge { private Configuration configuration; diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java index 9692eb18a63..28dbc281293 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java @@ -30,7 +30,7 @@ import java.util.List; import javax.persistence.Query; -public class PurgeEventOrphans extends Purge { +public final class PurgeEventOrphans extends Purge { public PurgeEventOrphans(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java index 1c27cbad87a..24bfd0f4467 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java @@ -32,7 +32,7 @@ import javax.persistence.Query; /** * @since 2.1 */ -public class PurgeOrphanResources extends Purge { +public final class PurgeOrphanResources extends Purge { public PurgeOrphanResources(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java index 6b56467cf85..251e94a2b6b 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java @@ -34,7 +34,7 @@ import javax.persistence.Query; /** * @since 2.2 */ -public class PurgePropertyOrphans extends Purge { +public final class PurgePropertyOrphans extends Purge { public PurgePropertyOrphans(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java index e10b9c9e927..87b3aa123a3 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java @@ -34,7 +34,7 @@ import javax.persistence.Query; /** * @since 1.12 */ -public class PurgeResourceRoles extends Purge { +public final class PurgeResourceRoles extends Purge { public PurgeResourceRoles(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java index aea260af275..a67a0903f07 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java @@ -35,7 +35,7 @@ import javax.persistence.Query; * * @since 1.11 */ -public class PurgeRuleMeasures extends Purge { +public final class PurgeRuleMeasures extends Purge { public PurgeRuleMeasures(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java index fb6f3630fc8..4911b3fe45d 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java @@ -35,7 +35,7 @@ import java.util.List; /** * @since 1.11 */ -public class PurgeUnprocessed extends Purge { +public final class PurgeUnprocessed extends Purge { private Configuration configuration; diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java index 8e435e40cbe..0a1f030e466 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java @@ -32,7 +32,7 @@ import javax.persistence.Query; /** * @since 1.11 */ -public class UnflagLastDoublons extends Purge { +public final class UnflagLastDoublons extends Purge { public UnflagLastDoublons(DatabaseSession session) { super(session); diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java index f3927f7606b..c914dbbf122 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java @@ -28,9 +28,6 @@ public final class DefaultPurgeContext implements org.sonar.api.batch.PurgeConte private Integer currentSid; private Integer previousSid; - public DefaultPurgeContext() { - } - public DefaultPurgeContext(Snapshot currentSnapshot) { this(currentSnapshot, null); } @@ -44,21 +41,11 @@ public final class DefaultPurgeContext implements org.sonar.api.batch.PurgeConte } } - public DefaultPurgeContext(Integer currentSid, Integer previousSid) { - this.currentSid = currentSid; - this.previousSid = previousSid; - } - public DefaultPurgeContext setLastSnapshotId(Integer previousSid) { this.previousSid = previousSid; return this; } - public DefaultPurgeContext setCurrentSnapshotId(Integer currentSid) { - this.currentSid = currentSid; - return this; - } - public Integer getSnapshotId() { return currentSid; } @@ -73,34 +60,6 @@ public final class DefaultPurgeContext implements org.sonar.api.batch.PurgeConte } @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - DefaultPurgeContext context = (DefaultPurgeContext) o; - - if (!currentSid.equals(context.currentSid)) { - return false; - } - if (currentSid != null ? !currentSid.equals(context.currentSid) : context.currentSid != null) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = currentSid != null ? currentSid.hashCode() : 0; - result = 31 * result + currentSid.hashCode(); - return result; - } - - @Override public String toString() { return new ToStringBuilder(this) .append("currentSid", currentSid) diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java index 83e1ebd94fe..1e514c2b466 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java @@ -31,7 +31,7 @@ import org.sonar.plugins.dbcleaner.api.Purge; import javax.persistence.Query; -public class PurgeRunner implements PostJob { +public final class PurgeRunner implements PostJob { private DatabaseSession session; private Snapshot snapshot; diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java index b0a601bdc3b..03a29472fb3 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java @@ -26,7 +26,7 @@ public interface DbCleanerConstants { 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 _1_MONTH = "1"; - String _12_MONTH = "12"; - String _36_MONTH = "36"; + String ONE_MONTH = "1"; + String ONE_YEAR = "12"; + String THREE_YEARS = "36"; } |