From 5c8261d9e7167fff843a1829589863c13f908217 Mon Sep 17 00:00:00 2001 From: klaudio-sinani-sonarsource <92299827+klaudio-sinani-sonarsource@users.noreply.github.com> Date: Tue, 26 Oct 2021 16:36:50 +0200 Subject: [PATCH] SONAR-15567 Add new `projectImportFeatureEnabled` feature flag (#4891) * SONAR-15567 Introduce new `projectImportFeatureEnabled` feature flag * SONAR-15567 Add test cases for new `projectImportFeatureEnabled` feature flag * SONAR-15567 Update API example payload for `api/navigation/global` * SONAR-15567 Minor fix on order of imports * SONAR-15567 Remove new line characters --- .../org/sonar/server/ui/ws/GlobalAction.java | 11 ++++++++ .../sonar/server/ui/ws/global-example.json | 1 + .../sonar/server/ui/ws/GlobalActionTest.java | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java index 28ed4f35898..32ff442e996 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/GlobalAction.java @@ -20,6 +20,7 @@ package org.sonar.server.ui.ws; import com.google.common.collect.ImmutableSet; +import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -34,6 +35,7 @@ import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService.NewController; import org.sonar.api.utils.text.JsonWriter; import org.sonar.api.web.page.Page; +import org.sonar.core.platform.EditionProvider; import org.sonar.core.platform.PlatformEditionProvider; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -54,6 +56,8 @@ import static org.sonar.core.config.WebConstants.SONAR_LF_ENABLE_GRAVATAR; import static org.sonar.core.config.WebConstants.SONAR_LF_GRAVATAR_SERVER_URL; import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_URL; import static org.sonar.core.config.WebConstants.SONAR_LF_LOGO_WIDTH_PX; +import static org.sonar.core.platform.EditionProvider.Edition.DATACENTER; +import static org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE; import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_ENABLED; import static org.sonar.process.ProcessProperties.Property.SONARCLOUD_HOMEPAGE_URL; import static org.sonar.process.ProcessProperties.Property.SONAR_ANALYTICS_GTM_TRACKING_ID; @@ -146,6 +150,7 @@ public class GlobalAction implements NavigationWsAction, Startable { writeBranchSupport(json); writeInstanceUsesDefaultAdminCredentials(json); writeMultipleAlmEnabled(json); + writeProjectImportFeature(json); editionProvider.get().ifPresent(e -> json.prop("edition", e.name().toLowerCase(Locale.ENGLISH))); writeNeedIssueSync(json); json.prop("standalone", webServer.isStandalone()); @@ -212,6 +217,12 @@ public class GlobalAction implements NavigationWsAction, Startable { json.prop("multipleAlmEnabled", multipleAlmFeatureProvider.enabled()); } + private void writeProjectImportFeature(JsonWriter json) { + EditionProvider.Edition edition = editionProvider.get().orElse(null); + boolean isEnabled = Arrays.asList(ENTERPRISE, DATACENTER).contains(edition); + json.prop("projectImportFeatureEnabled", isEnabled); + } + private void writeNeedIssueSync(JsonWriter json) { try (DbSession dbSession = dbClient.openSession(false)) { json.prop("needIssueSync", issueIndexSyncChecker.isIssueSyncInProgress(dbSession)); diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json index 700eee264bc..7a110f13d78 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/ui/ws/global-example.json @@ -26,6 +26,7 @@ "version": "6.2", "productionDatabase": true, "branchesEnabled": false, + "projectImportFeatureEnabled": false, "canAdmin": false, "standalone": true, "edition": "community" diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java index 7acb72b8df3..6f350accf9f 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/GlobalActionTest.java @@ -48,10 +48,12 @@ import org.sonar.server.ws.WsActionTester; import org.sonar.updatecenter.common.Version; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.optional; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.sonar.core.platform.EditionProvider.Edition.*; import static org.sonar.test.JsonAssert.assertJson; public class GlobalActionTest { @@ -254,6 +256,29 @@ public class GlobalActionTest { } + @Test + public void project_import_feature_enabled_ee_dce() { + init(); + when(editionProvider.get()).thenReturn(Optional.of(ENTERPRISE)); + assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}"); + + when(editionProvider.get()).thenReturn(Optional.of(DATACENTER)); + assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":true}"); + } + + @Test + public void project_import_feature_disabled_ce_de() { + init(); + when(editionProvider.get()).thenReturn(Optional.of(COMMUNITY)); + assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); + + when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER)); + assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); + + when(editionProvider.get()).thenReturn(Optional.empty()); + assertJson(call()).isSimilarTo("{\"projectImportFeatureEnabled\":false}"); + } + @Test public void return_need_issue_sync() { init(); -- 2.39.5