aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-02-21 18:32:18 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-02-21 18:34:11 +0100
commitc49b05d030f2bb87740d92eeb5626697239993f9 (patch)
treed6d709db0de2f8ab83373ae1050b2b3b1d7207e0
parentce227110b0670bd0df0485fdced7b8758e5b1f67 (diff)
downloadsonarqube-c49b05d030f2bb87740d92eeb5626697239993f9.tar.gz
sonarqube-c49b05d030f2bb87740d92eeb5626697239993f9.zip
SONAR-5069 Make sonar.sources optional
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/DefaultProjectBootstrapper.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/DefaultProjectBootstrapperTest.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java12
4 files changed, 21 insertions, 14 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 7ac6b45ca2c..6bbfc6ed50b 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
@@ -41,8 +41,11 @@ import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
+import java.util.Properties;
/**
* Class that creates a Sonar project definition based on a set of properties.
@@ -88,7 +91,7 @@ class DefaultProjectBootstrapper implements ProjectBootstrapper {
* Array of all mandatory properties required for a project without child.
*/
private static final String[] MANDATORY_PROPERTIES_FOR_SIMPLE_PROJECT = {
- PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY, PROPERTY_SOURCES
+ PROPERTY_PROJECT_BASEDIR, CoreProperties.PROJECT_KEY_PROPERTY, CoreProperties.PROJECT_NAME_PROPERTY, CoreProperties.PROJECT_VERSION_PROPERTY
};
/**
@@ -152,7 +155,7 @@ class DefaultProjectBootstrapper implements ProjectBootstrapper {
if (!ComponentKeys.isValidModuleKey(projectKey)) {
throw new IllegalStateException(String.format(
"Invalid project key '%s'.\n"
- + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", projectKey));
+ + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", projectKey));
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index daac1be3c4e..26477df4011 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -38,8 +38,10 @@ import org.sonar.api.utils.SonarException;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.File;
import java.nio.charset.Charset;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -67,7 +69,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
private boolean initialized;
public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project module, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer,
- ComponentIndexer componentIndexer) {
+ ComponentIndexer componentIndexer) {
super(moduleInputFileCache);
this.componentIndexer = componentIndexer;
this.moduleKey = module.getKey();
@@ -101,6 +103,10 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
@Override
public List<File> sourceDirs() {
+ if (sourceDirs.isEmpty()) {
+ // For backward compatibility with File::fromIOFile(file, sourceDirs) we need to always return something
+ return Arrays.asList(baseDir());
+ }
return sourceDirs;
}
@@ -279,7 +285,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
throw new IllegalArgumentException("Unsupported file attribute: " + key);
}
-
@Override
public boolean equals(Object o) {
if (this == o) {
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 c4a47e9d9da..ab0300248f6 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
@@ -85,10 +85,7 @@ 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");
-
+ public void shouldNotFailIfMissingSourceDirectory() throws IOException {
loadProjectDefinition("simple-project-with-missing-source-dir");
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
index 89d721d27ec..65215a0c2ff 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/scan/filesystem/ModuleFileSystem.java
@@ -20,8 +20,11 @@
package org.sonar.api.scan.filesystem;
import org.sonar.api.BatchComponent;
+import org.sonar.api.batch.fs.FileSystem;
+import org.sonar.api.batch.fs.InputFile;
import javax.annotation.CheckForNull;
+
import java.io.File;
import java.nio.charset.Charset;
import java.util.List;
@@ -46,16 +49,15 @@ public interface ModuleFileSystem extends BatchComponent {
File buildDir();
/**
- * Source directories. Non-existing directories are excluded.
- * Example in Maven : ${project.basedir}/src/main/java
- * @deprecated since 4.2 will always return {@link #baseDir()}
+ * Source directories.
+ * @deprecated since 4.2 use {@link FileSystem#files(org.sonar.api.batch.fs.FilePredicate)} to get all files with type {@link InputFile.Type#MAIN}.
*/
List<File> sourceDirs();
/**
* Test directories. Non-existing directories are excluded.
* Example in Maven : ${project.basedir}/src/test/java
- * @deprecated since 4.2 will always return {@link #baseDir()}
+ * @deprecated since 4.2 use {@link FileSystem#files(org.sonar.api.batch.fs.FilePredicate)} to get all files with type {@link InputFile.Type#TEST}.
*/
List<File> testDirs();
@@ -67,7 +69,7 @@ public interface ModuleFileSystem extends BatchComponent {
* <li>Binary directories can be empty</li>
* <li>Test binary directories are not supported yet.</li>
* </ul>
- * @deprecated since 4.2 sonar.binaries should be converted to language specific property
+ * @deprecated since 4.2 sonar.binaries will be converted to java specific property
*/
List<File> binaryDirs();