]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5047 Calculation of new_coverage measures on delta since X days and since Date...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 17:54:32 +0000 (18:54 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 5 Feb 2014 17:54:32 +0000 (18:54 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java
sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java
sonar-batch/src/main/java/org/sonar/batch/components/Period.java
sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java

index a5677b6a55c2b9ac479fa04fa56c2e53f18f42cc..ee9b2e1d97ff74ad1381927a928b8030c3f11ce6 100644 (file)
@@ -52,7 +52,7 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
   public AbstractNewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration) {
     structs = Lists.newArrayList();
     for (Period period : timeMachineConfiguration.periods()) {
-      structs.add(new PeriodStruct(period.getIndex(), period.getTargetDate()));
+      structs.add(new PeriodStruct(period.getIndex(), period.getDate()));
     }
   }
 
index 12db0e0bd17ef0cd8d3147414cfc51276dd55e66..d51c224564f46c88e354912e72a315eb6661afed 100644 (file)
@@ -95,7 +95,7 @@ public class CountUnresolvedIssuesDecoratorTest {
     sameSecond = DateUtils.truncate(rightNow, Calendar.SECOND);
 
     timeMachineConfiguration = mock(TimeMachineConfiguration.class);
-    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, fiveDaysAgo, afterFiveDaysAgo), new Period(2, tenDaysAgo, afterTenDaysAgo)));
+    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, afterFiveDaysAgo), new Period(2, afterTenDaysAgo)));
 
     project = mock(Project.class);
     resource = mock(Resource.class);
index 7880c222538d6a5f926d549b959cb8e8a981605f..2dfc4b3df366ea257a7c7c5906085976421f3e3e 100644 (file)
@@ -97,7 +97,7 @@ public class NewTechnicalDebtDecoratorTest {
     fiveDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -5);
     fourDaysAgo = org.apache.commons.lang.time.DateUtils.addDays(rightNow, -4);
 
-    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, fiveDaysAgo, fiveDaysAgo), new Period(2, tenDaysAgo, tenDaysAgo)));
+    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, fiveDaysAgo), new Period(2, tenDaysAgo)));
 
     decorator = new NewTechnicalDebtDecorator(perspectives, timeMachineConfiguration, technicalDebtConverter);
   }
@@ -179,7 +179,7 @@ public class NewTechnicalDebtDecoratorTest {
 
   @Test
   public void save_on_one_issue_with_changelog_and_periods_have_no_dates() {
-    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, null, null), new Period(2, null, null)));
+    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, null), new Period(2, null)));
 
     Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setTechnicalDebt(fiveDaysDebt).setChanges(
       newArrayList(
@@ -262,7 +262,7 @@ public class NewTechnicalDebtDecoratorTest {
 
   @Test
   public void save_on_one_issue_without_changelog_and_periods_have_no_dates() {
-    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, null, null), new Period(2, null, null)));
+    when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, null), new Period(2, null)));
 
     when(issuable.issues()).thenReturn(newArrayList(
       (Issue) new DefaultIssue().setKey("A").setCreationDate(nineDaysAgo).setTechnicalDebt(fiveDaysDebt))
index 51bd4d2f50f3aa27c9c35382baecacc743fa7376..91285fff70a2f2ab2f6daa4eaa05a0b3280b5ae2 100644 (file)
@@ -103,10 +103,17 @@ public class PastSnapshot {
     return projectSnapshot != null ? projectSnapshot.getQualifier() : null;
   }
 
-  public Date getTargetDate() {
+  private Date getTargetDate() {
     return targetDate;
   }
 
+  public PastSnapshot clone(){
+    PastSnapshot clone = new PastSnapshot(mode, targetDate, projectSnapshot);
+    clone.setIndex(index);
+    clone.setModeParameter(modeParameter);
+    return clone;
+  }
+
   @Override
   public String toString() {
     if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_VERSION)) {
index a152ffae00d720566e6dbed43ccca6abe4850049..a08a1a872fe577e6b3828ae06b2695b3da9db715 100644 (file)
@@ -28,12 +28,10 @@ import java.util.Date;
 public class Period {
 
   private int index;
-  private Date targetDate;
   private Date date;
 
-  public Period(int index, Date targetDate, @Nullable Date date) {
+  public Period(int index, @Nullable Date date) {
     this.index = index;
-    this.targetDate = targetDate;
     this.date = date;
   }
 
@@ -41,10 +39,6 @@ public class Period {
     return index;
   }
 
-  public Date getTargetDate() {
-    return targetDate;
-  }
-
   @CheckForNull
   public Date getDate() {
     return date;
index cae6da082c9895e7b545b653fceec17292fea486..23e33c5521f84ce9160285a564e012925e852999 100644 (file)
@@ -58,12 +58,10 @@ public class TimeMachineConfiguration implements BatchExtension {
     for (PastSnapshot projectPastSnapshot : periodsDefinition.getRootProjectPastSnapshots()) {
       Snapshot snapshot = findSnapshot(projectPastSnapshot.getProjectSnapshot());
 
-      PastSnapshot pastSnapshot = new PastSnapshot(projectPastSnapshot.getMode(), projectPastSnapshot.getTargetDate(), projectPastSnapshot.getProjectSnapshot());
-      pastSnapshot.setIndex(projectPastSnapshot.getIndex());
-      pastSnapshot.setModeParameter(projectPastSnapshot.getModeParameter());
+      PastSnapshot pastSnapshot = projectPastSnapshot.clone();
       modulePastSnapshots.add(pastSnapshot);
       // When no snapshot is found, date of the period is null
-      periods.add(new Period(pastSnapshot.getIndex(), pastSnapshot.getTargetDate(), snapshot != null ? snapshot.getCreatedAt() : null));
+      periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? snapshot.getCreatedAt() : null));
       log(pastSnapshot);
     }
   }
index dcd60faf5d30801b94d1c0cb415dded4db189d96..93a18980c91bb4f04764442a315aefc288a9d542 100644 (file)
@@ -50,6 +50,6 @@ public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTest
     PastSnapshot pastSnapshot = finder.findByPreviousAnalysis(projectSnapshot);
     assertThat(pastSnapshot.isRelatedToSnapshot(), is(false));
     assertThat(pastSnapshot.getProjectSnapshot(), nullValue());
-    assertThat(pastSnapshot.getTargetDate(), nullValue());
+    assertThat(pastSnapshot.getDate(), nullValue());
   }
 }