From 1f14e3bcda82079f1ebd577aaca7869f732e4467 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 16 Mar 2012 17:09:22 +0400 Subject: [PATCH] SONAR-3072 Restore behaviour of tracking of violations when importSources=false --- .../ViolationTrackingDecorator.java | 32 +++++++++++-------- 1 file 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 newViolations = prepareNewViolations(context); + return; + } + + String source = index.getSource(resource); + String referenceSource = referenceAnalysis.getSource(resource); - // Load reference violations - List referenceViolations = referenceAnalysis.getViolations(resource); + // Load new violations + List 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 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 prepareNewViolations(DecoratorContext context) { + private List prepareNewViolations(DecoratorContext context, String source) { List result = Lists.newArrayList(); - List checksums = SourceChecksum.lineChecksumsOfFile(index.getSource(context.getResource())); + List 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 pastViolationsByRule, Map violationMap) { + Multimap pastViolationsByRule, Map violationMap) { if (pastViolation != null) { newViolation.setCreatedAt(pastViolation.getCreatedAt()); newViolation.setPermanentId(pastViolation.getPermanentId()); -- 2.39.5