@Override public CloseableIterator<ScannerReport.Duplication> readComponentDuplications(int componentRef) { ensureInitialized(); return delegate.readComponentDuplications(componentRef); }
public List<ScannerReport.Duplication> duplicationsFor(InputFile file) { List<ScannerReport.Duplication> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
@Test public void empty_list_if_no_duplication_found() { assertThat(underTest.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty(); }
@Test public void empty_list_if_no_duplication_block_found() { assertThat(underTest.readComponentDuplications(UNKNOWN_COMPONENT_REF)).isEmpty(); }
private void updateDuplications(Component component) { duplicationEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.Duplication> it = reader.readComponentDuplications(component.getRef())) { while (it.hasNext()) { ScannerReport.Duplication dup = it.next(); duplicationEditor.getDocument().insertString(duplicationEditor.getDocument().getEndPosition().getOffset(), dup + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read duplications for " + getNodeName(component), e); } } }
private Duplication[] readDuplications(DefaultInputFile file, int expected) { assertThat(reader.readComponentDuplications(file.scannerId())).hasSize(expected); Duplication[] duplications = new Duplication[expected]; CloseableIterator<Duplication> dups = reader.readComponentDuplications(file.scannerId()); for (int i = 0; i < expected; i++) { duplications[i] = dups.next(); } dups.close(); return duplications; }
@Test public void dont_fail_if_nothing_to_save() { executor.saveDuplications(batchComponent1, Collections.<CloneGroup>emptyList()); assertThat(reader.readComponentDuplications(batchComponent1.scannerId())).hasSize(0); }
@Test public void should_limit_number_of_clones() { // 1 origin part + 101 duplicates = 102 List<CloneGroup> dups = new ArrayList<>(CpdExecutor.MAX_CLONE_GROUP_PER_FILE + 1); for (int i = 0; i < CpdExecutor.MAX_CLONE_GROUP_PER_FILE + 1; i++) { ClonePart clonePart = new ClonePart(batchComponent1.key(), i, i, i + 1); ClonePart dupPart = new ClonePart(batchComponent1.key(), i + 1, i + 1, i + 2); dups.add(newCloneGroup(clonePart, dupPart)); } executor.saveDuplications(batchComponent1, dups); assertThat(reader.readComponentDuplications(batchComponent1.scannerId())).hasSize(CpdExecutor.MAX_CLONE_GROUP_PER_FILE); assertThat(logTester.logs(LoggerLevel.WARN)) .contains("Too many duplication groups on file " + batchComponent1 + ". Keep only the first " + CpdExecutor.MAX_CLONE_GROUP_PER_FILE + " groups."); }
@Test public void read_duplications() { ScannerReportWriter writer = new ScannerReportWriter(dir); writer.writeMetadata(ScannerReport.Metadata.newBuilder() .setRootComponentRef(1).build()); writer.writeComponent(ScannerReport.Component.newBuilder() .setRef(1).build()); ScannerReport.Duplication duplication = ScannerReport.Duplication.newBuilder() .setOriginPosition(ScannerReport.TextRange.newBuilder() .setStartLine(1) .setEndLine(5) .build()) .addDuplicate(ScannerReport.Duplicate.newBuilder() .setOtherFileRef(2) .setRange(ScannerReport.TextRange.newBuilder() .setStartLine(6) .setEndLine(10) .build()) .build()) .build(); writer.writeComponentDuplications(1, asList(duplication)); ScannerReportReader sut = new ScannerReportReader(dir); assertThat(sut.readComponentDuplications(1)).hasSize(1); }
@Override public CloseableIterator<ScannerReport.Duplication> readComponentDuplications(int componentRef) { ensureInitialized(); return delegate.readComponentDuplications(componentRef); }
public List<ScannerReport.Duplication> duplicationsFor(InputFile file) { List<ScannerReport.Duplication> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.Duplication> it = getReportReader().readComponentDuplications(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
private void updateDuplications(Component component) { duplicationEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.Duplication> it = reader.readComponentDuplications(component.getRef())) { while (it.hasNext()) { ScannerReport.Duplication dup = it.next(); duplicationEditor.getDocument().insertString(duplicationEditor.getDocument().getEndPosition().getOffset(), dup + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read duplications for " + getNodeName(component), e); } } }