aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-12 13:25:15 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-12 13:25:15 +0000
commit969b85fd6ea0931c1d23174c7667cffe752c04a9 (patch)
tree760689eb68ae093f1ce4b8eadbc65424eaf5e482 /sonar-plugin-api
parent92e61d65dc65e01338e472615a846e3fc9620426 (diff)
downloadsonarqube-969b85fd6ea0931c1d23174c7667cffe752c04a9.tar.gz
sonarqube-969b85fd6ea0931c1d23174c7667cffe752c04a9.zip
SONAR-1953 Minimum period used in purge tasks should be configurable
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java40
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java41
2 files changed, 81 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java
new file mode 100644
index 00000000000..95f9c5fa94c
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/purge/PurgeUtils.java
@@ -0,0 +1,40 @@
+/*
+ * 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.api.purge;
+
+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";
+
+ 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;
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java
new file mode 100644
index 00000000000..f88ed19d98e
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/purge/PurgeUtilsTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.api.purge;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import static org.hamcrest.core.Is.is;
+
+import static org.junit.Assert.assertThat;
+
+public class PurgeUtilsTest {
+
+ @Test
+ public void shouldReturnDefaultMinimumPeriod() {
+ assertThat(PurgeUtils.getMinimumPeriodInHours(new PropertiesConfiguration()), is(PurgeUtils.DEFAULT_MINIMUM_PERIOD_IN_HOURS));
+ }
+
+ @Test
+ public void shouldReturnMinimumPeriod() {
+ PropertiesConfiguration conf = new PropertiesConfiguration();
+ conf.setProperty(PurgeUtils.PROP_KEY_MINIMUM_PERIOD_IN_HOURS, "9");
+ assertThat(PurgeUtils.getMinimumPeriodInHours(conf), is(9));
+ }
+}