aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-06-25 18:05:29 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-06-26 11:31:12 +0200
commitaae644fd6f1344fa9f304627335534485862ac04 (patch)
tree0ae90aa94d38e6ef428e7a5350eec3943443014f /sonar-batch
parent9d4402db8268d0f062f839445a201dcc257de685 (diff)
downloadsonarqube-aae644fd6f1344fa9f304627335534485862ac04.tar.gz
sonarqube-aae644fd6f1344fa9f304627335534485862ac04.zip
SONAR-4440 Allow empty list for "sonar.sources" property
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java32
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java13
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-blank-source-dir/sonar-project.properties6
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-missing-source-dir/sonar-project.properties5
4 files changed, 39 insertions, 17 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java b/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java
index 711fe004169..c70fc4fff31 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java
@@ -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);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java
index 3b1c6418c54..1c6d868c3db 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java
@@ -76,6 +76,19 @@ public class DefaultProjectBootstrapperTest {
}
@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
index 00000000000..ba79992d5a0
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-blank-source-dir/sonar-project.properties
@@ -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
index 00000000000..3a7a65335dc
--- /dev/null
+++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/DefaultProjectBootstrapperTest/simple-project-with-missing-source-dir/sonar-project.properties
@@ -0,0 +1,5 @@
+sonar.projectKey=com.foo.project
+sonar.projectName=Foo Project
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.projectDescription=Description of Foo Project
+