LogsIteratorInputStream(CloseableIterator<String> logsIterator, Charset charset) { checkArgument(logsIterator.hasNext(), "LogsIterator can't be empty or already read"); this.charset = charset; this.lineFeed = "\n".getBytes(charset); this.logsIterator = logsIterator; }
@Override public boolean hasNext() { if (delegate.hasNext()) { checkState(currentLine < numberOfLines, "Source of file '%s' has at least one more line than the expected number (%s)", file, numberOfLines); return true; } checkState((currentLine + 1) >= numberOfLines, "Source of file '%s' has less lines (%s) than the expected number (%s)", file, currentLine, numberOfLines); return currentLine < numberOfLines; }
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; }
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(); } }
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); } }
@Test public void readScannerLogs_no_logs() { CloseableIterator<String> logs = underTest.readScannerLogs(); assertThat(logs.hasNext()).isFalse(); }
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(); } }
@Test public void do_nothing_on_file() { underTest.visit(ReportComponent.builder(FILE, 1).build()); verifyZeroInteractions(issueLifecycle); CloseableIterator<DefaultIssue> issues = issueCache.traverse(); assertThat(issues.hasNext()).isFalse(); } }
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(); } }