aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-30 11:06:08 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-05-30 11:06:08 +0200
commitf0ab4532da5784d44f110240aadbf049cf588bcb (patch)
tree4922be24379fa69ea16e2c132971f0cca637efdb /sonar-batch
parent07d0afa82869f5757ceeff4393d9daf1a819e0ae (diff)
downloadsonarqube-f0ab4532da5784d44f110240aadbf049cf588bcb.tar.gz
sonarqube-f0ab4532da5784d44f110240aadbf049cf588bcb.zip
SONAR-4334 Add date of the latest snapshot in the error message displayed to user
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java24
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java4
2 files changed, 13 insertions, 15 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 d5caa5bde19..40d12a7fd28 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java
@@ -30,6 +30,7 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.SonarException;
import java.util.Date;
@@ -67,7 +68,7 @@ public class ProjectConfigurator implements BatchComponent {
public ProjectConfigurator configure(Project project) {
Date analysisDate = loadAnalysisDate();
- checkCurrentAnalyisIsTheLatestOne(project, analysisDate);
+ checkCurrentAnalyisIsTheLatestOne(project.getKey(), analysisDate);
project
.setConfiguration(new PropertiesConfiguration()) // will be populated by ProjectSettings
@@ -77,22 +78,19 @@ public class ProjectConfigurator implements BatchComponent {
return this;
}
- private void checkCurrentAnalyisIsTheLatestOne(Project project, Date analysisDate) {
- if (!isLatestAnalysis(project.getKey(), analysisDate)) {
- throw new IllegalArgumentException(
- "The value '" + settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "' of the sonar.projectDate property " +
- "can't be older than the date of last known quality snapshot " +
- "on this project. This property must only be used to rebuild the past in a chronological order.");
- }
- }
-
- boolean isLatestAnalysis(String projectKey, Date analysisDate) {
+ private void checkCurrentAnalyisIsTheLatestOne(String projectKey, Date analysisDate) {
ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true);
if (persistedProject != null) {
Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
- return lastSnapshot == null || lastSnapshot.getCreatedAt().before(analysisDate);
+ Date lastSnapshotCreationDate = lastSnapshot.getCreatedAt();
+ if (lastSnapshot != null && !lastSnapshotCreationDate.before(analysisDate)) {
+ throw new IllegalArgumentException(
+ "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '"+ settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
+ "Latest quality snapshot: '"+ DateUtils.formatDate(lastSnapshotCreationDate) +"'. This property may only be used to rebuild the past in a chronological order."
+ );
+ }
}
- return true;
+
}
Date loadAnalysisDate() {
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 ce13c0b7177..9ac9408c8bd 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java
@@ -154,8 +154,8 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase {
new ProjectConfigurator(getSession(), configuration).configure(project);
fail();
} catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The value '2005-12-25' of the sonar.projectDate property can't be older than the date " +
- "of last known quality snapshot on this project. This property must only be used to rebuild the past in a chronological order.");
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. " +
+ "Value: '2005-12-25'. Latest quality snapshot: '2010-12-02'. This property may only be used to rebuild the past in a chronological order.");
}
}