From 0bc8757a169ea48a058655d1c9fff017482b6550 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Beno=C3=AEt=20Gianinetti?= Date: Thu, 14 Mar 2019 15:07:47 +0100 Subject: [PATCH] SONAR-11449 Drop deprecated property sonar.language --- .../src/pages/analysis/analysis-parameters.md | 3 +- .../java/org/sonar/api/CoreProperties.java | 6 --- .../sonar-project.properties | 1 - .../sample/sonar-project.properties | 1 - .../scanner/scan/filesystem/FileIndexer.java | 5 +-- .../scan/filesystem/LanguageDetection.java | 33 +-------------- .../mediumtest/fs/FileSystemMediumTest.java | 7 +++- .../filesystem/LanguageDetectionTest.java | 41 ------------------- .../sonar-project.properties | 2 - .../sonar-project.properties | 2 - .../sonar-project.properties | 1 - .../sonar-project.properties | 1 - .../sonar-project.properties | 1 - .../sonar-project.properties | 1 - .../sonar-project.properties | 1 - .../xoo/sample/sonar-project.properties | 1 - 16 files changed, 10 insertions(+), 97 deletions(-) diff --git a/server/sonar-docs/src/pages/analysis/analysis-parameters.md b/server/sonar-docs/src/pages/analysis/analysis-parameters.md index 42ea1f02e89..a73703a23e6 100644 --- a/server/sonar-docs/src/pages/analysis/analysis-parameters.md +++ b/server/sonar-docs/src/pages/analysis/analysis-parameters.md @@ -99,7 +99,6 @@ Key | Description | Default Key | Description ---|----|--- `sonar.branch` **![](/images/cross.svg)Deprecated since SQ 6.7** | _The Developer Edition provides fuller-featured branch functionality._ Manage SCM branches. Two branches of the same project are considered to be different projects in SonarQube. As a consequence issues found in a project A in a branch B1 are not linked to issues found for this project A in a branch B2. There is no way to automatically resolve issues from B2 when they are resolved in B1 as again A-B1 & A-B2 are considered separated projects. -`sonar.language` **![](/images/cross.svg)Deprecated since SQ 4.5** | Set the language of the source code to analyze. Browse the Plugin Library page to get the list of all available languages. If not set, a multi-language analysis will be triggered. -`sonar.profile` **![](/images/cross.svg)Deprecated since SQ 4.5** | Override the profile to be used. This should be set on a per-language basis through the UI instead. +`sonar.profile` **![](/images/cross.svg)Deprecated since SQ 4.5** | Override the profile to be used. This should be set on a per-langauge basis through the UI instead. `sonar.links.scm_dev` **![](/images/cross.svg)Deprecated since SQ 7.1** | Developer connection. | `` for Maven projects diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java index 1fbd5925c0e..4f2dbe91fa1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java @@ -180,12 +180,6 @@ public interface CoreProperties { */ String LONG_LIVED_BRANCHES_REGEX = "sonar.branch.longLivedBranches.regex"; - /** - * @deprecated since 4.2 projects are now multi-language - */ - @Deprecated - String PROJECT_LANGUAGE_PROPERTY = "sonar.language"; - /* Exclusions */ String PROJECT_INCLUSIONS_PROPERTY = "sonar.inclusions"; String PROJECT_EXCLUSIONS_PROPERTY = "sonar.exclusions"; diff --git a/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample-with-symlink/sonar-project.properties b/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample-with-symlink/sonar-project.properties index 8810e376701..50adabc5bbb 100644 --- a/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample-with-symlink/sonar-project.properties +++ b/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample-with-symlink/sonar-project.properties @@ -3,4 +3,3 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo diff --git a/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample/sonar-project.properties b/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample/sonar-project.properties index 8810e376701..50adabc5bbb 100644 --- a/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample/sonar-project.properties +++ b/sonar-plugin-api/test-resources/org/sonar/api/filesystem/sample/sonar-project.properties @@ -3,4 +3,3 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java index bb0a550f452..982d413a71f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/FileIndexer.java @@ -118,11 +118,8 @@ public class FileIndexer { exclusionCounter.increaseByPatternsCount(); return; } + String language = langDetection.language(realAbsoluteFile, projectRelativePath); - if (language == null && langDetection.getForcedLanguage() != null) { - LOG.warn("File '{}' is ignored because it doesn't belong to the forced language '{}'", realAbsoluteFile.toAbsolutePath(), langDetection.getForcedLanguage()); - return; - } if (ignoreCommand != null && ignoreCommand.isIgnored(realAbsoluteFile)) { LOG.debug("File '{}' is excluded by the scm ignore settings.", realAbsoluteFile); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java index 1b74abd4aa9..57fbb86e23d 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/filesystem/LanguageDetection.java @@ -32,7 +32,6 @@ import javax.annotation.concurrent.ThreadSafe; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.CoreProperties; import org.sonar.api.batch.fs.internal.PathPattern; import org.sonar.api.config.Configuration; import org.sonar.api.utils.MessageException; @@ -52,7 +51,6 @@ public class LanguageDetection { */ private final Map patternsByLanguage; private final List languagesToConsider; - private final String forcedLanguage; public LanguageDetection(Configuration settings, LanguagesRepository languages) { Map patternsByLanguageBuilder = new LinkedHashMap<>(); @@ -75,29 +73,10 @@ public class LanguageDetection { } } - forcedLanguage = StringUtils.defaultIfBlank(settings.get(CoreProperties.PROJECT_LANGUAGE_PROPERTY).orElse(null), null); - // First try with lang patterns - if (forcedLanguage != null) { - if (!patternsByLanguageBuilder.containsKey(forcedLanguage)) { - throw MessageException.of("You must install a plugin that supports the language '" + forcedLanguage + "'"); - } - LOG.info("Language is forced to {}", forcedLanguage); - languagesToConsider = Collections.singletonList(forcedLanguage); - } else { - languagesToConsider = Collections.unmodifiableList(new ArrayList<>(patternsByLanguageBuilder.keySet())); - } - + languagesToConsider = Collections.unmodifiableList(new ArrayList<>(patternsByLanguageBuilder.keySet())); patternsByLanguage = Collections.unmodifiableMap(patternsByLanguageBuilder); } - public String getForcedLanguage() { - return forcedLanguage; - } - - Map patternsByLanguage() { - return patternsByLanguage; - } - @CheckForNull String language(Path absolutePath, Path relativePath) { String detectedLanguage = null; @@ -112,16 +91,8 @@ public class LanguageDetection { } } } - if (detectedLanguage != null) { - return detectedLanguage; - } - // Check if deprecated sonar.language is used and we are on a language without declared extensions. - // Languages without declared suffixes match everything. - if (forcedLanguage != null && patternsByLanguage.get(forcedLanguage).length == 0) { - return forcedLanguage; - } - return null; + return detectedLanguage; } private boolean isCandidateForLanguage(Path absolutePath, Path relativePath, String languageKey) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index dee1c8b1781..af073681944 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -789,6 +789,8 @@ public class FileSystemMediumTest { File projectDir = new File("test-resources/mediumtest/xoo/sample-with-symlink"); AnalysisResult result = tester .newAnalysis(new File(projectDir, "sonar-project.properties")) + .property("sonar.exclusions", "**/*.xoo.measures,**/*.xoo.scm") + .property("sonar.test.exclusions", "**/*.xoo.measures,**/*.xoo.scm") .execute(); assertThat(result.inputFiles()).hasSize(3); @@ -1071,9 +1073,10 @@ public class FileSystemMediumTest { File projectDir = new File("test-resources/mediumtest/xoo/sample-with-ignored-file"); AnalysisResult result = tester .newAnalysis(new File(projectDir, "sonar-project.properties")) + .property("sonar.exclusions", "**/*.xoo.ignore") + .property("sonar.test.exclusions", "**/*.xoo.ignore") .execute(); - assertThat(result.inputFiles()).hasSize(2); assertThat(result.inputFile("xources/hello/ClassTwo.xoo")).isNull(); assertThat(result.inputFile("testx/ClassTwoTest.xoo")).isNull(); @@ -1087,6 +1090,8 @@ public class FileSystemMediumTest { AnalysisResult result = tester .newAnalysis(new File(projectDir, "sonar-project.properties")) .property("sonar.scm.exclusions.disabled", "true") + .property("sonar.exclusions", "**/*.xoo.ignore") + .property("sonar.test.exclusions", "**/*.xoo.ignore") .execute(); assertThat(result.inputFiles()).hasSize(4); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java index 7e4a491f6d3..c924cb4c5e5 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java @@ -94,47 +94,6 @@ public class LanguageDetectionTest { assertThat(detectLanguage(detection, "abc.abap")).isEqualTo("abap"); } - @Test - public void language_with_no_extension() throws Exception { - // abap does not declare any file extensions. - // When analyzing an ABAP project, then all source files must be parsed. - LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("abap"))); - - // No side-effect on non-ABAP projects - LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); - assertThat(detectLanguage(detection, "abc")).isNull(); - assertThat(detectLanguage(detection, "abc.abap")).isNull(); - assertThat(detectLanguage(detection, "abc.java")).isEqualTo("java"); - - settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "abap"); - detection = new LanguageDetection(settings.asConfig(), languages); - assertThat(detectLanguage(detection, "abc")).isEqualTo("abap"); - assertThat(detectLanguage(detection, "abc.txt")).isEqualTo("abap"); - assertThat(detectLanguage(detection, "abc.java")).isEqualTo("abap"); - } - - @Test - public void force_language_using_deprecated_property() throws Exception { - LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); - - settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "java"); - LanguageDetection detection = new LanguageDetection(settings.asConfig(), languages); - assertThat(detectLanguage(detection, "abc")).isNull(); - assertThat(detectLanguage(detection, "abc.php")).isNull(); - assertThat(detectLanguage(detection, "abc.java")).isEqualTo("java"); - assertThat(detectLanguage(detection, "src/abc.java")).isEqualTo("java"); - } - - @Test - public void fail_if_invalid_language() { - thrown.expect(MessageException.class); - thrown.expectMessage("You must install a plugin that supports the language 'unknown'"); - - LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("java", "java"), new MockLanguage("php", "php"))); - settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, "unknown"); - new LanguageDetection(settings.asConfig(), languages); - } - @Test public void fail_if_conflicting_language_suffix() throws Exception { LanguagesRepository languages = new DefaultLanguagesRepository(new Languages(new MockLanguage("xml", "xhtml"), new MockLanguage("web", "xhtml"))); diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties index 53aacb54061..60280f9a2c5 100644 --- a/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties +++ b/sonar-scanner-engine/src/test/resources/org/sonar/scanner/scan/ProjectReactorBuilderTest/multi-language-definitions-all-in-root/sonar-project.properties @@ -4,10 +4,8 @@ sonar.projectVersion=1.0 sonar.modules=java-module,groovy-module -java-module.sonar.language=java java-module.sonar.projectBaseDir=. java-module.sonar.sources=src/main/java -groovy-module.sonar.language=groovy groovy-module.sonar.projectBaseDir=. groovy-module.sonar.sources=src/main/groovy diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/multi-modules-sample/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/multi-modules-sample/sonar-project.properties index b07be6f3e6f..a1e8405de78 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/multi-modules-sample/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/multi-modules-sample/sonar-project.properties @@ -3,8 +3,6 @@ sonar.projectKey=com.sonarsource.it.samples:multi-modules-sample sonar.projectName=Sonar :: Integration Tests :: Multi-modules Sample sonar.projectVersion=1.0-SNAPSHOT -sonar.language=xoo - # Some properties that will be inherited by the modules sonar.sources=src/main/xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-coverage/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-coverage/sonar-project.properties index ac18398a604..c641af8798a 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-coverage/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-coverage/sonar-project.properties @@ -1,3 +1,2 @@ sonar.projectKey=sample-generic-coverage sonar.sources=xources -sonar.language=xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/sonar-project.properties index 8810e376701..50adabc5bbb 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-generic-test-exec/sonar-project.properties @@ -3,4 +3,3 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties index 58f27e81f61..51e019b53ee 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties @@ -2,4 +2,3 @@ sonar.projectKey=sample-with-empty-file sonar.projectName=Sample With Empty sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources -sonar.language=xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-ignored-file/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-ignored-file/sonar-project.properties index 4e711d750b4..8abf61258ae 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-ignored-file/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-ignored-file/sonar-project.properties @@ -3,5 +3,4 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo sonar.scm.provider=xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties index 8810e376701..50adabc5bbb 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample-with-symlink/sonar-project.properties @@ -3,4 +3,3 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo diff --git a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample/sonar-project.properties b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample/sonar-project.properties index 8810e376701..50adabc5bbb 100644 --- a/sonar-scanner-engine/test-resources/mediumtest/xoo/sample/sonar-project.properties +++ b/sonar-scanner-engine/test-resources/mediumtest/xoo/sample/sonar-project.properties @@ -3,4 +3,3 @@ sonar.projectName=Sample sonar.projectVersion=0.1-SNAPSHOT sonar.sources=xources sonar.tests=testx -sonar.language=xoo -- 2.39.5