import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import javax.annotation.Nullable;
private static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir";
private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
private static final String SONAR_PROJECT_PROPERTIES_FILENAME = "sonar-project.properties";
- private static final String PROPERTY_SONAR_HOST_URL = "sonar.host.url";
+ static final String PROPERTY_SONAR_HOST_URL = "sonar.host.url";
private final Cli cli;
private final Logs logger;
return result;
}
- boolean isSonarCloud(@Nullable Properties testProperties) {
- String hostUrl = testProperties != null ? testProperties.getProperty(PROPERTY_SONAR_HOST_URL) : properties().getProperty(PROPERTY_SONAR_HOST_URL);
- if (hostUrl != null) {
- return hostUrl.toLowerCase(Locale.getDefault()).contains("sonarcloud");
- }
-
- return false;
- }
-
private Properties resolve(Properties props) {
PropertyResolver resolver = new PropertyResolver(props, env);
return resolver.resolve();
*/
package org.sonarsource.scanner.cli;
+import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import org.sonarsource.scanner.api.EmbeddedScanner;
private final Exit exit;
private final Cli cli;
private final Conf conf;
- private EmbeddedScanner runner;
- private ScannerFactory runnerFactory;
- private Logs logger;
+ private EmbeddedScanner embeddedScanner;
+ private final ScannerFactory runnerFactory;
+ private final Logs logger;
Main(Exit exit, Cli cli, Conf conf, ScannerFactory runnerFactory, Logs logger) {
this.exit = exit;
checkSkip(p);
configureLogging(p);
init(p);
- runner.start();
- logger.info(String.format("Analyzing on %s", conf.isSonarCloud(null) ? "SonarCloud" : ("SonarQube server " + runner.serverVersion())));
+ embeddedScanner.start();
+ if (isSonarCloud(p)) {
+ logger.info("Analyzing on SonarCloud");
+ } else {
+ String serverVersion = embeddedScanner.serverVersion();
+ logger.info(String.format("Analyzing on SonarQube server %s", serverVersion));
+ }
execute(stats, p);
status = Exit.SUCCESS;
} catch (Throwable e) {
} finally {
exit.exit(status);
}
+ }
+
+ static boolean isSonarCloud(Properties props) {
+ String hostUrl = props.getProperty(Conf.PROPERTY_SONAR_HOST_URL);
+ if (hostUrl != null) {
+ return hostUrl.toLowerCase(Locale.ENGLISH).contains("sonarcloud");
+ }
+ return false;
}
private void checkSkip(Properties properties) {
exit.exit(Exit.SUCCESS);
}
- runner = runnerFactory.create(p, cli.getInvokedFrom());
+ embeddedScanner = runnerFactory.create(p, cli.getInvokedFrom());
}
private void configureLogging(Properties props) {
}
private void execute(Stats stats, Properties p) {
- runner.execute((Map) p);
+ embeddedScanner.execute((Map) p);
displayExecutionResult(stats, "SUCCESS");
}
assertThat(properties.get("sonar.prop")).isEqualTo("expected");
}
- // SQSCANNER-57
- @Test
- public void should_return_true_is_sonar_cloud() {
-
- args.setProperty("sonar.host.url", "https://sonarcloud.io");
-
- conf.properties();
-
- assertThat(conf.isSonarCloud(null)).isTrue();
- }
-
- // SQSCANNER-57
- @Test
- public void should_return_false_is_sonar_cloud() {
- args.setProperty("sonar.host.url", "https://mysonarqube.com:9000/");
-
- //Still returns false, sonarcloud not detected in the content of the url
- Properties properties = conf.properties();
-
- assertThat(properties.getProperty("sonar.host.url")).isEqualTo("https://mysonarqube.com:9000/");
-
- assertThat(conf.isSonarCloud(null)).isFalse();
- }
-
- // SQSCANNER-57
- @Test
- public void should_return_false_is_sonar_cloud_host_is_null() {
-
- Properties emptyProperties = new Properties();
-
- assertThat(emptyProperties.getProperty("sonar.host.url")).isNull();
-
- assertThat(conf.isSonarCloud(emptyProperties)).isFalse();
- }
}
@Test
public void should_log_SonarCloud_server() {
Properties p = new Properties();
+ p.setProperty("sonar.host.url", "https://sonarcloud.io");
when(conf.properties()).thenReturn(p);
- when(conf.isSonarCloud(null)).thenReturn(true);
when(cli.getInvokedFrom()).thenReturn("");
Main main = new Main(exit, cli, conf, scannerFactory, logs);
verify(logs).info("Analyzing on SonarCloud");
}
+ // SQSCANNER-57
+ @Test
+ public void should_return_true_is_sonar_cloud() {
+
+ Properties properties = new Properties();
+ properties.setProperty("sonar.host.url", "https://sonarcloud.io");
+
+ assertThat(Main.isSonarCloud(properties)).isTrue();
+ }
+
+ // SQSCANNER-57
+ @Test
+ public void should_return_false_is_sonar_cloud() {
+ Properties properties = new Properties();
+ properties.setProperty("sonar.host.url", "https://mysonarqube.com:9000/");
+
+ assertThat(Main.isSonarCloud(properties)).isFalse();
+ }
+
+ // SQSCANNER-57
+ @Test
+ public void should_return_false_is_sonar_cloud_host_is_null() {
+ assertThat(Main.isSonarCloud(new Properties())).isFalse();
+ }
+
@Test
public void should_configure_logging() {
Properties analysisProps = testLogging("sonar.verbose", "true");