aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-29 14:54:27 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-07-29 16:57:18 +0200
commitf6f754fc4a291b18ea4c9d183b7a2bfecbe1e2e3 (patch)
treeb114fbd8f8d4c8cb2a5db79c8b24fca4d0a5015a /sonar-scanner-engine
parent92dc9ae705baaabf8e9fba2c27ce7016f97ff304 (diff)
downloadsonarqube-f6f754fc4a291b18ea4c9d183b7a2bfecbe1e2e3.tar.gz
sonarqube-f6f754fc4a291b18ea4c9d183b7a2bfecbe1e2e3.zip
Fix property sonar.core.startTime
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java14
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java6
2 files changed, 5 insertions, 15 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java
index 1862bfbfb23..594c7b5ba31 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/platform/DefaultServer.java
@@ -20,16 +20,14 @@
package org.sonar.scanner.platform;
import java.io.File;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.Server;
+import org.sonar.api.utils.DateUtils;
import org.sonar.scanner.bootstrap.BatchWsClient;
import static org.apache.commons.lang.StringUtils.trimToEmpty;
@@ -58,15 +56,7 @@ public class DefaultServer extends Server {
@Override
public Date getStartedAt() {
String dateString = settings.getString(CoreProperties.SERVER_STARTTIME);
- if (dateString != null) {
- try {
- return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(dateString);
-
- } catch (ParseException e) {
- LoggerFactory.getLogger(getClass()).error("The property " + CoreProperties.SERVER_STARTTIME + " is badly formatted.", e);
- }
- }
- return null;
+ return DateUtils.parseDateTime(dateString);
}
@Override
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
index 2140aab032b..70fe5399662 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/platform/DefaultServerTest.java
@@ -69,12 +69,12 @@ public class DefaultServerTest {
assertThat(metadata.getPublicRootUrl()).isEqualTo("http://foo.com");
}
- @Test
- public void invalidDate() {
+ @Test(expected = RuntimeException.class)
+ public void invalid_startup_date_throws_exception() {
Settings settings = new Settings();
settings.setProperty(CoreProperties.SERVER_STARTTIME, "invalid");
BatchWsClient client = mock(BatchWsClient.class);
DefaultServer metadata = new DefaultServer(settings, client);
- assertThat(metadata.getStartedAt()).isNull();
+ metadata.getStartedAt();
}
}