]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23250 Revert changes made in the plugin API for ActiveRule
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 18 Oct 2024 14:27:20 +0000 (16:27 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 21 Oct 2024 20:03:59 +0000 (20:03 +0000)
13 files changed:
gradle.properties
sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/rule/internal/DefaultActiveRule.java
sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/ChecksMediumIT.java
sonar-scanner-engine/src/it/java/org/sonar/scanner/mediumtest/issues/IssuesMediumIT.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/issue/IssuePublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/ActiveRulesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/DefaultActiveRulesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/rule/LoadedActiveRule.java [new file with mode: 0644]
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesProviderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultActiveRulesLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/LoadedActiveRuleTest.java [new file with mode: 0644]
sonar-scanner-engine/src/testFixtures/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java

index 3ad54d01b522ee3748051392caa5ca3f0bb27c11..fa2bfc99ee2b9c24a4a038440a67eaa1d62615f6 100644 (file)
@@ -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
index e893c7842c781c435aa5988906298b27d804f93b..873bcc24d7b9a5b06c05d9a28a3fd2f137b7dbb6 100644 (file)
@@ -65,7 +65,6 @@ public class DefaultActiveRule implements ActiveRule {
     return severity;
   }
 
-  @Override
   public Map<SoftwareQuality, Severity> impacts() {
     return impacts;
   }
index dfe3b7b90313aae512af98c13664dab6f519aab7..7883b4c064fec30a6846cc9dc003d5c4968531e5 100644 (file)
@@ -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;
index 27508c01b091c35b42c34963b39266899bbdb4b3..39c65da48615015fa373bfb3fcd24afbc8e1a7ea 100644 (file)
@@ -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;
index 53d04e5faa5391cf8d0006426292259762054a98..47e5f8fe1d71e4f4354538d055bf998f65459ecc 100644 (file)
@@ -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);
index 4cc20f04fe65ad35f2fec9bd3c0f4ea4022de0ff..1bd49f3ec272e3882b346ab77c36be9ad855ad0d 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.scanner.rule;
 
 import java.util.List;
-import org.sonar.api.batch.rule.LoadedActiveRule;
 
 public interface ActiveRulesLoader {
   List<LoadedActiveRule> load(String qualityProfileKey);
index 8e0691a069e005f6ac70423b73e9bb5552135344..eb703522dc31cffe1bc4fe6db8d8d3a1733d2a9d 100644 (file)
@@ -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;
index 9c2bb5d86d1f3522824f7dbb1921811d752a832b..78c047d590382754d3b8b507e13f0b56d566edf0 100644 (file)
@@ -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 (file)
index 0000000..8f2c364
--- /dev/null
@@ -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<SoftwareQuality, Severity> impacts;
+  private String name;
+  private String language;
+  private Map<String, String> params;
+  private long createdAt;
+  private long updatedAt;
+  private String templateRuleKey;
+  private String internalKey;
+  private Set<RuleKey> 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<SoftwareQuality, Severity> getImpacts() {
+    return impacts;
+  }
+
+  public void setImpacts(Map<SoftwareQuality, Severity> impacts) {
+    this.impacts = impacts;
+  }
+
+  public String getLanguage() {
+    return language;
+  }
+
+  public void setLanguage(String language) {
+    this.language = language;
+  }
+
+  public Map<String, String> getParams() {
+    return params;
+  }
+
+  public void setParams(Map<String, String> 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<RuleKey> getDeprecatedKeys() {
+    return deprecatedKeys;
+  }
+
+  public void setDeprecatedKeys(Set<RuleKey> deprecatedKeys) {
+    this.deprecatedKeys = deprecatedKeys;
+  }
+}
index 14a5036e254c4670949d2ea4027a6fe41a8682a0..4072d462f92d393df047202f899fa23d83a8cd8d 100644 (file)
@@ -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<String, ActiveRule> 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");
index ad70dd74d471cf13edc52b9c32d05e65275efa63..59a490847425b18159c1ef9ccf4e43f4cece793d 100644 (file)
@@ -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 (file)
index 0000000..735e48e
--- /dev/null
@@ -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));
+  }
+}
index 59eb6290e7970fd873a01874c046663fdda340bc..89f54283c45f6206fb43d9f7af5a3814658bb7d5 100644 (file)
@@ -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);
   }