private void updateSource(Component component) { File sourceFile = reader.getFileStructure().fileFor(Domain.SOURCE, component.getRef()); sourceEditor.setText(""); if (sourceFile.exists()) { try (Scanner s = new Scanner(sourceFile, StandardCharsets.UTF_8.name()).useDelimiter("\\Z")) { if (s.hasNext()) { sourceEditor.setText(s.next()); } } catch (IOException ex) { StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); sourceEditor.setText(errors.toString()); } } }
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 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); } }
@Test public void write_component() { // no data yet assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isFalse(); // write data ScannerReport.Component.Builder component = ScannerReport.Component.newBuilder() .setRef(1) .setLanguage("java") .setProjectRelativePath("src/Foo.java") .setType(ComponentType.FILE) .setIsTest(false) .addChildRef(5) .addChildRef(42); underTest.writeComponent(component.build()); assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1); assertThat(file).exists().isFile(); ScannerReport.Component read = Protobuf.read(file, ScannerReport.Component.parser()); assertThat(read.getRef()).isEqualTo(1); assertThat(read.getChildRefList()).containsOnly(5, 42); assertThat(read.getName()).isEmpty(); assertThat(read.getIsTest()).isFalse(); }
private Component buildProject(List<Component> children) { String projectKey = keyGenerator.generateKey(rootComponent.getKey(), null); String uuid = uuidSupplier.apply(projectKey); String projectPublicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), null); ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT) .setUuid(uuid) .setDbKey(projectKey) .setKey(projectPublicKey) .setStatus(convertStatus(rootComponent.getStatus())) .setProjectAttributes(new ProjectAttributes(createProjectVersion(rootComponent))) .setReportAttributes(createAttributesBuilder(rootComponent.getRef(), rootComponent.getProjectRelativePath(), scmBasePath).build()) .addChildren(children); setNameAndDescription(rootComponent, builder); return builder.build(); }
private void updateSignificantCode(Component component) { significantCodeEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.LineSgnificantCode> it = reader.readComponentSignificantCode(component.getRef())) { if (it != null) { while (it.hasNext()) { ScannerReport.LineSgnificantCode textBlock = it.next(); significantCodeEditor.getDocument().insertString(significantCodeEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null); } } } catch (Exception e) { throw new IllegalStateException("Can't read significant code for " + getNodeName(component), e); } } }
private ComponentImpl buildFile(ScannerReport.Component component) { String key = keyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); String publicKey = publicKeyGenerator.generateKey(rootComponent.getKey(), component.getProjectRelativePath()); return ComponentImpl.builder(Component.Type.FILE) .setUuid(uuidSupplier.apply(key)) .setDbKey(key) .setKey(publicKey) .setName(component.getProjectRelativePath()) .setShortName(FilenameUtils.getName(component.getProjectRelativePath())) .setStatus(convertStatus(component.getStatus())) .setDescription(trimToNull(component.getDescription())) .setReportAttributes(createAttributesBuilder(component.getRef(), component.getProjectRelativePath(), scmBasePath).build()) .setFileAttributes(createFileAttributes(component)) .build(); }
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 void updateCpdTextBlocks(Component component) { cpdTextBlocksEditor.setText(""); if (reader.hasCoverage(component.getRef())) { try (CloseableIterator<ScannerReport.CpdTextBlock> it = reader.readCpdTextBlocks(component.getRef())) { while (it.hasNext()) { ScannerReport.CpdTextBlock textBlock = it.next(); cpdTextBlocksEditor.getDocument().insertString(cpdTextBlocksEditor.getDocument().getEndPosition().getOffset(), textBlock + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read CPD text blocks for " + getNodeName(component), e); } } }
private static ScannerReport.IssueLocation moveLocation(ScannerReport.Component root, ScannerReport.Component component, ScannerReport.IssueLocation location) { String msg = "[" + component.getProjectRelativePath() + "] " + location.getMsg(); return ScannerReport.IssueLocation.newBuilder() .setComponentRef(root.getRef()) .setMsg(msg) .build(); }
private void updateCoverage(Component component) { coverageEditor.setText(""); try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) { while (it.hasNext()) { ScannerReport.LineCoverage coverage = it.next(); coverageEditor.getDocument().insertString(coverageEditor.getDocument().getEndPosition().getOffset(), coverage + "\n", null); } } catch (Exception e) { throw new IllegalStateException("Can't read code coverage for " + getNodeName(component), e); } }
public BatchReportReaderRule putComponent(ScannerReport.Component component) { this.components.put(component.getRef(), component); return this; }
public List<ScannerReport.Issue> issuesFor(Component reportComponent) { int ref = reportComponent.getRef(); return issuesFor(ref); }
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 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); } }
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 ScannerReport.Changesets getChangesets(File baseDir, String path) { File reportDir = new File(baseDir, ".sonar/scanner-report"); ScannerReportReader reader = new ScannerReportReader(reportDir); Component project = reader.readComponent(reader.readMetadata().getRootComponentRef()); for (Integer fileRef : project.getChildRefList()) { Component file = reader.readComponent(fileRef); if (file.getProjectRelativePath().equals(path)) { return reader.readChangesets(file.getRef()); } } return null; }
public File writeComponent(ScannerReport.Component component) { File file = fileStructure.fileFor(FileStructure.Domain.COMPONENT, component.getRef()); Protobuf.write(component, file); return file; }
public ScannerReport.Component add(ScannerReport.Component.Builder builder) { ScannerReport.Component component = builder.build(); ScannerReport.Component existing = components.put(component.getRef(), component); checkArgument(existing == null, "Component %s already set for ref %s", existing, component.getRef()); return component; } }