@@ -0,0 +1,48 @@ | |||
/* | |||
* 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; | |||
} | |||
} | |||
} |
@@ -0,0 +1,59 @@ | |||
/* | |||
* 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(); | |||
} | |||
} |
@@ -38,6 +38,7 @@ import org.sonar.core.platform.PlatformEditionProvider; | |||
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; | |||
@@ -80,12 +81,13 @@ public class GlobalAction implements NavigationWsAction, Startable { | |||
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; | |||
@@ -97,6 +99,7 @@ public class GlobalAction implements NavigationWsAction, Startable { | |||
this.branchFeature = branchFeature; | |||
this.userSession = userSession; | |||
this.editionProvider = editionProvider; | |||
this.multipleAlmFeatureProvider = multipleAlmFeatureProvider; | |||
this.webAnalyticsLoader = webAnalyticsLoader; | |||
this.systemSettingValuesByKey = new HashMap<>(); | |||
} | |||
@@ -140,6 +143,7 @@ public class GlobalAction implements NavigationWsAction, Startable { | |||
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); | |||
@@ -202,6 +206,10 @@ public class GlobalAction implements NavigationWsAction, Startable { | |||
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)); | |||
} |
@@ -37,6 +37,7 @@ import org.sonar.core.platform.PluginRepository; | |||
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; | |||
@@ -68,6 +69,7 @@ public class GlobalActionTest { | |||
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; | |||
@@ -239,6 +241,17 @@ public class GlobalActionTest { | |||
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(); | |||
@@ -350,7 +363,7 @@ public class GlobalActionTest { | |||
}}); | |||
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(); | |||
} |
@@ -38,6 +38,7 @@ import org.sonar.core.component.DefaultResourceTypes; | |||
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; | |||
@@ -503,6 +504,8 @@ public class PlatformLevel4 extends PlatformLevel { | |||
CoreExtensionBootstraper.class, | |||
CoreExtensionStopper.class, | |||
MultipleAlmFeatureProvider.class, | |||
// Compute engine (must be after Views and Developer Cockpit) | |||
ReportAnalysisFailureNotificationModule.class, | |||
CeModule.class, |