From b57d1e3fa0e8c0fb15d408eb7729da9823ac3540 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Mon, 31 Jan 2011 01:55:26 +0300 Subject: [PATCH] Add properties "sonar.projectName" and "sonar.projectDescription" --- .../java/org/sonar/batch/InMemoryPomCreator.java | 3 +++ .../org/sonar/batch/InMemoryPomCreatorTest.java | 15 +++++++++++++++ .../main/java/org/sonar/api/CoreProperties.java | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java index 68eb57b18f8..8e0ada5e60d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/InMemoryPomCreator.java @@ -73,6 +73,9 @@ public class InMemoryPomCreator { pom.setArtifactId(keys[1]); pom.setVersion(getPropertyOrDie(properties, CoreProperties.PROJECT_VERSION_PROPERTY)); + pom.setName(properties.getProperty(CoreProperties.PROJECT_NAME_PROPERTY, "Unnamed - " + key)); + pom.setDescription(properties.getProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, "")); + pom.getModel().setProperties(properties); pom.setArtifacts(Collections.EMPTY_SET); diff --git a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java index 83550c40c0d..260e6846d69 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java @@ -54,6 +54,8 @@ public class InMemoryPomCreatorTest { assertThat(pom.getBasedir(), is(project.getBaseDir())); assertThat(pom.getGroupId(), is("org.example")); assertThat(pom.getArtifactId(), is("example")); + assertThat(pom.getName(), is("Unnamed - org.example:example")); + assertThat(pom.getDescription(), is("")); assertThat(pom.getProperties(), is(project.getProperties())); assertThat(pom.getBasedir(), is(project.getBaseDir())); String buildDirectory = project.getWorkDir().getAbsolutePath() + "/target"; @@ -62,6 +64,19 @@ public class InMemoryPomCreatorTest { assertThat(pom.getReporting().getOutputDirectory(), is(buildDirectory + "/site")); } + @Test + public void nameAndDescription() { + createRequiredProperties(); + + properties.setProperty(CoreProperties.PROJECT_NAME_PROPERTY, "Foo"); + properties.setProperty(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, "Bar"); + + MavenProject pom = create(); + + assertThat(pom.getName(), is("Foo")); + assertThat(pom.getDescription(), is("Bar")); + } + @Test public void sourceDirectories() { createRequiredProperties(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index f39be2c6c7a..f8a64be0113 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -39,6 +39,16 @@ public interface CoreProperties { */ String PROJECT_KEY_PROPERTY = "sonar.projectKey"; + /** + * @since 2.6 + */ + String PROJECT_NAME_PROPERTY = "sonar.projectName"; + + /** + * @since 2.6 + */ + String PROJECT_DESCRIPTION_PROPERTY = "sonar.projectDescription"; + /** * To determine value of this property use {@link ProjectFileSystem#getSourceCharset()}. * -- 2.39.5