]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1937 fix calculation of new_violations : compare to a date instead of a snapshot
authorsimonbrandhof <simon.brandhof@gmail.com>
Wed, 8 Dec 2010 12:50:28 +0000 (12:50 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Wed, 8 Dec 2010 12:50:28 +0000 (12:50 +0000)
24 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshot.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinder.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDate.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDays.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysis.java [deleted file]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersion.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDateTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByDaysTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest.java [deleted file]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByVersionTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldFindLastAnalysis.xml [deleted file]
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldNotFindLastAnalysis.xml [deleted file]
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb

index 58e60a08f7a08ef10417c0a153af666581c1199e..2f67910eb81eb1e384c79fae4f66d039bcc807d1 100644 (file)
@@ -136,7 +136,7 @@ import java.util.List;
     ),
     @Property(
         key = "sonar.timemachine.variation4",
-        name = "Variation 4, only for projects",
+        name = "Variation 4",
         description = "To be defined. For the moment the number of days",
         project = true,
         global = false
@@ -228,7 +228,7 @@ public class CorePlugin implements Plugin {
     extensions.add(TendencyDecorator.class);
     extensions.add(PastSnapshotFinderByDate.class);
     extensions.add(PastSnapshotFinderByDays.class);
-    extensions.add(PastSnapshotFinderByLastAnalysis.class);
+    extensions.add(PastSnapshotFinderByPreviousAnalysis.class);
     extensions.add(PastSnapshotFinderByVersion.class);
     extensions.add(PastMeasuresLoader.class);
     extensions.add(PastSnapshotFinder.class);
index a51d564024768593c393fe938091a8ba746f5dcb..5f981991dd2d8f5297ac5bbf778f333b7c4264f3 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.plugins.core.timemachine;
 
 import com.google.common.collect.*;
+import org.apache.commons.lang.time.DateUtils;
 import org.sonar.api.batch.Decorator;
 import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.batch.DependedUpon;
@@ -89,10 +90,10 @@ public class NewViolationsDecorator implements Decorator {
 
   private void saveNewViolations(DecoratorContext context) {
     Measure measure = new Measure(CoreMetrics.NEW_VIOLATIONS);
-    for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
-      int variationIndex = variationSnapshot.getIndex();
+    for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+      int variationIndex = pastSnapshot.getIndex();
       Collection<Measure> children = context.getChildrenMeasures(CoreMetrics.NEW_VIOLATIONS);
-      int count = countViolations(context.getViolations(), variationSnapshot.getDate());
+      int count = countViolations(context.getViolations(), pastSnapshot.getTargetDate());
       double sum = sumChildren(variationIndex, children) + count;
       measure.setVariation(variationIndex, sum);
     }
@@ -103,9 +104,9 @@ public class NewViolationsDecorator implements Decorator {
     for (RulePriority priority : RulePriority.values()) {
       Metric metric = getMetricForSeverity(priority);
       Measure measure = new Measure(metric);
-      for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
-        int variationIndex = variationSnapshot.getIndex();
-        int count = countViolations(violationsBySeverity.get(priority), variationSnapshot.getDate());
+      for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+        int variationIndex = pastSnapshot.getIndex();
+        int count = countViolations(violationsBySeverity.get(priority), pastSnapshot.getTargetDate());
         Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
         double sum = sumChildren(variationIndex, children) + count;
         measure.setVariation(variationIndex, sum);
@@ -132,9 +133,9 @@ public class NewViolationsDecorator implements Decorator {
     for (Rule rule : rules) {
       RuleMeasure measure = RuleMeasure.createForRule(CoreMetrics.NEW_VIOLATIONS, rule, null);
       measure.setRulePriority(ruleToLevel.get(rule));
-      for (PastSnapshot variationSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
-        int variationIndex = variationSnapshot.getIndex();
-        int count = countViolations(violationsByRule.get(rule), variationSnapshot.getDate());
+      for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
+        int variationIndex = pastSnapshot.getIndex();
+        int count = countViolations(violationsByRule.get(rule), pastSnapshot.getTargetDate());
         double sum = sumChildren(variationIndex, childrenByRule.get(rule)) + count;
         measure.setVariation(variationIndex, sum);
       }
index f4c0e545652dc441ac4440ab05bc91474b31c9ca..9b3f34aba7d91492f6967a1acf1396e4d6d89a12 100644 (file)
@@ -29,13 +29,24 @@ public class PastSnapshot {
   private int index;
   private String mode, modeParameter;
   private Snapshot projectSnapshot;
+  private Date targetDate;
 
-  public PastSnapshot(int index, String mode, Snapshot projectSnapshot) {
-    this.index = index;
+  public PastSnapshot(String mode, Date targetDate, Snapshot projectSnapshot) {
     this.mode = mode;
+    this.targetDate = targetDate;
     this.projectSnapshot = projectSnapshot;
   }
 
+  public PastSnapshot(String mode, Snapshot projectSnapshot) {
+    this.mode = mode;
+    this.projectSnapshot = projectSnapshot;
+  }
+
+  public PastSnapshot setIndex(int index) {
+    this.index = index;
+    return this;
+  }
+
   public int getIndex() {
     return index;
   }
@@ -61,6 +72,14 @@ public class PastSnapshot {
     return this;
   }
 
+  public Integer getProjectSnapshotId() {
+    return (projectSnapshot!=null ? projectSnapshot.getId() : null);
+  }
+
+  public Date getTargetDate() {
+    return targetDate;
+  }
+
   @Override
   public String toString() {
     return ReflectionToStringBuilder.toString(this);
index 92ca2715ec3a6457418f73210b8ad1ca093acebb..927af7ea361eb7dbb63484212b058014bc297ac5 100644 (file)
@@ -22,30 +22,23 @@ package org.sonar.plugins.core.timemachine;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.BatchExtension;
-import org.sonar.api.database.model.Snapshot;
 
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 public class PastSnapshotFinder implements BatchExtension {
-
-  public static final String LAST__ANALYSIS_MODE = "last_analysis";
-  public static final String DATE_MODE = "date";
-  public static final String VERSION_MODE = "version";
-  public static final String DAYS_MODE = "days";
-  
   private PastSnapshotFinderByDays finderByDays;
   private PastSnapshotFinderByVersion finderByVersion;
   private PastSnapshotFinderByDate finderByDate;
-  private PastSnapshotFinderByLastAnalysis finderByLastAnalysis;
+  private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
 
   public PastSnapshotFinder(PastSnapshotFinderByDays finderByDays, PastSnapshotFinderByVersion finderByVersion,
-                            PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByLastAnalysis finderByLastAnalysis) {
+                            PastSnapshotFinderByDate finderByDate, PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis) {
     this.finderByDays = finderByDays;
     this.finderByVersion = finderByVersion;
     this.finderByDate = finderByDate;
-    this.finderByLastAnalysis = finderByLastAnalysis;
+    this.finderByPreviousAnalysis = finderByPreviousAnalysis;
   }
 
   public PastSnapshot find(Configuration conf, int index) {
@@ -57,62 +50,51 @@ public class PastSnapshotFinder implements BatchExtension {
       return null;
     }
 
-    PastSnapshot result = findByDays(index, property);
+    PastSnapshot result = findByDays(property);
     if (result == null) {
-      result = findByDate(index, property);
+      result = findByDate(property);
       if (result == null) {
-        result = findByLastAnalysis(index, property);
+        result = findByPreviousAnalysis(property);
         if (result == null) {
-          result = findByVersion(index, property);
+          result = findByVersion(property);
         }
       }
     }
+
+    if (result != null) {
+      result.setIndex(index);
+    }
+
     return result;
   }
 
-  private PastSnapshot findByLastAnalysis(int index, String property) {
-    if (StringUtils.equals(LAST__ANALYSIS_MODE, property)) {
-      Snapshot projectSnapshot = finderByLastAnalysis.findLastAnalysis();
-      if (projectSnapshot != null) {
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-        String date = format.format(projectSnapshot.getCreatedAt());
-        return new PastSnapshot(index, LAST__ANALYSIS_MODE, projectSnapshot).setModeParameter(date);
-      }
+  private PastSnapshot findByPreviousAnalysis(String property) {
+    PastSnapshot pastSnapshot = null;
+    if (StringUtils.equals(PastSnapshotFinderByPreviousAnalysis.MODE, property)) {
+      pastSnapshot = finderByPreviousAnalysis.findByPreviousAnalysis();
     }
-    return null;
+    return pastSnapshot;
   }
 
-  private PastSnapshot findByDate(int index, String property) {
+  private PastSnapshot findByDate(String property) {
     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
     try {
       Date date = format.parse(property);
-      Snapshot projectSnapshot = finderByDate.findByDate(date);
-      if (projectSnapshot != null) {
-        return new PastSnapshot(index, DATE_MODE, projectSnapshot).setModeParameter(property);
-      }
-      return null;
+      return finderByDate.findByDate(date);
 
     } catch (ParseException e) {
       return null;
     }
   }
 
-  private PastSnapshot findByVersion(int index, String property) {
-    Snapshot projectSnapshot = finderByVersion.findVersion(property);
-    if (projectSnapshot != null) {
-      return new PastSnapshot(index, VERSION_MODE, projectSnapshot).setModeParameter(property);
-    }
-    return null;
+  private PastSnapshot findByVersion(String property) {
+    return finderByVersion.findByVersion(property);
   }
 
-  private PastSnapshot findByDays(int index, String property) {
+  private PastSnapshot findByDays(String property) {
     try {
       int days = Integer.parseInt(property);
-      Snapshot projectSnapshot = finderByDays.findInDays(days);
-      if (projectSnapshot != null) {
-        return new PastSnapshot(index, DAYS_MODE, projectSnapshot).setModeParameter(String.valueOf(days));
-      }
-      return null;
+      return finderByDays.findFromDays(days);
 
     } catch (NumberFormatException e) {
       return null;
index 172b8b958433f92d412ed7bc1a6cf33921cbc801..d33ead7c16b31ab4f6af2c219df9f160d75889f2 100644 (file)
@@ -23,10 +23,15 @@ import org.sonar.api.BatchExtension;
 import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.Snapshot;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 
 public class PastSnapshotFinderByDate implements BatchExtension{
+
+  public static final String MODE = "date";
+
+
   private Snapshot projectSnapshot; // TODO replace by PersistenceManager
   private DatabaseSession session;
 
@@ -35,7 +40,7 @@ public class PastSnapshotFinderByDate implements BatchExtension{
     this.session = session;
   }
 
-  Snapshot findByDate(Date date) {
+  PastSnapshot findByDate(Date date) {
     String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status order by createdAt asc";
     List<Snapshot> snapshots = session.createQuery(hql)
         .setParameter("date", date)
@@ -43,7 +48,12 @@ public class PastSnapshotFinderByDate implements BatchExtension{
         .setParameter("status", Snapshot.STATUS_PROCESSED)
         .setMaxResults(1)
         .getResultList();
-    return snapshots.isEmpty() ? null : snapshots.get(0);
+    if (snapshots.isEmpty()) {
+      return null;
+    }
+
+    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+    return new PastSnapshot(MODE, date, snapshots.get(0)).setModeParameter(format.format(date));
   }
 
 }
index 9a49b23640222b391781a91a84b8bcb8b96c3bc3..618a539307f211f747a81e7589a8b3adb6542d72 100644 (file)
@@ -28,6 +28,9 @@ import java.util.Date;
 import java.util.List;
 
 public class PastSnapshotFinderByDays implements BatchExtension {
+
+  public static final String MODE = "days";
+
   private Snapshot projectSnapshot; // TODO replace by PersistenceManager
   private DatabaseSession session;
 
@@ -36,7 +39,7 @@ public class PastSnapshotFinderByDays implements BatchExtension {
     this.session = session;
   }
 
-  Snapshot findInDays(int days) {
+  PastSnapshot findFromDays(int days) {
     Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days);
     String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt>=:from AND createdAt<:to order by createdAt asc";
     List<Snapshot> snapshots = session.createQuery(hql)
@@ -47,6 +50,9 @@ public class PastSnapshotFinderByDays implements BatchExtension {
         .setMaxResults(1)
         .getResultList();
 
-    return snapshots.isEmpty() ? null : snapshots.get(0);
+    if (snapshots.isEmpty()) {
+      return null;
+    }
+    return new PastSnapshot(MODE, targetDate, snapshots.get(0)).setModeParameter(String.valueOf(days));
   }
 }
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysis.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysis.java
deleted file mode 100644 (file)
index f50509b..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.timemachine;
-
-import org.sonar.api.BatchExtension;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-
-import java.util.List;
-
-public class PastSnapshotFinderByLastAnalysis implements BatchExtension {
-  private Snapshot projectSnapshot; // TODO replace by PersistenceManager
-  private DatabaseSession session;
-
-  public PastSnapshotFinderByLastAnalysis(Snapshot projectSnapshot, DatabaseSession session) {
-    this.projectSnapshot = projectSnapshot;
-    this.session = session;
-  }
-
-  Snapshot findLastAnalysis() {
-    String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc";
-    List<Snapshot> snapshots = session.createQuery(hql)
-        .setParameter("date", projectSnapshot.getCreatedAt())
-        .setParameter("resourceId", projectSnapshot.getResourceId())
-        .setParameter("status", Snapshot.STATUS_PROCESSED)
-        .setMaxResults(1)
-        .getResultList();
-
-    return snapshots.isEmpty() ? null : snapshots.get(0);
-  }
-
-}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysis.java
new file mode 100644 (file)
index 0000000..e8c0432
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.timemachine;
+
+import org.sonar.api.BatchExtension;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.Snapshot;
+
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension {
+  public static final String MODE = "previous_analysis";
+
+  private Snapshot projectSnapshot; // TODO replace by PersistenceManager
+  private DatabaseSession session;
+
+  public PastSnapshotFinderByPreviousAnalysis(Snapshot projectSnapshot, DatabaseSession session) {
+    this.projectSnapshot = projectSnapshot;
+    this.session = session;
+  }
+
+  PastSnapshot findByPreviousAnalysis() {
+    String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=true order by createdAt desc";
+    List<Snapshot> snapshots = session.createQuery(hql)
+        .setParameter("date", projectSnapshot.getCreatedAt())
+        .setParameter("resourceId", projectSnapshot.getResourceId())
+        .setParameter("status", Snapshot.STATUS_PROCESSED)
+        .setMaxResults(1)
+        .getResultList();
+
+    if (snapshots.isEmpty()) {
+      return null;
+    }
+    Snapshot snapshot = snapshots.get(0);
+    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+    return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(format.format(snapshot.getCreatedAt()));
+  }
+
+}
index fc2ec93bf278c4fb01261b62718dd54e417f4842..bba16f91fade1233f67fbb45d2732a89633707f5 100644 (file)
@@ -26,6 +26,9 @@ import org.sonar.api.database.model.Snapshot;
 import java.util.List;
 
 public class PastSnapshotFinderByVersion implements BatchExtension {
+
+  public static final String MODE = "version";
+
   private Snapshot projectSnapshot; // TODO replace by PersistenceManager
   private DatabaseSession session;
 
@@ -34,7 +37,7 @@ public class PastSnapshotFinderByVersion implements BatchExtension {
     this.session = session;
   }
 
-  Snapshot findVersion(String version) {
+  PastSnapshot findByVersion(String version) {
     String hql = "from " + Snapshot.class.getSimpleName() + " where version=:version AND resourceId=:resourceId AND status=:status order by createdAt desc";
     List<Snapshot> snapshots = session.createQuery(hql)
         .setParameter("version", version)
@@ -43,7 +46,11 @@ public class PastSnapshotFinderByVersion implements BatchExtension {
         .setMaxResults(1)
         .getResultList();
 
-    return snapshots.isEmpty() ? null : snapshots.get(0);
+    if (snapshots.isEmpty()) {
+      return null;
+    }
+    Snapshot snapshot = snapshots.get(0);
+    return new PastSnapshot(MODE, snapshot.getCreatedAt(), snapshot).setModeParameter(snapshot.getVersion());
   }
 
 }
index 2fd987589aa79dc215f7c52d1ba7ef73eba5502f..84bd2b100ebbb640174fbc933dff03d9266b3a63 100644 (file)
@@ -67,11 +67,11 @@ public class NewViolationsDecoratorTest {
 
     PastSnapshot pastSnapshot = mock(PastSnapshot.class);
     when(pastSnapshot.getIndex()).thenReturn(1);
-    when(pastSnapshot.getDate()).thenReturn(fiveDaysAgo);
+    when(pastSnapshot.getTargetDate()).thenReturn(fiveDaysAgo);
 
     PastSnapshot pastSnapshot2 = mock(PastSnapshot.class);
     when(pastSnapshot2.getIndex()).thenReturn(2);
-    when(pastSnapshot2.getDate()).thenReturn(tenDaysAgo);
+    when(pastSnapshot2.getTargetDate()).thenReturn(tenDaysAgo);
 
     TimeMachineConfiguration timeMachineConfiguration = mock(TimeMachineConfiguration.class);
     when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(pastSnapshot, pastSnapshot2));
index 3d0190e1077f5b6f550342c466e6e87159802f4b..5ee48a6595d310ab22ec56acaa5d2dc501b4fdf0 100644 (file)
@@ -42,8 +42,8 @@ public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase {
 
     Date date = DATE_FORMAT.parse("2008-11-22");
 
-    Snapshot snapshot = finder.findByDate(date);
-    assertThat(snapshot.getId(), is(1006));
+    PastSnapshot pastSnapshot = finder.findByDate(date);
+    assertThat(pastSnapshot.getProjectSnapshotId(), is(1006));
   }
 
   @Test
@@ -55,7 +55,7 @@ public class PastSnapshotFinderByDateTest extends AbstractDbUnitTestCase {
 
     Date date = DATE_FORMAT.parse("2008-11-24");
    
-    Snapshot snapshot = finder.findByDate(date);
-    assertThat(snapshot.getId(), is(1009));
+    PastSnapshot pastSnapshot = finder.findByDate(date);
+    assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
   }
 }
index a09efeda4dc6b14767a61375e8c48142a9179c77..226010b327b545ce5f5a341418009b58bc6eb8b3 100644 (file)
@@ -27,6 +27,7 @@ import org.sonar.jpa.test.AbstractDbUnitTestCase;
 import java.text.ParseException;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
@@ -38,7 +39,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
     Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
     PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
 
-    assertThat(finder.findInDays(50).getId(), is(1000));
+    assertThat(finder.findFromDays(50).getProjectSnapshotId(), is(1000));
   }
 
   @Test
@@ -48,7 +49,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
     Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
     PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
 
-    assertThat(finder.findInDays(7).getId(), is(1006));
+    assertThat(finder.findFromDays(7).getProjectSnapshotId(), is(1006));
   }
 
   @Test
@@ -58,7 +59,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
     Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
     PastSnapshotFinderByDays finder = new PastSnapshotFinderByDays(projectSnapshot, getSession());
 
-    assertThat(finder.findInDays(1), IsNull.<Object>nullValue());
+    assertThat(finder.findFromDays(1), nullValue());
   }
 
 }
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest.java
deleted file mode 100644 (file)
index 03ad859..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2009 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
- */
-package org.sonar.plugins.core.timemachine;
-
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.text.ParseException;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-
-public class PastSnapshotFinderByLastAnalysisTest extends AbstractDbUnitTestCase {
-
-  @Test
-  public void shouldFindLastAnalysis() throws ParseException {
-    setupData("shouldFindLastAnalysis");
-
-    Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
-    PastSnapshotFinderByLastAnalysis finder = new PastSnapshotFinderByLastAnalysis(projectSnapshot, getSession());
-
-    Snapshot snapshot = finder.findLastAnalysis();
-    assertThat(snapshot.getId(), is(1009));
-  }
-
-  @Test
-  public void shouldNotFindLastAnalysis() throws ParseException {
-    setupData("shouldNotFindLastAnalysis");
-
-    Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
-    PastSnapshotFinderByLastAnalysis finder = new PastSnapshotFinderByLastAnalysis(projectSnapshot, getSession());
-
-    assertNull(finder.findLastAnalysis());
-  }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest.java
new file mode 100644 (file)
index 0000000..992ebc3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.timemachine;
+
+import org.junit.Test;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import java.text.ParseException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTestCase {
+
+  @Test
+  public void shouldFindPreviousAnalysis() throws ParseException {
+    setupData("shouldFindPreviousAnalysis");
+
+    Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+    PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession());
+
+    PastSnapshot pastSnapshot = finder.findByPreviousAnalysis();
+    assertThat(pastSnapshot.getProjectSnapshotId(), is(1009));
+  }
+
+  @Test
+  public void shouldNotFindPreviousAnalysis() throws ParseException {
+    setupData("shouldNotFindPreviousAnalysis");
+
+    Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
+    PastSnapshotFinderByPreviousAnalysis finder = new PastSnapshotFinderByPreviousAnalysis(projectSnapshot, getSession());
+
+    assertNull(finder.findByPreviousAnalysis());
+  }
+}
index 8e6d40ef1ea10eef6bb9968d96912ddbc79c355c..c051c5d4dae5b8c6254fa168f3c4a7d56f3791b1 100644 (file)
@@ -36,7 +36,7 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
     Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
     PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
 
-    assertThat(finder.findVersion("1.1").getId(), is(1009));
+    assertThat(finder.findByVersion("1.1").getProjectSnapshotId(), is(1009));
   }
 
   @Test
@@ -46,6 +46,6 @@ public class PastSnapshotFinderByVersionTest extends AbstractDbUnitTestCase {
     Snapshot currentProjectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
     PastSnapshotFinderByVersion finder = new PastSnapshotFinderByVersion(currentProjectSnapshot, getSession());
 
-    assertThat(finder.findVersion("1.0"), nullValue());
+    assertThat(finder.findByVersion("1.0"), nullValue());
   }
 }
index 79ae41629c6b8c0bdc4d363c46f96d86b7dc738f..048f34c2b32bf28952b9b11bd72f1e0a311f972c 100644 (file)
@@ -30,7 +30,9 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 import static junit.framework.Assert.assertNull;
+import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.*;
@@ -40,7 +42,7 @@ public class PastSnapshotFinderTest {
   private PastSnapshotFinderByDays finderByDays;
   private PastSnapshotFinderByDate finderByDate;
   private PastSnapshotFinderByVersion finderByVersion;
-  private PastSnapshotFinderByLastAnalysis finderByLastAnalysis;
+  private PastSnapshotFinderByPreviousAnalysis finderByPreviousAnalysis;
   private PastSnapshotFinder finder;
 
   @Before
@@ -48,17 +50,17 @@ public class PastSnapshotFinderTest {
     finderByDays = mock(PastSnapshotFinderByDays.class);
     finderByDate = mock(PastSnapshotFinderByDate.class);
     finderByVersion = mock(PastSnapshotFinderByVersion.class);
-    finderByLastAnalysis = mock(PastSnapshotFinderByLastAnalysis.class);
-    finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByLastAnalysis);
+    finderByPreviousAnalysis = mock(PastSnapshotFinderByPreviousAnalysis.class);
+    finder = new PastSnapshotFinder(finderByDays, finderByVersion, finderByDate, finderByPreviousAnalysis);
   }
 
   @Test
   public void shouldFindByNumberOfDays() {
-    when(finderByDays.findInDays(30)).thenReturn(new Snapshot());
+    when(finderByDays.findFromDays(30)).thenReturn(new PastSnapshot("days", null).setModeParameter("30"));
 
     PastSnapshot variationSnapshot = finder.find(1, "30");
 
-    verify(finderByDays).findInDays(30);
+    verify(finderByDays).findFromDays(30);
     assertNotNull(variationSnapshot);
     assertThat(variationSnapshot.getIndex(), is(1));
     assertThat(variationSnapshot.getMode(), is("days"));
@@ -69,7 +71,7 @@ public class PastSnapshotFinderTest {
   public void shouldNotFindByNumberOfDays() {
     PastSnapshot variationSnapshot = finder.find(1, "30");
 
-    verify(finderByDays).findInDays(30);
+    verify(finderByDays).findFromDays(30);
     assertNull(variationSnapshot);
   }
 
@@ -77,7 +79,7 @@ public class PastSnapshotFinderTest {
   public void shouldFindByDate() throws ParseException {
     final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
     final Date date = format.parse("2010-05-18");
-    when(finderByDate.findByDate(date)).thenReturn(new Snapshot());
+    when(finderByDate.findByDate(date)).thenReturn(new PastSnapshot("date", new Snapshot()));
 
     PastSnapshot variationSnapshot = finder.find(2, "2010-05-18");
 
@@ -92,7 +94,7 @@ public class PastSnapshotFinderTest {
     }));
     assertThat(variationSnapshot.getIndex(), is(2));
     assertThat(variationSnapshot.getMode(), is("date"));
-    assertThat(variationSnapshot.getModeParameter(), is("2010-05-18"));
+    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
   }
 
   @Test
@@ -106,57 +108,57 @@ public class PastSnapshotFinderTest {
   }
 
   @Test
-  public void shouldFindLastAnalysis() throws ParseException {
+  public void shouldFindByPreviousAnalysis() throws ParseException {
     final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
     final Date date = format.parse("2010-05-18");
     Snapshot snapshot = new Snapshot();
     snapshot.setCreatedAt(date);
-    when(finderByLastAnalysis.findLastAnalysis()).thenReturn(snapshot);
+    when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, snapshot));
 
-    PastSnapshot variationSnapshot = finder.find(2, "last_analysis");
+    PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE);
 
-    verify(finderByLastAnalysis).findLastAnalysis();
+    verify(finderByPreviousAnalysis).findByPreviousAnalysis();
     assertThat(variationSnapshot.getIndex(), is(2));
-    assertThat(variationSnapshot.getMode(), is("last_analysis"));
-    assertThat(variationSnapshot.getModeParameter(), is("2010-05-18"));
+    assertThat(variationSnapshot.getMode(), is(PastSnapshotFinderByPreviousAnalysis.MODE));
+    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
   }
 
   @Test
-  public void shouldNotFindLastAnalysis() {
-    when(finderByLastAnalysis.findLastAnalysis()).thenReturn(null);
+  public void shouldNotFindPreviousAnalysis() {
+    when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(null);
 
-    PastSnapshot variationSnapshot = finder.find(2, "last_analysis");
+    PastSnapshot variationSnapshot = finder.find(2, PastSnapshotFinderByPreviousAnalysis.MODE);
 
-    verify(finderByLastAnalysis).findLastAnalysis();
+    verify(finderByPreviousAnalysis).findByPreviousAnalysis();
 
     assertNull(variationSnapshot);
   }
 
   @Test
   public void shouldFindByVersion() {
-    when(finderByVersion.findVersion("1.2")).thenReturn(new Snapshot());
+    when(finderByVersion.findByVersion("1.2")).thenReturn(new PastSnapshot("version", new Snapshot()));
 
     PastSnapshot variationSnapshot = finder.find(2, "1.2");
 
-    verify(finderByVersion).findVersion("1.2");
+    verify(finderByVersion).findByVersion("1.2");
     assertThat(variationSnapshot.getIndex(), is(2));
     assertThat(variationSnapshot.getMode(), is("version"));
-    assertThat(variationSnapshot.getModeParameter(), is("1.2"));
+    assertThat(variationSnapshot.getProjectSnapshot(), not(nullValue()));
   }
 
   @Test
   public void shouldNotFindVersion() {
-    when(finderByVersion.findVersion("1.2")).thenReturn(null);
+    when(finderByVersion.findByVersion("1.2")).thenReturn(null);
 
     PastSnapshot variationSnapshot = finder.find(2, "1.2");
 
-    verify(finderByVersion).findVersion("1.2");
+    verify(finderByVersion).findByVersion("1.2");
     assertNull(variationSnapshot);
   }
 
   @Test
   public void shouldNotFailIfUnknownFormat() {
-    when(finderByLastAnalysis.findLastAnalysis()).thenReturn(new Snapshot()); // should not be called
+    when(finderByPreviousAnalysis.findByPreviousAnalysis()).thenReturn(new PastSnapshot(PastSnapshotFinderByPreviousAnalysis.MODE, new Snapshot())); // should not be called
     assertNull(finder.find(2, "foooo"));
   }
 }
index 0e25e21d7a3d223161a15ad263755758494ead95..613747a12ca207c955953b803a8a87f5ef5e0818 100644 (file)
@@ -35,10 +35,10 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas
     setupData("shared");
 
     TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
-    PastSnapshot vs1 = new PastSnapshot(1, "days", getSession().getSingleResult(Snapshot.class, "id", 100))
-        .setModeParameter("30");
-    PastSnapshot vs3 = new PastSnapshot(3, "version", getSession().getSingleResult(Snapshot.class, "id", 300))
-        .setModeParameter("1.2.3");
+    PastSnapshot vs1 = new PastSnapshot("days", getSession().getSingleResult(Snapshot.class, "id", 100))
+        .setModeParameter("30").setIndex(1);
+    PastSnapshot vs3 = new PastSnapshot("version", getSession().getSingleResult(Snapshot.class, "id", 300))
+        .setModeParameter("1.2.3").setIndex(3);
     when(conf.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
     Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
 
index 2070bc6b0d3ee3741b397ac1aba7660f26d10219..f9cbfc6cf6016c0589fa2a9101aeb5d06bf0c94b 100644 (file)
@@ -52,8 +52,8 @@ public class TimeMachineConfigurationTest extends AbstractDbUnitTestCase {
   public void shouldInitVariationSnapshots() throws ParseException {
     PropertiesConfiguration conf = new PropertiesConfiguration();
     PastSnapshotFinder snapshotReferenceFinder = mock(PastSnapshotFinder.class);
-    when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot(1, "days", newSnapshot("2010-10-15")));
-    when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot(3, "days", newSnapshot("2010-10-13")));
+    when(snapshotReferenceFinder.find(conf, 1)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-15")));
+    when(snapshotReferenceFinder.find(conf, 3)).thenReturn(new PastSnapshot("days", null, newSnapshot("2010-10-13")));
 
     TimeMachineConfiguration timeMachineConfiguration = new TimeMachineConfiguration(conf, snapshotReferenceFinder);
 
index a2d21bcb8044642041ba9b2611987d7420ed07ed..0f02f0c22687a1b3e28fed1e8d1711595390ff44 100644 (file)
@@ -58,8 +58,8 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
     Resource javaPackage = new JavaPackage("org.foo");
 
     PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
-    PastSnapshot pastSnapshot1 = new PastSnapshot(1, "days", new Snapshot());
-    PastSnapshot pastSnapshot3 = new PastSnapshot(3, "days", new Snapshot());
+    PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Snapshot()).setIndex(1);
+    PastSnapshot pastSnapshot3 = new PastSnapshot("days", new Snapshot()).setIndex(3);
 
     // first past analysis
     when(pastMeasuresLoader.getPastMeasures(javaPackage, pastSnapshot1)).thenReturn(Arrays.asList(
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldFindLastAnalysis.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldFindLastAnalysis.xml
deleted file mode 100644 (file)
index 0c02bb4..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1006"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-22 13:58:00.00" version="1.1" path=""
-             status="P" islast="false" depth="0" />
-
-
-  <!-- last analysis -->
-  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1009"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-25 13:58:00.00" version="1.1" path=""
-             status="P" islast="true" depth="0" />
-
-  <!-- current analysis -->
-  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1010"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
-             status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldNotFindLastAnalysis.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByLastAnalysisTest/shouldNotFindLastAnalysis.xml
deleted file mode 100644 (file)
index 5eaeff1..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<dataset>
-
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
-            root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-
-  <!-- unprocessed analysis -->
-  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1009"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-25 13:58:00.00" version="1.1" path=""
-             status="U" islast="false" depth="0" />
-
-  <!-- current analysis -->
-  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1010"
-             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
-             scope="PRJ" qualifier="TRK" created_at="2008-11-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
-             status="U" islast="false" depth="0" />
-
-</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml
new file mode 100644 (file)
index 0000000..0c02bb4
--- /dev/null
@@ -0,0 +1,26 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1006"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-22 13:58:00.00" version="1.1" path=""
+             status="P" islast="false" depth="0" />
+
+
+  <!-- last analysis -->
+  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1009"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-25 13:58:00.00" version="1.1" path=""
+             status="P" islast="true" depth="0" />
+
+  <!-- current analysis -->
+  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1010"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml
new file mode 100644 (file)
index 0000000..5eaeff1
--- /dev/null
@@ -0,0 +1,21 @@
+<dataset>
+
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="project" name="project"
+            root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+  <!-- unprocessed analysis -->
+  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1009"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-25 13:58:00.00" version="1.1" path=""
+             status="U" islast="false" depth="0" />
+
+  <!-- current analysis -->
+  <snapshots variation_mode_1="[null]" variation_param_1="[null]" variation_mode_2="[null]" variation_param_2="[null]" variation_mode_3="[null]" variation_param_3="[null]" variation_mode_4="[null]" variation_param_4="[null]" variation_mode_5="[null]" variation_param_5="[null]" id="1010"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2008-11-27 13:58:00.00" version="1.2-SNAPSHOT" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
index d5e095c22baa1345be13830d67a219f7cbeeaeda..2f97370f9db654a0b7ae22bbe9ffd9f6fc58b2d4 100644 (file)
@@ -38,8 +38,8 @@ module DashboardHelper
         label = "Last %s days" % mode_param
       elsif mode=='version'
         label = "Version %s" % mode_param
-      elsif mode=='last_analysis'
-        label = "Last analysis (%s)" % localize(Date.parse(mode_param))
+      elsif mode=='previous_analysis'
+        label = "Previous analysis (%s)" % localize(Date.parse(mode_param))
       elsif mode=='date'
         label = localize(Date.parse(mode_param))
       end