aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-07-11 16:44:21 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-07-11 16:44:21 +0200
commit014ba2d48296a2b98349ee4cd16a4767b737c239 (patch)
tree4e8ae08c193bfa9e97201e4f73df4af610498a4d /sonar-core
parent1e5df63f1c39eb43b49926330fe4912a713c4445 (diff)
downloadsonarqube-014ba2d48296a2b98349ee4cd16a4767b737c239.tar.gz
sonarqube-014ba2d48296a2b98349ee4cd16a4767b737c239.zip
SONAR-4248 SONAR-4238 Add created column and add the possibility the add links and last analysis (formerly date)
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java24
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml15
3 files changed, 41 insertions, 7 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
index 92bce6c6407..14af5ee8206 100644
--- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
+++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java
@@ -23,7 +23,9 @@ import org.sonar.api.measures.Metric;
class MeasureFilterSort {
public static enum Field {
- KEY, NAME, VERSION, LANGUAGE, DATE, METRIC, SHORT_NAME, DESCRIPTION
+ KEY, NAME, VERSION, LANGUAGE, METRIC, SHORT_NAME, DESCRIPTION,
+ DATE, // Sort by last analysis date
+ PROJECT_CREATION_DATE // Sort by project creation date
}
private Field field = Field.NAME;
@@ -76,7 +78,7 @@ class MeasureFilterSort {
}
boolean isOnDate() {
- return Field.DATE.equals(field);
+ return Field.DATE.equals(field) || Field.PROJECT_CREATION_DATE.equals(field);
}
boolean isAsc() {
@@ -108,6 +110,9 @@ class MeasureFilterSort {
case DATE:
column = "s.created_at";
break;
+ case PROJECT_CREATION_DATE:
+ column = "p.created_at";
+ break;
case METRIC:
if (metric.isNumericType()) {
column = (period != null ? "pmsort.variation_value_" + period : "pmsort.value");
diff --git a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
index 214ceba319c..392ead327cd 100644
--- a/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/measure/MeasureFilterExecutorTest.java
@@ -336,6 +336,30 @@ public class MeasureFilterExecutorTest {
}
@Test
+ public void sort_by_ascending_created_at() throws SQLException {
+ db.prepareDbUnit(getClass(), "shared.xml");
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE);
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+ verifyJavaProject(rows.get(0));// 2008
+ assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2008-12-19");
+ verifyPhpProject(rows.get(1));// 2012
+ assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2012-12-12");
+ }
+
+ @Test
+ public void sort_by_descending_created_at() throws SQLException {
+ db.prepareDbUnit(getClass(), "shared.xml");
+ MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).setSortOn(MeasureFilterSort.Field.PROJECT_CREATION_DATE).setSortAsc(false);
+ List<MeasureFilterRow> rows = executor.execute(filter, new MeasureFilterContext());
+
+ verifyPhpProject(rows.get(0));// 2012
+ assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2012-12-12");
+ verifyJavaProject(rows.get(1));// 2008
+ assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2008-12-19");
+ }
+
+ @Test
public void condition_on_numeric_measure() throws SQLException {
db.prepareDbUnit(getClass(), "shared.xml");
MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("CLA"))
diff --git a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml
index 8b4a6bbc26e..bcfe738a901 100644
--- a/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml
+++ b/sonar-core/src/test/resources/org/sonar/core/measure/MeasureFilterExecutorTest/shared.xml
@@ -25,20 +25,24 @@
<!-- java project -->
<projects kee="java_project" long_name="Java project" scope="PRJ" qualifier="TRK" name="Java project"
id="1" root_id="[null]"
- description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="2008-12-19 00:00:00.00"/>
<projects kee="java_project:org.sonar.foo" scope="DIR" qualifier="PAC" long_name="org.sonar.foo" name="org.sonar.foo"
id="2" root_id="1"
- description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="2008-12-19 00:00:00.00"/>
<projects kee="java_project:org.sonar.foo.Big" scope="FIL" qualifier="CLA" long_name="org.sonar.foo.Big"
name="Big"
id="3" root_id="1"
- description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="2008-12-19 00:00:00.00"/>
<projects kee="java_project:org.sonar.foo.Tiny" scope="FIL" qualifier="CLA" long_name="org.sonar.foo.Tiny" name="Tiny"
id="4" root_id="1"
- description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"
+ created_at="2008-12-19 00:00:00.00"/>
<snapshots id="101" project_id="1" root_project_id="1" root_snapshot_id="[null]" parent_snapshot_id="[null]"
scope="PRJ" qualifier="TRK" path="" depth="0"
@@ -125,7 +129,8 @@
<!-- php project -->
<projects kee="php_project" long_name="PHP project" scope="PRJ" qualifier="TRK" name="PHP project"
id="10" root_id="[null]"
- description="[null]" enabled="[true]" language="php" copy_resource_id="[null]" person_id="[null]"/>
+ description="[null]" enabled="[true]" language="php" copy_resource_id="[null]" person_id="[null]"
+ created_at="2012-12-12 04:06:00.00"/>
<snapshots id="110" project_id="10" root_project_id="10" root_snapshot_id="[null]" parent_snapshot_id="[null]"