]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Add BranchFeature to detect if branch is supported or not
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 23 Aug 2017 13:00:55 +0000 (15:00 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:50 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeature.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureExtension.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxy.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/branch/BranchFeatureProxyImpl.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/branch/package-info.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureProxyImplTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/branch/BranchFeatureRule.java [new file with mode: 0644]

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 (file)
index 0000000..2f5ceb7
--- /dev/null
@@ -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 (file)
index 0000000..60340cb
--- /dev/null
@@ -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 (file)
index 0000000..6fa3d92
--- /dev/null
@@ -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 (file)
index 0000000..6c11711
--- /dev/null
@@ -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 (file)
index 0000000..89444c2
--- /dev/null
@@ -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;
index 05a52047308d834d21f774b6fc49d45f24f1a52c..6786bec863881fa9a7e35ada7c7a40a6e59ef4e1 100644 (file)
@@ -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 (file)
index 0000000..a72d399
--- /dev/null
@@ -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 (file)
index 0000000..f0dd8c8
--- /dev/null
@@ -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;
+  }
+
+}