Search in sources :

Example 11 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition 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 12 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ComponentsPublisherTest method should_skip_dir_without_published_files.

@Test
public void should_skip_dir_without_published_files() {
    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").setName("Root project").setDescription("Root description");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.emptyList());
    // dir with files
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 2);
    tree.index(dir, root);
    // dir without files and issues
    DefaultInputDir dir2 = new DefaultInputDir("module1", "src2", 3);
    tree.index(dir2, root);
    // dir without files but has issues
    DefaultInputDir dir3 = new DefaultInputDir("module1", "src3", 4);
    tree.index(dir3, root);
    writeIssue(4);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 5).setLines(2).build();
    tree.index(file, dir);
    DefaultInputFile file2 = new TestInputFileBuilder("module1", "src2/Foo2.java", 6).setPublish(false).setLines(2).build();
    tree.index(file2, dir2);
    DefaultInputFile file3 = new TestInputFileBuilder("module1", "src2/Foo3.java", 7).setPublish(false).setLines(2).build();
    tree.index(file3, dir3);
    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, 5)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
    // file was not marked for publishing and directory doesn't contain issues, so directory won't be included as well
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isFalse();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isFalse();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse();
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) 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) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 13 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ModuleSettingsTest method test_loading_of_parent_module_settings_for_new_module.

// SONAR-6386
@Test
public void test_loading_of_parent_module_settings_for_new_module() {
    GlobalSettings globalSettings = newGlobalSettings(ImmutableMap.of("overridding", "batch", "on-batch", "true"));
    ProjectRepositories projRepos = createSettings("struts", ImmutableMap.of("on-module", "true", "overridding", "module"));
    ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
    ProjectDefinition.create().setKey("struts").addSubProject(module);
    ModuleSettings moduleSettings = new ModuleSettings(globalSettings, module, projRepos, mode, mock(AnalysisContextReportPublisher.class));
    assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
    assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
    assertThat(moduleSettings.getString("on-module")).isEqualTo("true");
}
Also used : GlobalSettings(org.sonar.scanner.bootstrap.GlobalSettings) AnalysisContextReportPublisher(org.sonar.scanner.report.AnalysisContextReportPublisher) ProjectRepositories(org.sonar.scanner.repository.ProjectRepositories) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 14 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ProjectReactorBuilderTest method shouldDefineMultiModuleProjectWithBaseDir.

@Test
public void shouldDefineMultiModuleProjectWithBaseDir() {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-basedir");
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(1);
    assertThat(modules.get(0).getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 15 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ProjectReactorBuilderTest method shouldDefineMultiLanguageProjectWithDefinitionsAllInRootProject.

// SONARPLUGINS-2421
@Test
public void shouldDefineMultiLanguageProjectWithDefinitionsAllInRootProject() throws IOException {
    ProjectDefinition rootProject = loadProjectDefinition("multi-language-definitions-all-in-root");
    // CHECK ROOT
    assertThat(rootProject.getKey()).isEqualTo("example");
    assertThat(rootProject.getName()).isEqualTo("Example");
    assertThat(rootProject.getVersion()).isEqualTo("1.0");
    // CHECK MODULES
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(2);
    // Module 1
    ProjectDefinition module1 = modules.get(0);
    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root"));
    assertThat(module1.sources()).contains("src/main/java");
    // and module properties must have been cleaned
    assertThat(module1.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root"));
    assertThat(module2.sources()).contains("src/main/groovy");
    // and module properties must have been cleaned
    assertThat(module2.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
}
Also used : File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)52 Test (org.junit.Test)29 File (java.io.File)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 ProjectReactor (org.sonar.api.batch.bootstrap.ProjectReactor)5 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)4 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 GlobalSettings (org.sonar.scanner.bootstrap.GlobalSettings)4 AnalysisContextReportPublisher (org.sonar.scanner.report.AnalysisContextReportPublisher)4 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)4 ProjectRepositories (org.sonar.scanner.repository.ProjectRepositories)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2