use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ProjectReactorValidatorTest method createProjectReactor.
private ProjectReactor createProjectReactor(String projectKey, Consumer<ProjectDefinition>... consumers) {
ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey);
Arrays.stream(consumers).forEach(c -> c.accept(def));
return new ProjectReactor(def);
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class DefaultInputProjectTest method testGetters.
@Test
public void testGetters() throws IOException {
ProjectDefinition def = ProjectDefinition.create();
def.setKey("projectKey");
def.setName("projectName");
File baseDir = temp.newFolder();
def.setBaseDir(baseDir);
def.setDescription("desc");
File workDir = temp.newFolder();
def.setWorkDir(workDir);
def.setSources("file1");
def.setTests("test1");
AbstractProjectOrModule project = new DefaultInputProject(def);
assertThat(project.key()).isEqualTo("projectKey");
assertThat(project.getName()).isEqualTo("projectName");
assertThat(project.getOriginalName()).isEqualTo("projectName");
assertThat(project.definition()).isEqualTo(def);
assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS));
assertThat(project.getDescription()).isEqualTo("desc");
assertThat(project.getWorkDir()).isEqualTo(workDir.toPath());
assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset());
assertThat(project.properties()).hasSize(5);
assertThat(project.isFile()).isFalse();
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ProjectReactorBuilder method defineChildren.
private void defineChildren(ProjectDefinition parentProject, Map<String, Map<String, String>> propertiesByModuleIdPath, String parentModuleIdPath) {
Map<String, String> parentProps = parentProject.properties();
if (parentProps.containsKey(PROPERTY_MODULES)) {
for (String moduleId : getListFromProperty(parentProps, PROPERTY_MODULES)) {
String moduleIdPath = parentModuleIdPath.isEmpty() ? moduleId : (parentModuleIdPath + "." + moduleId);
Map<String, String> moduleProps = propertiesByModuleIdPath.get(moduleIdPath);
ProjectDefinition childProject = loadChildProject(parentProject, moduleProps, moduleId);
// check the uniqueness of the child key
checkUniquenessOfChildKey(childProject, parentProject);
// the child project may have children as well
defineChildren(childProject, propertiesByModuleIdPath, moduleIdPath);
// and finally add this child project to its parent
parentProject.addSubProject(childProject);
}
}
}
use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.
the class ModuleSensorsExecutorTest method setUp.
@Before
public void setUp() throws IOException {
when(perModuleSensor.isGlobal()).thenReturn(false);
when(perModuleSensor.shouldExecute()).thenReturn(true);
when(perModuleSensor.wrappedSensor()).thenReturn(mock(Sensor.class));
when(globalSensor.isGlobal()).thenReturn(true);
when(globalSensor.shouldExecute()).thenReturn(true);
when(globalSensor.wrappedSensor()).thenReturn(mock(Sensor.class));
ModuleSensorExtensionDictionary selector = mock(ModuleSensorExtensionDictionary.class);
when(selector.selectSensors(false)).thenReturn(Collections.singleton(perModuleSensor));
when(selector.selectSensors(true)).thenReturn(Collections.singleton(globalSensor));
ProjectDefinition childDef = ProjectDefinition.create().setKey("sub").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
ProjectDefinition rootDef = ProjectDefinition.create().setKey("root").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder());
DefaultInputModule rootModule = TestInputFileBuilder.newDefaultInputModule(rootDef);
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(childDef);
InputModuleHierarchy hierarchy = mock(InputModuleHierarchy.class);
when(hierarchy.isRoot(rootModule)).thenReturn(true);
rootModuleExecutor = new ModuleSensorsExecutor(selector, rootModule, hierarchy, strategy, pluginRepository);
subModuleExecutor = new ModuleSensorsExecutor(selector, subModule, hierarchy, strategy, pluginRepository);
}
Aggregations