Search in sources :

Example 61 with ProjectDefinition

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

the class ProjectReactorBuilderTest method shouldDefineSimpleProject.

@Test
public void shouldDefineSimpleProject() {
    ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");
    assertThat(projectDefinition.getKey()).isEqualTo("com.foo.project");
    assertThat(projectDefinition.getName()).isEqualTo("Foo Project");
    assertThat(projectDefinition.getVersion()).isEqualTo("1.0-SNAPSHOT");
    assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project");
    assertThat(projectDefinition.sources()).contains("sources");
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 62 with ProjectDefinition

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

the class ProjectReactorBuilderTest method modulesRepeatedIds.

@Test
public void modulesRepeatedIds() {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-repeated-id");
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isOne();
    // Module 1
    ProjectDefinition module1 = modules.get(0);
    assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
    assertThat(module1.getName()).isEqualTo("Foo Module 1");
    // Module 1 -> Module 1
    ProjectDefinition module1_module1 = module1.getSubProjects().get(0);
    assertThat(module1_module1.getKey()).isEqualTo("com.foo.project:module1:module1");
    assertThat(module1_module1.getName()).isEqualTo("Foo Sub Module 1");
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 63 with ProjectDefinition

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

the class ProjectReactorBuilderTest method multiModuleProperties.

@Test
public void multiModuleProperties() {
    ProjectDefinition projectDefinition = loadProjectDefinition("big-multi-module-definitions-all-in-root");
    assertThat(projectDefinition.properties().get("module11.property")).isNull();
    ProjectDefinition module1 = null;
    ProjectDefinition module2 = null;
    for (ProjectDefinition prj : projectDefinition.getSubProjects()) {
        if (prj.getKey().equals("com.foo.project:module1")) {
            module1 = prj;
        } else if (prj.getKey().equals("com.foo.project:module2")) {
            module2 = prj;
        }
    }
    assertThat(module1.properties().get("module11.property")).isNull();
    assertThat(module1.properties().get("property")).isNull();
    assertThat(module2.properties().get("module11.property")).isNull();
    assertThat(module2.properties().get("property")).isNull();
    ProjectDefinition module11 = null;
    ProjectDefinition module12 = null;
    for (ProjectDefinition prj : module1.getSubProjects()) {
        if (prj.getKey().equals("com.foo.project:module1:module11")) {
            module11 = prj;
        } else if (prj.getKey().equals("com.foo.project:module1:module12")) {
            module12 = prj;
        }
    }
    assertThat(module11.properties().get("module1.module11.property")).isNull();
    assertThat(module11.properties().get("module11.property")).isNull();
    assertThat(module11.properties()).containsEntry("property", "My module11 property");
    assertThat(module12.properties().get("module11.property")).isNull();
    assertThat(module12.properties().get("property")).isNull();
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 64 with ProjectDefinition

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

the class ProjectReactorBuilderTest method shouldFailIf2ModulesWithSameKey.

@Test
public void shouldFailIf2ModulesWithSameKey() {
    Map<String, String> props = singletonMap("sonar.projectKey", "root");
    ProjectDefinition root = ProjectDefinition.create().setProperties(props);
    Map<String, String> props1 = singletonMap("sonar.projectKey", "mod1");
    root.addSubProject(ProjectDefinition.create().setProperties(props1));
    // Check uniqueness of a new module: OK
    Map<String, String> props2 = singletonMap("sonar.projectKey", "mod2");
    ProjectDefinition mod2 = ProjectDefinition.create().setProperties(props2);
    ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);
    // Now, add it and check again
    root.addSubProject(mod2);
    assertThatThrownBy(() -> ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root)).isInstanceOf(MessageException.class).hasMessage("Project 'root' can't have 2 modules with the following key: mod2");
}
Also used : MessageException(org.sonar.api.utils.MessageException) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 65 with ProjectDefinition

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

the class ProjectReactorBuilderTest method shouldDefineMultiModuleProjectWithModuleKey.

// SONAR-4876
@Test
public void shouldDefineMultiModuleProjectWithModuleKey() {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-moduleKey");
    // CHECK ROOT
    // module properties must have been cleaned
    assertThat(rootProject.properties().get("module1.sonar.moduleKey")).isNull();
    assertThat(rootProject.properties().get("module2.sonar.moduleKey")).isNull();
    // CHECK MODULES
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(2);
    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getKey()).isEqualTo("com.foo.project.module2");
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)69 Test (org.junit.Test)43 File (java.io.File)17 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)16 ProjectReactor (org.sonar.api.batch.bootstrap.ProjectReactor)10 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)7 DefaultInputProject (org.sonar.api.batch.fs.internal.DefaultInputProject)7 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)6 Path (java.nio.file.Path)5 MessageException (org.sonar.api.utils.MessageException)5 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)5 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)5 InputComponentStore (org.sonar.scanner.scan.filesystem.InputComponentStore)5 Before (org.junit.Before)4 ProjectInfo (org.sonar.scanner.ProjectInfo)4 GlobalSettings (org.sonar.scanner.bootstrap.GlobalSettings)4 AnalysisContextReportPublisher (org.sonar.scanner.report.AnalysisContextReportPublisher)4 ProjectRepositories (org.sonar.scanner.repository.ProjectRepositories)4 ArrayList (java.util.ArrayList)3 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)3