Browse Source

remove some SonarCloud specific code

tags/8.0
Sébastien Lesaint 4 years ago
parent
commit
7cb612b6fb

+ 0
- 5
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DataChange.java View File

@@ -21,7 +21,6 @@ package org.sonar.server.platform.db.migration.step;

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;

@@ -63,10 +62,6 @@ public abstract class DataChange implements MigrationStep {
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;

+ 1
- 18
server/sonar-webserver-webapi/src/main/java/org/sonar/server/notification/ws/DispatchersImpl.java View File

@@ -19,14 +19,8 @@
*/
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;
@@ -34,18 +28,13 @@ import static org.sonar.server.notification.NotificationDispatcherMetadata.PER_P

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
@@ -60,10 +49,8 @@ public class DispatchersImpl implements Dispatchers, Startable {

@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")
@@ -72,10 +59,6 @@ public class DispatchersImpl implements Dispatchers, Startable {
.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

+ 2
- 5
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/ChangeLogLevelActionModule.java View File

@@ -19,23 +19,20 @@
*/
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);

+ 2
- 5
server/sonar-webserver-webapi/src/main/java/org/sonar/server/platform/ws/WebSystemInfoModule.java View File

@@ -42,17 +42,14 @@ import org.sonar.server.platform.monitoring.cluster.ProcessInfoProvider;
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(
@@ -67,7 +64,7 @@ public class WebSystemInfoModule extends Module {
InfoAction.class

);
if (standalone || sonarcloud) {
if (standalone) {
add(
EsStateSection.class,
StandaloneSystemSection.class,

+ 1
- 22
server/sonar-webserver-webapi/src/test/java/org/sonar/server/notification/ws/DispatchersImplTest.java View File

@@ -20,7 +20,6 @@
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;
@@ -50,9 +49,7 @@ public class DispatchersImplTest {
},
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() {
@@ -62,15 +59,6 @@ public class DispatchersImplTest {
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();
@@ -79,13 +67,4 @@ public class DispatchersImplTest {
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);
}
}

+ 3
- 39
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/ChangeLogLevelActionModuleTest.java View File

@@ -19,15 +19,9 @@
*/
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;

@@ -36,19 +30,13 @@ import static org.mockito.Mockito.mock;
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);
@@ -62,23 +50,8 @@ public class ChangeLogLevelActionModuleTest {
}

@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);
@@ -95,13 +68,4 @@ public class ChangeLogLevelActionModuleTest {
.doesNotContain(ChangeLogLevelClusterService.class);
}

@DataProvider
public static Object[][] notOnSonarCloud() {
return new Object[][] {
{null},
{false}
};
}


}

+ 3
- 37
server/sonar-webserver-webapi/src/test/java/org/sonar/server/platform/ws/WebSystemInfoModuleTest.java View File

@@ -19,15 +19,9 @@
*/
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;

@@ -36,19 +30,13 @@ import static org.mockito.Mockito.mock;
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);
@@ -59,23 +47,8 @@ public class WebSystemInfoModuleTest {
}

@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);
@@ -89,11 +62,4 @@ public class WebSystemInfoModuleTest {
.hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 12);
}

@DataProvider
public static Object[][] notOnSonarCloud() {
return new Object[][] {
{null},
{false}
};
}
}

Loading…
Cancel
Save