--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.almsettings;
+
+import java.util.Optional;
+import org.sonar.core.platform.EditionProvider;
+import org.sonar.core.platform.PlatformEditionProvider;
+
+public class MultipleAlmFeatureProvider {
+
+ private PlatformEditionProvider editionProvider;
+
+ public MultipleAlmFeatureProvider(PlatformEditionProvider editionProvider) {
+ this.editionProvider = editionProvider;
+ }
+
+ public boolean enabled() {
+ Optional<EditionProvider.Edition> edition = editionProvider.get();
+ if (!edition.isPresent()) {
+ return false;
+ }
+ switch (edition.get()) {
+ case ENTERPRISE:
+ case DATACENTER:
+ return true;
+ default:
+ return false;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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.almsettings;
+
+import java.util.Optional;
+import org.assertj.core.api.Assertions;
+import org.junit.Test;
+import org.sonar.core.platform.EditionProvider;
+import org.sonar.core.platform.PlatformEditionProvider;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class MultipleAlmFeatureProviderTest {
+
+ private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class);
+ private final MultipleAlmFeatureProvider underTest = new MultipleAlmFeatureProvider(editionProvider);
+
+ @Test
+ public void is_enabled_on_CE() {
+ when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.COMMUNITY));
+ Assertions.assertThat(underTest.enabled()).isFalse();
+ }
+
+ @Test
+ public void is_enabled_on_DE() {
+ when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.DEVELOPER));
+ Assertions.assertThat(underTest.enabled()).isFalse();
+ }
+
+ @Test
+ public void is_enabled_on_EE() {
+ when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.ENTERPRISE));
+ Assertions.assertThat(underTest.enabled()).isTrue();
+ }
+
+ @Test
+ public void is_enabled_on_DCE() {
+ when(editionProvider.get()).thenReturn(Optional.of(EditionProvider.Edition.DATACENTER));
+ Assertions.assertThat(underTest.enabled()).isTrue();
+ }
+}
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.dialect.H2;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
import org.sonar.server.branch.BranchFeatureProxy;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.OrganizationFlags;
private final BranchFeatureProxy branchFeature;
private final UserSession userSession;
private final PlatformEditionProvider editionProvider;
+ private final MultipleAlmFeatureProvider multipleAlmFeatureProvider;
private final WebAnalyticsLoader webAnalyticsLoader;
public GlobalAction(PageRepository pageRepository, Configuration config, ResourceTypes resourceTypes, Server server,
WebServer webServer, DbClient dbClient, OrganizationFlags organizationFlags,
DefaultOrganizationProvider defaultOrganizationProvider, BranchFeatureProxy branchFeature, UserSession userSession, PlatformEditionProvider editionProvider,
- WebAnalyticsLoader webAnalyticsLoader) {
+ MultipleAlmFeatureProvider multipleAlmFeatureProvider, WebAnalyticsLoader webAnalyticsLoader) {
this.pageRepository = pageRepository;
this.config = config;
this.resourceTypes = resourceTypes;
this.branchFeature = branchFeature;
this.userSession = userSession;
this.editionProvider = editionProvider;
+ this.multipleAlmFeatureProvider = multipleAlmFeatureProvider;
this.webAnalyticsLoader = webAnalyticsLoader;
this.systemSettingValuesByKey = new HashMap<>();
}
writeDatabaseProduction(json);
writeOrganizationSupport(json);
writeBranchSupport(json);
+ writeMultipleAlmEnabled(json);
editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH)));
json.prop("standalone", webServer.isStandalone());
writeWebAnalytics(json);
json.prop("branchesEnabled", branchFeature.isEnabled());
}
+ private void writeMultipleAlmEnabled(JsonWriter json) {
+ json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled());
+ }
+
private void writeWebAnalytics(JsonWriter json) {
webAnalyticsLoader.getUrlPathToJs().ifPresent(p -> json.prop("webAnalyticsJsPath", p));
}
import org.sonar.db.DbClient;
import org.sonar.db.dialect.H2;
import org.sonar.db.dialect.PostgreSql;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
import org.sonar.server.organization.DefaultOrganizationProvider;
import org.sonar.server.organization.TestDefaultOrganizationProvider;
import org.sonar.server.organization.TestOrganizationFlags;
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.fromUuid("foo");
private BranchFeatureRule branchFeature = new BranchFeatureRule();
private PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class);
+ private MultipleAlmFeatureProvider multipleAlmFeatureProvider = mock(MultipleAlmFeatureProvider.class);
private WebAnalyticsLoader webAnalyticsLoader = mock(WebAnalyticsLoader.class);
private WsActionTester ws;
assertJson(call()).isSimilarTo("{\"branchesEnabled\":false}");
}
+ @Test
+ public void multiple_alm_enabled() {
+ init();
+ when(multipleAlmFeatureProvider.enabled()).thenReturn(true);
+ assertJson(call()).isSimilarTo("{\"multipleAlmEnabled\":true}");
+
+ when(multipleAlmFeatureProvider.enabled()).thenReturn(false);
+ assertJson(call()).isSimilarTo("{\"multipleAlmEnabled\":false}");
+
+ }
+
@Test
public void can_admin_on_global_level() {
init();
}});
pageRepository.start();
GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server,
- webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession, editionProvider, webAnalyticsLoader);
+ webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession, editionProvider, multipleAlmFeatureProvider, webAnalyticsLoader);
ws = new WsActionTester(wsAction);
wsAction.start();
}
import org.sonar.core.extension.CoreExtensionsInstaller;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.core.platform.PlatformEditionProvider;
+import org.sonar.server.almsettings.MultipleAlmFeatureProvider;
import org.sonar.server.authentication.AuthenticationModule;
import org.sonar.server.authentication.LogOAuthWarning;
import org.sonar.server.authentication.ws.AuthenticationWsModule;
CoreExtensionBootstraper.class,
CoreExtensionStopper.class,
+ MultipleAlmFeatureProvider.class,
+
// Compute engine (must be after Views and Developer Cockpit)
ReportAnalysisFailureNotificationModule.class,
CeModule.class,