private List<ScannerReport.ExternalIssue> externalIssuesFor(int ref) { List<ScannerReport.ExternalIssue> result = Lists.newArrayList(); try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(ref)) { while (it.hasNext()) { result.add(it.next()); } } return result; }
private List<ScannerReport.Issue> issuesFor(int ref) { List<ScannerReport.Issue> result = Lists.newArrayList(); try (CloseableIterator<ScannerReport.Issue> it = reader.readComponentIssues(ref)) { while (it.hasNext()) { result.add(it.next()); } } return result; }
private void updateActiveRules() { activeRuleEditor.setText(""); StringBuilder builder = new StringBuilder(); try (CloseableIterator<ScannerReport.ActiveRule> activeRuleCloseableIterator = reader.readActiveRules()) { while (activeRuleCloseableIterator.hasNext()) { builder.append(activeRuleCloseableIterator.next().toString()).append("\n"); } activeRuleEditor.setText(builder.toString()); } }
public List<ScannerReport.AdHocRule> adHocRules() { List<ScannerReport.AdHocRule> result = new ArrayList<>(); try (CloseableIterator<ScannerReport.AdHocRule> it = getReportReader().readAdHocRules()) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; } }
public List<ScannerReport.CpdTextBlock> duplicationBlocksFor(InputFile file) { List<ScannerReport.CpdTextBlock> result = new ArrayList<>(); int ref = ((DefaultInputComponent) file).scannerId(); try (CloseableIterator<ScannerReport.CpdTextBlock> it = getReportReader().readCpdTextBlocks(ref)) { while (it.hasNext()) { result.add(it.next()); } } catch (Exception e) { throw new IllegalStateException(e); } return result; }
public void relocate(ScannerReport.Component root, ScannerReport.Component component) { CloseableIterator<ScannerReport.Issue> issueIt = reader.readComponentIssues(component.getRef()); while (issueIt.hasNext()) { ScannerReport.Issue issue = issueIt.next(); movedIssues.add(moveIssueToRoot(root, component, issue)); } }
private void updateHighlighting(Component component) { highlightingEditor.setText(""); try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) { while (it.hasNext()) { ScannerReport.SyntaxHighlightingRule rule = it.next(); highlightingEditor.getDocument().insertString(highlightingEditor.getDocument().getEndPosition().getOffset(), rule + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read syntax highlighting for " + getNodeName(component), e); } }
private void updateMeasures(Component component) { measuresEditor.setText(""); try (CloseableIterator<ScannerReport.Measure> it = reader.readComponentMeasures(component.getRef())) { while (it.hasNext()) { ScannerReport.Measure measure = it.next(); measuresEditor.getDocument().insertString(measuresEditor.getDocument().getEndPosition().getOffset(), measure + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read measures for " + getNodeName(component), e); } }
private void updateSymbols(Component component) { symbolEditor.setText(""); try (CloseableIterator<ScannerReport.Symbol> it = reader.readComponentSymbols(component.getRef())) { while (it.hasNext()) { ScannerReport.Symbol symbol = it.next(); symbolEditor.getDocument().insertString(symbolEditor.getDocument().getEndPosition().getOffset(), symbol + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read symbol references for " + getNodeName(component), e); } }
private void updateIssues(Component component) { issuesEditor.setText(""); try (CloseableIterator<Issue> it = reader.readComponentIssues(component.getRef())) { while (it.hasNext()) { Issue issue = it.next(); int offset = issuesEditor.getDocument().getEndPosition().getOffset(); issuesEditor.getDocument().insertString(offset, issue.toString(), null); } } catch (Exception e) { throw new IllegalStateException("Can't read issues for " + getNodeName(component), e); } }
private void updateExternalIssues(Component component) { externalIssuesEditor.setText(""); try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(component.getRef())) { while (it.hasNext()) { ScannerReport.ExternalIssue issue = it.next(); int offset = externalIssuesEditor.getDocument().getEndPosition().getOffset(); externalIssuesEditor.getDocument().insertString(offset, issue.toString(), null); } } catch (Exception e) { throw new IllegalStateException("Can't read external issues for " + getNodeName(component), e); } }
@Test public void verify_readComponentIssues_returns_Issues() { writer.writeComponentIssues(COMPONENT_REF, of(ISSUE)); try (CloseableIterator<ScannerReport.Issue> res = underTest.readComponentIssues(COMPONENT_REF)) { assertThat(res.next()).isEqualTo(ISSUE); assertThat(res.hasNext()).isFalse(); } }
@Test public void verify_readComponentMeasures_returns_measures() { writer.writeComponentMeasures(COMPONENT_REF, of(MEASURE)); try (CloseableIterator<ScannerReport.Measure> measures = underTest.readComponentMeasures(COMPONENT_REF)) { assertThat(measures.next()).isEqualTo(MEASURE); assertThat(measures.hasNext()).isFalse(); } }
@Test public void verify_readComponentDuplications_returns_Issues() { writer.writeComponentDuplications(COMPONENT_REF, of(DUPLICATION)); try (CloseableIterator<ScannerReport.Duplication> res = underTest.readComponentDuplications(COMPONENT_REF)) { assertThat(res.next()).isEqualTo(DUPLICATION); assertThat(res.hasNext()).isFalse(); } }
@Override public void visitFile(Component file) { try (CloseableIterator<ScannerReport.Duplication> duplications = batchReportReader.readComponentDuplications(file.getReportAttributes().getRef())) { int idGenerator = 1; while (duplications.hasNext()) { loadDuplications(file, duplications.next(), idGenerator); idGenerator++; count++; } } }
private String computeRawSourceHash(Component file) { SourceHashComputer sourceHashComputer = new SourceHashComputer(); try (CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file)) { while (linesIterator.hasNext()) { sourceHashComputer.addLine(linesIterator.next(), linesIterator.hasNext()); } return sourceHashComputer.getHash(); } }
private List<String> createLineHashes(Component component, Optional<LineRange[]> significantCodePerLine) { LineHashesComputer processor = createLineHashesProcessor(component.getFileAttributes().getLines(), significantCodePerLine); try (CloseableIterator<String> lines = sourceLinesRepository.readLines(component)) { while (lines.hasNext()) { processor.addLine(lines.next()); } return processor.getResult(); } }
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 insert_fails_with_IAE_if_data_is_fully_read() { CloseableIterator<String> iterator = scannerContextInputStreamOf("aa"); iterator.next(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Scanner context can not be empty"); underTest.insert(dbSession, SOME_UUID, iterator); }