Package org.sonar.api.batch.bootstrap

Examples of org.sonar.api.batch.bootstrap.ProjectDefinition


import static org.fest.assertions.Assertions.assertThat;

public class ProjectExclusionsTest {

  ProjectReactor newReactor(String rootKey, String... moduleKeys) {
    ProjectDefinition root = ProjectDefinition.create().setKey(rootKey);
    for (String moduleKey : moduleKeys) {
      ProjectDefinition module = ProjectDefinition.create().setKey(moduleKey);
      root.addSubProject(module);
    }
    return new ProjectReactor(root);
  }
View Full Code Here


    assertThat(reactor.getProject("sub2")).isNull();
  }

  @Test
  public void shouldBeExcludedIfParentIsExcluded() {
    ProjectDefinition sub11 = ProjectDefinition.create().setKey("sub11");
    ProjectDefinition sub1 = ProjectDefinition.create().setKey("sub1").addSubProject(sub11);
    ProjectDefinition root = ProjectDefinition.create().setKey("root").addSubProject(sub1);

    Settings settings = new Settings();
    settings.setProperty("sonar.skippedModules", "sub1");

    ProjectReactor reactor = new ProjectReactor(root);
View Full Code Here

    thrown.expectMessage("\"sonar.phase\" is deprecated");
    validator.validate(reactor);
  }

  private ProjectReactor createProjectReactor(String projectKey) {
    ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey);
    ProjectReactor reactor = new ProjectReactor(def);
    return reactor;
  }
View Full Code Here

    ProjectReactor reactor = new ProjectReactor(def);
    return reactor;
  }

  private ProjectReactor createProjectReactor(String projectKey, String branch) {
    ProjectDefinition def = ProjectDefinition.create()
      .setProperty(CoreProperties.PROJECT_KEY_PROPERTY, projectKey)
      .setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, branch);
    ProjectReactor reactor = new ProjectReactor(def);
    settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, branch);
    return reactor;
View Full Code Here

    mode = mock(AnalysisMode.class);
  }

  @Test
  public void testOrderedProjects() {
    ProjectDefinition grandParent = ProjectDefinition.create();
    ProjectDefinition parent = ProjectDefinition.create();
    ProjectDefinition child = ProjectDefinition.create();
    grandParent.addSubProject(parent);
    parent.addSubProject(child);

    List<ProjectDefinition> hierarchy = ModuleSettings.getTopDownParentProjects(child);
    assertThat(hierarchy.get(0)).isEqualTo(grandParent);
View Full Code Here

      "overridding", "batch",
      "on-batch", "true"
      ));
    projectRef.addSettings("struts-core", ImmutableMap.of("on-module", "true", "overridding", "module"));

    ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");

    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);

    assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
    assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
View Full Code Here

    when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
      "sonar.foo.secured", "bar"
      ));
    projectRef.addSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));

    ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");

    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);

    assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
    assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
View Full Code Here

      ));
    projectRef.addSettings("struts-core", ImmutableMap.of("sonar.foo.license.secured", "bar2"));

    when(mode.isPreview()).thenReturn(true);

    ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");

    ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, projectRef, mode);

    assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
View Full Code Here

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Test
  public void shouldDefineMultiModuleProjectWithDefinitionsAllInEachModule() throws IOException {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module");

    // 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");
    // root project must not contain some properties - even if they are defined in the root properties file
    assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
    assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
    assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
    // and module properties must have been cleaned
    assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();

    // CHECK MODULES
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(2);

    // Module 1
    ProjectDefinition module1 = modules.get(0);
    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module1"));
    assertThat(module1.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
    assertThat(module1.getName()).isEqualTo("Foo Module 1");
    assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
    // Description should not be inherited from parent if not set
    assertThat(module1.getDescription()).isEqualTo("Description of Module 1");
    assertThat(module1.getSourceDirs()).contains("sources");
    assertThat(module1.getTestDirs()).contains("tests");
    assertThat(module1.getBinaries()).contains("target/classes");
    // and module properties must have been cleaned
    assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();

    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module2/newBaseDir"));
    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.getSourceDirs()).contains("src");
    assertThat(module2.getTestDirs()).contains("tests");
    assertThat(module2.getBinaries()).contains("target/classes");
    // and module properties must have been cleaned
    assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
  }
View Full Code Here

    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
  }

  @Test
  public void shouldDefineMultiModuleProjectWithDefinitionsModule1Inherited() throws IOException {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-in-each-module-inherited");

    // 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");
    // root project must not contain some properties - even if they are defined in the root properties file
    assertThat(rootProject.getSourceDirs().contains("sources")).isFalse();
    assertThat(rootProject.getTestDirs().contains("tests")).isFalse();
    assertThat(rootProject.getBinaries().contains("target/classes")).isFalse();
    // and module properties must have been cleaned
    assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull();

    // CHECK MODULES
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(2);

    // Module 1
    ProjectDefinition module1 = modules.get(0);
    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/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.getSourceDirs()).contains("sources");
    assertThat(module1.getTestDirs()).contains("tests");
    assertThat(module1.getBinaries()).contains("target/classes");
    // and module properties must have been cleaned
    assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull();

    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module-inherited/module2/newBaseDir"));
    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.getSourceDirs()).contains("src");
    assertThat(module2.getTestDirs()).contains("tests");
    assertThat(module2.getBinaries()).contains("target/classes");
    // and module properties must have been cleaned
    assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull();
    assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull();
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.batch.bootstrap.ProjectDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.