aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-19 11:02:02 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-19 11:02:02 +0200
commit03fd91021257124849677eb12e6b3330c5755c6d (patch)
treeb8f719e430203ecf48415e17bb559a4cac4408c3 /plugins
parentc0a0e72e7f05afb9a46e9fe3734ae1173009ae88 (diff)
downloadsonarqube-03fd91021257124849677eb12e6b3330c5755c6d.tar.gz
sonarqube-03fd91021257124849677eb12e6b3330c5755c6d.zip
SONAR-3887 add org.sonar.api.utils.DatabaseSemaphore
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java3
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DatabaseSemaphoreImpl.java43
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DatabaseSemaphoreImplTest.java41
3 files changed, 86 insertions, 1 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 074d8d3873e..cce3cd6870c 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
@@ -374,11 +374,12 @@ import java.util.List;
public final class CorePlugin extends SonarPlugin {
@SuppressWarnings("unchecked")
- public List<Class<? extends Extension>> getExtensions() {
+ public List getExtensions() {
return ImmutableList.of(
DefaultResourceTypes.class,
UserManagedMetrics.class,
ProjectFileSystemLogger.class,
+ DatabaseSemaphoreImpl.class,
// maven
MavenInitializer.class,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DatabaseSemaphoreImpl.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DatabaseSemaphoreImpl.java
new file mode 100644
index 00000000000..5c992b4ed35
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/DatabaseSemaphoreImpl.java
@@ -0,0 +1,43 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core;
+
+import org.sonar.api.utils.DatabaseSemaphore;
+import org.sonar.core.persistence.SemaphoreDao;
+
+/**
+ * @since 3.4
+ */
+public class DatabaseSemaphoreImpl implements DatabaseSemaphore {
+
+ private SemaphoreDao dao;
+
+ public DatabaseSemaphoreImpl(SemaphoreDao dao) {
+ this.dao = dao;
+ }
+
+ public boolean acquire(String name, int maxDurationInSeconds) {
+ return dao.acquire(name, maxDurationInSeconds);
+ }
+
+ public void release(String name) {
+ dao.release(name);
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DatabaseSemaphoreImplTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DatabaseSemaphoreImplTest.java
new file mode 100644
index 00000000000..c640159ba67
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/DatabaseSemaphoreImplTest.java
@@ -0,0 +1,41 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core;
+
+import org.junit.Test;
+import org.sonar.core.persistence.SemaphoreDao;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class DatabaseSemaphoreImplTest {
+
+ @Test
+ public void should_be_a_bridge_over_dao() {
+ SemaphoreDao dao = mock(SemaphoreDao.class);
+ DatabaseSemaphoreImpl impl = new DatabaseSemaphoreImpl(dao);
+
+ impl.acquire("do-xxx", 50000);
+ verify(dao).acquire("do-xxx", 50000);
+
+ impl.release("do-xxx");
+ verify(dao).release("do-xxx");
+ }
+}