From dd9ebd6a6f4b59c38ce1f1ca494f1d4231291513 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 18 Oct 2024 16:27:20 +0200 Subject: [PATCH] SONAR-23250 Revert changes made in the plugin API for ActiveRule --- gradle.properties | 2 +- .../rule/internal/DefaultActiveRule.java | 1 - .../mediumtest/issues/ChecksMediumIT.java | 2 +- .../mediumtest/issues/IssuesMediumIT.java | 2 +- .../sonar/scanner/issue/IssuePublisher.java | 3 +- .../sonar/scanner/rule/ActiveRulesLoader.java | 1 - .../scanner/rule/ActiveRulesProvider.java | 1 - .../rule/DefaultActiveRulesLoader.java | 1 - .../sonar/scanner/rule/LoadedActiveRule.java | 135 ++++++++++++++++++ .../scanner/rule/ActiveRulesProviderTest.java | 8 +- .../rule/DefaultActiveRulesLoaderTest.java | 2 +- .../scanner/rule/LoadedActiveRuleTest.java | 38 +++++ .../mediumtest/ScannerMediumTester.java | 3 +- 13 files changed, 184 insertions(+), 15 deletions(-) create mode 100644 sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/LoadedActiveRule.java create mode 100644 sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/LoadedActiveRuleTest.java diff --git a/gradle.properties b/gradle.properties index 3ad54d01b52..fa2bfc99ee2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ version=10.8 # 30 months from the release date for LTA versions # No change required for patch versions versionEOL=2025-05-27 -pluginApiVersion=10.12.0.2522 +pluginApiVersion=10.11.0.2468 description=Open source platform for continuous inspection of code quality projectTitle=SonarQube org.gradle.jvmargs=-Xmx2048m diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java index e893c7842c7..873bcc24d7b 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java @@ -65,7 +65,6 @@ public class DefaultActiveRule implements ActiveRule { return severity; } - @Override public Map impacts() { return impacts; } diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/ChecksMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/ChecksMediumIT.java index dfe3b7b9031..7883b4c064f 100644 --- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/ChecksMediumIT.java +++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/ChecksMediumIT.java @@ -30,7 +30,7 @@ import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import org.sonar.api.batch.rule.LoadedActiveRule; +import org.sonar.scanner.rule.LoadedActiveRule; import org.sonar.api.rule.RuleKey; import org.sonar.scanner.mediumtest.AnalysisResult; import org.sonar.scanner.mediumtest.ScannerMediumTester; diff --git a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/IssuesMediumIT.java b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/IssuesMediumIT.java index 27508c01b09..39c65da4861 100644 --- a/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/IssuesMediumIT.java +++ b/sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/IssuesMediumIT.java @@ -30,7 +30,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.slf4j.event.Level; -import org.sonar.api.batch.rule.LoadedActiveRule; +import org.sonar.scanner.rule.LoadedActiveRule; import org.sonar.api.rule.RuleKey; import org.sonar.api.testfixtures.log.LogTester; import org.sonar.scanner.mediumtest.AnalysisResult; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java index 53d04e5faa5..47e5f8fe1d7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java @@ -33,6 +33,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputComponent; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; +import org.sonar.api.batch.rule.internal.DefaultActiveRule; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.issue.Issue.Flow; @@ -78,7 +79,7 @@ public class IssuePublisher { return false; } - ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity(), activeRule.impacts()); + ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity(), ((DefaultActiveRule) activeRule).impacts()); if (filters.accept(inputComponent, rawIssue)) { write(inputComponent.scannerId(), rawIssue); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesLoader.java index 4cc20f04fe6..1bd49f3ec27 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesLoader.java @@ -20,7 +20,6 @@ package org.sonar.scanner.rule; import java.util.List; -import org.sonar.api.batch.rule.LoadedActiveRule; public interface ActiveRulesLoader { List load(String qualityProfileKey); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java index 8e0691a069e..eb703522dc3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java @@ -25,7 +25,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import org.sonar.api.batch.rule.LoadedActiveRule; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.rule.internal.DefaultActiveRules; import org.sonar.api.batch.rule.internal.NewActiveRule; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java index 9c2bb5d86d1..78c047d5903 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; -import org.sonar.api.batch.rule.LoadedActiveRule; import org.sonar.api.impl.utils.ScannerUtils; import org.sonar.api.issue.impact.Severity; import org.sonar.api.issue.impact.SoftwareQuality; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/LoadedActiveRule.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/LoadedActiveRule.java new file mode 100644 index 00000000000..8f2c3643237 --- /dev/null +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/LoadedActiveRule.java @@ -0,0 +1,135 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.rule; + +import java.util.Map; +import java.util.Set; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; +import org.sonar.api.issue.impact.Severity; +import org.sonar.api.issue.impact.SoftwareQuality; +import org.sonar.api.rule.RuleKey; + +public class LoadedActiveRule { + private RuleKey ruleKey; + private String severity; + private Map impacts; + private String name; + private String language; + private Map params; + private long createdAt; + private long updatedAt; + private String templateRuleKey; + private String internalKey; + private Set deprecatedKeys; + + public LoadedActiveRule() { + // nothing to do here + } + + public RuleKey getRuleKey() { + return ruleKey; + } + + public void setRuleKey(RuleKey ruleKey) { + this.ruleKey = ruleKey; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSeverity() { + return severity; + } + + public void setSeverity(String severity) { + this.severity = severity; + } + + public Map getImpacts() { + return impacts; + } + + public void setImpacts(Map impacts) { + this.impacts = impacts; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public Map getParams() { + return params; + } + + public void setParams(Map params) { + this.params = params; + } + + public long getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(long createdAt) { + this.createdAt = createdAt; + } + + public long getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(long updatedAt) { + this.updatedAt = updatedAt; + } + + @CheckForNull + public String getTemplateRuleKey() { + return templateRuleKey; + } + + public void setTemplateRuleKey(@Nullable String templateRuleKey) { + this.templateRuleKey = templateRuleKey; + } + + public String getInternalKey() { + return internalKey; + } + + public void setInternalKey(String internalKey) { + this.internalKey = internalKey; + } + + public Set getDeprecatedKeys() { + return deprecatedKeys; + } + + public void setDeprecatedKeys(Set deprecatedKeys) { + this.deprecatedKeys = deprecatedKeys; + } +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java index 14a5036e254..4072d462f92 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java @@ -31,7 +31,7 @@ import org.assertj.core.groups.Tuple; import org.junit.Test; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.rule.LoadedActiveRule; +import org.sonar.api.batch.rule.internal.DefaultActiveRule; import org.sonar.api.batch.rule.internal.DefaultActiveRules; import org.sonar.api.issue.impact.Severity; import org.sonar.api.issue.impact.SoftwareQuality; @@ -73,11 +73,11 @@ public class ActiveRulesProviderTest { RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3")); Map activeRuleByKey = activeRules.findAll().stream().collect(Collectors.toMap(e -> e.ruleKey().rule(), e -> e)); - assertThat(activeRuleByKey.get("rule1").impacts()) + assertThat(((DefaultActiveRule) activeRuleByKey.get("rule1")).impacts()) .containsExactlyInAnyOrderEntriesOf(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.HIGH)); - assertThat(activeRuleByKey.get("rule2").impacts()).isEmpty(); - assertThat(activeRuleByKey.get("rule3").impacts()).isEmpty(); + assertThat(((DefaultActiveRule) activeRuleByKey.get("rule2")).impacts()).isEmpty(); + assertThat(((DefaultActiveRule) activeRuleByKey.get("rule3")).impacts()).isEmpty(); verify(loader).load("qp1"); verify(loader).load("qp2"); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java index ad70dd74d47..59a49084742 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java @@ -26,7 +26,7 @@ import java.util.Map; import java.util.stream.IntStream; import org.junit.Before; import org.junit.Test; -import org.sonar.api.batch.rule.LoadedActiveRule; +import org.sonar.scanner.rule.LoadedActiveRule; import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/LoadedActiveRuleTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/LoadedActiveRuleTest.java new file mode 100644 index 00000000000..735e48e9473 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/LoadedActiveRuleTest.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program 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. + * + * This program 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.scanner.rule; + +import java.util.Map; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.sonar.api.issue.impact.Severity; +import org.sonar.api.issue.impact.SoftwareQuality; + +class LoadedActiveRuleTest { + + @Test + void should_return_expected_field() { + LoadedActiveRule loadedActiveRule = new LoadedActiveRule(); + loadedActiveRule.setImpacts(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.MEDIUM)); + + Assertions.assertThat(loadedActiveRule.getImpacts()) + .containsExactlyInAnyOrderEntriesOf(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.MEDIUM)); + } +} diff --git a/sonar-scanner-engine/src/testFixtures/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/testFixtures/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index 59eb6290e79..89f54283c45 100644 --- a/sonar-scanner-engine/src/testFixtures/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/testFixtures/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -49,7 +49,6 @@ import org.sonar.api.SonarEdition; import org.sonar.api.SonarProduct; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarRuntime; -import org.sonar.api.batch.rule.LoadedActiveRule; import org.sonar.api.impl.server.RulesDefinitionContext; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; @@ -76,6 +75,7 @@ import org.sonar.scanner.repository.SingleProjectRepository; import org.sonar.scanner.repository.settings.GlobalSettingsLoader; import org.sonar.scanner.repository.settings.ProjectSettingsLoader; import org.sonar.scanner.rule.ActiveRulesLoader; +import org.sonar.scanner.rule.LoadedActiveRule; import org.sonar.scanner.rule.RulesLoader; import org.sonar.scanner.scan.ScanProperties; import org.sonar.scanner.scan.branch.BranchConfiguration; @@ -280,7 +280,6 @@ public class ScannerMediumTester extends ExternalResource implements BeforeTestE } } - public AnalysisBuilder newAnalysis() { return new AnalysisBuilder(this); } -- 2.39.5