Search in sources :

Example 66 with ProjectDefinition

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);
}
Also used : ProjectReactor(org.sonar.api.batch.bootstrap.ProjectReactor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 67 with ProjectDefinition

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();
}
Also used : DefaultInputProject(org.sonar.api.batch.fs.internal.DefaultInputProject) AbstractProjectOrModule(org.sonar.api.batch.fs.internal.AbstractProjectOrModule) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 68 with ProjectDefinition

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);
        }
    }
}
Also used : ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 69 with ProjectDefinition

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);
}
Also used : InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) ModuleSensorExtensionDictionary(org.sonar.scanner.sensor.ModuleSensorExtensionDictionary) ModuleSensorsExecutor(org.sonar.scanner.sensor.ModuleSensorsExecutor) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) Sensor(org.sonar.api.batch.sensor.Sensor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

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