]> source.dussan.org Git - sonarqube.git/commitdiff
Revert SONAR-3407
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 31 May 2012 13:26:39 +0000 (15:26 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 31 May 2012 14:26:59 +0000 (16:26 +0200)
sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinder.java
sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByVersionTest.java

index f29752a07de79ac7c7426cd8fe7f281bfa0fcd90..2734e1650777ffd3ee7192341a562dd70fb63be2 100644 (file)
@@ -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;
   }
index 28f2fa81db3f643672d932e9ed5975376510d7cb..850171231180707ae88e9c3de8b36f32c6e326f9 100644 (file)
@@ -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;
   }
 
 }
index 9761c2f06a3017060d2153db3e632b6a15b32af5..3b8b61236ad6c3d8b50f061d57dc30f6c0bd3d9a 100644 (file)
@@ -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();
   }
 }