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;
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;
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;
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());
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));
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 {
}
+ @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();