aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-05-31 11:02:55 +0200
committerSonarTech <sonartech@sonarsource.com>2018-06-12 20:21:00 +0200
commita76567a39e9d61a42969898cb2db4a533da4078c (patch)
tree3137854ff842f0fe793a42cf91ff8f11422f56ce /sonar-core
parent02f499b51bcf8a681fb2acfadc8c88c8e4dd4f9d (diff)
downloadsonarqube-a76567a39e9d61a42969898cb2db4a533da4078c.tar.gz
sonarqube-a76567a39e9d61a42969898cb2db4a533da4078c.zip
LICENSE-98 add EditionProvider
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/EditionProvider.java47
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java47
-rw-r--r--sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java75
3 files changed, 169 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/EditionProvider.java b/sonar-core/src/main/java/org/sonar/core/platform/EditionProvider.java
new file mode 100644
index 00000000000..fa0dd84ea1f
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/platform/EditionProvider.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.core.platform;
+
+import java.util.Optional;
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.server.ServerSide;
+
+@ServerSide
+@ComputeEngineSide
+public interface EditionProvider {
+ enum Edition {
+ COMMUNITY("Community"),
+ DEVELOPER("Developer"),
+ ENTERPRISE("Enterprise"),
+ DATA_CENTER("Data Center");
+
+ private final String label;
+
+ Edition(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+ }
+
+ Optional<Edition> get();
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java b/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java
new file mode 100644
index 00000000000..8c42c66522c
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/platform/PlatformEditionProvider.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.core.platform;
+
+import java.util.Optional;
+
+import static com.google.common.base.Preconditions.checkState;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
+
+public class PlatformEditionProvider implements EditionProvider {
+ private static final EditionProvider[] NO_OTHER_PROVIDERS = new EditionProvider[0];
+ private final EditionProvider[] otherEditionProviders;
+
+ public PlatformEditionProvider() {
+ this(NO_OTHER_PROVIDERS);
+ }
+
+ public PlatformEditionProvider(EditionProvider[] otherEditionProviders) {
+ this.otherEditionProviders = otherEditionProviders;
+ }
+
+ @Override
+ public Optional<Edition> get() {
+ checkState(otherEditionProviders.length <= 1, "There can't be more than 1 other EditionProvider");
+ if (otherEditionProviders.length == 1) {
+ return otherEditionProviders[0].get();
+ }
+ return Optional.of(COMMUNITY);
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java
new file mode 100644
index 00000000000..032d9fbcd19
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/platform/PlatformEditionProviderTest.java
@@ -0,0 +1,75 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.core.platform;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static java.util.Optional.of;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.core.platform.EditionProvider.Edition.COMMUNITY;
+import static org.sonar.core.platform.EditionProvider.Edition.DATA_CENTER;
+import static org.sonar.core.platform.EditionProvider.Edition.DEVELOPER;
+
+public class PlatformEditionProviderTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void returns_COMMUNITY_when_there_is_no_other_EditionProvider() {
+ ComponentContainer container = new ComponentContainer();
+ ComponentContainer child = new ComponentContainer(container);
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+ assertThat(platformEditionProvider.get()).contains(COMMUNITY);
+ }
+
+ @Test
+ public void returns_edition_from_other_EditionProvider_in_any_container() {
+ ComponentContainer container = new ComponentContainer();
+ container.add((EditionProvider) () -> of(DATA_CENTER));
+ ComponentContainer child = new ComponentContainer(container);
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+ assertThat(platformEditionProvider.get()).contains(DATA_CENTER);
+ }
+
+ @Test
+ public void get_fails_with_ISE_if_there_is_more_than_one_other_EditionProvider_in_any_container() {
+ ComponentContainer container = new ComponentContainer();
+ container.add((EditionProvider) () -> of(DATA_CENTER));
+ ComponentContainer child = new ComponentContainer(container);
+ child.add((EditionProvider) () -> of(DEVELOPER));
+ child.add(PlatformEditionProvider.class);
+
+ assertThat(container.getComponentByType(PlatformEditionProvider.class)).isNull();
+ PlatformEditionProvider platformEditionProvider = child.getComponentByType(PlatformEditionProvider.class);
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("There can't be more than 1 other EditionProvider");
+
+ platformEditionProvider.get();
+ }
+}