import java.sql.Connection;
import java.sql.SQLException;
-import org.sonar.api.config.Configuration;
import org.sonar.db.Database;
import org.sonar.db.dialect.Dialect;
return res;
}
- protected static boolean isSonarCloud(Configuration configuration) {
- return configuration.getBoolean("sonar.sonarcloud.enabled").orElse(false);
- }
-
public static class Context {
private final Database db;
private final Connection readConnection;
*/
package org.sonar.server.notification.ws;
-import com.google.common.collect.ImmutableSet;
import java.util.List;
-import java.util.Set;
-import java.util.function.Predicate;
import org.sonar.api.Startable;
-import org.sonar.api.config.Configuration;
-import org.sonar.process.ProcessProperties;
-import org.sonar.server.qualitygate.notification.QGChangeNotificationHandler;
import static org.sonar.core.util.stream.MoreCollectors.toList;
import static org.sonar.server.notification.NotificationDispatcherMetadata.GLOBAL_NOTIFICATION;
public class DispatchersImpl implements Dispatchers, Startable {
- private static final Set<String> GLOBAL_DISPATCHERS_TO_IGNORE_ON_SONAR_CLOUD = ImmutableSet.of(
- QGChangeNotificationHandler.KEY);
-
private final NotificationCenter notificationCenter;
- private final Configuration configuration;
private List<String> projectDispatchers;
private List<String> globalDispatchers;
- public DispatchersImpl(NotificationCenter notificationCenter, Configuration configuration) {
+ public DispatchersImpl(NotificationCenter notificationCenter) {
this.notificationCenter = notificationCenter;
- this.configuration = configuration;
}
@Override
@Override
public void start() {
- boolean isOnSonarCloud = configuration.getBoolean(ProcessProperties.Property.SONARCLOUD_ENABLED.getKey()).orElse(false);
this.globalDispatchers = notificationCenter.getDispatcherKeysForProperty(GLOBAL_NOTIFICATION, "true")
.stream()
- .filter(filterDispatcherForSonarCloud(isOnSonarCloud))
.sorted()
.collect(toList());
this.projectDispatchers = notificationCenter.getDispatcherKeysForProperty(PER_PROJECT_NOTIFICATION, "true")
.collect(toList());
}
- private static Predicate<String> filterDispatcherForSonarCloud(boolean isOnSonarCloud) {
- return dispatcher -> !(isOnSonarCloud && GLOBAL_DISPATCHERS_TO_IGNORE_ON_SONAR_CLOUD.contains(dispatcher));
- }
-
@Override
public void stop() {
// nothing to do
*/
package org.sonar.server.platform.ws;
-import org.sonar.api.config.Configuration;
import org.sonar.core.platform.Module;
import org.sonar.server.platform.WebServer;
public class ChangeLogLevelActionModule extends Module {
private final WebServer webServer;
- private final Configuration configuration;
- public ChangeLogLevelActionModule(WebServer webServer, Configuration configuration) {
+ public ChangeLogLevelActionModule(WebServer webServer) {
this.webServer = webServer;
- this.configuration = configuration;
}
@Override
protected void configureModule() {
add(ChangeLogLevelAction.class);
- if (configuration.getBoolean("sonar.sonarcloud.enabled").orElse(false) || webServer.isStandalone()) {
+ if (webServer.isStandalone()) {
add(ChangeLogLevelStandaloneService.class);
} else {
add(ChangeLogLevelClusterService.class);
import org.sonar.server.platform.monitoring.cluster.SearchNodesInfoLoaderImpl;
public class WebSystemInfoModule extends Module {
- private final Configuration configuration;
private final WebServer webServer;
- public WebSystemInfoModule(Configuration configuration, WebServer webServer) {
- this.configuration = configuration;
+ public WebSystemInfoModule(WebServer webServer) {
this.webServer = webServer;
}
@Override
protected void configureModule() {
- boolean sonarcloud = configuration.getBoolean("sonar.sonarcloud.enabled").orElse(false);
boolean standalone = webServer.isStandalone();
add(
InfoAction.class
);
- if (standalone || sonarcloud) {
+ if (standalone) {
add(
EsStateSection.class,
StandaloneSystemSection.class,
package org.sonar.server.notification.ws;
import org.junit.Test;
-import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.notifications.NotificationChannel;
import org.sonar.server.issue.notification.FPOrWontFixNotificationHandler;
import org.sonar.server.issue.notification.MyNewIssuesNotificationHandler;
},
new NotificationChannel[] {});
- private final MapSettings settings = new MapSettings();
-
- private DispatchersImpl underTest = new DispatchersImpl(notificationCenter, settings.asConfig());
+ private DispatchersImpl underTest = new DispatchersImpl(notificationCenter);
@Test
public void get_sorted_global_dispatchers() {
QGChangeNotificationHandler.KEY, MyNewIssuesNotificationHandler.KEY);
}
- @Test
- public void get_global_dispatchers_on_sonarcloud() {
- settings.setProperty("sonar.sonarcloud.enabled", "true");
-
- underTest.start();
-
- assertThat(underTest.getGlobalDispatchers()).containsOnly(MyNewIssuesNotificationHandler.KEY);
- }
-
@Test
public void get_sorted_project_dispatchers() {
underTest.start();
QGChangeNotificationHandler.KEY, FPOrWontFixNotificationHandler.KEY, MyNewIssuesNotificationHandler.KEY);
}
- @Test
- public void get_project_dispatchers_on_sonarcloud() {
- settings.setProperty("sonar.sonarcloud.enabled", "true");
-
- underTest.start();
-
- assertThat(underTest.getProjectDispatchers()).containsOnly(
- MyNewIssuesNotificationHandler.KEY, QGChangeNotificationHandler.KEY, FPOrWontFixNotificationHandler.KEY);
- }
}
*/
package org.sonar.server.platform.ws;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Collection;
-import javax.annotation.Nullable;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.picocontainer.ComponentAdapter;
-import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.server.platform.WebServer;
import static org.mockito.Mockito.when;
import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER;
-@RunWith(DataProviderRunner.class)
public class ChangeLogLevelActionModuleTest {
private WebServer webServer = mock(WebServer.class);
- private MapSettings settings = new MapSettings();
- private ChangeLogLevelActionModule underTest = new ChangeLogLevelActionModule(webServer, settings.asConfig());
+ private ChangeLogLevelActionModule underTest = new ChangeLogLevelActionModule(webServer);
@Test
- @UseDataProvider("notOnSonarCloud")
- public void provide_returns_ChangeLogLevelClusterService_if_cluster_not_on_SonarCloud(@Nullable Boolean sonarcloudOrNot) {
+ public void provide_returns_ChangeLogLevelClusterService_if_cluster_not_on_SonarCloud() {
when(webServer.isStandalone()).thenReturn(false);
- if (sonarcloudOrNot != null) {
- settings.setProperty("sonar.sonarcloud.enabled", sonarcloudOrNot);
- }
ComponentContainer container = new ComponentContainer();
underTest.configure(container);
}
@Test
- public void provide_returns_ChangeLogLevelStandaloneService_on_SonarCloud() {
- when(webServer.isStandalone()).thenReturn(false);
- settings.setProperty("sonar.sonarcloud.enabled", true);
- ComponentContainer container = new ComponentContainer();
-
- underTest.configure(container);
-
- verifyInStandaloneSQ(container);
- }
-
- @Test
- @UseDataProvider("notOnSonarCloud")
- public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone(@Nullable Boolean sonarcloudOrNot) {
+ public void provide_returns_ChangeLogLevelStandaloneService_if_SQ_standalone() {
when(webServer.isStandalone()).thenReturn(true);
- if (sonarcloudOrNot != null) {
- settings.setProperty("sonar.sonarcloud.enabled", sonarcloudOrNot);
- }
ComponentContainer container = new ComponentContainer();
underTest.configure(container);
.doesNotContain(ChangeLogLevelClusterService.class);
}
- @DataProvider
- public static Object[][] notOnSonarCloud() {
- return new Object[][] {
- {null},
- {false}
- };
- }
-
-
}
*/
package org.sonar.server.platform.ws;
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Collection;
-import javax.annotation.Nullable;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.picocontainer.ComponentAdapter;
-import org.sonar.api.config.internal.MapSettings;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.server.platform.WebServer;
import static org.mockito.Mockito.when;
import static org.sonar.core.platform.ComponentContainer.COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER;
-@RunWith(DataProviderRunner.class)
public class WebSystemInfoModuleTest {
private WebServer webServer = mock(WebServer.class);
- private MapSettings settings = new MapSettings();
- private WebSystemInfoModule underTest = new WebSystemInfoModule(settings.asConfig(), webServer);
+ private WebSystemInfoModule underTest = new WebSystemInfoModule(webServer);
@Test
- @UseDataProvider("notOnSonarCloud")
- public void verify_system_info_configuration_in_cluster_mode(@Nullable Boolean notOnSonarCloud) {
+ public void verify_system_info_configuration_in_cluster_mode() {
when(webServer.isStandalone()).thenReturn(false);
- if (notOnSonarCloud != null) {
- settings.setProperty("sonar.sonarcloud.enabled", notOnSonarCloud);
- }
ComponentContainer container = new ComponentContainer();
underTest.configure(container);
}
@Test
- @UseDataProvider("notOnSonarCloud")
- public void verify_system_info_configuration_in_standalone_mode(@Nullable Boolean notOnSonarCloud) {
+ public void verify_system_info_configuration_in_standalone_mode() {
when(webServer.isStandalone()).thenReturn(true);
- if (notOnSonarCloud != null) {
- settings.setProperty("sonar.sonarcloud.enabled", notOnSonarCloud);
- }
- ComponentContainer container = new ComponentContainer();
-
- underTest.configure(container);
-
- verifyConfigurationStandaloneSQ(container);
- }
-
- @Test
- public void verify_system_info_configuration_on_SonarCloud() {
- when(webServer.isStandalone()).thenReturn(false);
- settings.setProperty("sonar.sonarcloud.enabled", true);
ComponentContainer container = new ComponentContainer();
underTest.configure(container);
.hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12);
}
- @DataProvider
- public static Object[][] notOnSonarCloud() {
- return new Object[][] {
- {null},
- {false}
- };
- }
}