aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2012-02-01 18:19:33 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2012-02-01 20:11:21 +0400
commit81928180ce26c452c38d9c060e0f79cf4f3b47f7 (patch)
tree05d71ed4aed1d138131b95382efb811aa6751c3c /sonar-batch
parente8631ce08c4f566cbe73b5b9542392c727027e79 (diff)
downloadsonarqube-81928180ce26c452c38d9c060e0f79cf4f3b47f7.tar.gz
sonarqube-81928180ce26c452c38d9c060e0f79cf4f3b47f7.zip
SONAR-3231 Allow to associate measure with committer
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java7
4 files changed, 22 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
index fce98a19737..326dfbb9b2d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
@@ -34,6 +34,7 @@ import org.sonar.api.resources.Resource;
import org.sonar.batch.index.DefaultIndex;
import javax.persistence.Query;
+
import java.util.*;
public class DefaultTimeMachine implements TimeMachine {
@@ -93,12 +94,14 @@ public class DefaultTimeMachine implements TimeMachine {
.append(MeasureModel.class.getSimpleName())
.append(" m, ")
.append(Snapshot.class.getSimpleName())
- .append(" s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND m.characteristic IS NULL AND s.qualifier<>:lib");
+ .append(" s WHERE m.snapshotId=s.id AND s.resourceId=:resourceId AND s.status=:status AND s.qualifier<>:lib");
params.put("resourceId", resource.getId());
params.put("status", Snapshot.STATUS_PROCESSED);
params.put("lib", Qualifiers.LIBRARY);
- sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL ");
+ sb.append(" AND m.characteristic IS NULL");
+ sb.append(" AND m.committer IS NULL");
+ sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL");
if (!metricIds.isEmpty()) {
sb.append(" AND m.metricId IN (:metricIds) ");
params.put("metricIds", metricIds);
@@ -159,6 +162,7 @@ public class DefaultTimeMachine implements TimeMachine {
measure.setVariation5(model.getVariationValue5());
measure.setUrl(model.getUrl());
measure.setCharacteristic(model.getCharacteristic());
+ measure.setCommitter(model.getCommitter());
return measure;
}
-} \ No newline at end of file
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
index a04a0311f0b..7b2560a3e28 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastMeasuresLoader.java
@@ -65,7 +65,7 @@ public class PastMeasuresLoader implements BatchExtension {
}
public List<Object[]> getPastMeasures(String resourceKey, Snapshot projectPastSnapshot) {
- String sql = "select m.metric_id, m.characteristic_id, m.rule_id, m.value from project_measures m, snapshots s" +
+ String sql = "select m.metric_id, m.characteristic_id, m.committer, m.rule_id, m.value from project_measures m, snapshots s" +
" where m.snapshot_id=s.id and m.metric_id in (:metricIds) " +
" and (s.root_snapshot_id=:rootSnapshotId or s.id=:rootSnapshotId) " +
" and s.status=:status and s.project_id=(select p.id from projects p where p.kee=:resourceKey and p.qualifier<>:lib)";
@@ -89,17 +89,22 @@ public class PastMeasuresLoader implements BatchExtension {
return number != null ? number.intValue() : null;
}
+ public static String getCommitter(Object[] row) {
+ return (String) row[2];
+ }
+
public static Integer getRuleId(Object[] row) {
// can be BigDecimal on Oracle
- Number number = (Number) row[2];
+ Number number = (Number) row[3];
return number != null ? number.intValue() : null;
}
public static boolean hasValue(Object[] row) {
- return row[3] != null;
+ return row[4] != null;
}
public static double getValue(Object[] row) {
- return ((Number) row[3]).doubleValue();
+ return ((Number) row[4]).doubleValue();
}
+
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 1f0326c55a1..620519345f0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -150,6 +150,7 @@ public final class MeasurePersister {
merge.setVariationValue5(measure.getVariation5());
merge.setUrl(measure.getUrl());
merge.setCharacteristic(measure.getCharacteristic());
+ merge.setCommitter(measure.getCommitter());
if (measure.getValue() != null) {
merge.setValue(measure.getValue().doubleValue());
} else {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
index 5d56fde9600..5c4e9638507 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastMeasuresLoaderTest.java
@@ -27,7 +27,6 @@ import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
import java.util.List;
-import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
@@ -53,11 +52,13 @@ public class PastMeasuresLoaderTest extends AbstractDbUnitTestCase {
Object[] pastMeasure = measures.get(0);
assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1));
assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
+ assertThat(PastMeasuresLoader.getCommitter(pastMeasure), nullValue());
assertThat(PastMeasuresLoader.getValue(pastMeasure), is(5.0));
pastMeasure = measures.get(1);
assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2));
assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
+ assertThat(PastMeasuresLoader.getCommitter(pastMeasure), nullValue());
assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0));
}
@@ -75,11 +76,13 @@ public class PastMeasuresLoaderTest extends AbstractDbUnitTestCase {
Object[] pastMeasure = measures.get(0);
assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(1));
assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
+ assertThat(PastMeasuresLoader.getCommitter(pastMeasure), nullValue());
assertThat(PastMeasuresLoader.getValue(pastMeasure), is(60.0));
pastMeasure = measures.get(1);
assertThat(PastMeasuresLoader.getMetricId(pastMeasure), is(2));
assertThat(PastMeasuresLoader.getCharacteristicId(pastMeasure), nullValue());
+ assertThat(PastMeasuresLoader.getCommitter(pastMeasure), nullValue());
assertThat(PastMeasuresLoader.getValue(pastMeasure), is(80.0));
}
@@ -94,7 +97,7 @@ public class PastMeasuresLoaderTest extends AbstractDbUnitTestCase {
List<Metric> metrics = Arrays.asList(ncloc, complexity, data);
PastMeasuresLoader loader = new PastMeasuresLoader(getSession(), metrics);
-
+
assertThat(loader.getMetrics().size(), is(2));
assertThat(loader.getMetrics(), hasItems(ncloc, complexity));
}