mergeParentProperties(childProps, rootProject.getProperties());
File baseDir = null;
if (childProps.containsKey(PROPERTY_MODULE_PATH)) {
- baseDir = getFileFromProperty(childProps, PROPERTY_MODULE_PATH, rootProject.getBaseDir());
+ baseDir = getFileFromPath(childProps.getProperty(PROPERTY_MODULE_PATH), rootProject.getBaseDir());
} else {
baseDir = new File(rootProject.getBaseDir(), moduleId);
}
}
private ProjectDefinition loadChildProjectFromPropertyFile(ProjectDefinition rootProject, Properties moduleProps, String moduleId) {
- File propertyFile = getFileFromProperty(moduleProps, PROPERTY_MODULE_FILE, rootProject.getBaseDir());
+ File propertyFile = getFileFromPath(moduleProps.getProperty(PROPERTY_MODULE_FILE), rootProject.getBaseDir());
if (!propertyFile.isFile()) {
throw new RunnerException("The properties file of the module '" + moduleId + "' does not exist: " + propertyFile.getAbsolutePath());
}
.setWorkDir(initWorkDir(baseDir));
if (!properties.containsKey(PROPERTY_SONAR_MODULES)) {
// this is not a "aggregator" project, so let's specify its sources, tests, ...
- definition.addSourceDirs(getListFromProperty(properties, "sources"));
+ String[] sourceDirs = getListFromProperty(properties, "sources");
+ checkExistenceOfDirectories(definition.getKey(), baseDir, sourceDirs);
+ definition.addSourceDirs(sourceDirs);
definition.addTestDirs(getListFromProperty(properties, "tests"));
for (String dir : getListFromProperty(properties, "binaries")) {
definition.addBinaryDir(dir);
return definition;
}
+ @VisibleForTesting
+ protected void checkExistenceOfDirectories(String projectKey, File baseDir, String[] sourceDirs) {
+ for (String path : sourceDirs) {
+ File sourceFolder = getFileFromPath(path, baseDir);
+ if (!sourceFolder.isDirectory()) {
+ throw new RunnerException("The source folder '" + path + "' does not exist for '" + projectKey +
+ "' project/module (base directory = " + baseDir.getAbsolutePath() + ")");
+ }
+ }
+
+ }
+
@VisibleForTesting
protected File initWorkDir(File baseDir) {
String workDir = properties.getProperty(PROPERTY_WORK_DIRECTORY);
}
/**
- * Returns the file denoted by the given property, may it be relative to "baseDir" or absolute.
+ * Returns the file denoted by the given path, may this path be relative to "baseDir" or absolute.
*/
@VisibleForTesting
- protected static File getFileFromProperty(Properties properties, String key, File baseDir) {
- File propertyFile = new File(properties.getProperty(key).trim());
+ protected static File getFileFromPath(String path, File baseDir) {
+ File propertyFile = new File(path.trim());
if (!propertyFile.isAbsolute()) {
propertyFile = new File(baseDir, propertyFile.getPath());
}
TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
}
+ @Test
+ public void shouldFailIfUnexistingSourceDirectory() throws IOException {
+ thrown.expect(RunnerException.class);
+ thrown.expectMessage("The source folder 'unexisting-source-dir' does not exist for 'com.foo.project' project/module (base directory = "
+ + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
+
+ loadProjectDefinition("simple-project-with-unexisting-source-dir");
+ }
+
@Test
public void shouldDefineMultiModuleProject() throws IOException {
ProjectDefinition rootProject = loadProjectDefinition("multi-module");
@Test
public void shouldGetRelativeFile() {
- Properties props = new Properties();
- props.put("path", "shouldGetFile/foo.properties");
-
- assertThat(SonarProjectBuilder.getFileFromProperty(props, "path", TestUtils.getResource(this.getClass(), "/")))
+ assertThat(SonarProjectBuilder.getFileFromPath("shouldGetFile/foo.properties", TestUtils.getResource(this.getClass(), "/")))
.isEqualTo(TestUtils.getResource("org/sonar/runner/model/SonarProjectBuilderTest/shouldGetFile/foo.properties"));
}
public void shouldGetAbsoluteFile() {
File file = TestUtils.getResource("org/sonar/runner/model/SonarProjectBuilderTest/shouldGetFile/foo.properties");
- Properties props = new Properties();
- props.put("path", file.getAbsolutePath());
-
- assertThat(SonarProjectBuilder.getFileFromProperty(props, "path", TestUtils.getResource(this.getClass(), "/")))
+ assertThat(SonarProjectBuilder.getFileFromPath(file.getAbsolutePath(), TestUtils.getResource(this.getClass(), "/")))
.isEqualTo(file);
}