aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-08-23 15:00:55 +0200
committerJanos Gyerik <janos.gyerik@sonarsource.com>2017-09-12 11:34:50 +0200
commit00a61114b3f0a16fab5b932cef6733542d5e9239 (patch)
tree2dbd251dd679ff752d9323afddda9e0e72f3b5d4
parentda4ad168305e74d8de03764be07acc3bf024f8d5 (diff)
downloadsonarqube-00a61114b3f0a16fab5b932cef6733542d5e9239.tar.gz
sonarqube-00a61114b3f0a16fab5b932cef6733542d5e9239.zip
SONAR-9616 Add BranchFeature to detect if branch is supported or not
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeature.java27
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureExtension.java31
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxy.java30
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java39
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/branch/package-info.java23
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java49
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureRule.java47
8 files changed, 250 insertions, 0 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeature.java b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeature.java
new file mode 100644
index 00000000000..2f5ceb756c0
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeature.java
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+interface BranchFeature {
+
+ boolean isEnabled();
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureExtension.java b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureExtension.java
new file mode 100644
index 00000000000..60340cb47b7
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureExtension.java
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+import org.sonar.api.server.ServerSide;
+
+/**
+ * The branch plugin needs to implement this in order to know that the branch feature is supported
+ */
+@ServerSide
+public interface BranchFeatureExtension extends BranchFeature {
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxy.java b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxy.java
new file mode 100644
index 00000000000..6fa3d926b3c
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxy.java
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+/**
+ * The goal of this class is to handle the 2 different use case :
+ * - The branch plugin exists, the proxy will redirect method calls to the plugin
+ * - No branch plugin, feature is disabled
+ */
+public interface BranchFeatureProxy extends BranchFeature {
+
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java
new file mode 100644
index 00000000000..6c1171110fa
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+public class BranchFeatureProxyImpl implements BranchFeatureProxy {
+
+ private final BranchFeatureExtension branchFeatureExtension;
+
+ public BranchFeatureProxyImpl() {
+ this.branchFeatureExtension = null;
+ }
+
+ public BranchFeatureProxyImpl(BranchFeatureExtension branchFeatureExtension) {
+ this.branchFeatureExtension = branchFeatureExtension;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return branchFeatureExtension != null && branchFeatureExtension.isEnabled();
+ }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/branch/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/branch/package-info.java
new file mode 100644
index 00000000000..89444c23cdc
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/branch/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.branch;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index 05a52047308..6786bec8638 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -35,6 +35,7 @@ import org.sonar.core.component.DefaultResourceTypes;
import org.sonar.core.timemachine.Periods;
import org.sonar.server.authentication.AuthenticationModule;
import org.sonar.server.batch.BatchWsModule;
+import org.sonar.server.branch.BranchFeatureProxyImpl;
import org.sonar.server.ce.ws.CeWsModule;
import org.sonar.server.component.ComponentCleanerService;
import org.sonar.server.component.ComponentFinder;
@@ -509,6 +510,9 @@ public class PlatformLevel4 extends PlatformLevel {
CancelAllAction.class,
PluginsWs.class,
+ // Branch
+ BranchFeatureProxyImpl.class,
+
// privileged plugins
PrivilegedPluginsBootstraper.class,
PrivilegedPluginsStopper.class,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java
new file mode 100644
index 00000000000..a72d399ed20
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class BranchFeatureProxyImplTest {
+
+ private BranchFeatureExtension branchFeatureExtension = mock(BranchFeatureExtension.class);
+
+ @Test
+ public void return_false_when_no_extension() {
+ assertThat(new BranchFeatureProxyImpl().isEnabled()).isFalse();
+ }
+
+ @Test
+ public void return_false_when_extension_returns_false() {
+ when(branchFeatureExtension.isEnabled()).thenReturn(false);
+ assertThat(new BranchFeatureProxyImpl(branchFeatureExtension).isEnabled()).isFalse();
+ }
+
+ @Test
+ public void return_true_when_extension_returns_ftrue() {
+ when(branchFeatureExtension.isEnabled()).thenReturn(true);
+ assertThat(new BranchFeatureProxyImpl(branchFeatureExtension).isEnabled()).isTrue();
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureRule.java b/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureRule.java
new file mode 100644
index 00000000000..f0dd8c89b86
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureRule.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.branch;
+
+import org.junit.rules.ExternalResource;
+
+public class BranchFeatureRule extends ExternalResource implements BranchFeatureProxy {
+
+ private boolean enabled;
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ protected void after() {
+ reset();
+ }
+
+ public void reset() {
+ this.enabled = false;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+}