diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-14 16:41:49 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-03-14 16:42:49 +0100 |
commit | f543653d4fc293d7d3f0a025665ac0a5c275c6b4 (patch) | |
tree | 3f99de91cfd83ef1fd28b5bd8046ab30ed345c68 /sonar-batch | |
parent | 62ca0c46b1a4e5a17e3a6d19d1b461d8a2ddd1f2 (diff) | |
download | sonarqube-f543653d4fc293d7d3f0a025665ac0a5c275c6b4.tar.gz sonarqube-f543653d4fc293d7d3f0a025665ac0a5c275c6b4.zip |
SONAR-2251 Unstable state of violations when stopping a build
Diffstat (limited to 'sonar-batch')
3 files changed, 13 insertions, 55 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 c840adbfa78..d6cbcf1ac27 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 @@ -40,38 +40,30 @@ public final class ViolationPersister { } void saveViolation(Project project, Violation violation) { - saveOrUpdateViolation(project, violation, null, null); + saveViolation(project, violation, null); } - public void saveOrUpdateViolation(Project project, Violation violation, RuleFailureModel model, String checksum) { + public void saveViolation(Project project, Violation violation, String checksum) { Snapshot snapshot = resourcePersister.saveResource(project, violation.getResource()); - if (model != null) { - // update - model = session.reattach(RuleFailureModel.class, model.getId()); - model = mergeModel(violation, model); - } else { - // insert - model = createModel(violation); - model.setCreatedAt(snapshot.getCreatedAt()); + if (violation.getCreatedAt()==null) { + violation.setCreatedAt(snapshot.getCreatedAt()); } + RuleFailureModel model = createModel(violation); model.setSnapshotId(snapshot.getId()); model.setChecksum(checksum); session.save(model); violation.setMessage(model.getMessage());// the message can be changed in the class RuleFailure (truncate + trim) - violation.setCreatedAt(model.getCreatedAt()); } private RuleFailureModel createModel(Violation violation) { - return mergeModel(violation, new RuleFailureModel()); - } - - private RuleFailureModel mergeModel(Violation violation, RuleFailureModel merge) { + RuleFailureModel model = new RuleFailureModel(); Rule rule = ruleFinder.findByKey(violation.getRule().getRepositoryKey(), violation.getRule().getKey()); - merge.setRuleId(rule.getId()); - merge.setPriority(violation.getSeverity()); - merge.setLine(violation.getLineId()); - merge.setMessage(violation.getMessage()); - merge.setCost(violation.getCost()); - return merge; + model.setRuleId(rule.getId()); + model.setPriority(violation.getSeverity()); + model.setCreatedAt(violation.getCreatedAt()); + model.setLine(violation.getLineId()); + model.setMessage(violation.getMessage()); + model.setCost(violation.getCost()); + return 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 7d90a707941..9b27d33b251 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 @@ -73,15 +73,4 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase { checkTables("shouldInsertViolations", "rule_failures"); } - @Test - public void shouldUpdateViolation() { - Violation violation = Violation.create(rule1, javaFile) - .setLineId(20).setCost(55.6).setSeverity(RulePriority.MINOR); - RuleFailureModel model = getSession().getSingleResult(RuleFailureModel.class, "id", 1); - - violationPersister.saveOrUpdateViolation(new Project("project"), violation, model, null); - - assertThat(violation.getCreatedAt(), notNullValue()); - checkTables("shouldUpdateViolation", "rule_failures"); - } } 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 deleted file mode 100644 index b54b33d0fe2..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml +++ /dev/null @@ -1,23 +0,0 @@ -<dataset> - <rules_categories id="1" name="Efficiency" description="[null]"/> - <rules_categories id="6" name="Usability" description="[null]"/> - - <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck" - plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true" - cardinality="SINGLE" parent_id="[null]"/> - - <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck" - plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true" - cardinality="SINGLE" parent_id="[null]"/> - - <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]" - name="Bar" long_name="org.foo.Bar" description="[null]" - enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/> - - <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]" - scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path="" - status="U" islast="false" depth="3" /> - - <RULE_FAILURES ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="1" MESSAGE="old message" LINE="20" COST="55.6" created_at="2008-11-01 13:58:00.00" checksum="[null]"/> - <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" checksum="[null]"/> -</dataset> |