diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-03-16 17:09:22 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-03-16 17:10:33 +0400 |
commit | 1f14e3bcda82079f1ebd577aaca7869f732e4467 (patch) | |
tree | 0fb7cdefa3d2dc29555a84e9c6d90a2cf708da1b /plugins/sonar-core-plugin | |
parent | 0a6fa1963cb0463cc4edb3da74fcebd1916d4f32 (diff) | |
download | sonarqube-1f14e3bcda82079f1ebd577aaca7869f732e4467.tar.gz sonarqube-1f14e3bcda82079f1ebd577aaca7869f732e4467.zip |
SONAR-3072 Restore behaviour of tracking of violations when importSources=false
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r-- | plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java index 705069235c9..ad06764637d 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecorator.java @@ -55,25 +55,31 @@ public class ViolationTrackingDecorator implements Decorator { ViolationQuery violationQuery = ViolationQuery.create().forResource(resource).setSwitchMode(ViolationQuery.SwitchMode.BOTH); if (!context.getViolations(violationQuery).isEmpty()) { - // Load new violations - List<Violation> newViolations = prepareNewViolations(context); + return; + } + + String source = index.getSource(resource); + String referenceSource = referenceAnalysis.getSource(resource); - // Load reference violations - List<RuleFailureModel> referenceViolations = referenceAnalysis.getViolations(resource); + // Load new violations + List<Violation> newViolations = prepareNewViolations(context, source); - // SONAR-3072 Construct blocks recognizer based on reference source - String referenceSource = referenceAnalysis.getSource(resource); - String source = index.getSource(context.getResource()); - ViolationTrackingBlocksRecognizer rec = new ViolationTrackingBlocksRecognizer(referenceSource, source); + // Load reference violations + List<RuleFailureModel> referenceViolations = referenceAnalysis.getViolations(resource); - // Map new violations with old ones - mapViolations(newViolations, referenceViolations, rec); + // SONAR-3072 Construct blocks recognizer based on reference source + ViolationTrackingBlocksRecognizer rec = null; + if (source != null && referenceSource != null) { + rec = new ViolationTrackingBlocksRecognizer(referenceSource, source); } + + // Map new violations with old ones + mapViolations(newViolations, referenceViolations, rec); } - private List<Violation> prepareNewViolations(DecoratorContext context) { + private List<Violation> prepareNewViolations(DecoratorContext context, String source) { List<Violation> result = Lists.newArrayList(); - List<String> checksums = SourceChecksum.lineChecksumsOfFile(index.getSource(context.getResource())); + List<String> checksums = SourceChecksum.lineChecksumsOfFile(source); for (Violation violation : context.getViolations()) { violation.setChecksum(SourceChecksum.getChecksumForLine(checksums, violation.getLineId())); result.add(violation); @@ -236,7 +242,7 @@ public class ViolationTrackingDecorator implements Decorator { } private void mapViolation(Violation newViolation, RuleFailureModel pastViolation, - Multimap<Integer, RuleFailureModel> pastViolationsByRule, Map<Violation, RuleFailureModel> violationMap) { + Multimap<Integer, RuleFailureModel> pastViolationsByRule, Map<Violation, RuleFailureModel> violationMap) { if (pastViolation != null) { newViolation.setCreatedAt(pastViolation.getCreatedAt()); newViolation.setPermanentId(pastViolation.getPermanentId()); |