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;
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;
}
.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;
}
}
*/
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;
public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
@Test
public void shouldFindByVersion() {
setupData("shared");
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();
}
}