aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2017-09-11 16:18:34 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-09-15 08:51:08 +0200
commitf76f82c6ef66e60e4986521d141514763e5c405a (patch)
tree87f9aae33bcf56de22a0f1f2306d2a209682d935 /sonar-scanner-engine/src/main/java/org/sonar
parent3078c44cf8dd58238ac05ee39b77dff660a20560 (diff)
downloadsonarqube-f76f82c6ef66e60e4986521d141514763e5c405a.tar.gz
sonarqube-f76f82c6ef66e60e4986521d141514763e5c405a.zip
SONAR-9718 Fail with a clear message when sonar.projectDate is empty
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org/sonar')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java20
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java2
2 files changed, 13 insertions, 9 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java
index c0eed526886..33b8810aa76 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectAnalysisInfo.java
@@ -19,16 +19,14 @@
*/
package org.sonar.scanner;
+import java.time.Clock;
import java.util.Date;
import java.util.Optional;
-
import org.picocontainer.Startable;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.DateUtils;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.System2;
/**
* @since 6.3
@@ -37,15 +35,15 @@ import org.sonar.api.utils.System2;
*/
@ScannerSide
public class ProjectAnalysisInfo implements Startable {
- private final System2 system2;
+ private final Clock clock;
private Configuration settings;
private Date analysisDate;
private String analysisVersion;
- public ProjectAnalysisInfo(Configuration settings, System2 system2) {
+ public ProjectAnalysisInfo(Configuration settings, Clock clock) {
this.settings = settings;
- this.system2 = system2;
+ this.clock = clock;
}
public Date analysisDate() {
@@ -59,15 +57,19 @@ public class ProjectAnalysisInfo implements Startable {
private Date loadAnalysisDate() {
Optional<String> value = settings.get(CoreProperties.PROJECT_DATE_PROPERTY);
if (!value.isPresent()) {
- return new Date(system2.now());
+ return Date.from(clock.instant());
}
- Date date;
try {
// sonar.projectDate may have been specified as a time
return DateUtils.parseDateTime(value.get());
- } catch (SonarException e) {
+ } catch (RuntimeException e) {
// this is probably just a date
+ }
+ try {
+ // sonar.projectDate may have been specified as a date
return DateUtils.parseDate(value.get());
+ } catch (RuntimeException e) {
+ throw new IllegalArgumentException("Illegal value for '" + CoreProperties.PROJECT_DATE_PROPERTY + "'", e);
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
index 94dbe459a7c..54510fc24ce 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalContainer.java
@@ -19,6 +19,7 @@
*/
package org.sonar.scanner.bootstrap;
+import java.time.Clock;
import java.util.List;
import java.util.Map;
import org.sonar.api.Plugin;
@@ -94,6 +95,7 @@ public class GlobalContainer extends ComponentContainer {
UriReader.class,
new FileCacheProvider(),
System2.INSTANCE,
+ Clock.systemDefaultZone(),
new MetricsRepositoryProvider(),
UuidFactoryImpl.INSTANCE);
addIfMissing(ScannerPluginInstaller.class, PluginInstaller.class);