]> source.dussan.org Git - sonarqube.git/commitdiff
Do not allow to change ProjectDefinition#properties
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 7 Jun 2011 09:07:25 +0000 (11:07 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 7 Jun 2011 09:07:43 +0000 (11:07 +0200)
sonar-batch/src/main/java/org/sonar/batch/MavenProjectConverter.java
sonar-batch/src/main/java/org/sonar/batch/bootstrapper/ProjectDefinition.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java

index ec3104f755c01f919c75ab01152cb77e8becffed..5c35f335a1d0de2a9e9d1111ff73010024a24573 100644 (file)
@@ -66,9 +66,8 @@ public final class MavenProjectConverter {
    */
   static ProjectDefinition convert(MavenProject pom) {
     String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString();
-    ProjectDefinition definition = ProjectDefinition.create();
-    definition.setProperties(pom.getModel().getProperties())
-        .setKey(key)
+    ProjectDefinition definition = ProjectDefinition.create(pom.getModel().getProperties());
+    definition.setKey(key)
         .setVersion(pom.getVersion())
         .setName(pom.getName())
         .setDescription(pom.getDescription())
index 0c59c79993505e0da66008f1ca1e3d1a91ac669e..71f3861f941b7e4075d317ea399415853789389e 100644 (file)
@@ -42,10 +42,9 @@ public class ProjectDefinition {
    * @param properties project properties
    */
   public ProjectDefinition(File baseDir, File workDir, Properties properties) {
-    target = org.sonar.api.batch.bootstrap.ProjectDefinition.create()
+    target = org.sonar.api.batch.bootstrap.ProjectDefinition.create(properties)
         .setBaseDir(baseDir)
-        .setWorkDir(workDir)
-        .setProperties(properties);
+        .setWorkDir(workDir);
   }
 
   public File getBaseDir() {
index cec0930c949969f06b2e7502ca23df44bb228988..df7acb38b3a3b59a6c23e30a4d89ebdb285ad60a 100644 (file)
@@ -54,20 +54,16 @@ public final class ProjectDefinition implements BatchComponent {
   private List<ProjectDefinition> subProjects = Lists.newArrayList();
   private List<Object> containerExtensions = Lists.newArrayList();
 
-  private ProjectDefinition() {
-  }
-
-  public static ProjectDefinition create() {
-    return new ProjectDefinition();
+  private ProjectDefinition(Properties p) {
+    this.properties = p;
   }
 
-  public ProjectDefinition setProperties(Properties p) {
-    this.properties = p;
-    return this;
+  public static ProjectDefinition create(Properties properties) {
+    return new ProjectDefinition(properties);
   }
 
-  public File getBaseDir() {
-    return baseDir;
+  public static ProjectDefinition create() {
+    return new ProjectDefinition(new Properties());
   }
 
   public ProjectDefinition setBaseDir(File baseDir) {
@@ -75,6 +71,9 @@ public final class ProjectDefinition implements BatchComponent {
     return this;
   }
 
+  public File getBaseDir() {
+    return baseDir;
+  }
   public ProjectDefinition setWorkDir(File workDir) {
     this.workDir = workDir;
     return this;
index 93b9bcdfefa14ba5425181c2dec72932d4dbdb03..581e9ff3361b6d44fa7ca4797924e6d329338e85 100644 (file)
@@ -30,7 +30,6 @@ import java.util.Properties;
 import static org.hamcrest.CoreMatchers.nullValue;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
 
 public class ProjectDefinitionTest {
 
@@ -56,12 +55,12 @@ public class ProjectDefinitionTest {
     def.setKey("myKey");
     assertThat(def.getName(), is("Unnamed - myKey"));
   }
+
   @Test
   public void shouldGetKeyFromProperties() {
     Properties props = new Properties();
     props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
-    ProjectDefinition def = ProjectDefinition.create();
-    def.setProperties(props);
+    ProjectDefinition def = ProjectDefinition.create(props);
     assertThat(def.getKey(), is("foo"));
   }