From 1dd1cd5c6517ffe91ae9b0b003d65c126d54b4b4 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 21 Aug 2015 17:26:04 +0200 Subject: [PATCH] SONAR-6658 Drop validation on sonar.libraries and sonar.binaries --- .../sonar/batch/scan/ModuleScanContainer.java | 2 - .../batch/scan/ProjectReactorBuilder.java | 27 -- .../filesystem/DefaultModuleFileSystem.java | 14 +- .../ModuleFileSystemInitializer.java | 17 -- .../DeprecatedProjectReactorBuilderTest.java | 54 ++-- .../batch/scan/ProjectReactorBuilderTest.java | 83 ++---- .../DefaultModuleFileSystemTest.java | 7 +- .../ModuleFileSystemInitializerTest.java | 7 +- .../module1/src/Fake.java | 1 - .../sonar-project.properties | 9 - .../module1/src/Fake.java | 1 - .../sonar-project.properties | 9 - .../lib/Fake.class | 3 - .../sonar-project.properties | 7 - .../sources/Fake.java | 3 - .../sonar-project.properties | 7 - .../sources/Fake.java | 1 - .../sonar-project.properties | 7 - .../sources/Fake.java | 1 - .../org/sonar/api/batch/ProjectClasspath.java | 90 ------- .../batch/bootstrap/ProjectDefinition.java | 245 ------------------ .../api/scan/filesystem/ModuleFileSystem.java | 9 +- .../batch/bootstrap/ProjectBuilderTest.java | 4 +- .../bootstrap/ProjectDefinitionTest.java | 129 +++------ 24 files changed, 87 insertions(+), 650 deletions(-) delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java delete mode 100644 sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java 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 1363134d449..beeec9e389f 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,7 +22,6 @@ 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; @@ -134,7 +133,6 @@ 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 670bf714eef..ad67711a857 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,8 +81,6 @@ 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. @@ -344,22 +342,9 @@ 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); } } @@ -384,16 +369,6 @@ 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 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 @@ -414,8 +389,6 @@ 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 24e26f5eb94..cb67cf534eb 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,19 +19,26 @@ */ 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; @@ -46,6 +53,7 @@ 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; @@ -54,7 +62,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module private File buildDir; private List sourceDirsOrFiles = Lists.newArrayList(); private List testDirsOrFiles = Lists.newArrayList(); - private List binaryDirs = Lists.newArrayList(); private ComponentIndexer componentIndexer; private boolean initialized; @@ -69,7 +76,6 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module this.buildDir = initializer.buildDir(); this.sourceDirsOrFiles = initializer.sources(); this.testDirsOrFiles = initializer.tests(); - this.binaryDirs = initializer.binaryDirs(); } @VisibleForTesting @@ -84,7 +90,6 @@ 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() { @@ -131,7 +136,8 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module @Override public List binaryDirs() { - return binaryDirs; + LOG.warn("ModuleFileSystem#binaryDirs() is deprecated and will always return an empty list"); + return new LinkedList<>(); } @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 fd2e8a9226a..aa8e20813e1 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,13 +42,11 @@ public class ModuleFileSystemInitializer { private File buildDir; private List sourceDirsOrFiles = Lists.newArrayList(); private List testDirsOrFiles = Lists.newArrayList(); - private List 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); } @@ -84,13 +82,6 @@ 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; } @@ -111,12 +102,4 @@ public class ModuleFileSystemInitializer { List tests() { return testDirsOrFiles; } - - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - List 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 0aaf6e2dfd2..f42cdc208d5 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,12 +52,11 @@ 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.getSourceDirs().contains("sources")).isFalse(); - assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); - assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); + assertThat(rootProject.sources().contains("sources")).isFalse(); + assertThat(rootProject.tests().contains("tests")).isFalse(); // and module properties must have been cleaned - assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); // CHECK MODULES List modules = rootProject.getSubProjects(); @@ -71,12 +70,11 @@ 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.getSourceDirs()).contains("sources"); - assertThat(module1.getTestDirs()).contains("tests"); - assertThat(module1.getBinaries()).contains("target/classes"); + assertThat(module1.sources()).contains("sources"); + assertThat(module1.tests()).contains("tests"); // and module properties must have been cleaned - assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); // Module 2 ProjectDefinition module2 = modules.get(1); @@ -85,12 +83,11 @@ 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.getSourceDirs()).contains("src"); - assertThat(module2.getTestDirs()).contains("tests"); - assertThat(module2.getBinaries()).contains("target/classes"); + assertThat(module2.sources()).contains("src"); + assertThat(module2.tests()).contains("tests"); // and module properties must have been cleaned - assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(module2.properties().get("module2.sonar.projectKey")).isNull(); } @Test @@ -103,12 +100,11 @@ 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.getSourceDirs().contains("sources")).isFalse(); - assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); - assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); + assertThat(rootProject.sources().contains("sources")).isFalse(); + assertThat(rootProject.tests().contains("tests")).isFalse(); // and module properties must have been cleaned - assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(rootProject.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull(); // CHECK MODULES List modules = rootProject.getSubProjects(); @@ -122,12 +118,11 @@ 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.getSourceDirs()).contains("sources"); - assertThat(module1.getTestDirs()).contains("tests"); - assertThat(module1.getBinaries()).contains("target/classes"); + assertThat(module1.sources()).contains("sources"); + assertThat(module1.tests()).contains("tests"); // and module properties must have been cleaned - assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(module1.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(module1.properties().get("module2.sonar.projectKey")).isNull(); // Module 2 ProjectDefinition module2 = modules.get(1); @@ -136,12 +131,11 @@ 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.getSourceDirs()).contains("src"); - assertThat(module2.getTestDirs()).contains("tests"); - assertThat(module2.getBinaries()).contains("target/classes"); + assertThat(module2.sources()).contains("src"); + assertThat(module2.tests()).contains("tests"); // and module properties must have been cleaned - assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); - assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); + assertThat(module2.properties().get("module1.sonar.projectKey")).isNull(); + assertThat(module2.properties().get("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 b4bdeb07877..8db640586d8 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,9 +52,7 @@ 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.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()); + assertThat(projectDefinition.sources()).contains("sources"); } @Test @@ -96,9 +94,8 @@ 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.getSourceDirs().contains("sources")).isFalse(); - assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); - assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); + assertThat(rootProject.sources().contains("sources")).isFalse(); + assertThat(rootProject.tests().contains("tests")).isFalse(); // and module properties must have been cleaned assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -120,9 +117,8 @@ 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.getSourceDirs()).contains("sources"); - assertThat(module1.getTestDirs()).contains("tests"); - assertThat(module1.getBinaries()).contains("target/classes"); + assertThat(module1.sources()).contains("sources"); + assertThat(module1.tests()).contains("tests"); // and module properties must have been cleaned assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -139,9 +135,8 @@ 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.getSourceDirs()).contains("src"); - assertThat(module2.getTestDirs()).contains("tests"); - assertThat(module2.getBinaries()).contains("target/classes"); + assertThat(module2.sources()).contains("src"); + assertThat(module2.tests()).contains("tests"); // and module properties must have been cleaned assertThat(module2.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module2.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -188,7 +183,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.getSourceDirs()).contains("src/main/java"); + assertThat(module1.sources()).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")); @@ -196,7 +191,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.getSourceDirs()).contains("src/main/groovy"); + assertThat(module2.sources()).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")); @@ -242,33 +237,6 @@ public class ProjectReactorBuilderTest { loadProjectDefinition("simple-project-with-unexisting-test-dir"); } - @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); @@ -278,24 +246,6 @@ public class ProjectReactorBuilderTest { loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir"); } - @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"); @@ -583,9 +533,8 @@ 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.getSourceDirs().contains("sources")).isFalse(); - assertThat(rootProject.getTestDirs().contains("tests")).isFalse(); - assertThat(rootProject.getBinaries().contains("target/classes")).isFalse(); + assertThat(rootProject.sources().contains("sources")).isFalse(); + assertThat(rootProject.tests().contains("tests")).isFalse(); // and module properties must have been cleaned assertThat(rootProject.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(rootProject.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -607,9 +556,8 @@ 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.getSourceDirs()).contains("sources"); - assertThat(module1.getTestDirs()).contains("tests"); - assertThat(module1.getBinaries()).contains("target/classes"); + assertThat(module1.sources()).contains("sources"); + assertThat(module1.tests()).contains("tests"); // and module properties must have been cleaned assertThat(module1.getProperties().getProperty("module1.sonar.projectKey")).isNull(); assertThat(module1.getProperties().getProperty("module2.sonar.projectKey")).isNull(); @@ -626,9 +574,8 @@ 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.getSourceDirs()).contains("src"); - assertThat(module1Feature.getTestDirs()).contains("tests"); - assertThat(module1Feature.getBinaries()).contains("target/classes"); + assertThat(module1Feature.sources()).contains("src"); + assertThat(module1Feature.tests()).contains("tests"); // 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 4a5e04b4a8e..1486b1b5482 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.sourceCharset()).isEqualTo(Charset.defaultCharset()); + assertThat(fs.encoding()).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.sourceCharset()).isEqualTo(Charset.forName("Cp1124")); + assertThat(fs.encoding()).isEqualTo(Charset.forName("Cp1124")); // This test fails when default Java encoding is "IBM AIX Ukraine". Sorry for that. assertThat(fs.isDefaultJvmEncoding()).isFalse(); @@ -109,7 +109,6 @@ 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"); @@ -127,7 +126,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(1); + assertThat(fs.binaryDirs()).hasSize(0); } @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 53ee455adfb..815ead7e5bd 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,9 +69,8 @@ public class ModuleFileSystemInitializerTest { ProjectDefinition project = ProjectDefinition.create() .setBaseDir(baseDir) .setBuildDir(buildDir) - .addSourceDirs("src/main/java", "src/main/unknown") - .addTestDirs("src/test/java", "src/test/unknown") - .addBinaryDir("target/classes"); + .addSources("src/main/java", "src/main/unknown") + .addTests("src/test/java", "src/test/unknown"); ModuleFileSystemInitializer initializer = new ModuleFileSystemInitializer(project, mock(TempFolder.class), pathResolver); @@ -81,8 +80,6 @@ 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 deleted file mode 100644 index 8b137891791..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/module1/src/Fake.java +++ /dev/null @@ -1 +0,0 @@ - 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 deleted file mode 100644 index 8007363a9c4..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-binary-dir/sonar-project.properties +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 8b137891791..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/module1/src/Fake.java +++ /dev/null @@ -1 +0,0 @@ - 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 deleted file mode 100644 index d97a18bb16d..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/multi-module-with-explicit-unexisting-lib/sonar-project.properties +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index bf2c3a09e07..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/lib/Fake.class +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 0cada50b51f..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index aee03e60b4a..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-lib-dir/sources/Fake.java +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index 55d1ddf0242..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index e67004defc5..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-binary/sources/Fake.java +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 69ccd8d1411..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index e67004defc5..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/scan/ProjectReactorBuilderTest/simple-project-with-unexisting-lib/sources/Fake.java +++ /dev/null @@ -1 +0,0 @@ -class Fake {} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java deleted file mode 100644 index e9f71cc17d1..00000000000 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/ProjectClasspath.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.api.batch; - -import com.google.common.collect.Lists; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.List; -import org.sonar.api.BatchComponent; -import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.resources.ProjectFileSystem; -import org.sonar.api.utils.SonarException; - -/** - * @since 2.2 - * @deprecated since 4.5 this is some Java specific stuff that should by handled by SQ Java plugin - */ -@Deprecated -public class ProjectClasspath implements BatchComponent { - - private final ProjectDefinition def; - private final ProjectFileSystem projectFileSystem; - private List elements; - private URLClassLoader classloader; - - public ProjectClasspath(ProjectDefinition def, ProjectFileSystem projectFileSystem) { - this.def = def; - this.projectFileSystem = projectFileSystem; - } - - public URLClassLoader getClassloader() { - if (classloader == null) { - classloader = createClassLoader(); - } - return classloader; - } - - /** - * bytecode directory + JARs (dependencies) - */ - public List getElements() { - if (elements == null) { - elements = createElements(); - } - return elements; - } - - protected URLClassLoader createClassLoader() { - try { - List urls = Lists.newArrayList(); - for (File file : getElements()) { - urls.add(file.toURI().toURL()); - } - return new URLClassLoader(urls.toArray(new URL[urls.size()]), null); - - } catch (MalformedURLException e) { - throw new SonarException("Fail to create the project classloader. Classpath element is unvalid.", e); - } - } - - protected List createElements() { - List elements = Lists.newArrayList(); - for (String path : def.getBinaries()) { - elements.add(projectFileSystem.resolvePath(path)); - } - for (String path : def.getLibraries()) { - elements.add(projectFileSystem.resolvePath(path)); - } - return elements; - } -} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java index 88f80180cc9..49ec7b68fd0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java @@ -42,38 +42,8 @@ import org.sonar.api.CoreProperties; public class ProjectDefinition { public static final String SOURCES_PROPERTY = "sonar.sources"; - /** - * @deprecated since 4.5 use {@link #SOURCES_PROPERTY} - */ - @Deprecated - public static final String SOURCE_DIRS_PROPERTY = SOURCES_PROPERTY; - /** - * @deprecated since 4.5 use {@link #SOURCES_PROPERTY} - */ - @Deprecated - public static final String SOURCE_FILES_PROPERTY = "sonar.sourceFiles"; public static final String TESTS_PROPERTY = "sonar.tests"; - /** - * @deprecated since 4.5 use {@link #TESTS_PROPERTY} - */ - @Deprecated - public static final String TEST_DIRS_PROPERTY = TESTS_PROPERTY; - /** - * @deprecated since 4.5 use {@link #TESTS_PROPERTY} - */ - @Deprecated - public static final String TEST_FILES_PROPERTY = "sonar.testFiles"; - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public static final String BINARIES_PROPERTY = "sonar.binaries"; - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public static final String LIBRARIES_PROPERTY = "sonar.libraries"; public static final String BUILD_DIR_PROPERTY = "sonar.buildDir"; private static final char SEPARATOR = ','; @@ -256,14 +226,6 @@ public class ProjectDefinition { return trim(StringUtils.split(sources, SEPARATOR)); } - /** - * @deprecated since 4.5 use {@link #sources()} - */ - @Deprecated - public List getSourceDirs() { - return sources(); - } - /** * @param paths paths to file or directory with main sources. * They can be absolute or relative to project base directory. @@ -275,14 +237,6 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #addSources(String...)} - */ - @Deprecated - public ProjectDefinition addSourceDirs(String... paths) { - return addSources(paths); - } - public ProjectDefinition addSources(File... fileOrDirs) { for (File fileOrDir : fileOrDirs) { addSources(fileOrDir.getAbsolutePath()); @@ -290,40 +244,16 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #addSources(File...)} - */ - @Deprecated - public ProjectDefinition addSourceDirs(File... dirs) { - return addSources(dirs); - } - public ProjectDefinition resetSources() { properties.remove(SOURCES_PROPERTY); return this; } - /** - * @deprecated since 4.5 use {@link #resetSources()} - */ - @Deprecated - public ProjectDefinition resetSourceDirs() { - return resetSources(); - } - public ProjectDefinition setSources(String... paths) { resetSources(); return addSources(paths); } - /** - * @deprecated since 4.5 use {@link #setSources(String...)} - */ - @Deprecated - public ProjectDefinition setSourceDirs(String... paths) { - return setSources(paths); - } - public ProjectDefinition setSources(File... filesOrDirs) { resetSources(); for (File fileOrDir : filesOrDirs) { @@ -332,65 +262,11 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #setSources(File...)} - */ - @Deprecated - public ProjectDefinition setSourceDirs(File... dirs) { - resetSourceDirs(); - for (File dir : dirs) { - addSourceDirs(dir.getAbsolutePath()); - } - return this; - } - - /** - * @deprecated since 4.5 use {@link #addSources(File...)} - */ - @Deprecated - public ProjectDefinition addSourceFiles(String... paths) { - // Hack for visual studio project builder that used to add baseDir first as source dir - List sourceDirs = getSourceDirs(); - if (sourceDirs.size() == 1 && isDirectory(sourceDirs.get(0))) { - resetSources(); - } - return addSources(paths); - } - - /** - * @deprecated since 4.5 use {@link #addSources(File...)} - */ - @Deprecated - public ProjectDefinition addSourceFiles(File... files) { - // Hack for visual studio project builder that used to add baseDir first as source dir - List sourceDirs = getSourceDirs(); - if (sourceDirs.size() == 1 && isDirectory(sourceDirs.get(0))) { - resetSources(); - } - return addSources(files); - } - - /** - * @deprecated since 4.5 use {@link #sources()} - */ - @Deprecated - public List getSourceFiles() { - return sources(); - } - public List tests() { String sources = (String) ObjectUtils.defaultIfNull(properties.get(TESTS_PROPERTY), ""); return trim(StringUtils.split(sources, SEPARATOR)); } - /** - * @deprecated since 4.5 use {@link #tests()} - */ - @Deprecated - public List getTestDirs() { - return tests(); - } - /** * @param paths path to files or directories with test sources. * It can be absolute or relative to project directory. @@ -402,14 +278,6 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #addTests(String...)} - */ - @Deprecated - public ProjectDefinition addTestDirs(String... paths) { - return addTests(paths); - } - public ProjectDefinition addTests(File... fileOrDirs) { for (File fileOrDir : fileOrDirs) { addTests(fileOrDir.getAbsolutePath()); @@ -417,27 +285,11 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #addTests(File...)} - */ - @Deprecated - public ProjectDefinition addTestDirs(File... dirs) { - return addTests(dirs); - } - public ProjectDefinition setTests(String... paths) { resetTests(); return addTests(paths); } - /** - * @deprecated since 4.5 use {@link #setTests(String...)} - */ - @Deprecated - public ProjectDefinition setTestDirs(String... paths) { - return setTests(paths); - } - public ProjectDefinition setTests(File... fileOrDirs) { resetTests(); for (File dir : fileOrDirs) { @@ -459,103 +311,6 @@ public class ProjectDefinition { return this; } - /** - * @deprecated since 4.5 use {@link #resetTests()} - */ - @Deprecated - public ProjectDefinition resetTestDirs() { - return resetTests(); - } - - /** - * @deprecated since 4.5 use {@link #addTests(String...)} - */ - @Deprecated - public ProjectDefinition addTestFiles(String... paths) { - // Hack for visual studio project builder that used to add baseDir first as test dir - List testDirs = getTestDirs(); - if (testDirs.size() == 1 && isDirectory(testDirs.get(0))) { - resetTests(); - } - return addTests(paths); - } - - private boolean isDirectory(String relativeOrAbsoluteDir) { - File file = new File(relativeOrAbsoluteDir); - if (!file.isAbsolute()) { - file = new File(baseDir, relativeOrAbsoluteDir); - } - return file.isDirectory(); - } - - /** - * @deprecated since 4.5 use {@link #addTests(File...)} - */ - @Deprecated - public ProjectDefinition addTestFiles(File... files) { - // Hack for visual studio project builder that used to add baseDir first as test dir - List testDirs = getTestDirs(); - if (testDirs.size() == 1 && isDirectory(testDirs.get(0))) { - resetTests(); - } - return addTests(files); - } - - /** - * @deprecated since 4.5 use {@link #tests()} - */ - @Deprecated - public List getTestFiles() { - return tests(); - } - - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public List getBinaries() { - String sources = (String) ObjectUtils.defaultIfNull(properties.get(BINARIES_PROPERTY), ""); - return trim(StringUtils.split(sources, SEPARATOR)); - } - - /** - * @param path path to directory with compiled source. In case of Java this is directory with class files. - * It can be absolute or relative to project directory. - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public ProjectDefinition addBinaryDir(String path) { - appendProperty(BINARIES_PROPERTY, path); - return this; - } - - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public ProjectDefinition addBinaryDir(File f) { - return addBinaryDir(f.getAbsolutePath()); - } - - /** - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public List getLibraries() { - String sources = (String) ObjectUtils.defaultIfNull(properties.get(LIBRARIES_PROPERTY), ""); - return trim(StringUtils.split(sources, SEPARATOR)); - } - - /** - * @param path path to file with third-party library. In case of Java this is path to jar file. - * It can be absolute or relative to project directory. - * @deprecated since 4.5.1 use SonarQube Java specific API - */ - @Deprecated - public void addLibrary(String path) { - appendProperty(LIBRARIES_PROPERTY, path); - } - /** * Adds an extension, which would be available in PicoContainer during analysis of this project. * 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 8979f73b7c1..dd88f5b9bfd 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 @@ -63,14 +63,7 @@ public interface ModuleFileSystem { List testDirs(); /** - * Optional directories that contain the compiled sources, for example java bytecode. - * Note that : - *
    - *
  • Maven projects have only a single binary directory, which is generally ${project.basedir}/target/classes
  • - *
  • Binary directories can be empty
  • - *
  • Test binary directories are not supported yet.
  • - *
- * @deprecated since 4.2 sonar.binaries will be converted to java specific property + * @deprecated since 4.2 - returns always empty list */ List binaryDirs(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java index 7a13e851401..14280131018 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectBuilderTest.java @@ -43,7 +43,7 @@ public class ProjectBuilderTest { ProjectDefinition root = projectReactor.getRoot(); assertThat(root.getName(), is("Name changed by plugin")); assertThat(root.getSubProjects().size(), is(1)); - assertThat(root.getSubProjects().get(0).getSourceDirs(), hasItem("src")); + assertThat(root.getSubProjects().get(0).sources(), hasItem("src")); } final static class ProjectBuilderSample extends ProjectBuilder { @@ -68,7 +68,7 @@ public class ProjectBuilderTest { subProject.setKey("groupId:parentProjectId"); subProject.setVersion(root.getVersion()); subProject.setName("Sub Project"); - subProject.setSourceDirs("src"); + subProject.setSources("src"); root.addSubProject(subProject); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java index 14faa2ec0a0..db99a5f3fbf 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectDefinitionTest.java @@ -25,11 +25,9 @@ import org.junit.rules.TemporaryFolder; import org.sonar.api.CoreProperties; import java.io.File; -import java.io.IOException; import java.util.List; import java.util.Properties; -import static org.assertj.core.api.Assertions.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; @@ -81,10 +79,8 @@ public class ProjectDefinitionTest { @Test public void testDefaultValues() { ProjectDefinition def = ProjectDefinition.create(); - assertThat(def.getSourceDirs().size(), is(0)); - assertThat(def.getTestDirs().size(), is(0)); - assertThat(def.getBinaries().size(), is(0)); - assertThat(def.getLibraries().size(), is(0)); + assertThat(def.sources().size(), is(0)); + assertThat(def.tests().size(), is(0)); } /** @@ -93,54 +89,43 @@ public class ProjectDefinitionTest { @Test public void shouldTrimPaths() { ProjectDefinition def = ProjectDefinition.create(); - def.setProperty(ProjectDefinition.SOURCE_DIRS_PROPERTY, "src1, src2 , with whitespace"); - def.setProperty(ProjectDefinition.TEST_DIRS_PROPERTY, "test1, test2 , with whitespace"); - def.setProperty(ProjectDefinition.BINARIES_PROPERTY, "bin1, bin2 , with whitespace"); - def.setProperty(ProjectDefinition.LIBRARIES_PROPERTY, "lib1, lib2 , with whitespace"); - - assertFiles(def.getSourceDirs(), "src1", "src2", "with whitespace"); - assertFiles(def.getTestDirs(), "test1", "test2", "with whitespace"); - assertFiles(def.getBinaries(), "bin1", "bin2", "with whitespace"); - assertFiles(def.getLibraries(), "lib1", "lib2", "with whitespace"); + def.setProperty(ProjectDefinition.SOURCES_PROPERTY, "src1, src2 , with whitespace"); + def.setProperty(ProjectDefinition.TESTS_PROPERTY, "test1, test2 , with whitespace"); + + + assertFiles(def.sources(), "src1", "src2", "with whitespace"); + assertFiles(def.tests(), "test1", "test2", "with whitespace"); } @Test public void shouldAddDirectoriesAsPath() { ProjectDefinition def = ProjectDefinition.create(); - def.addSourceDirs("src/main/java", "src/main/java2"); - def.addTestDirs("src/test/java"); - def.addTestDirs("src/test/java2"); - def.addBinaryDir("target/classes"); - def.addBinaryDir("target/classes2"); - def.addLibrary("junit.jar"); - def.addLibrary("mockito.jar"); - - assertFiles(def.getSourceDirs(), "src/main/java", "src/main/java2"); - assertFiles(def.getTestDirs(), "src/test/java", "src/test/java2"); - assertFiles(def.getBinaries(), "target/classes", "target/classes2"); - assertFiles(def.getLibraries(), "junit.jar", "mockito.jar"); + def.addSources("src/main/java", "src/main/java2"); + def.addTests("src/test/java"); + def.addTests("src/test/java2"); + + assertFiles(def.sources(), "src/main/java", "src/main/java2"); + assertFiles(def.tests(), "src/test/java", "src/test/java2"); } @Test public void shouldAddDirectories() { ProjectDefinition def = ProjectDefinition.create(); - def.addSourceDirs(new File("src/main/java"), new File("src/main/java2")); - def.addTestDirs(new File("src/test/java"), new File("src/test/java2")); - def.addBinaryDir(new File("target/classes")); + def.addSources(new File("src/main/java"), new File("src/main/java2")); + def.addTests(new File("src/test/java"), new File("src/test/java2")); - assertThat(def.getSourceDirs().size(), is(2)); - assertThat(def.getTestDirs().size(), is(2)); - assertThat(def.getBinaries().size(), is(1)); + assertThat(def.sources().size(), is(2)); + assertThat(def.tests().size(), is(2)); } @Test public void shouldAddFiles() { ProjectDefinition def = ProjectDefinition.create(); - def.addSourceFiles("src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); - def.addTestFiles("src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); + def.addSources("src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); + def.addTests("src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); - assertFiles(def.getSourceFiles(), "src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); - assertFiles(def.getTestFiles(), "src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); + assertFiles(def.sources(), "src/main/java/foo/Bar.java", "src/main/java/hello/World.java"); + assertFiles(def.tests(), "src/test/java/foo/BarTest.java", "src/test/java/hello/WorldTest.java"); } @Test @@ -159,75 +144,21 @@ public class ProjectDefinitionTest { @Test public void shouldResetSourceDirs() { ProjectDefinition root = ProjectDefinition.create(); - root.addSourceDirs("src", "src2/main"); - assertThat(root.getSourceDirs().size(), is(2)); + root.addSources("src", "src2/main"); + assertThat(root.sources().size(), is(2)); - root.resetSourceDirs(); - assertThat(root.getSourceDirs().size(), is(0)); + root.resetSources(); + assertThat(root.sources().size(), is(0)); } @Test public void shouldResetTestDirs() { ProjectDefinition root = ProjectDefinition.create(); - root.addTestDirs("src", "src2/test"); - assertThat(root.getTestDirs().size(), is(2)); - - root.resetTestDirs(); - assertThat(root.getTestDirs().size(), is(0)); - } - - @Test - public void shouldResetSourceDirsWhenUsindDeprecatedMethod() throws IOException { - File baseDir = temp.newFolder(); - ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); - File src = new File(baseDir, "src"); - src.mkdir(); - root.addSourceDirs("src"); - assertThat(root.getSourceDirs()).containsOnly("src"); - - root.addSourceFiles("foo.java"); - assertThat(root.getSourceDirs()).containsOnly("foo.java"); - } + root.addTests("src", "src2/test"); + assertThat(root.tests().size(), is(2)); - @Test - public void shouldResetTestDirsWhenUsindDeprecatedMethod() throws IOException { - File baseDir = temp.newFolder(); - ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); - File test = new File(baseDir, "test"); - test.mkdir(); - root.addTestDirs("test"); - assertThat(root.getTestDirs()).containsOnly("test"); - - root.addTestFiles("fooTest.java"); - assertThat(root.getTestDirs()).containsOnly("fooTest.java"); - } - - @Test - public void shouldResetSourceDirsWhenUsindDeprecatedFileMethod() throws IOException { - File baseDir = temp.newFolder(); - ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); - File src = new File(baseDir, "src"); - src.mkdir(); - root.addSourceDirs("src"); - assertThat(root.getSourceDirs()).containsOnly("src"); - - File file = new File(src, "foo.java"); - root.addSourceFiles(file); - assertThat(root.getSourceDirs()).containsOnly(file.getAbsolutePath()); - } - - @Test - public void shouldResetTestDirsWhenUsindDeprecatedFileMethod() throws IOException { - File baseDir = temp.newFolder(); - ProjectDefinition root = ProjectDefinition.create().setBaseDir(baseDir); - File test = new File(baseDir, "test"); - test.mkdir(); - root.addTestDirs("test"); - assertThat(root.getTestDirs()).containsOnly("test"); - - File file = new File(test, "fooTest.java"); - root.addTestFiles(file); - assertThat(root.getTestDirs()).containsOnly(file.getAbsolutePath()); + root.resetTests(); + assertThat(root.tests().size(), is(0)); } private static void assertFiles(List paths, String... values) { -- 2.39.5