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();
assertThat(projectDefinition.properties().get("sonar.profile")).isEqualTo("Foo");
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(module1.properties().get("sonar.profile")).isEqualTo("Foo");
assertThat(module2.properties().get("module11.property")).isNull();
assertThat(module2.properties().get("property")).isNull();
assertThat(module2.properties().get("sonar.profile")).isEqualTo("Foo");
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().get("property")).isEqualTo("My module11 property");
assertThat(module11.properties().get("sonar.profile")).isEqualTo("Foo");
assertThat(module12.properties().get("module11.property")).isNull();
assertThat(module12.properties().get("property")).isNull();
assertThat(module12.properties().get("sonar.profile")).isEqualTo("Foo");
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ProjectReactorBuilderTest method doNotMixPropertiesWhenModuleKeyIsPrefixOfAnother.
@Test
public void doNotMixPropertiesWhenModuleKeyIsPrefixOfAnother() throws IOException {
ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-same-prefix");
// 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();
// 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(), "multi-module-definitions-same-prefix"));
assertThat(rootProject.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".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(), "multi-module-definitions-same-prefix/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(), "multi-module-definitions-same-prefix/module1"));
assertThat(module1.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_module1"));
// Module 1 Feature
ProjectDefinition module1Feature = modules.get(1);
assertThat(module1Feature.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
assertThat(module1Feature.getKey()).isEqualTo("com.foo.project:com.foo.project.module1.feature");
assertThat(module1Feature.getName()).isEqualTo("Foo Module 1 Feature");
assertThat(module1Feature.getVersion()).isEqualTo("1.0-SNAPSHOT");
assertThat(module1Feature.getDescription()).isEqualTo("Description of Module 1 Feature");
assertThat(module1Feature.sources()).contains("src");
assertThat(module1Feature.tests()).contains("tests");
// and module properties must have been cleaned
assertThat(module1Feature.properties().get("module1.sonar.projectKey")).isNull();
assertThat(module1Feature.properties().get("module2.sonar.projectKey")).isNull();
// Check baseDir and workDir
assertThat(module1Feature.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
assertThat(module1Feature.getWorkDir().getCanonicalFile()).isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_com.foo.project.module1.feature"));
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ProjectReactorBuilderTest method shouldDefineProjectWithBuildDir.
@Test
public void shouldDefineProjectWithBuildDir() {
ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-build-dir");
File buildDir = rootProject.getBuildDir();
assertThat(buildDir).isDirectory().exists();
assertThat(new File(buildDir, "report.txt")).isFile().exists();
assertThat(buildDir.getName()).isEqualTo("build");
}
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");
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ModuleFileSystemInitializerTest method test_default_directories.
@Test
public void test_default_directories() throws Exception {
File baseDir = temp.newFolder("base");
File workDir = temp.newFolder("work");
ProjectDefinition module = ProjectDefinition.create().setBaseDir(baseDir).setWorkDir(workDir);
ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(module, mock(TempFolder.class), pathResolver);
assertThat(initializer.baseDir().getCanonicalPath()).isEqualTo(baseDir.getCanonicalPath());
assertThat(initializer.workingDir().getCanonicalPath()).isEqualTo(workDir.getCanonicalPath());
assertThat(initializer.sources()).isEmpty();
assertThat(initializer.tests()).isEmpty();
}
Aggregations