From: Julien HENRY Date: Fri, 21 Feb 2014 17:32:18 +0000 (+0100) Subject: SONAR-5069 Make sonar.sources optional X-Git-Tag: 4.2~64 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c49b05d030f2bb87740d92eeb5626697239993f9;p=sonarqube.git SONAR-5069 Make sonar.sources optional --- 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 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 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 testDirs(); @@ -67,7 +69,7 @@ public interface ModuleFileSystem extends BatchComponent { *
  • Binary directories can be empty
  • *
  • Test binary directories are not supported yet.
  • * - * @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 binaryDirs();