continue;
}
- processClassMeasure(duplicationsData, firstFile, firstLine, secondFile, secondLine, match.getLineCount());
+ processClassMeasure(duplicationsData, firstFile, firstLine, secondFile, secondLine, match.getLineCount(), match);
}
}
}
}
private void processClassMeasure(Map<Resource, DuplicationsData> fileContainer, Resource file, int duplicationStartLine,
- Resource targetFile, int targetDuplicationStartLine, int duplicatedLines) {
+ Resource targetFile, int targetDuplicationStartLine, int duplicatedLines, Match match) {
if (file != null && targetFile != null) {
DuplicationsData data = fileContainer.get(file);
if (data == null) {
data = new DuplicationsData(file, context);
fileContainer.put(file, data);
}
- data.cumulate(targetFile, targetDuplicationStartLine, duplicationStartLine, duplicatedLines);
+ data.cumulate(targetFile, targetDuplicationStartLine, duplicationStartLine, duplicatedLines, match);
}
}
private static final class DuplicationsData {
protected Set<Integer> duplicatedLines = new HashSet<Integer>();
- protected double duplicatedBlocks;
+ protected Set<Match> duplicatedBlocks = new HashSet<Match>();
protected Resource resource;
private SensorContext context;
private List<StringBuilder> duplicationXMLEntries = new ArrayList<StringBuilder>();
this.resource = resource;
}
- protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines) {
+ protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines,
+ Match match) {
StringBuilder xml = new StringBuilder();
- xml.append("<duplication lines=\"").append(duplicatedLines).append("\" start=\"").append(duplicationStartLine).append(
- "\" target-start=\"").append(targetDuplicationStartLine).append("\" target-resource=\"").append(
- context.saveResource(targetResource)).append("\"/>");
+ xml.append("<duplication lines=\"").append(duplicatedLines).append("\" start=\"").append(duplicationStartLine)
+ .append("\" target-start=\"").append(targetDuplicationStartLine).append("\" target-resource=\"")
+ .append(context.saveResource(targetResource)).append("\"/>");
duplicationXMLEntries.add(xml);
for (int duplicatedLine = duplicationStartLine; duplicatedLine < duplicationStartLine + duplicatedLines; duplicatedLine++) {
this.duplicatedLines.add(duplicatedLine);
}
- this.duplicatedBlocks++;
+ duplicatedBlocks.add(match);
}
protected void saveUsing(SensorContext context) {
context.saveMeasure(resource, CoreMetrics.DUPLICATED_FILES, 1d);
context.saveMeasure(resource, CoreMetrics.DUPLICATED_LINES, (double) duplicatedLines.size());
- context.saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, duplicatedBlocks);
+ context.saveMeasure(resource, CoreMetrics.DUPLICATED_BLOCKS, (double) duplicatedBlocks.size());
context.saveMeasure(resource, new Measure(CoreMetrics.DUPLICATIONS_DATA, getDuplicationXMLData()));
}
cpdAnalyser.analyse(Arrays.asList(match).iterator());
verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_FILES, 1d);
- verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_BLOCKS, 3d);
+ verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_BLOCKS, 1d);
verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_LINES, 200d);
verify(context).saveMeasure(
eq(resource1),
verify(context).saveMeasure(resource3, CoreMetrics.DUPLICATED_FILES, 1d);
verify(context).saveMeasure(resource3, CoreMetrics.DUPLICATED_LINES, 200d);
- verify(context).saveMeasure(resource3, CoreMetrics.DUPLICATED_BLOCKS, 3d);
+ verify(context).saveMeasure(resource3, CoreMetrics.DUPLICATED_BLOCKS, 1d);
verify(context).saveMeasure(
eq(resource2),
argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>"
verify(context).saveMeasure(resource2, CoreMetrics.DUPLICATED_FILES, 1d);
verify(context).saveMeasure(resource2, CoreMetrics.DUPLICATED_LINES, 200d);
- verify(context).saveMeasure(resource2, CoreMetrics.DUPLICATED_BLOCKS, 3d);
+ verify(context).saveMeasure(resource2, CoreMetrics.DUPLICATED_BLOCKS, 1d);
verify(context).saveMeasure(
eq(resource3),
argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>"
verify(context).saveMeasure(resource4, CoreMetrics.DUPLICATED_LINES, 200d);
verify(context).saveMeasure(resource4, CoreMetrics.DUPLICATED_FILES, 1d);
- verify(context).saveMeasure(resource4, CoreMetrics.DUPLICATED_BLOCKS, 3d);
+ verify(context).saveMeasure(resource4, CoreMetrics.DUPLICATED_BLOCKS, 1d);
verify(context).saveMeasure(
eq(resource4),
argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>"
cpdAnalyser.analyse(Arrays.asList(match1).iterator());
verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_FILES, 1d);
- verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_BLOCKS, 2d);
verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_LINES, 400d);
+ verify(context).saveMeasure(resource1, CoreMetrics.DUPLICATED_BLOCKS, 1d);
verify(context).saveMeasure(
eq(resource1),
argThat(new IsMeasure(CoreMetrics.DUPLICATIONS_DATA, "<duplications>"
- + "<duplication lines=\"200\" start=\"5\" target-start=\"215\" target-resource=\"key1\"/>"
- + "<duplication lines=\"200\" start=\"215\" target-start=\"5\" target-resource=\"key1\"/>"
- + "</duplications>")));
-
+ + "<duplication lines=\"200\" start=\"5\" target-start=\"215\" target-resource=\"key1\"/>"
+ + "<duplication lines=\"200\" start=\"215\" target-start=\"5\" target-resource=\"key1\"/>" + "</duplications>")));
+
verify(context, atLeastOnce()).saveResource(resource1);
}
-
+
private static TokenEntry createTokenEntry(String sourceId, int line) {
TokenEntry entry = new TokenEntry(null, sourceId, line);
entry.setHashCode(sourceId.hashCode() + line);