aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java15
-rw-r--r--plugins/sonar-dbcleaner-plugin/pom.xml55
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java74
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/Purge.java49
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeContext.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java)31
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilter.java30
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilter.java30
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilter.java54
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilter.java42
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java136
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SQLRequests.java51
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SnapshotFilter.java43
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java (renamed from plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/OldDependenciesPurge.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java)18
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java)21
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java)17
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java)15
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java)14
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java)14
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java (renamed from plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java110
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java109
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java32
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java129
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java33
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/Utils.java57
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/IntegrationTest.java67
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilterTest.java (renamed from sonar-core/src/test/java/org/sonar/core/purge/AbstractPurgeTest.java)45
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilterTest.java48
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilterTest.java50
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilterTest.java51
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/PeriodCleanerTest.java51
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java (renamed from plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/OldDependenciesPurgeTest.java)10
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEntitiesTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEventOrphansTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgePropertyOrphansTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeResourceRolesTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest.java)13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeUnprocessedTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest.java (renamed from plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/UnflagLastDoublonsTest.java)2
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest.java121
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java (renamed from sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java)19
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent-result.xml167
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent.xml142
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies-result.xml (renamed from plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies.xml (renamed from plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/sharedFixture.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/sharedFixture.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml (renamed from plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest/shared.xml53
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml (renamed from sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots-result.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml (renamed from sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots.xml)0
-rw-r--r--plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java3
-rw-r--r--pom.xml3
-rw-r--r--sonar-application/pom.xml6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java31
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java15
-rw-r--r--sonar-core/src/main/java/org/sonar/core/purge/DefaultPurgeContext.java86
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/Purge.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/batch/Purge.java)2
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/PurgeContext.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/batch/PurgeContext.java)2
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/core/purge/AbstractPurge.java (renamed from sonar-core/src/main/java/org/sonar/core/purge/AbstractPurge.java)0
-rw-r--r--sonar-server/pom.xml6
-rw-r--r--tests/volume/pom.xml1
103 files changed, 1969 insertions, 300 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 6e082c1c692..b18eeff5366 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -33,7 +33,6 @@ import org.sonar.plugins.core.defaultsourceviewer.DefaultSourceViewer;
import org.sonar.plugins.core.duplicationsviewer.DuplicationsViewerDefinition;
import org.sonar.plugins.core.hotspots.Hotspots;
import org.sonar.plugins.core.metrics.UserManagedMetrics;
-import org.sonar.plugins.core.purges.*;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
import org.sonar.plugins.core.sensors.*;
import org.sonar.plugins.core.testdetailsviewer.TestsViewerDefinition;
@@ -187,20 +186,6 @@ public class CorePlugin implements Plugin {
extensions.add(DirectoriesDecorator.class);
extensions.add(FilesDecorator.class);
-
- // purges
- extensions.add(PurgeOrphanResources.class);
- extensions.add(PurgeEntities.class);
- extensions.add(PurgeRuleMeasures.class);
- extensions.add(PurgeUnprocessed.class);
- extensions.add(PurgeDeletedResources.class);
- extensions.add(PurgeDeprecatedLast.class);
- extensions.add(UnflagLastDoublons.class);
- extensions.add(PurgeDisabledResources.class);
- extensions.add(PurgeResourceRoles.class);
- extensions.add(PurgeEventOrphans.class);
- extensions.add(PurgePropertyOrphans.class);
-
return extensions;
}
diff --git a/plugins/sonar-dbcleaner-plugin/pom.xml b/plugins/sonar-dbcleaner-plugin/pom.xml
new file mode 100644
index 00000000000..65b1a4fea6f
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/pom.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar</artifactId>
+ <version>2.5-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <groupId>org.codehaus.sonar.plugins</groupId>
+ <artifactId>sonar-dbcleaner-plugin</artifactId>
+ <packaging>sonar-plugin</packaging>
+
+ <name>Sonar :: Plugins :: Database Cleaner</name>
+ <description>Optimizes database performances by removing old and useless data.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-plugin-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-deprecated</artifactId>
+ </dependency>
+
+ <!-- unit tests -->
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-testing-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-packaging-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <pluginName>DbCleaner</pluginName>
+ <pluginClass>org.sonar.plugins.dbcleaner.DbCleanerPlugin</pluginClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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
new file mode 100644
index 00000000000..fc32c8334f6
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
@@ -0,0 +1,74 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner;
+
+import org.sonar.api.Plugin;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.plugins.dbcleaner.period.PeriodCleaner;
+import org.sonar.plugins.dbcleaner.purges.*;
+import org.sonar.plugins.dbcleaner.runner.PurgeRunner;
+import org.sonar.plugins.dbcleaner.util.DbCleanerConstants;
+
+import java.util.Arrays;
+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",
+ 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",
+ 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,
+ 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 {
+
+ @Override
+ public String toString() {
+ return DbCleanerConstants.PLUGIN_NAME;
+ }
+
+ public String getKey() {
+ return DbCleanerConstants.PLUGIN_KEY;
+ }
+
+ public String getName() {
+ return DbCleanerConstants.PLUGIN_NAME;
+ }
+
+ public String getDescription() {
+ return "The DbCleaner optimizes the Sonar DB performances by removing old and useless quality snapshots.";
+ }
+
+ public List getExtensions() {
+ return Arrays.asList(
+ // purges
+ PurgeOrphanResources.class, PurgeEntities.class, PurgeRuleMeasures.class, PurgeUnprocessed.class,
+ PurgeDeletedResources.class, PurgeDeprecatedLast.class, UnflagLastDoublons.class, PurgeDisabledResources.class,
+ PurgeResourceRoles.class, PurgeEventOrphans.class, PurgePropertyOrphans.class, PeriodCleaner.class,
+
+ // post-job
+ PurgeRunner.class);
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/Purge.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/Purge.java
new file mode 100644
index 00000000000..d5177d3fa6c
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/Purge.java
@@ -0,0 +1,49 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.api;
+
+import org.sonar.api.BatchExtension;
+import org.sonar.api.database.DatabaseSession;
+
+/**
+ * Implement this component in order to define your own rules to cleanup database.
+ *
+ * @since 2.5
+ */
+public abstract class Purge implements BatchExtension {
+
+ private DatabaseSession session;
+
+ protected Purge(DatabaseSession session) {
+ this.session = session;
+ }
+
+ protected final DatabaseSession getSession() {
+ return session;
+ }
+
+ /**
+ * Snapshots include the current snapshot (flagged as last) and optionally the penultimate one.
+ *
+ * @snapshots never null.
+ */
+ public abstract void purge(PurgeContext context);
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeContext.java
index 95f9c5fa94c..f7c72adad54 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeContext.java
@@ -17,24 +17,21 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.api.purge;
+package org.sonar.plugins.dbcleaner.api;
-import org.apache.commons.configuration.Configuration;
-
-public final class PurgeUtils {
-
- public static final int DEFAULT_MINIMUM_PERIOD_IN_HOURS = 12;
- public static final String PROP_KEY_MINIMUM_PERIOD_IN_HOURS = "sonar.purge.minimumPeriodInHours";
+/**
+ *
+ * @since 2.5
+ */
+public interface PurgeContext {
- private PurgeUtils() {
- // only static methods
- }
+ /**
+ * @return the snapshot id of the current project
+ */
+ Integer getSnapshotId();
- public static int getMinimumPeriodInHours(Configuration conf) {
- int hours = DEFAULT_MINIMUM_PERIOD_IN_HOURS;
- if (conf != null) {
- hours = conf.getInt(PROP_KEY_MINIMUM_PERIOD_IN_HOURS, DEFAULT_MINIMUM_PERIOD_IN_HOURS);
- }
- return hours;
- }
+ /**
+ * Can be null
+ */
+ Integer getPreviousSnapshotId();
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilter.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilter.java
new file mode 100644
index 00000000000..829c3b05056
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilter.java
@@ -0,0 +1,30 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import org.sonar.api.database.model.Snapshot;
+
+class KeepLastSnapshotFilter extends SnapshotFilter {
+
+ @Override
+ boolean filter(Snapshot snapshot) {
+ return snapshot.getLast();
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilter.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilter.java
new file mode 100644
index 00000000000..b29ec613456
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilter.java
@@ -0,0 +1,30 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import org.sonar.api.database.model.Snapshot;
+
+class KeepLibrarySnapshotFilter extends SnapshotFilter {
+
+ @Override
+ boolean filter(Snapshot snapshot) {
+ return snapshot.getQualifier().equals("LIB");
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilter.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilter.java
new file mode 100644
index 00000000000..7e8c8c7484c
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilter.java
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.sonar.api.database.model.Snapshot;
+
+class KeepOneSnapshotByPeriodBetweenTwoDatesFilter extends SnapshotFilter {
+
+ private final Date before;
+ private final Date after;
+ private GregorianCalendar calendar = new GregorianCalendar();
+ private int lastFieldValue = -1;
+ private final int dateField;
+
+ KeepOneSnapshotByPeriodBetweenTwoDatesFilter(int dateField, Date before, Date after) {
+ this.before = before;
+ this.after = after;
+ this.dateField = dateField;
+ }
+
+ @Override
+ boolean filter(Snapshot snapshot) {
+ boolean result = false;
+ Date createdAt = snapshot.getCreatedAt();
+ calendar.setTime(createdAt);
+ int currentFieldValue = calendar.get(dateField);
+ if (lastFieldValue != currentFieldValue && snapshot.getCreatedAt().after(after) && snapshot.getCreatedAt().before(before)) {
+ result = true;
+ }
+ lastFieldValue = currentFieldValue;
+ return result;
+ }
+
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilter.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilter.java
new file mode 100644
index 00000000000..d1746129ebd
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilter.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import java.util.Date;
+
+import org.sonar.api.database.model.Snapshot;
+
+class KeepSnapshotsBetweenTwoDatesFilter extends SnapshotFilter {
+
+ private Date before;
+ private Date after;
+
+ KeepSnapshotsBetweenTwoDatesFilter(Date before, Date after) {
+ this.before = before;
+ this.after = after;
+ }
+
+ @Override
+ boolean filter(Snapshot snapshot) {
+ Date createdAt = snapshot.getCreatedAt();
+ return createdAt.before(before) && createdAt.after(after);
+ }
+
+}
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
new file mode 100644
index 00000000000..2df7a355d4c
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/PeriodCleaner.java
@@ -0,0 +1,136 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+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;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public 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;
+ Date dateToStartDeletingAllSnapshots;
+
+ public PeriodCleaner(DatabaseSession session, Project project) {
+ super(session);
+ this.sql = new SQLRequests(session);
+ this.project = project;
+ initMilestones();
+ }
+
+ public void purge(PurgeContext context) {
+ purge(context.getSnapshotId());
+ }
+
+ 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) {
+ List<Snapshot> snapshotHistory = Lists.newLinkedList(sql.getProjectSnapshotsOrderedByCreatedAt(snapshotId));
+ LOG.info("The project '" + project.getName() + "' has " + snapshotHistory.size() + " snapshots.");
+ return snapshotHistory;
+ }
+
+ private void deleteSnapshotsAndAllRelatedData(List<Snapshot> snapshotHistory) {
+ if (snapshotHistory.isEmpty()) {
+ LOG.info("There are no snapshots to purge");
+ return;
+ }
+ List<Integer> ids = Lists.newArrayList();
+ for (Snapshot snapshot : snapshotHistory) {
+ ids.addAll(sql.getChildIds(snapshot));
+ }
+ LOG.info("There are " + snapshotHistory.size() + " snapshots and " + (ids.size() - snapshotHistory.size())
+ + " children snapshots which are obsolete and are going to be deleted.");
+ if (LOG.isDebugEnabled()) {
+ DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
+ for (Snapshot snapshot : snapshotHistory) {
+ LOG.debug("Delete snapshot created at " + format.format(snapshot.getCreatedAt()));
+ }
+ }
+ PurgeUtils.deleteSnapshotsData(getSession(), ids);
+ }
+
+ private void applyFilters(List<Snapshot> snapshotHistory, List<SnapshotFilter> filters) {
+ for (SnapshotFilter filter : filters) {
+ filter.filter(snapshotHistory);
+ }
+ }
+
+ private void initMilestones() {
+ dateToStartKeepingOneSnapshotByWeek = getDate(project.getConfiguration(),
+ DbCleanerConstants.MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK, DbCleanerConstants._1_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);
+ 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);
+ LOG.debug("Delete all snapshots after : " + dateFormat.format(dateToStartDeletingAllSnapshots));
+ }
+
+ private List<SnapshotFilter> initDbCleanerFilters() {
+ List<SnapshotFilter> filters = Lists.newArrayList();
+ filters.add(new KeepLibrarySnapshotFilter());
+ filters.add(new KeepSnapshotsBetweenTwoDatesFilter(new Date(), dateToStartKeepingOneSnapshotByWeek));
+ filters.add(new KeepOneSnapshotByPeriodBetweenTwoDatesFilter(GregorianCalendar.WEEK_OF_YEAR, dateToStartKeepingOneSnapshotByWeek,
+ dateToStartKeepingOneSnapshotByMonth));
+ filters.add(new KeepOneSnapshotByPeriodBetweenTwoDatesFilter(GregorianCalendar.MONTH, dateToStartKeepingOneSnapshotByMonth,
+ dateToStartDeletingAllSnapshots));
+ filters.add(new KeepLastSnapshotFilter());
+ return filters;
+ }
+
+ protected Date getDate(Configuration conf, String propertyKey, String defaultNumberOfMonths) {
+ int months = conf.getInt(propertyKey, Integer.parseInt(defaultNumberOfMonths));
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.add(GregorianCalendar.MONTH, -months);
+ return calendar.getTime();
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SQLRequests.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SQLRequests.java
new file mode 100644
index 00000000000..1e6c5b80f61
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SQLRequests.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import org.sonar.api.batch.Event;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.Snapshot;
+
+import javax.persistence.Query;
+import java.util.List;
+
+final class SQLRequests {
+
+ private final DatabaseSession session;
+
+ SQLRequests(DatabaseSession session) {
+ this.session = session;
+ }
+
+ List<Snapshot> getProjectSnapshotsOrderedByCreatedAt(int oneProjectSnapshotId) {
+ Query query = session.createQuery("FROM " + Snapshot.class.getSimpleName()
+ + " sp1 WHERE sp1.resourceId = (select sp2.resourceId FROM " + Snapshot.class.getSimpleName()
+ + " sp2 WHERE sp2.id = :id) and sp1.rootId= null and not exists (from " + Event.class.getSimpleName() + " e where e.snapshot=sp1) order by sp1.createdAt");
+ query.setParameter("id", oneProjectSnapshotId);
+ return query.getResultList();
+ }
+
+ List<Integer> getChildIds(Snapshot parentSnapshot) {
+ Query query = session.createQuery("select sp.id FROM " + Snapshot.class.getSimpleName()
+ + " sp WHERE sp.rootId = :rootId or id = :rootId");
+ query.setParameter("rootId", parentSnapshot.getId());
+ return query.getResultList();
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SnapshotFilter.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SnapshotFilter.java
new file mode 100644
index 00000000000..53915591ac3
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/SnapshotFilter.java
@@ -0,0 +1,43 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import java.util.List;
+import java.util.ListIterator;
+
+import org.sonar.api.database.model.Snapshot;
+
+abstract class SnapshotFilter {
+
+ final int filter(List<Snapshot> snapshots) {
+ int before = snapshots.size();
+ ListIterator<Snapshot> iterator = snapshots.listIterator();
+ while (iterator.hasNext()) {
+ Snapshot snapshot = iterator.next();
+ if(filter(snapshot)){
+ iterator.remove();
+ }
+ }
+ int after = snapshots.size();
+ return before - after;
+ }
+
+ abstract boolean filter(Snapshot snapshot);
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java
index fff6b0101ac..5d944367cb3 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeletedResources.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java
@@ -17,13 +17,14 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -32,7 +33,7 @@ import javax.persistence.Query;
/**
* @since 1.11
*/
-public class PurgeDeletedResources extends AbstractPurge {
+public class PurgeDeletedResources extends Purge {
public PurgeDeletedResources(DatabaseSession session) {
super(session);
@@ -41,8 +42,8 @@ public class PurgeDeletedResources extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() +
" s WHERE NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=s.resourceId)");
- final List<Integer> snapshotIds = selectIds(query);
+ final List<Integer> snapshotIds = query.getResultList();
- deleteSnapshotData(snapshotIds);
+ PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
}
}
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/OldDependenciesPurge.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
index 2a17e576721..2e88570e570 100644
--- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/batch/OldDependenciesPurge.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
@@ -17,20 +17,21 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.design.batch;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.design.DependencyDto;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import javax.persistence.Query;
import java.util.List;
-public class OldDependenciesPurge extends AbstractPurge {
+public class PurgeDependencies extends Purge {
- public OldDependenciesPurge(DatabaseSession session) {
+ public PurgeDependencies(DatabaseSession session) {
super(session);
}
@@ -39,6 +40,6 @@ public class OldDependenciesPurge extends AbstractPurge {
" d WHERE NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last)");
query.setParameter("last", true);
final List<Integer> projectSnapshotIds = query.getResultList();
- executeQuery(projectSnapshotIds, "DELETE FROM " + DependencyDto.class.getSimpleName() + " WHERE projectSnapshotId in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", projectSnapshotIds, "DELETE FROM " + DependencyDto.class.getSimpleName() + " WHERE projectSnapshotId in (:ids)");
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
index bf8e44a7f02..fe59d2aeb56 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDeprecatedLast.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
@@ -17,12 +17,13 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -31,7 +32,7 @@ import javax.persistence.Query;
/**
* @since 1.11
*/
-public class PurgeDeprecatedLast extends AbstractPurge {
+public class PurgeDeprecatedLast extends Purge {
public PurgeDeprecatedLast(DatabaseSession session) {
super(session);
@@ -40,8 +41,8 @@ public class PurgeDeprecatedLast extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() +
" s WHERE s.last=true AND s.rootId IS NOT NULL AND NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s2 WHERE s2.id=s.rootId AND s2.last=true)");
- List<Integer> snapshotIds = selectIds(query);
+ List<Integer> snapshotIds = query.getResultList();
- deleteSnapshotData(snapshotIds);
+ PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
index f9cd5de642b..562b7c68f9c 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeDisabledResources.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
@@ -17,13 +17,15 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.core.purge.AbstractPurge;
+
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -32,32 +34,32 @@ import javax.persistence.Query;
/**
* @since 1.11
*/
-public class PurgeDisabledResources extends AbstractPurge {
+public class PurgeDisabledResources extends Purge {
public PurgeDisabledResources(DatabaseSession session) {
super(session);
}
public void purge(PurgeContext context) {
- deleteSnapshotData(getSnapshotIds());
+ PurgeUtils.deleteSnapshotsData(getSession(), getSnapshotIds());
deleteResources();
}
private void deleteResources() {
final List<Integer> resourceIds = getResourceIds();
if ( !resourceIds.isEmpty()) {
- executeQuery(resourceIds, "delete from " + ResourceModel.class.getSimpleName() + " r where r.id in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", resourceIds, "delete from " + ResourceModel.class.getSimpleName() + " r where r.id in (:ids)");
}
}
private List<Integer> getResourceIds() {
Query query = getSession().createQuery("SELECT r.id FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.enabled=false");
- return selectIds(query);
+ return query.getResultList();
}
private List<Integer> getSnapshotIds() {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE " +
" EXISTS (FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=s.resourceId AND r.enabled=false)");
- return selectIds(query);
+ return query.getResultList();
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
index 80b2843aee5..99952e48cf7 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEntities.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
@@ -17,27 +17,26 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.purge.PurgeUtils;
import org.sonar.api.resources.Resource;
import org.sonar.api.utils.Logs;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import javax.persistence.Query;
import java.util.Date;
import java.util.List;
-import javax.persistence.Query;
-
/**
* @since 1.11
*/
-public class PurgeEntities extends AbstractPurge {
+public class PurgeEntities extends Purge {
private Configuration configuration;
@@ -48,14 +47,14 @@ public class PurgeEntities extends AbstractPurge {
public void purge(PurgeContext context) {
int minimumPeriodInHours = PurgeUtils.getMinimumPeriodInHours(configuration);
- final Date beforeDate = DateUtils.addHours(new Date(), - minimumPeriodInHours);
+ final Date beforeDate = DateUtils.addHours(new Date(), -minimumPeriodInHours);
Logs.INFO.info("Deleting files data before " + beforeDate);
-
+
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=false AND scope=:scope AND s.createdAt<:date");
query.setParameter("scope", Resource.SCOPE_ENTITY);
query.setParameter("date", beforeDate);
- List<Integer> snapshotIds = selectIds(query);
+ List<Integer> snapshotIds = query.getResultList();
- deleteSnapshotData(snapshotIds);
+ PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
index 8132b19af2f..9692eb18a63 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeEventOrphans.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
@@ -17,19 +17,20 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.sonar.api.batch.Event;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
import javax.persistence.Query;
-public class PurgeEventOrphans extends AbstractPurge {
+public class PurgeEventOrphans extends Purge {
public PurgeEventOrphans(DatabaseSession session) {
super(session);
@@ -38,7 +39,7 @@ public class PurgeEventOrphans extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT e.id FROM " + Event.class.getSimpleName() +
" e WHERE e.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=e.resourceId)");
- final List<Integer> eventIds = selectIds(query);
- executeQuery(eventIds, "DELETE FROM " + Event.class.getSimpleName() + " WHERE id in (:ids)");
+ final List<Integer> eventIds = query.getResultList();
+ PurgeUtils.executeQuery(getSession(), "", eventIds, "DELETE FROM " + Event.class.getSimpleName() + " WHERE id in (:ids)");
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java
index 3552bf9018a..1c27cbad87a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeOrphanResources.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java
@@ -17,12 +17,13 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -31,7 +32,7 @@ import javax.persistence.Query;
/**
* @since 2.1
*/
-public class PurgeOrphanResources extends AbstractPurge {
+public class PurgeOrphanResources extends Purge {
public PurgeOrphanResources(DatabaseSession session) {
super(session);
@@ -40,9 +41,9 @@ public class PurgeOrphanResources extends AbstractPurge {
public void purge(PurgeContext context) {
Query query = getSession().createQuery("SELECT r1.id FROM " + ResourceModel.class.getSimpleName() +
" r1 WHERE r1.rootId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r2 WHERE r1.rootId=r2.id)");
- List<Integer> idsToDelete = selectIds(query);
+ List<Integer> idsToDelete = query.getResultList();
if (idsToDelete.size() > 0) {
- executeQuery(idsToDelete, "DELETE FROM " + ResourceModel.class.getSimpleName() + " WHERE id in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", idsToDelete, "DELETE FROM " + ResourceModel.class.getSimpleName() + " WHERE id in (:ids)");
}
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java
index 4cbd3e423b6..6b56467cf85 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgePropertyOrphans.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java
@@ -17,14 +17,15 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.configuration.Property;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.User;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -33,7 +34,7 @@ import javax.persistence.Query;
/**
* @since 2.2
*/
-public class PurgePropertyOrphans extends AbstractPurge {
+public class PurgePropertyOrphans extends Purge {
public PurgePropertyOrphans(DatabaseSession session) {
super(session);
@@ -47,18 +48,18 @@ public class PurgePropertyOrphans extends AbstractPurge {
void purgeResourceOrphans() {
Query query = getSession().createQuery("SELECT p.id FROM " + Property.class.getSimpleName() +
" p WHERE p.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=p.resourceId)");
- List<Integer> idsToDelete = selectIds(query);
+ List<Integer> idsToDelete = query.getResultList();
if (idsToDelete.size() > 0) {
- executeQuery(idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
}
}
void purgeUserOrphans() {
Query query = getSession().createQuery("SELECT p.id FROM " + Property.class.getSimpleName() +
" p WHERE p.userId IS NOT NULL AND NOT EXISTS(FROM " + User.class.getSimpleName() + " u WHERE u.id=p.userId)");
- List<Integer> idsToDelete = selectIds(query);
+ List<Integer> idsToDelete = query.getResultList();
if (idsToDelete.size() > 0) {
- executeQuery(idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", idsToDelete, "DELETE FROM " + Property.class.getSimpleName() + " WHERE id in (:ids)");
}
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java
index b29d0d25fef..e10b9c9e927 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeResourceRoles.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java
@@ -17,14 +17,15 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.security.GroupRole;
import org.sonar.api.security.UserRole;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -33,7 +34,7 @@ import javax.persistence.Query;
/**
* @since 1.12
*/
-public class PurgeResourceRoles extends AbstractPurge {
+public class PurgeResourceRoles extends Purge {
public PurgeResourceRoles(DatabaseSession session) {
super(session);
@@ -47,9 +48,7 @@ public class PurgeResourceRoles extends AbstractPurge {
private void deleteRoles(String classname) {
Query query = getSession().createQuery("SELECT rol.id FROM " + classname + " rol "
+ " WHERE rol.resourceId IS NOT NULL AND NOT EXISTS(FROM " + ResourceModel.class.getSimpleName() + " r WHERE r.id=rol.resourceId)");
- List<Integer> roleIds = selectIds(query);
- if ( !roleIds.isEmpty()) {
- executeQuery(roleIds, "delete from " + classname + " rol where rol.id in (:ids)");
- }
+ List<Integer> roleIds = query.getResultList();
+ PurgeUtils.executeQuery(getSession(), "", roleIds, "delete from " + classname + " rol where rol.id in (:ids)");
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
index 50c42189cda..aea260af275 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeRuleMeasures.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
@@ -17,13 +17,14 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -34,7 +35,7 @@ import javax.persistence.Query;
*
* @since 1.11
*/
-public class PurgeRuleMeasures extends AbstractPurge {
+public class PurgeRuleMeasures extends Purge {
public PurgeRuleMeasures(DatabaseSession session) {
super(session);
@@ -50,8 +51,7 @@ public class PurgeRuleMeasures extends AbstractPurge {
Query query = getSession().createQuery("SELECT m.id FROM " + MeasureModel.class.getSimpleName() + " m, " + Snapshot.class.getSimpleName() + " s WHERE s.id = m.snapshotId and " +
"(s.rootId=:rootSid OR s.id=:rootSid) and (m.rule is not null or m.rulesCategoryId is not null or m.rulePriority is not null)");
query.setParameter("rootSid", sid);
- List<Integer> measureIds = selectIds(query);
-
- deleteMeasuresById(measureIds);
+ List<Integer> measureIds = query.getResultList();
+ PurgeUtils.deleteMeasuresById(getSession(), measureIds);
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
index e4c6004a7c1..fb6f3630fc8 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/PurgeUnprocessed.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
@@ -17,16 +17,16 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.purge.PurgeUtils;
import org.sonar.api.utils.Logs;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import javax.persistence.Query;
import java.util.Date;
@@ -35,7 +35,7 @@ import java.util.List;
/**
* @since 1.11
*/
-public class PurgeUnprocessed extends AbstractPurge {
+public class PurgeUnprocessed extends Purge {
private Configuration configuration;
@@ -52,8 +52,8 @@ public class PurgeUnprocessed extends AbstractPurge {
Query query = getSession().createQuery("SELECT s.id FROM " + Snapshot.class.getSimpleName() + " s WHERE s.last=false AND status=:status AND s.createdAt<:date");
query.setParameter("status", Snapshot.STATUS_UNPROCESSED);
query.setParameter("date", beforeDate);
- List<Integer> snapshotIds = selectIds(query);
+ List<Integer> snapshotIds = query.getResultList();
- deleteSnapshotData(snapshotIds);
+ PurgeUtils.deleteSnapshotsData(getSession(), snapshotIds);
}
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java
index b72ffcb818c..8e435e40cbe 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/purges/UnflagLastDoublons.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java
@@ -17,12 +17,13 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.core.purge.AbstractPurge;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+import org.sonar.plugins.dbcleaner.util.PurgeUtils;
import java.util.List;
@@ -31,7 +32,7 @@ import javax.persistence.Query;
/**
* @since 1.11
*/
-public class UnflagLastDoublons extends AbstractPurge {
+public class UnflagLastDoublons extends Purge {
public UnflagLastDoublons(DatabaseSession session) {
super(session);
@@ -41,8 +42,8 @@ public class UnflagLastDoublons extends AbstractPurge {
Query query = getSession().createQuery(
"SELECT olds.id FROM " + Snapshot.class.getSimpleName() + " olds " +
" where olds.last=true AND EXISTS (from " + Snapshot.class.getSimpleName() + " news WHERE news.last=true AND news.resourceId=olds.resourceId AND news.createdAt>olds.createdAt)");
- List<Integer> snapshotIds = selectIds(query);
+ List<Integer> snapshotIds = query.getResultList();
- executeQuery(snapshotIds, "UPDATE " + Snapshot.class.getSimpleName() + " SET last=false WHERE id in (:ids)");
+ PurgeUtils.executeQuery(getSession(), "", snapshotIds, "UPDATE " + Snapshot.class.getSimpleName() + " SET last=false WHERE id in (:ids)");
}
}
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
new file mode 100644
index 00000000000..f3927f7606b
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/DefaultPurgeContext.java
@@ -0,0 +1,110 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.runner;
+
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+
+public final class DefaultPurgeContext implements org.sonar.api.batch.PurgeContext, PurgeContext {
+
+ private Integer currentSid;
+ private Integer previousSid;
+
+ public DefaultPurgeContext() {
+ }
+
+ public DefaultPurgeContext(Snapshot currentSnapshot) {
+ this(currentSnapshot, null);
+ }
+
+ public DefaultPurgeContext(Snapshot currentSnapshot, Snapshot previousSnapshot) {
+ if (currentSnapshot != null) {
+ currentSid = currentSnapshot.getId();
+ }
+ if (previousSnapshot != null) {
+ previousSid = previousSnapshot.getId();
+ }
+ }
+
+ 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;
+ }
+
+ public Integer getPreviousSnapshotId() {
+ return previousSid;
+ }
+
+ @Deprecated
+ public Integer getLastSnapshotId() {
+ return currentSid;
+ }
+
+ @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)
+ .append("previousSid", previousSid)
+ .toString();
+ }
+}
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
new file mode 100644
index 00000000000..83e1ebd94fe
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/runner/PurgeRunner.java
@@ -0,0 +1,109 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.runner;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.PostJob;
+import org.sonar.api.batch.SensorContext;
+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 javax.persistence.Query;
+
+public class PurgeRunner implements PostJob {
+
+ private DatabaseSession session;
+ private Snapshot snapshot;
+ private Purge[] purges;
+ private org.sonar.api.batch.Purge[] deprecatedPurges;
+
+ public PurgeRunner(DatabaseSession session, Snapshot snapshot, Purge[] purges) {
+ this.session = session;
+ this.snapshot = snapshot;
+ this.purges = purges;
+ this.deprecatedPurges = new org.sonar.api.batch.Purge[0];
+ }
+
+ public PurgeRunner(DatabaseSession session, Snapshot snapshot, Purge[] purges, org.sonar.api.batch.Purge[] deprecatedPurges) {
+ this.session = session;
+ this.snapshot = snapshot;
+ this.purges = purges;
+ this.deprecatedPurges = deprecatedPurges;
+ }
+
+ public void executeOn(Project project, SensorContext context) {
+ if (shouldExecuteOn(project)) {
+ purge();
+ }
+ }
+
+ static boolean shouldExecuteOn(Project project) {
+ return project.isRoot();
+ }
+
+ public void purge() {
+ final Logger logger = LoggerFactory.getLogger(PurgeRunner.class);
+ TimeProfiler profiler = new TimeProfiler(logger).start("Database optimization");
+ DefaultPurgeContext context = newContext();
+ logger.debug("Snapshots to purge: " + context);
+ executeDeprecatedPurges(logger, context);
+ executePurges(logger, context);
+ profiler.stop();
+ }
+
+ private void executeDeprecatedPurges(Logger logger, DefaultPurgeContext context) {
+ for (org.sonar.api.batch.Purge purge : deprecatedPurges) {
+ logger.debug("Executing {}...", purge.getClass().getName());
+ purge.purge(context);
+ }
+ }
+
+ private void executePurges(Logger logger, DefaultPurgeContext context) {
+ for (Purge purge : purges) {
+ logger.debug("Executing {}...", purge.getClass().getName());
+ purge.purge(context);
+ }
+ }
+
+ private DefaultPurgeContext newContext() {
+ DefaultPurgeContext context = new DefaultPurgeContext(snapshot);
+ Snapshot previousLastSnapshot = getPreviousLastSnapshot();
+ if (previousLastSnapshot != null && previousLastSnapshot.getCreatedAt().before(snapshot.getCreatedAt())) {
+ context.setLastSnapshotId(previousLastSnapshot.getId());
+ }
+ return context;
+ }
+
+ private Snapshot getPreviousLastSnapshot() {
+ Query query = session.createQuery(
+ "SELECT s FROM " + Snapshot.class.getSimpleName() + " s " +
+ "WHERE s.status=:status AND s.resourceId=:resourceId AND s.createdAt<:date AND s.id <> :sid ORDER BY s.createdAt DESC");
+ query.setParameter("status", Snapshot.STATUS_PROCESSED);
+ query.setParameter("resourceId", snapshot.getResourceId());
+ query.setParameter("date", snapshot.getCreatedAt());
+ query.setParameter("sid", snapshot.getId());
+ query.setMaxResults(1);
+ return session.getSingleResult(query, null);
+ }
+}
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
new file mode 100644
index 00000000000..b0a601bdc3b
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java
@@ -0,0 +1,32 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.util;
+
+public interface DbCleanerConstants {
+
+ String PLUGIN_KEY = "dbcleaner";
+ String PLUGIN_NAME = "DbCleaner";
+ 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";
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java
new file mode 100644
index 00000000000..1fc28b31b57
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java
@@ -0,0 +1,129 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.util;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.*;
+import org.sonar.api.design.DependencyDto;
+import org.sonar.api.utils.TimeProfiler;
+
+import javax.persistence.Query;
+import java.util.List;
+
+/**
+ * @since 2.5
+ */
+public final class PurgeUtils {
+
+ public static final int DEFAULT_MINIMUM_PERIOD_IN_HOURS = 12;
+ public static final String PROP_KEY_MINIMUM_PERIOD_IN_HOURS = "sonar.purge.minimumPeriodInHours";
+
+ /**
+ * Maximum elements in the SQL statement "IN" due to an Oracle limitation (see error ORA-01795)
+ */
+ public static final int MAX_IN_ELEMENTS = 950;
+
+ private PurgeUtils() {
+ // only static methods
+ }
+
+ public static int getMinimumPeriodInHours(Configuration conf) {
+ int hours = DEFAULT_MINIMUM_PERIOD_IN_HOURS;
+ if (conf != null) {
+ hours = conf.getInt(PROP_KEY_MINIMUM_PERIOD_IN_HOURS, DEFAULT_MINIMUM_PERIOD_IN_HOURS);
+ }
+ return hours;
+ }
+
+ public static void deleteSnapshotsData(DatabaseSession session, List<Integer> snapshotIds) {
+ deleteMeasuresBySnapshotId(session, snapshotIds);
+ deleteSources(session, snapshotIds);
+ deleteViolations(session, snapshotIds);
+ deleteDependencies(session, snapshotIds);
+ deleteSnapshots(session, snapshotIds);
+ }
+
+ public static void deleteDependencies(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.fromSnapshotId in (:ids)");
+ executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.toSnapshotId in (:ids)");
+ }
+
+ /**
+ * Delete all measures, including MEASURE_DATA
+ */
+ public static void deleteMeasuresBySnapshotId(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.snapshotId in (:ids)");
+ executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.snapshotId in (:ids)");
+ }
+
+ /**
+ * Delete all measures, including MEASURE_DATA
+ */
+ public static void deleteMeasuresById(DatabaseSession session, List<Integer> measureIds) {
+ executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.measure.id in (:ids)");
+ executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.id in (:ids)");
+ }
+
+ /**
+ * Delete SNAPSHOT_SOURCES table
+ */
+ public static void deleteSources(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete sources", snapshotIds, "delete from " + SnapshotSource.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+ }
+
+ /**
+ * Delete violations (RULE_FAILURES table)
+ */
+ public static void deleteViolations(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete violations", snapshotIds, "delete from " + RuleFailureModel.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+ }
+
+ /**
+ * Delete SNAPSHOTS table
+ */
+ public static void deleteSnapshots(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete snapshots", snapshotIds, "delete from " + Snapshot.class.getSimpleName() + " s where s.id in (:ids)");
+ }
+
+ /**
+ * Paginate execution of SQL requests to avoid exceeding size of rollback segment
+ */
+ public static void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) {
+ if (ids == null || ids.isEmpty()) {
+ return;
+ }
+
+ TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description);
+
+ int index = 0;
+ while (index < ids.size()) {
+ Query query = session.createQuery(hql);
+ List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS));
+ query.setParameter("ids", paginedSids);
+ query.executeUpdate();
+ index += MAX_IN_ELEMENTS;
+ session.commit();
+ }
+
+ profiler.stop();
+ }
+
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
new file mode 100644
index 00000000000..607be2e770e
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerPluginTest.java
@@ -0,0 +1,33 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner;
+
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+
+public class DbCleanerPluginTest {
+
+ @Test
+ public void shouldGetExtensions() {
+ assertThat(new DbCleanerPlugin().getExtensions().size(), greaterThan(5));
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/Utils.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/Utils.java
new file mode 100644
index 00000000000..17590cf2ed7
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/Utils.java
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import org.sonar.api.database.model.Snapshot;
+
+public class Utils {
+
+ public static Snapshot createSnapshot(int id, String version) {
+ Snapshot snapshot = new Snapshot();
+ snapshot.setId(id);
+ snapshot.setVersion(version);
+ snapshot.setCreatedAt(new GregorianCalendar().getTime());
+ return snapshot;
+ }
+
+ public static Snapshot createSnapshot(int id, Date createdAt) {
+ Snapshot snapshot = new Snapshot();
+ snapshot.setId(id);
+ snapshot.setCreatedAt(createdAt);
+ return snapshot;
+ }
+
+ public static Date day(int delta) {
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.add(GregorianCalendar.DAY_OF_YEAR, delta);
+ return calendar.getTime();
+ }
+
+ public static Date week(int delta, int dayOfWeek) {
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.add(GregorianCalendar.WEEK_OF_YEAR, delta);
+ calendar.set(GregorianCalendar.DAY_OF_WEEK, dayOfWeek);
+ return calendar.getTime();
+ }
+
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/IntegrationTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/IntegrationTest.java
new file mode 100644
index 00000000000..5c70a57162b
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/IntegrationTest.java
@@ -0,0 +1,67 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.GregorianCalendar;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+
+public class IntegrationTest extends AbstractDbUnitTestCase {
+
+ PeriodCleaner purge;
+
+ @Before
+ public void init() {
+
+ Project project = new Project("myproject");
+ project.setConfiguration(new PropertiesConfiguration());
+ purge = new PeriodCleaner(getSession(), project);
+ GregorianCalendar calendar = new GregorianCalendar(2010, 10, 1);
+ purge.dateToStartKeepingOneSnapshotByWeek = calendar.getTime();
+ calendar.set(2010, 7, 1);
+ purge.dateToStartKeepingOneSnapshotByMonth = calendar.getTime();
+ calendar.set(2010, 2, 1);
+ purge.dateToStartDeletingAllSnapshots = calendar.getTime();
+ }
+
+ @Test
+ public void dbCleanerITTest() {
+ setupData("dbContent");
+ PurgeContext context = mock(PurgeContext.class);
+ when(context.getSnapshotId()).thenReturn(1010);
+ purge.purge(context);
+ checkTables("dbContent", "snapshots");
+
+ //After a first run, no more snapshot should be deleted
+ setupData("dbContent-result");
+ context = mock(PurgeContext.class);
+ when(context.getSnapshotId()).thenReturn(1010);
+ purge.purge(context);
+ checkTables("dbContent");
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/purge/AbstractPurgeTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilterTest.java
index c1b8d49d975..57f8853bd62 100644
--- a/sonar-core/src/test/java/org/sonar/core/purge/AbstractPurgeTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLastSnapshotFilterTest.java
@@ -1,6 +1,6 @@
/*
* Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
+ * Copyright (C) 2010 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
@@ -17,35 +17,30 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.core.purge;
+package org.sonar.plugins.dbcleaner.period;
+import com.google.common.collect.Lists;
import org.junit.Test;
-import org.sonar.api.batch.PurgeContext;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.api.database.model.Snapshot;
-import java.sql.SQLException;
-import java.util.Arrays;
+import java.util.List;
-public class AbstractPurgeTest extends AbstractDbUnitTestCase {
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.sonar.plugins.dbcleaner.Utils.createSnapshot;
- @Test
- public void purgeSnapshots() throws SQLException {
- setupData("purgeSnapshots");
-
- final FakePurge purge = new FakePurge(getSession());
- purge.purge(null);
+public class KeepLastSnapshotFilterTest {
- checkTables("purgeSnapshots", "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "dependencies");
+ @Test
+ public void testFilter() {
+ List<Snapshot> snapshots = Lists.newLinkedList();
+ snapshots.add(createSnapshot(1, "0.1"));
+ Snapshot lastSnapshot = createSnapshot(2, "0.1");
+ lastSnapshot.setLast(true);
+ snapshots.add(lastSnapshot);
+
+ assertThat(new KeepLastSnapshotFilter().filter(snapshots), is(1));
+ assertThat(snapshots.size(), is(1));
+ assertThat(snapshots.get(0).getId(), is(1));
}
}
-
-class FakePurge extends AbstractPurge {
- public FakePurge(DatabaseSession session) {
- super(session);
- }
-
- public void purge(PurgeContext context) {
- deleteSnapshotData(Arrays.asList(3, 4));
- }
-} \ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilterTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilterTest.java
new file mode 100644
index 00000000000..61aa1e93df6
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepLibrarySnapshotFilterTest.java
@@ -0,0 +1,48 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.sonar.plugins.dbcleaner.Utils.createSnapshot;
+
+public class KeepLibrarySnapshotFilterTest {
+
+ @Test
+ public void testFilter() {
+ List<Snapshot> snapshots = Lists.newLinkedList();
+ Snapshot snapshot = createSnapshot(2, "0.1");
+ snapshots.add(snapshot);
+ snapshot.setQualifier("TRK");
+ snapshot = createSnapshot(2, "0.1");
+ snapshot.setQualifier("LIB");
+ snapshots.add(snapshot);
+
+ assertThat(new KeepLibrarySnapshotFilter().filter(snapshots), is(1));
+ assertThat(snapshots.size(), is(1));
+ assertThat(snapshots.get(0).getId(), is(2));
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilterTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilterTest.java
new file mode 100644
index 00000000000..4f9888a645e
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepOneSnapshotByPeriodBetweenTwoDatesFilterTest.java
@@ -0,0 +1,50 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.plugins.dbcleaner.Utils;
+
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class KeepOneSnapshotByPeriodBetweenTwoDatesFilterTest {
+
+ @Test
+ public void testFilter() {
+ List<Snapshot> snapshots = Lists.newLinkedList();
+ snapshots.add(Utils.createSnapshot(1, Utils.week(-7, 1)));
+ snapshots.add(Utils.createSnapshot(2, Utils.week(-7, 2)));
+ snapshots.add(Utils.createSnapshot(3, Utils.week(-7, 3)));
+ snapshots.add(Utils.createSnapshot(4, Utils.week(-6, 3)));
+ snapshots.add(Utils.createSnapshot(5, Utils.week(-6, 4)));
+
+ assertThat(new KeepOneSnapshotByPeriodBetweenTwoDatesFilter(GregorianCalendar.WEEK_OF_YEAR, Utils.week(-3, 1), Utils.week(-9, 1)).filter(snapshots), is(2));
+ assertThat(snapshots.size(), is(3));
+ assertThat(snapshots.get(0).getId(), is(2));
+ assertThat(snapshots.get(1).getId(), is(3));
+ assertThat(snapshots.get(2).getId(), is(5));
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilterTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilterTest.java
new file mode 100644
index 00000000000..7fffd2b85be
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/KeepSnapshotsBetweenTwoDatesFilterTest.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+
+import java.util.Date;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.sonar.plugins.dbcleaner.Utils.createSnapshot;
+import static org.sonar.plugins.dbcleaner.Utils.day;
+
+public class KeepSnapshotsBetweenTwoDatesFilterTest {
+
+ @Test
+ public void testFilter() {
+ List<Snapshot> snapshots = Lists.newLinkedList();
+ snapshots.add(createSnapshot(1, day(-100)));
+ snapshots.add(createSnapshot(2, day(-70)));
+ snapshots.add(createSnapshot(3, day(-40)));
+ snapshots.add(createSnapshot(4, day(-10)));
+
+ assertThat(new KeepSnapshotsBetweenTwoDatesFilter(new Date(), day(-1)).filter(snapshots), is(0));
+ assertThat(snapshots.size(), is(4));
+
+ assertThat(new KeepSnapshotsBetweenTwoDatesFilter(new Date(), day(-80)).filter(snapshots), is(3));
+ assertThat(snapshots.size(), is(1));
+ assertThat(snapshots.get(0).getId(), is(1));
+ }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/PeriodCleanerTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/PeriodCleanerTest.java
new file mode 100644
index 00000000000..dd3d1963c50
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/PeriodCleanerTest.java
@@ -0,0 +1,51 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 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
+ */
+package org.sonar.plugins.dbcleaner.period;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class PeriodCleanerTest {
+
+ @Test
+ public void getDateShouldReturnCurrentTimeMinusDesiredMonths() {
+ Project project = new Project("myproject");
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty("KEY", "2");
+ project.setConfiguration(conf);
+
+ PeriodCleaner purge = new PeriodCleaner(null, project);
+
+ Date date = purge.getDate(conf, "KEY", "2");
+
+ GregorianCalendar calendar = new GregorianCalendar();
+ calendar.add(GregorianCalendar.MONTH, -2);
+ Date expectedDate = calendar.getTime();
+
+ assertThat(date.getMonth(), is(expectedDate.getMonth()));
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest.java
index b662d1e1cac..867d6f2a984 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/OldDependenciesPurgeTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java
index 300139b78e3..7983b474f5a 100644
--- a/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/OldDependenciesPurgeTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java
@@ -17,23 +17,23 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.design.batch;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.sql.SQLException;
-public class OldDependenciesPurgeTest extends AbstractDbUnitTestCase {
+public class PurgeDependenciesTest extends AbstractDbUnitTestCase {
@Test
- public void purgeOldDependencies() throws SQLException {
- assertPurge("purgeOldDependencies");
+ public void purgeDependencies() throws SQLException {
+ assertPurge("purgeDependencies");
}
private void assertPurge(String testName) {
setupData(testName);
- new OldDependenciesPurge(getSession()).purge(null);
+ new PurgeDependencies(getSession()).purge(null);
checkTables(testName, "dependencies");
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest.java
index c4b9f82ead9..63712b04496 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java
index 08138016e5f..f83d8527957 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEntitiesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest.java
index 6eef94262f3..ab7e63eef83 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEntitiesTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEventOrphansTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest.java
index 6712eb6f69e..7418ec6dcee 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeEventOrphansTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java
index fdbb986d9d3..fcc9073156c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgePropertyOrphansTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest.java
index 277fe317c61..373117d7829 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgePropertyOrphansTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeResourceRolesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest.java
index 041a888eca3..af037daa59e 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeResourceRolesTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest.java
index 76ae0121867..a3e715157e4 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest.java
@@ -17,11 +17,11 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
public class PurgeRuleMeasuresTest extends AbstractDbUnitTestCase {
@@ -29,13 +29,14 @@ public class PurgeRuleMeasuresTest extends AbstractDbUnitTestCase {
public void purgeRuleMeasures() {
setupData("sharedFixture", "purgeRuleMeasures");
- new PurgeRuleMeasures(getSession()).purge(new PurgeContext(){
+ new PurgeRuleMeasures(getSession()).purge(new PurgeContext() {
+ public Integer getSnapshotId() {
+ return 4;
+ }
public Integer getPreviousSnapshotId() {
return 1;
}
- public Integer getLastSnapshotId() {
- return 4;
- }
+
});
checkTables("purgeRuleMeasures", "snapshots", "project_measures", "measure_data");
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeUnprocessedTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest.java
index 943768afdf1..0848a69c5de 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/PurgeUnprocessedTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/UnflagLastDoublonsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest.java
index e6633fc8d70..0be4e984e4c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/purges/UnflagLastDoublonsTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest.java
@@ -17,7 +17,7 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.plugins.core.purges;
+package org.sonar.plugins.dbcleaner.purges;
import org.junit.Test;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest.java
new file mode 100644
index 00000000000..37832b2d7df
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest.java
@@ -0,0 +1,121 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.runner;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.plugins.dbcleaner.api.Purge;
+import org.sonar.plugins.dbcleaner.api.PurgeContext;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class PurgeRunnerTest extends AbstractDbUnitTestCase {
+
+ @Test
+ public void shouldExecutePurges() {
+ setupData("shared");
+ final int currentSID = 400;
+ final int previousSID = 300;
+ Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", currentSID);
+
+ Purge purge1 = mock(Purge.class);
+ Purge purge2 = mock(Purge.class);
+ Purge[] purges = new Purge[]{purge1, purge2};
+
+ new PurgeRunner(getSession(), snapshot, purges).purge();
+
+ verify(purge1).purge(argThat(new BaseMatcher<PurgeContext>() {
+ public boolean matches(Object o) {
+ PurgeContext context = (PurgeContext) o;
+ return context.getSnapshotId() == currentSID && context.getPreviousSnapshotId() == previousSID;
+ }
+
+ public void describeTo(Description description) {
+ }
+ }));
+ }
+
+ @Test
+ public void shouldExecutePurgesEvenIfSingleAnalysis() {
+ setupData("shared");
+ final int currentSID = 1000;
+ Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", currentSID);
+
+ Purge purge1 = mock(Purge.class);
+ Purge purge2 = mock(Purge.class);
+ Purge[] purges = new Purge[]{purge1, purge2};
+
+ new PurgeRunner(getSession(), snapshot, purges).purge();
+
+ verify(purge1).purge(argThat(new BaseMatcher<PurgeContext>() {
+ public boolean matches(Object o) {
+ PurgeContext context = (PurgeContext) o;
+ return context.getSnapshotId() == currentSID && context.getPreviousSnapshotId() == null;
+ }
+
+ public void describeTo(Description description) {
+ }
+ }));
+ }
+
+
+ @Test
+ public void shouldExecuteDeprecatedPurges() {
+ setupData("shared");
+ final int currentSID = 400;
+ final int previousSID = 300;
+ Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", currentSID);
+
+
+ org.sonar.api.batch.Purge deprecated1 = mock(org.sonar.api.batch.Purge.class), deprecated2 = mock(org.sonar.api.batch.Purge.class);
+ org.sonar.api.batch.Purge[] deprecatedPurges = new org.sonar.api.batch.Purge[]{deprecated1, deprecated2};
+
+ new PurgeRunner(getSession(), snapshot, new Purge[0], deprecatedPurges).purge();
+
+ verify(deprecated1).purge(argThat(new BaseMatcher<org.sonar.api.batch.PurgeContext>() {
+ public boolean matches(Object o) {
+ org.sonar.api.batch.PurgeContext context = (org.sonar.api.batch.PurgeContext) o;
+ return context.getLastSnapshotId() == currentSID && context.getPreviousSnapshotId() == previousSID;
+ }
+
+ public void describeTo(Description description) {
+ }
+ }));
+ }
+
+ @Test
+ public void shouldExecuteOnlyOnRootProjects() {
+ Project project = mock(Project.class);
+ when(project.isRoot()).thenReturn(true);
+ assertTrue(PurgeRunner.shouldExecuteOn(project));
+
+ when(project.isRoot()).thenReturn(false);
+ assertFalse(PurgeRunner.shouldExecuteOn(project));
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java
index f88ed19d98e..31de15a3824 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java
@@ -17,15 +17,19 @@
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
-package org.sonar.api.purge;
+package org.sonar.plugins.dbcleaner.util;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
-import static org.hamcrest.core.Is.is;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class PurgeUtilsTest {
+public class PurgeUtilsTest extends AbstractDbUnitTestCase {
@Test
public void shouldReturnDefaultMinimumPeriod() {
@@ -38,4 +42,13 @@ public class PurgeUtilsTest {
conf.setProperty(PurgeUtils.PROP_KEY_MINIMUM_PERIOD_IN_HOURS, "9");
assertThat(PurgeUtils.getMinimumPeriodInHours(conf), is(9));
}
+
+ @Test
+ public void purgeSnapshots() throws SQLException {
+ setupData("purgeSnapshots");
+
+ PurgeUtils.deleteSnapshotsData(getSession(), Arrays.asList(3, 4));
+
+ checkTables("purgeSnapshots", "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "dependencies");
+ }
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent-result.xml
new file mode 100644
index 00000000000..042878aa032
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent-result.xml
@@ -0,0 +1,167 @@
+<dataset>
+ <!-- projects -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="myproject"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+ <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:org.sonar" name="org.osnar"
+ root_id="1"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+ <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:org.sonar.MyClass"
+ name="org.osnar.MyClass"
+ root_id="1"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+ <!-- snapshots older than the dateToStartDeletingAllSnapshots-->
+ <!-- keep this one because version event -->
+ <snapshots depth="[null]" id="1" scope="PRJ" qualifier="TRK" created_at="2009-11-02 13:58:00.00" version="0.9"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]"
+ diff_value_3="[null]"
+ rule_priority="[null]"
+ alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"
+ RULE_ID="1"
+ text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+ alert_status="[null]" description="[null]"/>
+ <!--<snapshots depth="[null]" id="2" scope="PRJ" qualifier="TRK" created_at="2010-01-01 13:58:00.00"-->
+ <!--version="1.0-SNAPSHOT"-->
+ <!--project_id="1"-->
+ <!--parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"-->
+ <!--path="[null]"/>-->
+ <!--<project_measures ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2"/>-->
+ <!--<snapshots depth="1" id="10" scope="DIR" qualifier="PAC" created_at="2010-01-01 13:58:00.00" version="[null]"-->
+ <!--project_id="2"-->
+ <!--parent_snapshot_id="2" root_project_id="1" root_snapshot_id="2" status="P" islast="false"-->
+ <!--path="1"/>-->
+ <!--<snapshots depth="2" id="20" scope="FIL" qualifier="CLA" created_at="2010-01-01 13:58:00.00" version="[null]"-->
+ <!--project_id="3"-->
+ <!--parent_snapshot_id="10" root_project_id="1" root_snapshot_id="2" status="P" islast="false"-->
+ <!--path="1.10"/>-->
+
+
+
+
+
+ <!-- snapshots between dateToStartKeepingOneSnapshotByMonth and dateToStartDeletingAllSnapshots-->
+ <!-- single snapshot on this month (except version events) -->
+ <snapshots depth="[null]" id="100" scope="PRJ" qualifier="TRK" created_at="2010-03-01 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <!--<snapshots depth="[null]" id="110" scope="PRJ" qualifier="TRK" created_at="2010-03-02 13:58:00.00"-->
+ <!--version="1.0-SNAPSHOT"-->
+ <!--project_id="1"-->
+ <!--parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"-->
+ <!--path="[null]"/>-->
+
+ <!--<snapshots depth="[null]" id="120" scope="PRJ" qualifier="TRK" created_at="2010-03-03 13:58:00.00"-->
+ <!--version="1.0-SNAPSHOT"-->
+ <!--project_id="1"-->
+ <!--parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"-->
+ <!--path="[null]"/>-->
+
+ <!-- this one has a version event -->
+ <snapshots depth="[null]" id="130" scope="PRJ" qualifier="TRK" created_at="2010-04-01 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!-- keep this one -->
+ <snapshots depth="[null]" id="140" scope="PRJ" qualifier="TRK" created_at="2010-04-15 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+
+
+
+ <!-- snapshots whose qualifier = LIB must not be deleted -->
+ <snapshots depth="[null]" id="150" scope="PRJ" qualifier="LIB" created_at="2010-04-22 13:58:00.00" version="0.1"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="160" scope="PRJ" qualifier="LIB" created_at="2010-04-23 13:58:00.00" version="0.2"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+
+
+
+
+ <!-- snapshots between dateToStartKeepingOneSnapshotByWeek and dateToStartKeepingOneSnapshotByMonth-->
+ <!-- keep this one -->
+ <snapshots depth="[null]" id="500" scope="PRJ" qualifier="TRK" created_at="2010-08-15 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!--<snapshots depth="[null]" id="510" scope="PRJ" qualifier="TRK" created_at="2010-08-16 13:58:00.00"-->
+ <!--version="1.1-SNAPSHOT"-->
+ <!--project_id="1"-->
+ <!--parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"-->
+ <!--path="[null]"/>-->
+
+ <!-- this one has a version event -->
+ <snapshots depth="[null]" id="520" scope="PRJ" qualifier="TRK" created_at="2010-08-25 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <!-- this one has a version event -->
+ <snapshots depth="[null]" id="530" scope="PRJ" qualifier="TRK" created_at="2010-08-26 13:58:00.00"
+ version="1.2-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+
+ <!--
+ snapshots before dateToStartKeepingOneSnapshotByWeek : nothing is currently purged
+ It will be improved later by keeping only one daily snapshot : snapshot 1010 should be removed -->
+ -->
+ <snapshots depth="[null]" id="1000" scope="PRJ" qualifier="TRK" created_at="2010-11-02 13:58:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="1010" scope="PRJ" qualifier="TRK" created_at="2010-11-03 13:58:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+ <!-- same day than 1010 -->
+ <snapshots depth="[null]" id="1020" scope="PRJ" qualifier="TRK" created_at="2010-11-03 20:26:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+
+
+ <events id="1" name="Version 0.9" resource_id="1" snapshot_id="1" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="2" name="Version 1.0-SNAPSHOT" resource_id="1" snapshot_id="130" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="3" name="Version 1.1-SNAPSHOT" resource_id="1" snapshot_id="520" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="4" name="Version 1.2-SNAPSHOT" resource_id="1" snapshot_id="530" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+
+</dataset> \ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent.xml
new file mode 100644
index 00000000000..0a66a38e452
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/period/IntegrationTest/dbContent.xml
@@ -0,0 +1,142 @@
+<dataset>
+ <!-- projects -->
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="myproject"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+ <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:org.sonar" name="org.osnar"
+ root_id="1"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+ <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:org.sonar.MyClass"
+ name="org.osnar.MyClass"
+ root_id="1"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+ <!-- snapshots older than the dateToStartDeletingAllSnapshots-->
+ <snapshots depth="[null]" id="1" scope="PRJ" qualifier="TRK" created_at="2009-11-02 13:58:00.00" version="0.9"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]"
+ diff_value_3="[null]"
+ rule_priority="[null]"
+ alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"
+ RULE_ID="1"
+ text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+ alert_status="[null]" description="[null]"/>
+ <snapshots depth="[null]" id="2" scope="PRJ" qualifier="TRK" created_at="2010-01-01 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <project_measures ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2"/>
+ <snapshots depth="1" id="10" scope="DIR" qualifier="PAC" created_at="2010-01-01 13:58:00.00" version="[null]"
+ project_id="2"
+ parent_snapshot_id="2" root_project_id="1" root_snapshot_id="2" status="P" islast="false"
+ path="1"/>
+ <snapshots depth="2" id="20" scope="FIL" qualifier="CLA" created_at="2010-01-01 13:58:00.00" version="[null]"
+ project_id="3"
+ parent_snapshot_id="10" root_project_id="1" root_snapshot_id="2" status="P" islast="false"
+ path="1.10"/>
+
+
+
+
+ <!-- snapshots between dateToStartKeepingOneSnapshotByMonth and dateToStartDeletingAllSnapshots-->
+ <snapshots depth="[null]" id="100" scope="PRJ" qualifier="TRK" created_at="2010-03-01 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="110" scope="PRJ" qualifier="TRK" created_at="2010-03-02 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="120" scope="PRJ" qualifier="TRK" created_at="2010-03-03 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="130" scope="PRJ" qualifier="TRK" created_at="2010-04-01 13:58:00.00"
+ version="1.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="140" scope="PRJ" qualifier="TRK" created_at="2010-04-15 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+
+
+
+ <!-- snapshots whose qualifier = LIB must not be deleted -->
+ <snapshots depth="[null]" id="150" scope="PRJ" qualifier="LIB" created_at="2010-04-22 13:58:00.00" version="0.1"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="160" scope="PRJ" qualifier="LIB" created_at="2010-04-23 13:58:00.00" version="0.2"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!-- snapshots between dateToStartKeepingOneSnapshotByWeek and dateToStartKeepingOneSnapshotByMonth-->
+ <snapshots depth="[null]" id="500" scope="PRJ" qualifier="TRK" created_at="2010-08-15 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="510" scope="PRJ" qualifier="TRK" created_at="2010-08-16 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="520" scope="PRJ" qualifier="TRK" created_at="2010-08-25 13:58:00.00"
+ version="1.1-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="530" scope="PRJ" qualifier="TRK" created_at="2010-08-26 13:58:00.00"
+ version="1.2-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!-- snapshots before dateToStartKeepingOneSnapshotByWeek-->
+ <snapshots depth="[null]" id="1000" scope="PRJ" qualifier="TRK" created_at="2010-11-02 13:58:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+ <snapshots depth="[null]" id="1010" scope="PRJ" qualifier="TRK" created_at="2010-11-03 13:58:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+ <!-- same day than 1010 -->
+ <snapshots depth="[null]" id="1020" scope="PRJ" qualifier="TRK" created_at="2010-11-03 20:26:00.00"
+ version="3.0-SNAPSHOT"
+ project_id="1"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+
+
+ <events id="1" name="Version 0.9" resource_id="1" snapshot_id="1" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="2" name="Version 1.0-SNAPSHOT" resource_id="1" snapshot_id="130" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="3" name="Version 1.1-SNAPSHOT" resource_id="1" snapshot_id="520" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+ <events id="4" name="Version 1.2-SNAPSHOT" resource_id="1" snapshot_id="530" category="Version" description="[null]"
+ event_date="2008-12-02 13:58:00.00" CREATED_AT="[null]" data="[null]"/>
+
+</dataset> \ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml
index e9bcbeea46c..e9bcbeea46c 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml
index a67a05e5291..a67a05e5291 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/purgeDeletedResources.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml
index 8d4d27778c7..8d4d27778c7 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeletedResourcesTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml
diff --git a/plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies-result.xml
index 6b0bf1b88c4..6b0bf1b88c4 100644
--- a/plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies-result.xml
diff --git a/plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies.xml
index 5ffbb85ac9f..5ffbb85ac9f 100644
--- a/plugins/sonar-design-plugin/src/test/resources/org/sonar/plugins/design/batch/OldDependenciesPurgeTest/purgeOldDependencies.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/purgeDependencies.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml
index 5c3493f167f..5c3493f167f 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml
index baad4416b01..baad4416b01 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/purgeDeprecatedLast.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml
index 8d4d27778c7..8d4d27778c7 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDeprecatedLastTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml
index c7125729940..c7125729940 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge.xml
index c7125729940..c7125729940 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/nothingToPurge.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/nothingToPurge.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml
index fbe36205e74..fbe36205e74 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml
index 90abf33096c..90abf33096c 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledModule.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml
index e99e5ca29af..e99e5ca29af 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml
index 884a048a5fb..884a048a5fb 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/purgeDisabledProject.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml
index eee1bfaad3c..eee1bfaad3c 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeDisabledResourcesTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities-result.xml
index 796b6b9e576..796b6b9e576 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities.xml
index 6f34d16ace9..6f34d16ace9 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/purgeEntities.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/purgeEntities.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml
index 8d4d27778c7..8d4d27778c7 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEntitiesTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
index 46bd9b39c93..46bd9b39c93 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
index 6e462083c40..6e462083c40 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphansTest/purgeEventOrphans.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml
index 7b43ac967c3..7b43ac967c3 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml
index 0be6420e8d1..0be6420e8d1 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResourcesTest/purgeOrphanResources.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml
index e2cf33e7e40..e2cf33e7e40 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml
index 35b75197444..35b75197444 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeResourceOrphans.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml
index 44ac13dd9d6..44ac13dd9d6 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml
index 1b595f06123..1b595f06123 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphansTest/purgeUserOrphans.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml
index c4c0be5ed7a..c4c0be5ed7a 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles.xml
index 0678e9ec63b..0678e9ec63b 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeResourceRolesTest/purgeResourceRoles.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeResourceRolesTest/purgeResourceRoles.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml
index 86dbc05aba1..86dbc05aba1 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml
index 87f10a699e1..87f10a699e1 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/purgeRuleMeasures.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml
index d4e59f25a41..d4e59f25a41 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeRuleMeasuresTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml
index c86354320cd..c86354320cd 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed.xml
index d0bbb1424bb..d0bbb1424bb 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/purgeUnprocessed.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/purgeUnprocessed.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml
index 8d4d27778c7..8d4d27778c7 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/PurgeUnprocessedTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/sharedFixture.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/sharedFixture.xml
index ae4f6b24985..ae4f6b24985 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/sharedFixture.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/sharedFixture.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml
index e6a3e32080f..e6a3e32080f 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons-result.xml
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml
index e8a0a7f145d..e8a0a7f145d 100644
--- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublonsTest/unflagLastDoublons.xml
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest/shared.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest/shared.xml
new file mode 100644
index 00000000000..d79f7c846c8
--- /dev/null
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/runner/PurgeRunnerTest/shared.xml
@@ -0,0 +1,53 @@
+<dataset>
+
+ <!--
+
+ PROJECT WITH HISTORIC DATA
+
+ -->
+
+ <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="myproject"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+ <!-- first snapshot -->
+ <snapshots id="100" scope="PRJ" qualifier="TRK" created_at="2009-11-02 13:58:00.00" version="0.1-SNAPSHOT"
+ project_id="1" depth="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!-- unvalid snapshot (status = UNPROCESSED) -->
+ <snapshots id="200" scope="PRJ" qualifier="TRK" created_at="2009-11-03 13:58:00.00" version="0.1-SNAPSHOT"
+ project_id="1" depth="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false"
+ path="[null]"/>
+
+ <!-- second snapshot -->
+ <snapshots id="300" scope="PRJ" qualifier="TRK" created_at="2009-11-04 13:58:00.00" version="0.1-SNAPSHOT"
+ project_id="1" depth="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false"
+ path="[null]"/>
+
+ <!-- last snapshot -->
+ <snapshots id="400" scope="PRJ" qualifier="TRK" created_at="2009-11-05 13:58:00.00" version="0.1-SNAPSHOT"
+ project_id="1" depth="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+
+
+
+
+ <!-- PROJECT WITH ONLY A SINGLE ANALYSIS - NO TIME MACHINE -->
+ <projects long_name="[null]" id="2" scope="PRJ" qualifier="TRK" kee="mygroup2:myartifact2" name="myproject2"
+ root_id="[null]"
+ description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]"/>
+
+ <snapshots id="1000" scope="PRJ" qualifier="TRK" created_at="2009-11-05 13:58:00.00" version="0.1-SNAPSHOT"
+ project_id="2" depth="[null]"
+ parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true"
+ path="[null]"/>
+
+</dataset> \ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml
index f5039b0e8ec..f5039b0e8ec 100644
--- a/sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml
index 93ef910270a..93ef910270a 100644
--- a/sonar-core/src/test/resources/org/sonar/core/purge/AbstractPurgeTest/purgeSnapshots.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
index 90fe463ed82..fdb70535b59 100644
--- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
+++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
@@ -23,11 +23,11 @@ import org.sonar.api.*;
import org.sonar.plugins.design.batch.*;
import org.sonar.plugins.design.ui.dependencies.GwtDependenciesTab;
import org.sonar.plugins.design.ui.lcom4.GwtLcom4Tab;
+import org.sonar.plugins.design.ui.libraries.GwtLibrariesPage;
import org.sonar.plugins.design.ui.page.GwtDesignPage;
import org.sonar.plugins.design.ui.widgets.ChidamberKemererWidget;
import org.sonar.plugins.design.ui.widgets.FileDesignWidget;
import org.sonar.plugins.design.ui.widgets.PackageDesignWidget;
-import org.sonar.plugins.design.ui.libraries.GwtLibrariesPage;
import java.util.ArrayList;
import java.util.List;
@@ -62,7 +62,6 @@ public class DesignPlugin implements Plugin {
extensions.add(ProjectDsmDecorator.class);
extensions.add(PackageTangleIndexDecorator.class);
extensions.add(FileTangleIndexDecorator.class);
- extensions.add(OldDependenciesPurge.class);
extensions.add(SuspectLcom4DensityDecorator.class);
extensions.add(GwtLibrariesPage.class);
diff --git a/pom.xml b/pom.xml
index 767e12aeba0..87372bca58a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,7 @@
<module>sonar-ws-client</module>
<module>plugins/sonar-core-plugin</module>
+ <module>plugins/sonar-dbcleaner-plugin</module>
<module>plugins/sonar-checkstyle-plugin</module>
<module>plugins/sonar-pmd-plugin</module>
<module>plugins/sonar-cobertura-plugin</module>
@@ -202,7 +203,7 @@
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-dev-maven-plugin</artifactId>
- <version>0.7</version>
+ <version>1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.sonar</groupId>
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml
index ef4e7ce947e..d297a351ff3 100644
--- a/sonar-application/pom.xml
+++ b/sonar-application/pom.xml
@@ -176,6 +176,12 @@
</dependency>
<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
+ <artifactId>sonar-dbcleaner-plugin</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-pmd-plugin</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
diff --git a/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java b/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
index 46bdb418441..722ad0cd7d8 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/FinalizeSnapshotsJob.java
@@ -19,29 +19,22 @@
*/
package org.sonar.batch;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Purge;
-import org.sonar.api.batch.PurgeContext;
import org.sonar.api.batch.SensorContext;
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.core.purge.DefaultPurgeContext;
import javax.persistence.Query;
public class FinalizeSnapshotsJob implements CoreJob {
private DatabaseSession session;
- private Purge[] purges;
private ServerMetadata server;
private Snapshot snapshot;
- public FinalizeSnapshotsJob(ServerMetadata server, DatabaseSession session, Purge[] purges, Snapshot snapshot) {
+ public FinalizeSnapshotsJob(ServerMetadata server, DatabaseSession session, Snapshot snapshot) {
this.session = session;
- this.purges = purges;
this.server = server;
this.snapshot = snapshot;
}
@@ -50,7 +43,6 @@ public class FinalizeSnapshotsJob implements CoreJob {
if (shouldExecuteOn(project)) {
Snapshot previousLastSnapshot = getPreviousLastSnapshot(snapshot);
updateFlags(snapshot, previousLastSnapshot);
- purge(snapshot, previousLastSnapshot);
}
}
@@ -98,25 +90,4 @@ public class FinalizeSnapshotsJob implements CoreJob {
snapshot.setLast(last);
}
-
- private void purge(Snapshot currentSnapshot, Snapshot previousLastSnapshot) {
- final Logger logger = LoggerFactory.getLogger(FinalizeSnapshotsJob.class);
- TimeProfiler profiler = new TimeProfiler(logger).start("Database optimization");
- PurgeContext context = createPurgeContext(currentSnapshot, previousLastSnapshot);
- logger.debug("Snapshots to purge: " + context);
- for (Purge purge : purges) {
- logger.debug("Executing {}...", purge.getClass().getName());
- purge.purge(context);
- }
- profiler.stop();
- }
-
- private PurgeContext createPurgeContext(Snapshot currentSnapshot, Snapshot previousLastSnapshot) {
- DefaultPurgeContext context = new DefaultPurgeContext(currentSnapshot);
- if (previousLastSnapshot != null && previousLastSnapshot.getCreatedAt().before(currentSnapshot.getCreatedAt())) {
- context.setLastSnapshotId(previousLastSnapshot.getId());
- }
- return context;
- }
-
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
index 9158839ea1a..d16822861e4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/FinalizeSnapshotsJobTest.java
@@ -19,50 +19,37 @@
*/
package org.sonar.batch;
-import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.batch.Purge;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
-import org.sonar.core.purge.DefaultPurgeContext;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import javax.persistence.Query;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
public class FinalizeSnapshotsJobTest extends AbstractDbUnitTestCase {
- private Purge purgeMock=null;
-
- @Before
- public void before() {
- purgeMock = mock(Purge.class);
- }
@Test
public void shouldUnflagPenultimateLastSnapshot() throws Exception {
assertAnalysis(11, "shouldUnflagPenultimateLastSnapshot");
- verify(purgeMock).purge(new DefaultPurgeContext(11, 1));
}
@Test
public void doNotFailIfNoPenultimateLast() throws Exception {
assertAnalysis(5, "doNotFailIfNoPenultimateLast");
- verify(purgeMock).purge(new DefaultPurgeContext(5, null));
}
@Test
public void lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot() {
assertAnalysis(6, "lastSnapshotIsNotUpdatedWhenAnalyzingPastSnapshot");
- verify(purgeMock).purge(new DefaultPurgeContext(6, null));
}
private void assertAnalysis(int snapshotId, String fixture) {
setupData("sharedFixture", fixture);
- FinalizeSnapshotsJob sensor = new FinalizeSnapshotsJob(mock(ServerMetadata.class), getSession(), new Purge[]{purgeMock}, loadSnapshot(snapshotId));
+ FinalizeSnapshotsJob sensor = new FinalizeSnapshotsJob(mock(ServerMetadata.class), getSession(), loadSnapshot(snapshotId));
sensor.execute(new Project("key"), null);
getSession().stop();
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/DefaultPurgeContext.java b/sonar-core/src/main/java/org/sonar/core/purge/DefaultPurgeContext.java
deleted file mode 100644
index f2106a6bd58..00000000000
--- a/sonar-core/src/main/java/org/sonar/core/purge/DefaultPurgeContext.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package org.sonar.core.purge;
-
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.batch.PurgeContext;
-import org.sonar.api.database.model.Snapshot;
-
-public class DefaultPurgeContext implements PurgeContext {
-
- private Integer currentSid;
- private Integer lastSid;
-
- public DefaultPurgeContext() {
- }
-
- public DefaultPurgeContext(Snapshot currentSnapshot) {
- this(currentSnapshot, null);
- }
-
- public DefaultPurgeContext(Snapshot currentSnapshot, Snapshot lastSnapshot) {
- if (currentSnapshot != null) {
- currentSid = currentSnapshot.getId();
- }
- if (lastSnapshot != null) {
- lastSid = lastSnapshot.getId();
- }
- }
-
- public DefaultPurgeContext(Integer currentSid, Integer lastSid) {
- this.currentSid = currentSid;
- this.lastSid = lastSid;
- }
-
- public DefaultPurgeContext setLastSnapshotId(Integer lastSid) {
- this.lastSid = lastSid;
- return this;
- }
-
- public DefaultPurgeContext setCurrentSnapshotId(Integer currentSid) {
- this.currentSid = currentSid;
- return this;
- }
-
- public Integer getPreviousSnapshotId() {
- return lastSid;
- }
-
- public Integer getLastSnapshotId() {
- return currentSid;
- }
-
- @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 (lastSid != null ? !lastSid.equals(context.lastSid) : context.lastSid != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = lastSid != null ? lastSid.hashCode() : 0;
- result = 31 * result + currentSid.hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("currentSid", currentSid)
- .append("lastSid", lastSid)
- .toString();
- }
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Purge.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/Purge.java
index 9f78dc2933d..d08323bb23a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Purge.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/Purge.java
@@ -27,7 +27,9 @@ import org.sonar.api.BatchExtension;
* <p>It is executed when the batch finishes.
*
* @since 1.10
+ * @deprecated since 2.5. The DBCleaner plugin implements all required purge taks.
*/
+@Deprecated
public interface Purge extends BatchExtension {
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/PurgeContext.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/PurgeContext.java
index cc6c4f8818e..92a1f1f2e8e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/PurgeContext.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/PurgeContext.java
@@ -22,7 +22,9 @@ package org.sonar.api.batch;
/**
*
* @since 1.10
+ * @deprecated since 2.5
*/
+@Deprecated
public interface PurgeContext {
Integer getPreviousSnapshotId();
diff --git a/sonar-core/src/main/java/org/sonar/core/purge/AbstractPurge.java b/sonar-deprecated/src/main/java/org/sonar/core/purge/AbstractPurge.java
index a0f46d286d1..a0f46d286d1 100644
--- a/sonar-core/src/main/java/org/sonar/core/purge/AbstractPurge.java
+++ b/sonar-deprecated/src/main/java/org/sonar/core/purge/AbstractPurge.java
diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml
index 2f6ebc3cc84..8a2c4987d44 100644
--- a/sonar-server/pom.xml
+++ b/sonar-server/pom.xml
@@ -403,6 +403,12 @@
</dependency>
<dependency>
<groupId>org.codehaus.sonar.plugins</groupId>
+ <artifactId>sonar-dbcleaner-plugin</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.sonar.plugins</groupId>
<artifactId>sonar-pmd-plugin</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
diff --git a/tests/volume/pom.xml b/tests/volume/pom.xml
index b4a8084de39..610810c8e52 100644
--- a/tests/volume/pom.xml
+++ b/tests/volume/pom.xml
@@ -63,7 +63,6 @@
<plugin>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-dev-maven-plugin</artifactId>
- <version>0.7</version>
<executions>
<execution>
<id>start-server</id>