Package org.sonar.api.batch.bootstrap

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


    assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile/any-folder"));
  }

  @Test
  public void shouldDefineMultiModuleProjectWithConfigFileAndOverwrittenBasedir() throws IOException {
    ProjectDefinition rootProject = loadProjectDefinition("multi-module-with-configfile-and-overwritten-basedir");
    List<ProjectDefinition> modules = rootProject.getSubProjects();
    assertThat(modules.size()).isEqualTo(1);
    ProjectDefinition module = modules.get(0);
    assertThat(module.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
    // verify the base directory that has been changed in this config file
    assertThat(module.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-with-configfile-and-overwritten-basedir/any-folder"));
  }
View Full Code Here


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

  @Test
  public void shouldDefineSimpleProject() throws IOException {
    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.getSourceDirs()).contains("sources");
    assertThat(projectDefinition.getLibraries()).contains(TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath(),
      TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
  }
View Full Code Here

    root.getModules().add("module/pom.xml");
    MavenProject module = newMavenProject("com.foo", "moduleA", "1.0-SNAPSHOT");
    module.setFile(new File(basedir, "module/pom.xml"));
    module.getBuild().setDirectory("target");
    module.getBuild().setOutputDirectory("target/classes");
    ProjectDefinition project = converter.configure(Arrays.asList(root, module), root);

    assertThat(project.getSubProjects().size(), is(1));
  }
View Full Code Here

    pom.setVersion("1.0.1");
    pom.setName("Test");
    pom.setDescription("just test");
    pom.setFile(new File("/foo/pom.xml"));
    pom.getBuild().setDirectory("target");
    ProjectDefinition project = ProjectDefinition.create();
    converter.merge(pom, project);

    Properties properties = project.getProperties();
    assertThat(properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY), is("foo:bar"));
    assertThat(properties.getProperty(CoreProperties.PROJECT_VERSION_PROPERTY), is("1.0.1"));
    assertThat(properties.getProperty(CoreProperties.PROJECT_NAME_PROPERTY), is("Test"));
    assertThat(properties.getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY), is("just test"));
  }
View Full Code Here

    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/").toURI());
    MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true);
    MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false);
    MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false);

    ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module1, module2), parent);

    assertThat(rootDef.getSubProjects().size(), Is.is(2));
    assertThat(rootDef.getKey(), Is.is("org.test:parent"));
    assertNull(rootDef.getParent());
    assertThat(rootDef.getBaseDir(), is(rootDir));

    ProjectDefinition module1Def = rootDef.getSubProjects().get(0);
    assertThat(module1Def.getKey(), Is.is("org.test:module1"));
    assertThat(module1Def.getParent(), Is.is(rootDef));
    assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "module1")));
    assertThat(module1Def.getSubProjects().size(), Is.is(0));
  }
View Full Code Here

    loadProjectDefinition("simple-project-with-blank-source-dir");
  }

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

    // 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 baseDir and workDir
    assertThat(rootProject.getBaseDir().getCanonicalFile())
      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
    assertThat(rootProject.getWorkDir().getCanonicalFile())
      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".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(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/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();
    // Check baseDir and workDir
    assertThat(module1.getBaseDir().getCanonicalFile())
      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
    assertThat(module1.getWorkDir().getCanonicalFile())
      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));

    // Module 2
    ProjectDefinition module2 = modules.get(1);
    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/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.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();
    // Check baseDir and workDir
    assertThat(module2.getBaseDir().getCanonicalFile())
      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
    assertThat(module2.getWorkDir().getCanonicalFile())
      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
  }
View Full Code Here

    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/").toURI());
    MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true);
    MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false);
    MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false);

    ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module1, module2), parent);

    assertThat(rootDef.getSubProjects().size(), is(2));
    assertThat(rootDef.getKey(), is("org.test:parent"));
    assertNull(rootDef.getParent());
    assertThat(rootDef.getBaseDir(), is(rootDir));

    ProjectDefinition module1Def = rootDef.getSubProjects().get(0);
    assertThat(module1Def.getKey(), Is.is("org.test:module1"));
    assertThat(module1Def.getParent(), Is.is(rootDef));
    assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "path1")));
    assertThat(module1Def.getSubProjects().size(), Is.is(0));
  }
View Full Code Here

  public void should_find_module_with_maven_project_file_naming_different_from_pom_xml() throws Exception {
    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/").toURI());
    MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true);
    MavenProject module = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false);

    ProjectDefinition rootDef = converter.configure(Arrays.asList(parent, module), parent);

    assertThat(rootDef.getSubProjects().size(), Is.is(1));
    assertThat(rootDef.getKey(), Is.is("org.test:parent"));
    assertNull(rootDef.getParent());
    assertThat(rootDef.getBaseDir(), is(rootDir));

    ProjectDefinition module1Def = rootDef.getSubProjects().get(0);
    assertThat(module1Def.getKey(), Is.is("org.test:module"));
    assertThat(module1Def.getParent(), Is.is(rootDef));
    assertThat(module1Def.getBaseDir(), Is.is(new File(rootDir, "module")));
    assertThat(module1Def.getSubProjects().size(), Is.is(0));
  }
View Full Code Here

  @Test
  public void testSingleProjectWithoutModules() throws Exception {
    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/").toURI());
    MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true);

    ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom);

    assertThat(rootDef.getKey(), is("org.test:parent"));
    assertThat(rootDef.getSubProjects().size(), is(0));
    assertNull(rootDef.getParent());
    assertThat(rootDef.getBaseDir(), is(rootDir));
  }
View Full Code Here

  @Test
  public void shouldConvertLinksToProperties() throws Exception {
    MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/projectWithLinks/pom.xml", true);

    ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom);

    Properties props = rootDef.getProperties();
    assertThat(props.getProperty(CoreProperties.LINKS_HOME_PAGE)).isEqualTo("http://home.com");
    assertThat(props.getProperty(CoreProperties.LINKS_CI)).isEqualTo("http://ci.com");
    assertThat(props.getProperty(CoreProperties.LINKS_ISSUE_TRACKER)).isEqualTo("http://issues.com");
    assertThat(props.getProperty(CoreProperties.LINKS_SOURCES)).isEqualTo("http://sources.com");
    assertThat(props.getProperty(CoreProperties.LINKS_SOURCES_DEV)).isEqualTo("http://sources-dev.com");
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.