diff options
author | Godin <mandrikov@gmail.com> | 2010-11-30 15:40:42 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-30 15:40:42 +0000 |
commit | 1579738e5bf05a0a1e8d230585762eb75ea5cb7b (patch) | |
tree | 3835e3853ad1cf741ece543af6d07e810f2ba845 /sonar-batch | |
parent | def12c0752dae492e4aa9ba8c1fb3b65404b6e33 (diff) | |
download | sonarqube-1579738e5bf05a0a1e8d230585762eb75ea5cb7b.tar.gz sonarqube-1579738e5bf05a0a1e8d230585762eb75ea5cb7b.zip |
SONAR-1450: Add support for incremental review of incoming violations
Diffstat (limited to 'sonar-batch')
5 files changed, 20 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java index 84d6d8f847c..04291e9f080 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java @@ -27,6 +27,8 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.rules.Violation; +import java.util.List; + public final class ViolationPersister { private DatabaseSession session; @@ -46,10 +48,18 @@ public final class ViolationPersister { public RuleFailureModel selectPreviousViolation(Violation violation) { Snapshot snapshot = resourcePersister.getSnapshot(violation.getResource()); Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, true); - return session.getSingleResult(RuleFailureModel.class, + if (previousLastSnapshot == null) { + return null; + } + // Can be several violations on line with same message: for example - "'3' is a magic number" + List<RuleFailureModel> models = session.getResults(RuleFailureModel.class, "snapshotId", previousLastSnapshot.getId(), "line", violation.getLineId(), "message", violation.getMessage()); + if (models != null && !models.isEmpty()) { + return models.get(0); + } + return null; } public void saveOrUpdateViolation(Project project, Violation violation) { @@ -61,7 +71,7 @@ public final class ViolationPersister { } else { // insert model = createModel(violation); - model.setCreatedAt(project.getAnalysisDate()); + model.setCreatedAt(snapshot.getCreatedAt()); } model.setSnapshotId(snapshot.getId()); session.save(model); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java index 238d6e4ab57..61e60f7e613 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java @@ -39,8 +39,6 @@ import org.sonar.api.rules.Violation; import org.sonar.core.components.DefaultRuleFinder; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import java.sql.Date; - public class ViolationPersisterTest extends AbstractDbUnitTestCase { private ViolationPersister violationPersister; @@ -68,7 +66,7 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase { .setPriority(RulePriority.CRITICAL).setLineId(50).setCost(80.0); Violation violation2 = Violation.create(rule2, javaFile) .setPriority(RulePriority.MINOR); - Project project = new Project("project").setAnalysisDate(Date.valueOf("2010-09-01")); + Project project = new Project("project"); violationPersister.saveViolation(project, violation1a); violationPersister.saveViolation(project, violation1b); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml index e32d3cbd7b5..1e7edba42a5 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml @@ -20,4 +20,5 @@ status="U" islast="false" depth="3" /> <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" /> + <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" /> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml index 1266940fe0d..d9b10b4d1c6 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml @@ -19,7 +19,8 @@ status="U" islast="false" depth="3" /> <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" /> - <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6" created_at="2010-09-01 00:00:00.0" /> - <RULE_FAILURES ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80" created_at="2010-09-01 00:00:00.0" /> - <RULE_FAILURES ID="4" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]" created_at="2010-09-01 00:00:00.0" /> + <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" /> + <RULE_FAILURES ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6" created_at="2008-11-01 13:58:00.00" /> + <RULE_FAILURES ID="4" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80" created_at="2008-11-01 13:58:00.00" /> + <RULE_FAILURES ID="5" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" /> </dataset>
\ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml index 0025c82b089..e84072b474d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml @@ -19,4 +19,5 @@ status="U" islast="false" depth="3" /> <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="55.6" created_at="2008-11-01 13:58:00.00" /> -</dataset>
\ No newline at end of file + <RULE_FAILURES ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" /> +</dataset> |