aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-10-25 12:17:39 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-10-25 12:20:00 +0200
commit053e6b05a29382c8256d9ac22f09a7edc53c3307 (patch)
tree22d61aaace4284b276de565a51c8401e71f1f15d /sonar-batch
parentba361714c6dbc63d1cf78976cae41b43aa21c368 (diff)
downloadsonarqube-053e6b05a29382c8256d9ac22f09a7edc53c3307.tar.gz
sonarqube-053e6b05a29382c8256d9ac22f09a7edc53c3307.zip
SONAR-801 Events on Dashboard confused for same project dates
It is now possible to specify 'sonar.projectDate' as a standard ISO time. (ex. "2011-10-25T10:45:42+0100")
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java10
2 files changed, 22 insertions, 4 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
index ed9db7d9e05..06ce83b81de 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch;
+import java.util.Date;
+
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.project.MavenProject;
@@ -31,8 +33,7 @@ import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
-
-import java.util.Date;
+import org.sonar.api.utils.SonarException;
public class ProjectConfigurator implements BatchComponent {
@@ -50,7 +51,7 @@ public class ProjectConfigurator implements BatchComponent {
// For backward compatibility we must set POM and actual packaging
project.setDescription(StringUtils.defaultString(definition.getDescription()));
project.setPackaging("jar");
-
+
for (Object component : definition.getContainerExtensions()) {
if (component instanceof MavenProject) {
MavenProject pom = (MavenProject) component;
@@ -96,7 +97,14 @@ public class ProjectConfigurator implements BatchComponent {
}
Date loadAnalysisDate() {
- Date date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY);
+ Date date = null;
+ try {
+ // sonar.projectDate may have been specified as a time
+ date = settings.getDateTime(CoreProperties.PROJECT_DATE_PROPERTY);
+ } catch (SonarException e) {
+ // this is probably just a date
+ date = settings.getDate(CoreProperties.PROJECT_DATE_PROPERTY);
+ }
if (date == null) {
date = new Date();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
index 4d2903e1e0a..3d556413ee8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
@@ -111,6 +111,16 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
assertEquals("30012005", new SimpleDateFormat("ddMMyyyy").format(project.getAnalysisDate()));
}
+ @Test
+ public void analysisTimestampCouldBeExplicitlySet() {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2005-01-30T08:45:10+0000");
+ Project project = new Project("key");
+ new ProjectConfigurator(getSession(), settings).configure(project);
+
+ assertEquals("30012005-4510", new SimpleDateFormat("ddMMyyyy-mmss").format(project.getAnalysisDate()));
+ }
+
@Test(expected = RuntimeException.class)
public void failIfAnalyisDateIsNotValid() {
Settings configuration = new Settings();