Search in sources :

Example 41 with ProjectDefinition

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

the class ModuleFileSystemInitializerTest method should_init_directories.

@Test
public void should_init_directories() throws IOException {
    File baseDir = temp.newFolder("base");
    File sourceDir = new File(baseDir, "src/main/java");
    FileUtils.forceMkdir(sourceDir);
    File testDir = new File(baseDir, "src/test/java");
    FileUtils.forceMkdir(testDir);
    File binaryDir = new File(baseDir, "target/classes");
    FileUtils.forceMkdir(binaryDir);
    ProjectDefinition project = ProjectDefinition.create().setBaseDir(baseDir).addSources("src/main/java", "src/main/unknown").addTests("src/test/java", "src/test/unknown");
    ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(project, mock(TempFolder.class), pathResolver);
    assertThat(initializer.baseDir().getCanonicalPath()).isEqualTo(baseDir.getCanonicalPath());
    assertThat(initializer.sources()).hasSize(1);
    assertThat(path(initializer.sources().get(0))).endsWith("src/main/java");
    assertThat(initializer.tests()).hasSize(1);
    assertThat(path(initializer.tests().get(0))).endsWith("src/test/java");
}
Also used : TempFolder(org.sonar.api.utils.TempFolder) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 42 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)

Example 43 with ProjectDefinition

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

the class ProjectReactorBuilderTest method execMultiModule.

public ProjectDefinition execMultiModule(String key) throws IOException {
    ProjectDefinition rootProject = loadProjectDefinition(key);
    // CHECK ROOT
    assertThat(rootProject.getKey()).isEqualTo("com.foo.project");
    assertThat(rootProject.getName()).isEqualTo("Foo Project");
    assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT");
    assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project");
    assertThat(rootProject.sources().contains("sources")).isTrue();
    assertThat(rootProject.tests().contains("tests")).isTrue();
    // and module properties must have been cleaned
    assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull();
    assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull();
    // Check baseDir and workDir
    assertThat(rootProject.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key));
    assertThat(rootProject.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), key), ".sonar"));
    // 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(), key + "/module1"));
    assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
    assertThat(module1.getName()).isEqualTo("module1");
    assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
    // Description should not be inherited from parent if not set
    assertThat(module1.getDescription()).isNull();
    assertThat(module1.sources()).contains("sources");
    assertThat(module1.tests()).contains("tests");
    // and module properties must have been cleaned
    assertThat(module1.properties().get("module1.sonar.projectKey")).isNull();
    assertThat(module1.properties().get("module2.sonar.projectKey")).isNull();
    // Check baseDir and workDir
    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module1"));
    assertThat(module1.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), key), ".sonar/com.foo.project_module1"));
    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module2"));
    assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
    assertThat(module2.getName()).isEqualTo("Foo Module 2");
    assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
    assertThat(module2.getDescription()).isEqualTo("Description of Module 2");
    assertThat(module2.sources()).contains("src");
    assertThat(module2.tests()).contains("tests");
    // and module properties must have been cleaned
    assertThat(module2.properties().get("module1.sonar.projectKey")).isNull();
    assertThat(module2.properties().get("module2.sonar.projectKey")).isNull();
    // Check baseDir and workDir
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), key + "/module2"));
    assertThat(module2.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), key), ".sonar/com.foo.project_com.foo.project.module2"));
    return rootProject;
}
Also used : File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 44 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()).isEqualTo(1);
    // 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 45 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 = new HashMap<>();
    props.put("sonar.projectKey", "root");
    ProjectDefinition root = ProjectDefinition.create().setProperties(props);
    Map<String, String> props1 = new HashMap<>();
    props1.put("sonar.projectKey", "mod1");
    root.addSubProject(ProjectDefinition.create().setProperties(props1));
    // Check uniqueness of a new module: OK
    Map<String, String> props2 = new HashMap<>();
    props2.put("sonar.projectKey", "mod2");
    ProjectDefinition mod2 = ProjectDefinition.create().setProperties(props2);
    ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);
    // Now, add it and check again
    root.addSubProject(mod2);
    thrown.expect(MessageException.class);
    thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2");
    ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root);
}
Also used : HashMap(java.util.HashMap) 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