From b6c0e733080d9f53516bc865b1179da360499dca Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 31 May 2012 15:26:39 +0200 Subject: [PATCH] Revert SONAR-3407 --- .../batch/components/PastSnapshotFinder.java | 4 ++-- .../components/PastSnapshotFinderByVersion.java | 11 +++++++---- .../PastSnapshotFinderByVersionTest.java | 17 +++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java index f29752a07de..2734e165077 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java @@ -21,10 +21,10 @@ package org.sonar.batch.components; import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.StringUtils; +import org.slf4j.LoggerFactory; import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.utils.Logs; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -52,7 +52,7 @@ public class PastSnapshotFinder implements BatchExtension { String propertyValue = getPropertyValue(conf, index); PastSnapshot pastSnapshot = find(projectSnapshot, index, propertyValue); if (pastSnapshot == null && StringUtils.isNotBlank(propertyValue)) { - Logs.INFO.debug("The property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " has an unvalid value: " + propertyValue); + LoggerFactory.getLogger(PastSnapshotFinder.class).debug("Property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue); } return pastSnapshot; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java index 28f2fa81db3..85017123118 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java @@ -46,12 +46,15 @@ public class PastSnapshotFinderByVersion implements BatchExtension { .setMaxResults(1) .getResultList(); + PastSnapshot result; if (snapshots.isEmpty()) { - throw new IllegalStateException("Unknown project version: " + version +". Please check differential views in project settings."); + result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION); + } else { + Snapshot snapshot = snapshots.get(0); + Date targetDate = snapshot.getCreatedAt(); + result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version); } - Snapshot snapshot = snapshots.get(0); - Date targetDate = snapshot.getCreatedAt(); - return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version); + return result; } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java index 9761c2f06a3..3b8b61236ad 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java @@ -19,9 +19,7 @@ */ package org.sonar.batch.components; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.database.model.Snapshot; import org.sonar.jpa.test.AbstractDbUnitTestCase; @@ -29,9 +27,6 @@ import static org.fest.assertions.Assertions.assertThat; public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void shouldFindByVersion() { setupData("shared"); @@ -42,16 +37,18 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase { assertThat(finder.findByVersion(currentProjectSnapshot, "1.1").getProjectSnapshotId()).isEqualTo(1009); } + /** + * Revert SONAR-3407 + */ @Test - public void failIfUnknownVersion() { - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Unknown project version: 0.1.2"); - + public void doNotFailIfUnknownVersion() { setupData("shared"); Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010); PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(getSession()); - finder.findByVersion(currentProjectSnapshot, "0.1.2"); + PastSnapshot pastSnapshot = finder.findByVersion(currentProjectSnapshot, "0.1.2"); + assertThat(pastSnapshot).isNotNull(); + assertThat(pastSnapshot.getDate()).isNull(); } } -- 2.39.5