@Override public ScannerReport.Component readComponent(int componentRef) { ensureInitialized(); return delegate.readComponent(componentRef); }
public Component getReportComponent(int scannerId) { return getReportReader().readComponent(scannerId); }
public Component getReportComponent(InputComponent inputComponent) { return getReportReader().readComponent(((DefaultInputComponent) inputComponent).scannerId()); }
private void loadChildren(Component parentComponent, DefaultMutableTreeNode parentNode) { for (int ref : parentComponent.getChildRefList()) { Component child = reader.readComponent(ref); DefaultMutableTreeNode childNode = createNode(child); parentNode.add(childNode); loadChildren(child, childNode); } }
@Test(expected = IllegalStateException.class) public void fail_if_missing_file_on_component() { underTest.readComponent(UNKNOWN_COMPONENT_REF); }
private void loadComponents() { int rootComponentRef = metadata.getRootComponentRef(); Component component = reader.readComponent(rootComponentRef); DefaultMutableTreeNode project = createNode(component); loadChildren(component, project); getComponentTree().setModel(new DefaultTreeModel(project)); }
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; }
@Test public void scanProjectWithoutProjectName() throws IOException { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent", StandardCharsets.UTF_8); AnalysisResult result = tester.newAnalysis() .properties(builder .put("sonar.sources", "src") .build()) .execute(); int ref = result.getReportReader().readMetadata().getRootComponentRef(); assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty(); assertThat(result.inputFiles()).hasSize(1); DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo"); assertThat(file.type()).isEqualTo(InputFile.Type.MAIN); assertThat(file.relativePath()).isEqualTo("src/sample.xoo"); assertThat(file.language()).isEqualTo("xoo"); // file was published, since language matched xoo assertThat(file.isPublished()).isTrue(); assertThat(result.getReportComponent(file.scannerId())).isNotNull(); }
@Test public void scanMultiModuleWithBranch() throws IOException { Path srcDir = baseDir.toPath().resolve("moduleA").resolve("src"); Files.createDirectories(srcDir); File xooFile = new File(srcDir.toFile(), "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "branch") .put("sonar.modules", "moduleA") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("moduleA/src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA/src/sample.xoo"); // no branch in the report DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("moduleA/src/sample.xoo"); assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getProjectRelativePath()).isEqualTo("moduleA/src/sample.xoo"); assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch"); result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "") .put("sonar.modules", "moduleA") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("moduleA/src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA/src/sample.xoo"); }
@Test public void scanProjectWithBranch() throws IOException { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "branch") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo"); assertThat(result.getReportReader().readComponent(inputfile.scannerId()).getProjectRelativePath()).isEqualTo("src/sample.xoo"); assertThat(result.getReportReader().readMetadata().getDeprecatedBranch()).isEqualTo("branch"); result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "") .build()) .execute(); assertThat(result.inputFiles()).hasSize(1); assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo"); }
@Test public void read_components() { ScannerReportWriter writer = new ScannerReportWriter(dir); ScannerReport.Component.Builder component = ScannerReport.Component.newBuilder() .setRef(1) .setProjectRelativePath("src/main/java/Foo.java"); writer.writeComponent(component.build()); assertThat(underTest.readComponent(1).getProjectRelativePath()).isEqualTo("src/main/java/Foo.java"); }
@Test public void publish_project_without_version_and_name() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); ProjectDefinition rootDef = ProjectDefinition.create() .setKey("foo") .setDescription("Root description") .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()); DefaultInputProject project = new DefaultInputProject(rootDef, 1); InputComponentStore store = new InputComponentStore(branchConfiguration); ComponentsPublisher publisher = new ComponentsPublisher(project, store); publisher.publish(writer); assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); ScannerReportReader reader = new ScannerReportReader(outputDir); Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getName()).isEqualTo(""); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); assertThat(rootProtobuf.getVersion()).isEqualTo(""); assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); }
@Test public void should_set_modified_name_with_branch() throws IOException { ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class); when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12")); ProjectDefinition rootDef = ProjectDefinition.create() .setKey("foo") .setDescription("Root description") .setBaseDir(temp.newFolder()) .setWorkDir(temp.newFolder()) .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch"); DefaultInputProject project = new DefaultInputProject(rootDef, 1); InputComponentStore store = new InputComponentStore(branchConfiguration); ComponentsPublisher publisher = new ComponentsPublisher(project, store); publisher.publish(writer); Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getName()).isEqualTo("foo my_branch"); }
Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getVersion()).isEqualTo("1.0"); assertThat(rootProtobuf.getLinkCount()).isEqualTo(2);
Component rootProtobuf = reader.readComponent(1); assertThat(rootProtobuf.getKey()).isEqualTo("foo"); assertThat(rootProtobuf.getDescription()).isEqualTo("Root description"); assertThat(rootProtobuf.getLinkCount()).isEqualTo(0); assertThat(reader.readComponent(4).getStatus()).isEqualTo(FileStatus.SAME); assertThat(reader.readComponent(6).getStatus()).isEqualTo(FileStatus.CHANGED); assertThat(reader.readComponent(7).getStatus()).isEqualTo(FileStatus.ADDED);
@Override public ScannerReport.Component readComponent(int componentRef) { ensureInitialized(); return delegate.readComponent(componentRef); }
public Component getReportComponent(int scannerId) { return getReportReader().readComponent(scannerId); }
public Component getReportComponent(InputComponent inputComponent) { return getReportReader().readComponent(((DefaultInputComponent) inputComponent).scannerId()); }
private void loadChildren(Component parentComponent, DefaultMutableTreeNode parentNode) { for (int ref : parentComponent.getChildRefList()) { Component child = reader.readComponent(ref); DefaultMutableTreeNode childNode = createNode(child); parentNode.add(childNode); loadChildren(child, childNode); } }
private void loadComponents() { int rootComponentRef = metadata.getRootComponentRef(); Component component = reader.readComponent(rootComponentRef); DefaultMutableTreeNode project = createNode(component); loadChildren(component, project); getComponentTree().setModel(new DefaultTreeModel(project)); }