]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4440 Allow empty list for "sonar.sources" property
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 25 Jun 2013 16:05:29 +0000 (18:05 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Wed, 26 Jun 2013 09:31:12 +0000 (11:31 +0200)
sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java
sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-blank-source-dir/sonar-project.properties [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-missing-source-dir/sonar-project.properties [new file with mode: 0644]

index 711fe004169b5426318d26fe05a7f622aada3edd..c70fc4fff31841325a89f38fefb71bc67e4d3421 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.commons.io.filefilter.WildcardFileFilter;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectBootstrapper;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
@@ -54,10 +55,6 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
 
   private static final String PROPERTY_PROJECT_BASEDIR = "sonar.projectBaseDir";
   private static final String PROPERTY_PROJECT_CONFIG_FILE = "sonar.projectConfigFile";
-  private static final String PROPERTY_PROJECT_KEY = "sonar.projectKey";
-  private static final String PROPERTY_PROJECT_NAME = "sonar.projectName";
-  private static final String PROPERTY_PROJECT_DESCRIPTION = "sonar.projectDescription";
-  private static final String PROPERTY_PROJECT_VERSION = "sonar.projectVersion";
   private static final String PROPERTY_MODULES = "sonar.modules";
 
   /**
@@ -96,23 +93,24 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
    * Array of all mandatory properties required for a project without child.
    */
   private static final String[] MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT = {
-    PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION
+    PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY, PROPERTY_SOURCES
   };
 
   /**
    * Array of all mandatory properties required for a project with children.
    */
-  private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME, PROPERTY_PROJECT_VERSION};
+  private static final String[] MANDATORY_PROPERTIES_FOR_MULTIMODULE_PROJECT = {PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY,
+    CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY};
 
   /**
    * Array of all mandatory properties required for a child project before its properties get merged with its parent ones.
    */
-  private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {PROPERTY_PROJECT_KEY, PROPERTY_PROJECT_NAME};
+  private static final String[] MANDATORY_PROPERTIES_FOR_CHILD = {CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY};
 
   /**
    * Properties that must not be passed from the parent project to its children.
    */
-  private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, PROPERTY_MODULES, PROPERTY_PROJECT_DESCRIPTION);
+  private static final List<String> NON_HERITED_PROPERTIES_FOR_CHILD = Lists.newArrayList(PROPERTY_PROJECT_BASEDIR, PROPERTY_MODULES, CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
 
   private Settings settings;
   private File rootProjectWorkDir;
@@ -141,7 +139,7 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
     }
     File workDir;
     if (parent == null) {
-      validateDirectories(properties, baseDir, properties.getProperty(PROPERTY_PROJECT_KEY));
+      validateDirectories(properties, baseDir, properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY));
       workDir = initRootProjectWorkDir(baseDir);
     } else {
       workDir = initModuleWorkDir(properties);
@@ -169,7 +167,7 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
 
   @VisibleForTesting
   protected File initModuleWorkDir(Properties properties) {
-    String cleanKey = StringUtils.deleteWhitespace(properties.getProperty(PROPERTY_PROJECT_KEY));
+    String cleanKey = StringUtils.deleteWhitespace(properties.getProperty(CoreProperties.PROJECT_KEY_PROPERTY));
     cleanKey = StringUtils.replace(cleanKey, ":", "_");
     return new File(rootProjectWorkDir, cleanKey);
   }
@@ -277,11 +275,11 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
 
   @VisibleForTesting
   protected static void setProjectKeyAndNameIfNotDefined(Properties childProps, String moduleId) {
-    if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
-      childProps.put(PROPERTY_PROJECT_KEY, moduleId);
+    if (!childProps.containsKey(CoreProperties.PROJECT_KEY_PROPERTY)) {
+      childProps.put(CoreProperties.PROJECT_KEY_PROPERTY, moduleId);
     }
-    if (!childProps.containsKey(PROPERTY_PROJECT_NAME)) {
-      childProps.put(PROPERTY_PROJECT_NAME, moduleId);
+    if (!childProps.containsKey(CoreProperties.PROJECT_NAME_PROPERTY)) {
+      childProps.put(CoreProperties.PROJECT_NAME_PROPERTY, moduleId);
     }
   }
 
@@ -296,8 +294,8 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
 
   @VisibleForTesting
   protected static void prefixProjectKeyWithParentKey(Properties childProps, String parentKey) {
-    String childKey = childProps.getProperty(PROPERTY_PROJECT_KEY);
-    childProps.put(PROPERTY_PROJECT_KEY, parentKey + ":" + childKey);
+    String childKey = childProps.getProperty(CoreProperties.PROJECT_KEY_PROPERTY);
+    childProps.put(CoreProperties.PROJECT_KEY_PROPERTY, parentKey + ":" + childKey);
   }
 
   private static void setProjectBaseDir(File baseDir, Properties childProps, String moduleId) {
@@ -319,7 +317,7 @@ class DefaultProjectBootstrapper extends ProjectBootstrapper {
         missing.append(mandatoryProperty);
       }
     }
-    String projectKey = props.getProperty(PROPERTY_PROJECT_KEY);
+    String projectKey = props.getProperty(CoreProperties.PROJECT_KEY_PROPERTY);
     if (missing.length() != 0) {
       throw new IllegalStateException("You must define the following mandatory properties for '" + (projectKey == null ? "Unknown" : projectKey) + "': " + missing);
     }
index 3b1c6418c54b8f78c595db3bcc88e2539481608e..1c6d868c3db3671701df89a51f68c9755a30d327 100644 (file)
@@ -75,6 +75,19 @@ public class DefaultProjectBootstrapperTest {
     loadProjectDefinition("simple-project-with-unexisting-source-dir");
   }
 
+  @Test
+  public void shouldFailIfMissingSourceDirectory() throws IOException {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("You must define the following mandatory properties for 'com.foo.project': sonar.sources");
+
+    loadProjectDefinition("simple-project-with-missing-source-dir");
+  }
+
+  @Test
+  public void shouldNotFailIfBlankSourceDirectory() throws IOException {
+    loadProjectDefinition("simple-project-with-blank-source-dir");
+  }
+
   @Test
   public void shouldDefineMultiModuleProjectWithDefinitionsAllInRootProject() throws IOException {
     ProjectDefinition rootProject = loadProjectDefinition("multi-module-definitions-all-in-root");
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-blank-source-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-blank-source-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..ba79992
--- /dev/null
@@ -0,0 +1,6 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+
+sonar.sources=
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-missing-source-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-missing-source-dir/sonar-project.properties
new file mode 100644 (file)
index 0000000..3a7a653
--- /dev/null
@@ -0,0 +1,5 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+