Skip to content

Commit 8cb2402

Browse files
committed
SCANJLIB-215 Analysis should default to SonarCloud
1 parent becf21f commit 8cb2402

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

lib/src/main/java/org/sonarsource/scanner/lib/EmbeddedScanner.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
* @since 2.2
4242
*/
4343
public class EmbeddedScanner {
44-
private static final String BITBUCKET_CLOUD_ENV_VAR = "BITBUCKET_BUILD_NUMBER";
4544
private static final String SONAR_HOST_URL_ENV_VAR = "SONAR_HOST_URL";
4645
private static final String SONARCLOUD_HOST = "https://sonarcloud.io";
4746
private final IsolatedLauncherFactory launcherFactory;
@@ -131,14 +130,15 @@ private void initBootstrapDefaultValues() {
131130
String sonarHostUrl = system.getEnvironmentVariable(SONAR_HOST_URL_ENV_VAR);
132131
if (sonarHostUrl != null) {
133132
setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, sonarHostUrl);
134-
} else if (system.getEnvironmentVariable(BITBUCKET_CLOUD_ENV_VAR) != null) {
135-
setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, SONARCLOUD_HOST);
136-
logger.info("Bitbucket Cloud Pipelines detected, no host variable set. Defaulting to sonarcloud.io.");
137133
} else {
138-
setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, "http://localhost:9000");
134+
setBootstrapPropertyIfNotAlreadySet(ScannerProperties.HOST_URL, getSonarCloudUrl());
139135
}
140136
}
141137

138+
private String getSonarCloudUrl() {
139+
return bootstrapProperties.getOrDefault("sonar.scanner.sonarcloudUrl", SONARCLOUD_HOST);
140+
}
141+
142142
private void initAnalysisProperties(Map<String, String> p) {
143143
initSourceEncoding(p);
144144
new Dirs(logger).init(p);

lib/src/test/java/org/sonarsource/scanner/lib/EmbeddedScannerTest.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,19 @@ public void test_app() {
9999
}
100100

101101
@Test
102-
public void should_set_localhost_as_host_by_default() {
103-
scanner.start();
104-
105-
assertThat(scanner.getBootstrapProperty("sonar.host.url", null)).isEqualTo("http://localhost:9000");
106-
}
107-
108-
@Test
109-
public void should_set_sonarcloud_as_host_if_executed_from_bitbucket_cloud_and_no_host_env() {
110-
when(system.getEnvironmentVariable("BITBUCKET_BUILD_NUMBER")).thenReturn("123");
111-
102+
public void should_set_sonarcloud_as_host_by_default() {
112103
scanner.start();
113104

114105
assertThat(scanner.getBootstrapProperty("sonar.host.url", null)).isEqualTo("https://sonarcloud.io");
115106
}
116107

117108
@Test
118-
public void should_set_url_from_env_as_host_if_host_env_var_provided_even_on_bitbucket_cloud() {
119-
when(system.getEnvironmentVariable("BITBUCKET_BUILD_NUMBER")).thenReturn("123");
120-
when(system.getEnvironmentVariable("SONAR_HOST_URL")).thenReturn("http://from-env.org:9000");
109+
public void should_use_sonarcloud_url_from_property() {
110+
scanner
111+
.setBootstrapProperty("sonar.scanner.sonarcloudUrl", "https://preprod.sonarcloud.io")
112+
.start();
121113

122-
scanner.start();
123-
124-
assertThat(scanner.getBootstrapProperty("sonar.host.url", null)).isEqualTo("http://from-env.org:9000");
114+
assertThat(scanner.getBootstrapProperty("sonar.host.url", null)).isEqualTo("https://preprod.sonarcloud.io");
125115
}
126116

127117
@Test

0 commit comments

Comments
 (0)