Browse Source

SCANCLI-130 Set sonar.scanner.bootstrapStartTime

undefined
Claire Villard 1 week ago
parent
commit
e2da1c367c

+ 5
- 0
src/main/java/org/sonarsource/scanner/cli/Conf.java View File

@@ -43,15 +43,18 @@ class Conf {
private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
private static final String SONAR_PROJECT_PROPERTIES_FILENAME = "sonar-project.properties";
static final String PROPERTY_SONAR_HOST_URL = "sonar.host.url";
private static final String BOOTSTRAP_START_TIME = "sonar.scanner.bootstrapStartTime";

private final Cli cli;
private final Logs logger;
private final Map<String, String> env;
private final long startTimeMs;

Conf(Cli cli, Logs logger, Map<String, String> env) {
this.cli = cli;
this.logger = logger;
this.env = env;
this.startTimeMs = System.currentTimeMillis();
}

Properties properties() {
@@ -66,6 +69,8 @@ class Conf {
// root project base directory must be present and be absolute
result.setProperty(PROPERTY_PROJECT_BASEDIR, getRootProjectBaseDir(result).toString());
result.remove(PROJECT_HOME);

result.setProperty(BOOTSTRAP_START_TIME, String.valueOf(startTimeMs));
return result;
}


+ 11
- 0
src/test/java/org/sonarsource/scanner/cli/ConfTest.java View File

@@ -76,6 +76,17 @@ public class ConfTest {
assertThat(conf.properties().getProperty("sonar.projectBaseDir")).isEqualTo(Paths.get("").toAbsolutePath().toString());
}

@Test
public void should_set_bootstrap_time_only_once() {
Properties properties = conf.properties();

assertThat(properties).containsKey("sonar.scanner.bootstrapStartTime");
String value = properties.getProperty("sonar.scanner.bootstrapStartTime");

assertThat(conf.properties())
.containsEntry("sonar.scanner.bootstrapStartTime", value);
}

@Test
public void base_dir_can_be_relative() throws URISyntaxException {
Path projectHome = Paths.get(getClass().getResource("ConfTest/shouldLoadModuleConfiguration/project").toURI());

+ 16
- 3
src/test/java/org/sonarsource/scanner/cli/MainTest.java View File

@@ -299,6 +299,12 @@ public class MainTest {
assertThat(analysisProps.getProperty("sonar.log.level")).isEqualTo("TRACE");
}

@Test
public void should_set_bootstrap_start_time_in_millis() {
Properties analysisProps = execute("sonar.scanner.bootstrapStartTime", "1714137496104");
assertThat(analysisProps.getProperty("sonar.scanner.bootstrapStartTime")).isEqualTo("1714137496104");
}

@Test
public void should_configure_logging_debug() {
Properties analysisProps = testLogging("sonar.log.level", "DEBUG");
@@ -306,17 +312,24 @@ public class MainTest {
}

private Properties testLogging(String propKey, String propValue) {
Properties actualProps = execute(propKey, propValue);

// Logger used for callback should have debug enabled
verify(logs).setDebugEnabled(true);

return actualProps;
}

private Properties execute(String propKey, String propValue) {
Properties p = new Properties();
p.put(propKey, propValue);

when(conf.properties()).thenReturn(p);
when(cli.getInvokedFrom()).thenReturn("");

Main main = new Main(exit, cli, conf, scannerFactory, logs);
main.execute();

// Logger used for callback should have debug enabled
verify(logs).setDebugEnabled(true);

ArgumentCaptor<Properties> propertiesCapture = ArgumentCaptor.forClass(Properties.class);
verify(scanner).execute((Map) propertiesCapture.capture());


Loading…
Cancel
Save