import java.util.List;
import java.util.Map;
+
import org.sonar.api.Plugin;
import org.sonar.api.internal.SonarQubeVersionFactory;
import org.sonar.api.utils.System2;
import org.sonar.api.utils.UriReader;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.index.CachesManager;
import org.sonar.batch.platform.DefaultServer;
import org.sonar.batch.repository.DefaultGlobalRepositoriesLoader;
import org.sonar.core.util.UuidFactoryImpl;
public class GlobalContainer extends ComponentContainer {
-
+ private static final Logger LOG = Loggers.get(GlobalContainer.class);
private final Map<String, String> bootstrapProperties;
private GlobalContainer(Map<String, String> bootstrapProperties) {
}
public void executeTask(Map<String, String> taskProperties, Object... components) {
+ long startTime = System.currentTimeMillis();
new TaskContainer(this, taskProperties, components).execute();
+
+ LOG.info("Task total time: {}", formatTime(System.currentTimeMillis() - startTime));
+ }
+
+ static String formatTime(long time) {
+ long h = time / (60 * 60 * 1000);
+ long m = (time - h * 60 * 60 * 1000) / (60 * 1000);
+ long s = (time - h * 60 * 60 * 1000 - m * 60 * 1000) / 1000;
+ long ms = time % 1000;
+ final String format;
+ if (h > 0) {
+ format = "%1$d:%2$02d:%3$02d.%4$03ds";
+ } else if (m > 0) {
+ format = "%2$d:%3$02d.%4$03ds";
+ } else {
+ format = "%3$d.%4$03ds";
+ }
+ return String.format(format, h, m, s, ms);
}
}
assertThat(container.getComponentByType(Bar.class)).isNotNull();
}
+ @Test
+ public void shouldFormatTime() {
+ assertThat(GlobalContainer.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
+ assertThat(GlobalContainer.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
+ assertThat(GlobalContainer.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
+ assertThat(GlobalContainer.formatTime(400)).isEqualTo("0.400s");
+ }
+
@BatchSide
public static class Foo {