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");
}
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");
}
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;
}
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");
}
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);
}
Aggregations