Skip to content

Commit

Permalink
SONAR-11449 Drop deprecated property sonar.language
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-sns authored and SonarTech committed Mar 19, 2019
1 parent e9417f7 commit 0bc8757
Show file tree
Hide file tree
Showing 16 changed files with 10 additions and 97 deletions.
3 changes: 1 addition & 2 deletions server/sonar-docs/src/pages/analysis/analysis-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | `<scm><developerConnection>` for Maven projects
<!-- /sonarqube -->
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sonar.projectName=Sample
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=xources
sonar.tests=testx
sonar.language=xoo
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sonar.projectName=Sample
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=xources
sonar.tests=testx
sonar.language=xoo
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ void indexFile(DefaultInputModule module, ModuleExclusionFilters moduleExclusion
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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;
Expand All @@ -52,7 +51,6 @@ public class LanguageDetection {
*/
private final Map<String, PathPattern[]> patternsByLanguage;
private final List<String> languagesToConsider;
private final String forcedLanguage;

public LanguageDetection(Configuration settings, LanguagesRepository languages) {
Map<String, PathPattern[]> patternsByLanguageBuilder = new LinkedHashMap<>();
Expand All @@ -75,29 +73,10 @@ public LanguageDetection(Configuration settings, LanguagesRepository languages)
}
}

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<String, PathPattern[]> patternsByLanguage() {
return patternsByLanguage;
}

@CheckForNull
String language(Path absolutePath, Path relativePath) {
String detectedLanguage = null;
Expand All @@ -112,16 +91,8 @@ String language(Path absolutePath, Path relativePath) {
}
}
}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ public void scanProjectWithSourceSymlink() {
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);
Expand Down Expand Up @@ -1071,9 +1073,10 @@ public void exclusion_based_on_scm_info() {
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();

Expand All @@ -1087,6 +1090,8 @@ public void no_exclusion_when_scm_exclusions_is_disabled() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,47 +94,6 @@ public void plugin_can_declare_a_file_extension_twice_for_case_sensitivity() thr
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")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
sonar.projectKey=sample-generic-coverage
sonar.sources=xources
sonar.language=xoo
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sonar.projectName=Sample
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=xources
sonar.tests=testx
sonar.language=xoo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sonar.projectName=Sample
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=xources
sonar.tests=testx
sonar.language=xoo
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ sonar.projectName=Sample
sonar.projectVersion=0.1-SNAPSHOT
sonar.sources=xources
sonar.tests=testx
sonar.language=xoo

0 comments on commit 0bc8757

Please sign in to comment.