Search in sources :

Example 1 with Component

use of org.sonar.scanner.protocol.output.ScannerReport.Component in project sonarqube by SonarSource.

the class ComponentsPublisherTest method add_components_with_links_and_branch.

@Test
public void add_components_with_links_and_branch() throws Exception {
    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch").setName("Root project").setProperty(CoreProperties.LINKS_HOME_PAGE, "http://home").setDescription("Root description");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setProperty(CoreProperties.LINKS_CI, "http://ci").setDescription("Module description");
    rootDef.addSubProject(module1Def);
    DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
    tree.index(module1, root);
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
    tree.index(dir, module1);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
    tree.index(file, dir);
    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
    publisher.publish(writer);
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    Component rootProtobuf = reader.readComponent(1);
    assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
    assertThat(rootProtobuf.getLinkCount()).isEqualTo(1);
    assertThat(rootProtobuf.getLink(0).getType()).isEqualTo(ComponentLinkType.HOME);
    assertThat(rootProtobuf.getLink(0).getHref()).isEqualTo("http://home");
    Component module1Protobuf = reader.readComponent(2);
    assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
    assertThat(module1Protobuf.getLinkCount()).isEqualTo(1);
    assertThat(module1Protobuf.getLink(0).getType()).isEqualTo(ComponentLinkType.CI);
    assertThat(module1Protobuf.getLink(0).getHref()).isEqualTo("http://ci");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) ComponentsPublisher(org.sonar.scanner.report.ComponentsPublisher) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 2 with Component

use of org.sonar.scanner.protocol.output.ScannerReport.Component in project sonarqube by SonarSource.

the class ComponentsPublisherTest method add_components_without_version_and_name.

@Test
public void add_components_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");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setDescription("Module description");
    rootDef.addSubProject(module1Def);
    DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
    tree.index(module1, root);
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
    tree.index(dir, module1);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
    tree.index(file, dir);
    DefaultInputFile fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 5).setLines(10).build();
    tree.index(fileWithoutLang, dir);
    DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 6).setType(Type.TEST).setLines(4).build();
    tree.index(testFile, dir);
    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
    // no such reference
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse();
    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);
    Component module1Protobuf = reader.readComponent(2);
    assertThat(module1Protobuf.getKey()).isEqualTo("module1");
    assertThat(module1Protobuf.getName()).isEqualTo("");
    assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
    assertThat(module1Protobuf.getVersion()).isEqualTo("");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) ComponentsPublisher(org.sonar.scanner.report.ComponentsPublisher) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 3 with Component

use of org.sonar.scanner.protocol.output.ScannerReport.Component in project sonarqube by SonarSource.

the class ScannerReportViewerApp method loadComponents.

private void loadComponents() {
    int rootComponentRef = metadata.getRootComponentRef();
    Component component = reader.readComponent(rootComponentRef);
    DefaultMutableTreeNode project = createNode(component);
    loadChildren(component, project);
    getComponentTree().setModel(new DefaultTreeModel(project));
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Component(org.sonar.scanner.protocol.output.ScannerReport.Component)

Example 4 with Component

use of org.sonar.scanner.protocol.output.ScannerReport.Component in project sonarqube by SonarSource.

the class ScannerReportViewerApp method loadChildren.

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);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Component(org.sonar.scanner.protocol.output.ScannerReport.Component)

Example 5 with Component

use of org.sonar.scanner.protocol.output.ScannerReport.Component in project sonarqube by SonarSource.

the class ScmMediumTest method getChangesets.

private ScannerReport.Changesets getChangesets(File baseDir, String path) {
    File reportDir = new File(baseDir, ".sonar/batch-report");
    ScannerReportReader reader = new ScannerReportReader(reportDir);
    Component project = reader.readComponent(reader.readMetadata().getRootComponentRef());
    Component dir = reader.readComponent(project.getChildRef(0));
    for (Integer fileRef : dir.getChildRefList()) {
        Component file = reader.readComponent(fileRef);
        if (file.getPath().equals(path)) {
            return reader.readChangesets(file.getRef());
        }
    }
    return null;
}
Also used : ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) File(java.io.File)

Aggregations

Component (org.sonar.scanner.protocol.output.ScannerReport.Component)7 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Test (org.junit.Test)3 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)3 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)3 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)3 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)3 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)3 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)3 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 Cursor (java.awt.Cursor)1 Dimension (java.awt.Dimension)1 File (java.io.File)1 IOException (java.io.IOException)1 JEditorPane (javax.swing.JEditorPane)1 JFrame (javax.swing.JFrame)1 JScrollPane (javax.swing.JScrollPane)1