diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-14 14:10:07 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-02-14 14:11:05 +0100 |
commit | 1065f1eb91fb05b26c32432625236ea39ea4fcee (patch) | |
tree | 31eba53ea07bcf84d776a81d2e4f8c5c4fc20c50 /plugins/sonar-dbcleaner-plugin | |
parent | 16773f7fbbbf5f8418474da63624a4168b883420 (diff) | |
download | sonarqube-1065f1eb91fb05b26c32432625236ea39ea4fcee.tar.gz sonarqube-1065f1eb91fb05b26c32432625236ea39ea4fcee.zip |
Improve the component org.sonar.dbcleaner.api.PurgeTask
* add javadoc
* use simple and generic method names
Diffstat (limited to 'plugins/sonar-dbcleaner-plugin')
4 files changed, 36 insertions, 19 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java index 8ccad6d0c5d..9e9a5c6e909 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java @@ -52,24 +52,24 @@ public class DefaultPurgeTask implements PurgeTask { this.periodCleaner = periodCleaner; } - public PurgeTask deleteProject(long projectId) { - purgeDao.deleteProject(projectId); + public PurgeTask delete(long resourceId) { + purgeDao.deleteProject(resourceId); return this; } - public PurgeTask purgeProject(long projectId) { - cleanHistoricalData(projectId); - doPurgeProject(projectId); + public PurgeTask purge(long resourceId) { + cleanHistoricalData(resourceId); + doPurge(resourceId); return this; } - private void cleanHistoricalData(long projectId) { + private void cleanHistoricalData(long resourceId) { try { - LOG.debug("Clean project historical data [id=" + projectId + "]"); - periodCleaner.purge(projectId); + LOG.debug("Clean historical data [id=" + resourceId + "]"); + periodCleaner.purge(resourceId); } catch (Exception e) { // purge errors must no fail the batch - LOG.error("Fail to clean project historical data [id=" + projectId + "]", e); + LOG.error("Fail to clean historical data [id=" + resourceId + "]", e); } } @@ -80,13 +80,13 @@ public class DefaultPurgeTask implements PurgeTask { return new String[]{Scopes.FILE}; } - private void doPurgeProject(long projectId) { + private void doPurge(long resourceId) { try { - LOG.debug("Purge project [id=" + projectId + "]"); - purgeDao.purgeProject(projectId, getScopesWithoutHistoricalData()); + LOG.debug("Purge data [id=" + resourceId + "]"); + purgeDao.purgeProject(resourceId, getScopesWithoutHistoricalData()); } catch (Exception e) { // purge errors must no fail the batch - LOG.error("Fail to purge project [id=" + projectId + "]", e); + LOG.error("Fail to purge data [id=" + resourceId + "]", e); } } } diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java index ba8150cdbd6..adaf87e31aa 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/ProjectPurgePostJob.java @@ -35,6 +35,6 @@ public class ProjectPurgePostJob implements PostJob { } public void executeOn(final Project project, SensorContext context) { - purgeTask.purgeProject((long) project.getId()); + purgeTask.purge((long) project.getId()); } } diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeTask.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeTask.java index 326143d8d8e..2a40bf84b0a 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeTask.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeTask.java @@ -19,12 +19,29 @@ */ package org.sonar.plugins.dbcleaner.api; +import com.google.common.annotations.Beta; import org.sonar.api.BatchExtension; /** * @since 2.14 */ +@Beta public interface PurgeTask extends BatchExtension { - PurgeTask purgeProject(long projectId); - PurgeTask deleteProject(long projectId); + /** + * Purges the data related to a tree of resources. + * + * Exceptions are logged and are not thrown again, so this method fails only on {@link Error}s. + * + * @param resourceId the root of the tree + * @return this + */ + PurgeTask purge(long resourceId); + + /** + * Completely deletes a tree of resources. + * + * @param resourceId the root of the tree + * @return this + */ + PurgeTask delete(long resourceId); } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java index 4aa4fa4dd9f..8947b8e21fd 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DefaultPurgeTaskTest.java @@ -37,7 +37,7 @@ public class DefaultPurgeTaskTest { settings.setProperty(DbCleanerConstants.PROPERTY_CLEAN_DIRECTORY, "false"); DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class)); - task.purgeProject(1L); + task.purge(1L); verify(purgeDao).purgeProject(1L, new String[]{Scopes.FILE}); } @@ -48,7 +48,7 @@ public class DefaultPurgeTaskTest { Settings settings = new Settings(new PropertyDefinitions(DefaultPurgeTask.class)); DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, settings, mock(DefaultPeriodCleaner.class)); - task.purgeProject(1L); + task.purge(1L); verify(purgeDao).purgeProject(1L, new String[]{Scopes.DIRECTORY, Scopes.FILE}); } @@ -59,7 +59,7 @@ public class DefaultPurgeTaskTest { when(purgeDao.purgeProject(anyLong(), (String[]) any())).thenThrow(new RuntimeException()); DefaultPurgeTask task = new DefaultPurgeTask(purgeDao, new Settings(), mock(DefaultPeriodCleaner.class)); - task.purgeProject(1L); + task.purge(1L); verify(purgeDao).purgeProject(anyLong(), (String[]) any()); } |