diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-24 13:30:14 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-08-24 13:30:14 +0200 |
commit | c66a8ff27bb4c208886780410738dd3c99828354 (patch) | |
tree | 4aee979f13d940311cbb1a71315a5ebbd28eeb7a /sonar-batch | |
parent | d172a42d012bc511fdbf43d9de826d0c69388fe5 (diff) | |
download | sonarqube-c66a8ff27bb4c208886780410738dd3c99828354.tar.gz sonarqube-c66a8ff27bb4c208886780410738dd3c99828354.zip |
Revert "SONAR-6658 Drop validation on sonar.libraries and sonar.binaries"
This reverts commit 1dd1cd5c6517ffe91ae9b0b003d65c126d54b4b4.
Diffstat (limited to 'sonar-batch')
19 files changed, 206 insertions, 54 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index beeec9e389f..1363134d449 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -22,6 +22,7 @@ package org.sonar.batch.scan; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.InstantiationStrategy; +import org.sonar.api.batch.ProjectClasspath; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.FileMetadata; import org.sonar.api.batch.rule.CheckFactory; @@ -133,6 +134,7 @@ public class ModuleScanContainer extends ComponentContainer { DefaultModuleFileSystem.class, ModuleFileSystemInitializer.class, ProjectFileSystemAdapter.class, + ProjectClasspath.class, QProfileVerifier.class, SensorOptimizer.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java index ad67711a857..670bf714eef 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectReactorBuilder.java @@ -81,6 +81,8 @@ public class ProjectReactorBuilder { */ private static final String PROPERTY_SOURCES = "sonar.sources"; private static final String PROPERTY_TESTS = "sonar.tests"; + private static final String PROPERTY_BINARIES = "sonar.binaries"; + private static final String PROPERTY_LIBRARIES = "sonar.libraries"; /** * Array of all mandatory properties required for a project without child. @@ -342,9 +344,22 @@ public class ProjectReactorBuilder { if (!props.containsKey(PROPERTY_MODULES)) { // SONARPLUGINS-2285 Not an aggregator project so we can validate that paths are correct if defined + // We need to resolve patterns that may have been used in "sonar.libraries" + for (String pattern : getListFromProperty(props, PROPERTY_LIBRARIES)) { + File[] files = getLibraries(baseDir, pattern); + if (files == null || files.length == 0) { + LOG.error(MessageFormat.format(INVALID_VALUE_OF_X_FOR_Y, PROPERTY_LIBRARIES, projectId)); + throw new IllegalStateException("No files nor directories matching '" + pattern + "' in directory " + baseDir); + } + } + // Check sonar.tests String[] testPaths = getListFromProperty(props, PROPERTY_TESTS); checkExistenceOfPaths(projectId, baseDir, testPaths, PROPERTY_TESTS); + + // Check sonar.binaries + String[] binDirs = getListFromProperty(props, PROPERTY_BINARIES); + checkExistenceOfDirectories(projectId, baseDir, binDirs, PROPERTY_BINARIES); } } @@ -369,6 +384,16 @@ public class ProjectReactorBuilder { // We need to check the existence of source directories String[] sourcePaths = getListFromProperty(properties, PROPERTY_SOURCES); checkExistenceOfPaths(project.getKey(), project.getBaseDir(), sourcePaths, PROPERTY_SOURCES); + + // And we need to resolve patterns that may have been used in "sonar.libraries" + List<String> libPaths = Lists.newArrayList(); + for (String pattern : getListFromProperty(properties, PROPERTY_LIBRARIES)) { + for (File file : getLibraries(project.getBaseDir(), pattern)) { + libPaths.add(file.getAbsolutePath()); + } + } + properties.remove(PROPERTY_LIBRARIES); + properties.put(PROPERTY_LIBRARIES, StringUtils.join(libPaths, ",")); } @VisibleForTesting @@ -389,6 +414,8 @@ public class ProjectReactorBuilder { // "aggregator" project must not have the following properties: properties.remove(PROPERTY_SOURCES); properties.remove(PROPERTY_TESTS); + properties.remove(PROPERTY_BINARIES); + properties.remove(PROPERTY_LIBRARIES); } @VisibleForTesting 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 cb67cf534eb..24e26f5eb94 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 @@ -19,26 +19,19 @@ */ package org.sonar.batch.scan.filesystem; -import org.sonar.api.utils.log.Logger; -import org.sonar.api.utils.log.Loggers; - import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; - import java.io.File; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; -import java.util.LinkedList; import java.util.List; import java.util.Map; - import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import org.apache.commons.lang.StringUtils; import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.FilePredicate; @@ -53,7 +46,6 @@ import org.sonar.api.utils.MessageException; * @since 3.5 */ public class DefaultModuleFileSystem extends DefaultFileSystem implements ModuleFileSystem { - private static final Logger LOG = Loggers.get(DefaultModuleFileSystem.class); private final String moduleKey; private final FileIndexer indexer; @@ -62,6 +54,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module private File buildDir; private List<File> sourceDirsOrFiles = Lists.newArrayList(); private List<File> testDirsOrFiles = Lists.newArrayList(); + private List<File> binaryDirs = Lists.newArrayList(); private ComponentIndexer componentIndexer; private boolean initialized; @@ -76,6 +69,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); + this.binaryDirs = initializer.binaryDirs(); } @VisibleForTesting @@ -90,6 +84,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); + this.binaryDirs = initializer.binaryDirs(); } public boolean isInitialized() { @@ -136,8 +131,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module @Override public List<File> binaryDirs() { - LOG.warn("ModuleFileSystem#binaryDirs() is deprecated and will always return an empty list"); - return new LinkedList<>(); + return binaryDirs; } @Override diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java index aa8e20813e1..fd2e8a9226a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializer.java @@ -42,11 +42,13 @@ public class ModuleFileSystemInitializer { private File buildDir; private List<File> sourceDirsOrFiles = Lists.newArrayList(); private List<File> testDirsOrFiles = Lists.newArrayList(); + private List<File> binaryDirs = Lists.newArrayList(); public ModuleFileSystemInitializer(ProjectDefinition module, TempFolder tempUtils, PathResolver pathResolver) { baseDir = module.getBaseDir(); buildDir = module.getBuildDir(); initWorkingDir(module, tempUtils); + initBinaryDirs(module, pathResolver); initSources(module, pathResolver); initTests(module, pathResolver); } @@ -82,6 +84,13 @@ public class ModuleFileSystemInitializer { } } + private void initBinaryDirs(ProjectDefinition module, PathResolver pathResolver) { + for (String path : module.getBinaries()) { + File dir = pathResolver.relativeFile(module.getBaseDir(), path); + binaryDirs.add(dir); + } + } + File baseDir() { return baseDir; } @@ -102,4 +111,12 @@ public class ModuleFileSystemInitializer { List<File> tests() { return testDirsOrFiles; } + + /** + * @deprecated since 4.5.1 use SonarQube Java specific API + */ + @Deprecated + List<File> binaryDirs() { + return binaryDirs; + } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java index f42cdc208d5..0aaf6e2dfd2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/DeprecatedProjectReactorBuilderTest.java @@ -52,11 +52,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); // root project must not contain some properties - even if they are defined in the root properties file - assertThat(rootProject.sources().contains("sources")).isFalse(); - assertThat(rootProject.tests().contains("tests")).isFalse(); + assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); + assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); + assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); // and module properties must have been cleaned - assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); // CHECK MODULES List<ProjectDefinition> modules = rootProject.getSubProjects(); @@ -70,11 +71,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); // Description should not be inherited from parent if not set assertThat(module1.getDescription()).isEqualTo("Description of Module 1"); - assertThat(module1.sources()).contains("sources"); - assertThat(module1.tests()).contains("tests"); + assertThat(module1.getSourceDirs()).contains("sources"); + assertThat(module1.getTestDirs()).contains("tests"); + assertThat(module1.getBinaries()).contains("target/classes"); // and module properties must have been cleaned - assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); // Module 2 ProjectDefinition module2 = modules.get(1); @@ -83,11 +85,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(module2.getName()).isEqualTo("Foo Module 2"); assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(module2.getDescription()).isEqualTo("Description of Module 2"); - assertThat(module2.sources()).contains("src"); - assertThat(module2.tests()).contains("tests"); + assertThat(module2.getSourceDirs()).contains("src"); + assertThat(module2.getTestDirs()).contains("tests"); + assertThat(module2.getBinaries()).contains("target/classes"); // and module properties must have been cleaned - assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(module2.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); } @Test @@ -100,11 +103,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); // root project must not contain some properties - even if they are defined in the root properties file - assertThat(rootProject.sources().contains("sources")).isFalse(); - assertThat(rootProject.tests().contains("tests")).isFalse(); + assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); + assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); + assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); // and module properties must have been cleaned - assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); // CHECK MODULES List<ProjectDefinition> modules = rootProject.getSubProjects(); @@ -118,11 +122,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); // Description should not be inherited from parent if not set assertThat(module1.getDescription()).isNull(); - assertThat(module1.sources()).contains("sources"); - assertThat(module1.tests()).contains("tests"); + assertThat(module1.getSourceDirs()).contains("sources"); + assertThat(module1.getTestDirs()).contains("tests"); + assertThat(module1.getBinaries()).contains("target/classes"); // and module properties must have been cleaned - assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); // Module 2 ProjectDefinition module2 = modules.get(1); @@ -131,11 +136,12 @@ public class DeprecatedProjectReactorBuilderTest { assertThat(module2.getName()).isEqualTo("Foo Module 2"); assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(module2.getDescription()).isEqualTo("Description of Module 2"); - assertThat(module2.sources()).contains("src"); - assertThat(module2.tests()).contains("tests"); + assertThat(module2.getSourceDirs()).contains("src"); + assertThat(module2.getTestDirs()).contains("tests"); + assertThat(module2.getBinaries()).contains("target/classes"); // and module properties must have been cleaned - assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); - assertThat(module2.properties().get("module2.sonar.projectKey")).isNull(); + assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); + assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java index 8db640586d8..b4bdeb07877 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java @@ -52,7 +52,9 @@ public class ProjectReactorBuilderTest { assertThat(projectDefinition.getName()).isEqualTo("Foo Project"); assertThat(projectDefinition.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(projectDefinition.getDescription()).isEqualTo("Description of Foo Project"); - assertThat(projectDefinition.sources()).contains("sources"); + assertThat(projectDefinition.getSourceDirs()).contains("sources"); + assertThat(projectDefinition.getLibraries()).contains(TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath(), + TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath()); } @Test @@ -94,8 +96,9 @@ public class ProjectReactorBuilderTest { assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); // root project must not contain some properties - even if they are defined in the root properties file - assertThat(rootProject.sources().contains("sources")).isFalse(); - assertThat(rootProject.tests().contains("tests")).isFalse(); + assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); + assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); + assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); // and module properties must have been cleaned assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -117,8 +120,9 @@ public class ProjectReactorBuilderTest { assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); // Description should not be inherited from parent if not set assertThat(module1.getDescription()).isNull(); - assertThat(module1.sources()).contains("sources"); - assertThat(module1.tests()).contains("tests"); + assertThat(module1.getSourceDirs()).contains("sources"); + assertThat(module1.getTestDirs()).contains("tests"); + assertThat(module1.getBinaries()).contains("target/classes"); // and module properties must have been cleaned assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -135,8 +139,9 @@ public class ProjectReactorBuilderTest { assertThat(module2.getName()).isEqualTo("Foo Module 2"); assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(module2.getDescription()).isEqualTo("Description of Module 2"); - assertThat(module2.sources()).contains("src"); - assertThat(module2.tests()).contains("tests"); + assertThat(module2.getSourceDirs()).contains("src"); + assertThat(module2.getTestDirs()).contains("tests"); + assertThat(module2.getBinaries()).contains("target/classes"); // and module properties must have been cleaned assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -183,7 +188,7 @@ public class ProjectReactorBuilderTest { // Module 1 ProjectDefinition module1 = modules.get(0); assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root")); - assertThat(module1.sources()).contains("src/main/java"); + assertThat(module1.getSourceDirs()).contains("src/main/java"); // and module properties must have been cleaned assertThat(module1.getWorkDir().getCanonicalFile()) .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module")); @@ -191,7 +196,7 @@ public class ProjectReactorBuilderTest { // Module 2 ProjectDefinition module2 = modules.get(1); assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root")); - assertThat(module2.sources()).contains("src/main/groovy"); + assertThat(module2.getSourceDirs()).contains("src/main/groovy"); // and module properties must have been cleaned assertThat(module2.getWorkDir().getCanonicalFile()) .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module")); @@ -238,6 +243,33 @@ public class ProjectReactorBuilderTest { } @Test + public void shouldFailIfExplicitUnexistingBinaryFolder() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("The folder 'bin' does not exist for 'com.foo.project' (base directory = " + + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-binary").getAbsolutePath()); + + loadProjectDefinition("simple-project-with-unexisting-binary"); + } + + @Test + public void shouldFailIfExplicitUnmatchingLibFolder() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("No files nor directories matching 'libs/*.txt' in directory " + + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-lib").getAbsolutePath()); + + loadProjectDefinition("simple-project-with-unexisting-lib"); + } + + @Test + public void shouldGetLibDirectory() { + ProjectDefinition def = loadProjectDefinition("simple-project-with-lib-dir"); + assertThat(def.getLibraries()).hasSize(1); + File libDir = new File(def.getLibraries().get(0)); + assertThat(libDir).isDirectory().exists(); + assertThat(libDir.getName()).isEqualTo("lib"); + } + + @Test public void shouldFailIfExplicitUnexistingTestFolderOnModule() { thrown.expect(IllegalStateException.class); thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = " @@ -247,6 +279,24 @@ public class ProjectReactorBuilderTest { } @Test + public void shouldFailIfExplicitUnexistingBinaryFolderOnModule() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("The folder 'bin' does not exist for 'module1' (base directory = " + + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-binary-dir").getAbsolutePath() + File.separator + "module1)"); + + loadProjectDefinition("multi-module-with-explicit-unexisting-binary-dir"); + } + + @Test + public void shouldFailIfExplicitUnmatchingLibFolderOnModule() { + thrown.expect(IllegalStateException.class); + thrown.expectMessage("No files nor directories matching 'lib/*.jar' in directory " + + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-lib").getAbsolutePath() + File.separator + "module1"); + + loadProjectDefinition("multi-module-with-explicit-unexisting-lib"); + } + + @Test public void multiModuleProperties() { ProjectDefinition projectDefinition = loadProjectDefinition("big-multi-module-definitions-all-in-root"); @@ -533,8 +583,9 @@ public class ProjectReactorBuilderTest { assertThat(rootProject.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(rootProject.getDescription()).isEqualTo("Description of Foo Project"); // root project must not contain some properties - even if they are defined in the root properties file - assertThat(rootProject.sources().contains("sources")).isFalse(); - assertThat(rootProject.tests().contains("tests")).isFalse(); + assertThat(rootProject.getSourceDirs().contains("sources")).isFalse(); + assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); + assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); // and module properties must have been cleaned assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -556,8 +607,9 @@ public class ProjectReactorBuilderTest { assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT"); // Description should not be inherited from parent if not set assertThat(module1.getDescription()).isNull(); - assertThat(module1.sources()).contains("sources"); - assertThat(module1.tests()).contains("tests"); + assertThat(module1.getSourceDirs()).contains("sources"); + assertThat(module1.getTestDirs()).contains("tests"); + assertThat(module1.getBinaries()).contains("target/classes"); // and module properties must have been cleaned assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -574,8 +626,9 @@ public class ProjectReactorBuilderTest { assertThat(module1Feature.getName()).isEqualTo("Foo Module 1 Feature"); assertThat(module1Feature.getVersion()).isEqualTo("1.0-SNAPSHOT"); assertThat(module1Feature.getDescription()).isEqualTo("Description of Module 1 Feature"); - assertThat(module1Feature.sources()).contains("src"); - assertThat(module1Feature.tests()).contains("tests"); + assertThat(module1Feature.getSourceDirs()).contains("src"); + assertThat(module1Feature.getTestDirs()).contains("tests"); + assertThat(module1Feature.getBinaries()).contains("target/classes"); // and module properties must have been cleaned assertThat(module1Feature.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module1Feature.getProperties().getProperty("module2.sonar.projectKey")).isNull(); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java index 1486b1b5482..4a5e04b4a8e 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java @@ -82,7 +82,7 @@ public class DefaultModuleFileSystemTest { DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache, new Project("foo"), settings, fileIndexer, initializer, componentIndexer); - assertThat(fs.encoding()).isEqualTo(Charset.defaultCharset()); + assertThat(fs.sourceCharset()).isEqualTo(Charset.defaultCharset()); assertThat(fs.isDefaultJvmEncoding()).isTrue(); } @@ -93,7 +93,7 @@ public class DefaultModuleFileSystemTest { new Project("foo"), settings, fileIndexer, initializer, componentIndexer); assertThat(fs.encoding()).isEqualTo(Charset.forName("Cp1124")); - assertThat(fs.encoding()).isEqualTo(Charset.forName("Cp1124")); + assertThat(fs.sourceCharset()).isEqualTo(Charset.forName("Cp1124")); // This test fails when default Java encoding is "IBM AIX Ukraine". Sorry for that. assertThat(fs.isDefaultJvmEncoding()).isFalse(); @@ -109,6 +109,7 @@ public class DefaultModuleFileSystemTest { when(initializer.baseDir()).thenReturn(basedir); when(initializer.buildDir()).thenReturn(buildDir); when(initializer.workingDir()).thenReturn(workingDir); + when(initializer.binaryDirs()).thenReturn(Arrays.asList(new File(basedir, "target/classes"))); File javaSrc = new File(basedir, "src/main/java"); javaSrc.mkdirs(); File groovySrc = new File(basedir, "src/main/groovy"); @@ -126,7 +127,7 @@ public class DefaultModuleFileSystemTest { assertThat(fs.buildDir().getCanonicalPath()).isEqualTo(buildDir.getCanonicalPath()); assertThat(fs.sourceDirs()).hasSize(2); assertThat(fs.testDirs()).hasSize(1); - assertThat(fs.binaryDirs()).hasSize(0); + assertThat(fs.binaryDirs()).hasSize(1); } @Test diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializerTest.java index 815ead7e5bd..53ee455adfb 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ModuleFileSystemInitializerTest.java @@ -69,8 +69,9 @@ public class ModuleFileSystemInitializerTest { ProjectDefinition project = ProjectDefinition.create() .setBaseDir(baseDir) .setBuildDir(buildDir) - .addSources("src/main/java", "src/main/unknown") - .addTests("src/test/java", "src/test/unknown"); + .addSourceDirs("src/main/java", "src/main/unknown") + .addTestDirs("src/test/java", "src/test/unknown") + .addBinaryDir("target/classes"); ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(project, mock(TempFolder.class), pathResolver); @@ -80,6 +81,8 @@ public class ModuleFileSystemInitializerTest { assertThat(path(initializer.sources().get(0))).endsWith("src/main/java"); assertThat(initializer.tests()).hasSize(1); assertThat(path(initializer.tests().get(0))).endsWith("src/test/java"); + assertThat(initializer.binaryDirs()).hasSize(1); + assertThat(path(initializer.binaryDirs().get(0))).endsWith("target/classes"); } private String path(File f) throws IOException { diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java @@ -0,0 +1 @@ + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties new file mode 100644 index 00000000000..8007363a9c4 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties @@ -0,0 +1,9 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=src + +sonar.modules=module1 +module1.sonar.binaries=bin diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java @@ -0,0 +1 @@ + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties new file mode 100644 index 00000000000..d97a18bb16d --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties @@ -0,0 +1,9 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=src + +sonar.modules=module1 +module1.sonar.libraries=lib/*.jar diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class new file mode 100644 index 00000000000..bf2c3a09e07 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class @@ -0,0 +1,3 @@ +package org.sonar.runner.batch.ProjectReactorBuilderTest.simple + +Fake
\ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties new file mode 100644 index 00000000000..0cada50b51f --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties @@ -0,0 +1,7 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=sources +sonar.libraries=lib diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java new file mode 100644 index 00000000000..aee03e60b4a --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java @@ -0,0 +1,3 @@ +package org.sonar.runner.batch.ProjectReactorBuilderTest.simple; + +class Fake {} diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties new file mode 100644 index 00000000000..55d1ddf0242 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties @@ -0,0 +1,7 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=sources +sonar.binaries=bin diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java new file mode 100644 index 00000000000..e67004defc5 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java @@ -0,0 +1 @@ +class Fake {} diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties new file mode 100644 index 00000000000..69ccd8d1411 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties @@ -0,0 +1,7 @@ +sonar.projectKey=com.foo.project +sonar.projectName=Foo Project +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Description of Foo Project + +sonar.sources=sources +sonar.libraries=libs/*.txt diff --git a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java new file mode 100644 index 00000000000..e67004defc5 --- /dev/null +++ b/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java @@ -0,0 +1 @@ +class Fake {} |