diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2023-04-26 10:59:09 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-04-28 20:02:57 +0000 |
commit | db1a20f20ebcee549d47d0eb59b3b8882f58efef (patch) | |
tree | 6cdd75eaa9760dd5747f459cd44e5ebf7c5c8230 | |
parent | a8b0bf6f8eafc033ce0a1f97609a25f23a95b0bc (diff) | |
download | sonarqube-db1a20f20ebcee549d47d0eb59b3b8882f58efef.tar.gz sonarqube-db1a20f20ebcee549d47d0eb59b3b8882f58efef.zip |
Revert "SONAR-19050 Upgrade sonar-plugin-api to v9.16.0.549"
This reverts commit 27f1179c0cb7e4add8cb8c9f49d5864da4681c66.
34 files changed, 192 insertions, 175 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java index 427cc2c31ca..058a8154414 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/rule/XooRulesDefinition.java @@ -21,8 +21,8 @@ package org.sonar.xoo.rule; import javax.annotation.Nullable; import org.sonar.api.SonarRuntime; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleScope; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RuleDescriptionSection; import org.sonar.api.server.rule.RuleParamType; @@ -146,7 +146,7 @@ public class XooRulesDefinition implements RulesDefinition { NewRule oneBugIssuePerTestLine = repo.createRule(OneBugIssuePerTestLineSensor.RULE_KEY).setName("One Bug Issue Per Test Line") .setScope(RuleScope.TEST) - .setType(RuleType.BUG).setCharacteristic(CodeCharacteristic.COMPLIANT); + .setType(RuleType.BUG).setCharacteristic(RuleCharacteristic.COMPLIANT); addAllDescriptionSections(oneBugIssuePerTestLine, "Generate a bug issue on each line of a test file. It requires the metric \"lines\"."); oneBugIssuePerTestLine @@ -190,7 +190,7 @@ public class XooRulesDefinition implements RulesDefinition { NewRule hotspotWithRangeAndMultipleLocations = repo.createRule(MultilineHotspotSensor.RULE_KEY) .setName("Creates hotspots with ranges/multiple locations") .setType(RuleType.SECURITY_HOTSPOT) - .setCharacteristic(CodeCharacteristic.PORTABLE); + .setCharacteristic(RuleCharacteristic.PORTABLE); addAllDescriptionSections(hotspotWithRangeAndMultipleLocations, "Hotspot with range and multiple locations"); NewRule issueOnEachFileWithExtUnknown = repo.createRule(OneIssuePerUnknownFileSensor.RULE_KEY).setName("Creates issues on each file with extension 'unknown'"); @@ -204,13 +204,13 @@ public class XooRulesDefinition implements RulesDefinition { NewRule oneCodeSmellIssuePerLine = repo.createRule(OneCodeSmellIssuePerLineSensor.RULE_KEY).setName("One Code Smell Issue Per Line") .setType(RuleType.CODE_SMELL) - .setCharacteristic(CodeCharacteristic.STRUCTURED); + .setCharacteristic(RuleCharacteristic.STRUCTURED); oneCodeSmellIssuePerLine .setDebtRemediationFunction(oneCodeSmellIssuePerLine.debtRemediationFunctions().linear("9min")); addAllDescriptionSections(oneCodeSmellIssuePerLine, "Generate a code smell issue on each line of a file. It requires the metric \"lines\"."); NewRule oneVulnerabilityIssuePerModule = repo.createRule(OneVulnerabilityIssuePerModuleSensor.RULE_KEY).setName("One Vulnerability Issue Per Module") - .setType(RuleType.VULNERABILITY).setCharacteristic(CodeCharacteristic.ROBUST); + .setType(RuleType.VULNERABILITY).setCharacteristic(RuleCharacteristic.ROBUST); addAllDescriptionSections(oneVulnerabilityIssuePerModule, "Generate an issue on each module"); oneVulnerabilityIssuePerModule @@ -276,7 +276,7 @@ public class XooRulesDefinition implements RulesDefinition { NewRule hotspotWithSingleContext = repo.createRule(HotspotWithSingleContextSensor.RULE_KEY) .setName("Find security hotspots, how_to_fix with single context") .setType(RuleType.SECURITY_HOTSPOT) - .setCharacteristic(CodeCharacteristic.SECURE) + .setCharacteristic(RuleCharacteristic.SECURE) .setActivatedByDefault(false) .addDescriptionSection(howToFixSectionWithContext("single_context")); addDescriptionSectionsWithoutContexts(hotspotWithSingleContext, "Search for Security Hotspots with single context in Xoo files"); diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java index ac96be2d050..d851fb4f26f 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/rule/XooRulesDefinitionTest.java @@ -23,9 +23,9 @@ import org.junit.Before; import org.junit.Test; import org.sonar.api.SonarEdition; import org.sonar.api.SonarQubeSide; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.impl.server.RulesDefinitionContext; import org.sonar.api.internal.SonarRuntimeImpl; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.Version; @@ -120,7 +120,7 @@ public class XooRulesDefinitionTest { public void define_xoo_rule_with_characteristic() { RulesDefinition.Repository repo = context.repository("xoo"); RulesDefinition.Rule oneCodeSmellIssuePerLine = repo.rule("OneCodeSmellIssuePerLine"); - assertThat(oneCodeSmellIssuePerLine.characteristic()).isEqualTo(CodeCharacteristic.STRUCTURED); + assertThat(oneCodeSmellIssuePerLine.characteristic()).isEqualTo(RuleCharacteristic.STRUCTURED); } private RulesDefinition.Repository getRepository() { diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java index a089f5258fa..1bcd0b5d3d8 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/issue/IssueDaoIT.java @@ -27,8 +27,8 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; @@ -124,8 +124,8 @@ public class IssueDaoIT { assertThat(issue.parseLocations()).isNull(); assertThat(issue.isExternal()).isTrue(); assertThat(issue.getRuleType()).isEqualTo(RuleType.CODE_SMELL.getDbConstant()); - assertThat(issue.getRuleCharacteristic()).isEqualTo(CodeCharacteristic.CLEAR); - assertThat(issue.getEffectiveRuleCharacteristic()).isEqualTo(CodeCharacteristic.CLEAR); + assertThat(issue.getRuleCharacteristic()).isEqualTo(RuleCharacteristic.CLEAR); + assertThat(issue.getEffectiveRuleCharacteristic()).isEqualTo(RuleCharacteristic.CLEAR); assertFalse(issue.isQuickFixAvailable()); } diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/rule/RuleDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/rule/RuleDaoIT.java index b15339f6fb9..ec138783b03 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/rule/RuleDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/rule/RuleDaoIT.java @@ -34,10 +34,10 @@ import org.apache.ibatis.exceptions.PersistenceException; import org.jetbrains.annotations.NotNull; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleQuery; import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; @@ -57,6 +57,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.sonar.api.rule.RuleStatus.REMOVED; +import static org.sonar.api.rules.RuleCharacteristic.CLEAR; public class RuleDaoIT { private static final String UNKNOWN_RULE_UUID = "unknown-uuid"; @@ -83,6 +84,7 @@ public class RuleDaoIT { assertThat(underTest.selectByKey(db.getSession(), ruleDto.getKey())).isNotEmpty(); } + @Test public void selectByUuid() { RuleDto ruleDto = db.rules().insert(); @@ -456,7 +458,7 @@ public class RuleDaoIT { .setSystemTags(newHashSet("systag1", "systag2")) .setSecurityStandards(newHashSet("owaspTop10:a1", "cwe:123")) .setType(RuleType.BUG) - .setCharacteristic(CodeCharacteristic.TESTED) + .setCharacteristic(RuleCharacteristic.TESTED) .setScope(Scope.ALL) .setCreatedAt(1_500_000_000_000L) .setUpdatedAt(2_000_000_000_000L); @@ -484,7 +486,7 @@ public class RuleDaoIT { assertThat(ruleDto.getSecurityStandards()).containsOnly("owaspTop10:a1", "cwe:123"); assertThat(ruleDto.getScope()).isEqualTo(Scope.ALL); assertThat(ruleDto.getType()).isEqualTo(RuleType.BUG.getDbConstant()); - assertThat(ruleDto.getCharacteristic()).isEqualTo(CodeCharacteristic.TESTED); + assertThat(ruleDto.getCharacteristic()).isEqualTo(RuleCharacteristic.TESTED); assertThat(ruleDto.getCreatedAt()).isEqualTo(1_500_000_000_000L); assertThat(ruleDto.getUpdatedAt()).isEqualTo(2_000_000_000_000L); assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN); @@ -519,7 +521,7 @@ public class RuleDaoIT { .setSecurityStandards(newHashSet("owaspTop10:a1", "cwe:123")) .setScope(Scope.ALL) .setType(RuleType.BUG) - .setCharacteristic(CodeCharacteristic.PORTABLE) + .setCharacteristic(RuleCharacteristic.PORTABLE) .setUpdatedAt(2_000_000_000_000L); underTest.update(db.getSession(), ruleToUpdate); @@ -545,7 +547,7 @@ public class RuleDaoIT { assertThat(ruleDto.getSecurityStandards()).containsOnly("owaspTop10:a1", "cwe:123"); assertThat(ruleDto.getScope()).isEqualTo(Scope.ALL); assertThat(ruleDto.getType()).isEqualTo(RuleType.BUG.getDbConstant()); - assertThat(ruleDto.getCharacteristic()).isEqualTo(CodeCharacteristic.PORTABLE); + assertThat(ruleDto.getCharacteristic()).isEqualTo(RuleCharacteristic.PORTABLE); assertThat(ruleDto.getCreatedAt()).isEqualTo(rule.getCreatedAt()); assertThat(ruleDto.getUpdatedAt()).isEqualTo(2_000_000_000_000L); assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java index e3c25bcd54c..62f799723ae 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java @@ -34,8 +34,8 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; @@ -57,7 +57,7 @@ public final class IssueDto implements Serializable { private int type; private int ruleType; - private CodeCharacteristic ruleCharacteristic; + private RuleCharacteristic ruleCharacteristic; private String kee; private String componentUuid; private String projectUuid; @@ -716,18 +716,18 @@ public final class IssueDto implements Serializable { } @CheckForNull - public CodeCharacteristic getRuleCharacteristic() { + public RuleCharacteristic getRuleCharacteristic() { return ruleCharacteristic; } @VisibleForTesting - IssueDto setRuleCharacteristic(CodeCharacteristic ruleCharacteristic) { + IssueDto setRuleCharacteristic(RuleCharacteristic ruleCharacteristic) { this.ruleCharacteristic = ruleCharacteristic; return this; } @CheckForNull - public CodeCharacteristic getEffectiveRuleCharacteristic() { + public RuleCharacteristic getEffectiveRuleCharacteristic() { return ruleCharacteristic != null ? ruleCharacteristic : convertToRuleCharacteristic(ruleType); } @@ -736,7 +736,7 @@ public final class IssueDto implements Serializable { } @VisibleForTesting - IssueDto setRuleType(int ruleType) { + IssueDto setRuleType(int ruleType) { this.ruleType = ruleType; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java index a3f1180e9c0..5a01ffd4ff4 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java @@ -31,9 +31,9 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static com.google.common.base.Preconditions.checkArgument; @@ -99,7 +99,7 @@ public class RuleDto { private String systemTagsField = null; private String securityStandardsField = null; private int type = 0; - private CodeCharacteristic characteristic = null; + private RuleCharacteristic characteristic = null; private Scope scope = null; private RuleKey key = null; @@ -398,15 +398,15 @@ public class RuleDto { } @CheckForNull - public CodeCharacteristic getCharacteristic() { + public RuleCharacteristic getCharacteristic() { return this.characteristic; } - public CodeCharacteristic getEffectiveCharacteristic() { + public RuleCharacteristic getEffectiveCharacteristic() { return characteristic != null ? characteristic : RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(type); } - public RuleDto setCharacteristic(@Nullable CodeCharacteristic characteristic) { + public RuleDto setCharacteristic(@Nullable RuleCharacteristic characteristic) { this.characteristic = characteristic; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java index 522b03ef125..1d66b777748 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleForIndexingDto.java @@ -25,9 +25,9 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; import javax.annotation.CheckForNull; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; public class RuleForIndexingDto { @@ -54,7 +54,7 @@ public class RuleForIndexingDto { private long createdAt; private long updatedAt; private Set<RuleDescriptionSectionDto> ruleDescriptionSectionsDtos = new HashSet<>(); - private CodeCharacteristic characteristic; + private RuleCharacteristic characteristic; @VisibleForTesting public RuleForIndexingDto() { @@ -209,7 +209,7 @@ public class RuleForIndexingDto { this.type = type; } - public CodeCharacteristic getCharacteristic() { + public RuleCharacteristic getCharacteristic() { return characteristic; } } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java index 38f8b643900..90349c596ce 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java @@ -19,7 +19,7 @@ */ package org.sonar.db.rule; -import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; public class RuleTypeToRuleCharacteristicConverter { @@ -27,18 +27,18 @@ public class RuleTypeToRuleCharacteristicConverter { private RuleTypeToRuleCharacteristicConverter() { } - public static CodeCharacteristic convertToRuleCharacteristic(int ruleType) { + public static RuleCharacteristic convertToRuleCharacteristic(int ruleType) { if (ruleType == 0) { - return CodeCharacteristic.CLEAR; + return RuleCharacteristic.CLEAR; } return convertToRuleCharacteristic(RuleType.valueOf(ruleType)); } - public static CodeCharacteristic convertToRuleCharacteristic(RuleType ruleType) { + public static RuleCharacteristic convertToRuleCharacteristic(RuleType ruleType) { return switch (ruleType) { - case BUG -> CodeCharacteristic.ROBUST; - case CODE_SMELL -> CodeCharacteristic.CLEAR; - case SECURITY_HOTSPOT, VULNERABILITY -> CodeCharacteristic.SECURE; + case BUG -> RuleCharacteristic.ROBUST; + case CODE_SMELL -> RuleCharacteristic.CLEAR; + case SECURITY_HOTSPOT, VULNERABILITY -> RuleCharacteristic.SECURE; }; } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java index b8d95de4d58..7366e54998e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDtoTest.java @@ -27,9 +27,9 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang.time.DateUtils; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.issue.Issue; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.core.issue.DefaultIssue; @@ -240,13 +240,13 @@ public class IssueDtoTest { @Test public void getEffectiveCharacteristic_when_characteristicInitialized_should_return_characteristicDbConstantValue() { - IssueDto issueDto = new IssueDto().setRuleType(RuleType.CODE_SMELL.getDbConstant()).setRuleCharacteristic(CodeCharacteristic.CLEAR); - assertThat(issueDto.getEffectiveRuleCharacteristic()).isEqualTo(CodeCharacteristic.CLEAR); + IssueDto issueDto = new IssueDto().setRuleType(RuleType.CODE_SMELL.getDbConstant()).setRuleCharacteristic(RuleCharacteristic.CLEAR); + assertThat(issueDto.getEffectiveRuleCharacteristic()).isEqualTo(RuleCharacteristic.CLEAR); } @Test public void getEffectiveCharacteristic_when_characteristicNotInitialized_should_return_characteristicDbConstantValue() { IssueDto issueDto = new IssueDto().setRuleType(RuleType.CODE_SMELL.getDbConstant()); - assertThat(issueDto.getEffectiveRuleCharacteristic()).isEqualTo(CodeCharacteristic.CLEAR); + assertThat(issueDto.getEffectiveRuleCharacteristic()).isEqualTo(RuleCharacteristic.CLEAR); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java index e8483c24d5b..fc701c189ae 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java @@ -20,12 +20,17 @@ package org.sonar.db.rule; import com.google.common.collect.ImmutableSet; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Collections; import java.util.Set; import java.util.TreeSet; import org.jetbrains.annotations.NotNull; +import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; +import org.junit.runner.RunWith; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.core.util.Uuids; @@ -185,31 +190,31 @@ public class RuleDtoTest { public void getEffectiveCharacteristic_when_noCharacteristicInitialized_should_return_dbConstantValueFromConverter() { RuleDto rule = new RuleDto().setType(RuleType.BUG); - CodeCharacteristic characteristic = rule.getCharacteristic(); + RuleCharacteristic characteristic = rule.getCharacteristic(); assertThat(characteristic).isNull(); - CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); - CodeCharacteristic expected = RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(RuleType.BUG); + RuleCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); + RuleCharacteristic expected = RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(RuleType.BUG); assertThat(effectiveCharacteristic).isEqualTo(expected); } @Test public void getEffectiveCharacteristic_when_characteristicInitialized_should_return_characteristicDbConstantValue() { - RuleDto rule = new RuleDto().setType(RuleType.BUG).setCharacteristic(CodeCharacteristic.COMPLIANT); + RuleDto rule = new RuleDto().setType(RuleType.BUG).setCharacteristic(RuleCharacteristic.COMPLIANT); - CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); - CodeCharacteristic characteristic = rule.getCharacteristic(); + RuleCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); + RuleCharacteristic characteristic = rule.getCharacteristic(); - assertThat(effectiveCharacteristic).isEqualTo(characteristic).isEqualTo(CodeCharacteristic.COMPLIANT); + assertThat(effectiveCharacteristic).isEqualTo(characteristic).isEqualTo(RuleCharacteristic.COMPLIANT); } @Test public void getEffectiveCharacteristic_whenType0_shouldReturnClearCharacteristic() { RuleDto rule = new RuleDto().setType(0); - CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); + RuleCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); - assertThat(effectiveCharacteristic).isEqualTo(CodeCharacteristic.CLEAR); + assertThat(effectiveCharacteristic).isEqualTo(RuleCharacteristic.CLEAR); } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java index 508b40744b4..8bf53ac0984 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java @@ -24,7 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static org.assertj.core.api.Assertions.assertThat; @@ -36,17 +36,17 @@ public class RuleTypeToRuleCharacteristicConverterTest { @Test @UseDataProvider("ruleTypeToRulCharacteristicData") public void convertToRuleCharacteristic_when_receivedNonNullRuleType_should_convertToCorrespondingDefaultCharacteristic(RuleType type, - CodeCharacteristic expectedCharacteristic) { + RuleCharacteristic expectedCharacteristic) { assertThat(convertToRuleCharacteristic(type)).isEqualTo(expectedCharacteristic); } @DataProvider public static Object[][] ruleTypeToRulCharacteristicData() { return new Object[][] { - {RuleType.CODE_SMELL, CodeCharacteristic.CLEAR}, - {RuleType.BUG, CodeCharacteristic.ROBUST}, - {RuleType.VULNERABILITY, CodeCharacteristic.SECURE}, - {RuleType.SECURITY_HOTSPOT, CodeCharacteristic.SECURE} + {RuleType.CODE_SMELL, RuleCharacteristic.CLEAR}, + {RuleType.BUG, RuleCharacteristic.ROBUST}, + {RuleType.VULNERABILITY, RuleCharacteristic.SECURE}, + {RuleType.SECURITY_HOTSPOT, RuleCharacteristic.SECURE} }; } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java index 31879e8ba83..07524e2c744 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/rule/RuleTesting.java @@ -23,10 +23,10 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; import javax.annotation.Nullable; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RuleParamType; import org.sonar.core.util.UuidFactory; @@ -62,10 +62,10 @@ public class RuleTesting { // only static helpers } + public static RuleDto newRule() { return newRule(RuleKey.of(randomAlphanumeric(30), randomAlphanumeric(30))); } - public static RuleDto newRule(RuleDescriptionSectionDto... ruleDescriptionSectionDtos) { return newRule(randomRuleKey(), ruleDescriptionSectionDtos); } @@ -93,7 +93,7 @@ public class RuleTesting { .setName("name_" + randomAlphanumeric(5)) .setDescriptionFormat(RuleDto.Format.HTML) .setType(CODE_SMELL) - .setCharacteristic(CodeCharacteristic.CLEAR) + .setCharacteristic(RuleCharacteristic.CLEAR) .setStatus(RuleStatus.READY) .setConfigKey("configKey_" + ruleKey.rule()) .setSeverity(Severity.ALL.get(nextInt(Severity.ALL.size()))) @@ -151,6 +151,7 @@ public class RuleTesting { return newRule(XOO_X2).setLanguage("xoo"); } + public static RuleDto newTemplateRule(RuleKey ruleKey) { return newRule(ruleKey) .setIsTemplate(true); @@ -213,7 +214,7 @@ public class RuleTesting { return rule -> rule.setType(type); } - public static Consumer<RuleDto> setCharacteristic(CodeCharacteristic characteristic) { + public static Consumer<RuleDto> setCharacteristic(RuleCharacteristic characteristic) { return rule -> rule.setCharacteristic(characteristic); } diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIteratorFactoryIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIteratorFactoryIT.java index b39391ba298..cc243f2428e 100644 --- a/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIteratorFactoryIT.java +++ b/server/sonar-server-common/src/it/java/org/sonar/server/issue/index/IssueIteratorFactoryIT.java @@ -27,7 +27,7 @@ import java.util.function.Function; import java.util.stream.Stream; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; @@ -91,7 +91,7 @@ public class IssueIteratorFactoryIT { assertThat(issue.getTags()).containsOnly("tag1", "tag2", "tag3"); assertThat(issue.effort().toMinutes()).isPositive(); assertThat(issue.type().getDbConstant()).isEqualTo(2); - assertThat(issue.characteristic()).isEqualTo(CodeCharacteristic.CLEAR); + assertThat(issue.characteristic()).isEqualTo(RuleCharacteristic.CLEAR); } @Test diff --git a/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexIT.java b/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexIT.java index 819a173657f..9e1f34bff98 100644 --- a/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexIT.java +++ b/server/sonar-server-common/src/it/java/org/sonar/server/rule/index/RuleIndexIT.java @@ -29,7 +29,6 @@ import java.util.Set; import java.util.function.Consumer; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; @@ -56,14 +55,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.entry; import static org.junit.Assert.fail; -import static org.sonar.api.code.CodeCharacteristic.CLEAR; -import static org.sonar.api.code.CodeCharacteristic.COMPLIANT; -import static org.sonar.api.code.CodeCharacteristic.SECURE; import static org.sonar.api.rule.Severity.BLOCKER; import static org.sonar.api.rule.Severity.CRITICAL; import static org.sonar.api.rule.Severity.INFO; import static org.sonar.api.rule.Severity.MAJOR; import static org.sonar.api.rule.Severity.MINOR; +import static org.sonar.api.rules.RuleCharacteristic.CLEAR; +import static org.sonar.api.rules.RuleCharacteristic.COMPLIANT; +import static org.sonar.api.rules.RuleCharacteristic.SECURE; import static org.sonar.api.rules.RuleType.BUG; import static org.sonar.api.rules.RuleType.CODE_SMELL; import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java index 20866ba6283..abcef42ccc6 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueDoc.java @@ -25,8 +25,8 @@ import java.util.Date; import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.server.es.BaseDoc; @@ -134,8 +134,8 @@ public class IssueDoc extends BaseDoc { return RuleType.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_TYPE)); } - public CodeCharacteristic characteristic() { - return CodeCharacteristic.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_CHARACTERISTIC)); + public RuleCharacteristic characteristic() { + return RuleCharacteristic.valueOf(getField(IssueIndexDefinition.FIELD_ISSUE_CHARACTERISTIC)); } @CheckForNull @@ -271,7 +271,7 @@ public class IssueDoc extends BaseDoc { return this; } - public IssueDoc setCharacteristic(CodeCharacteristic characteristic) { + public IssueDoc setCharacteristic(RuleCharacteristic characteristic) { setField(IssueIndexDefinition.FIELD_ISSUE_CHARACTERISTIC, characteristic.toString()); return this; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java index a55ddac51f3..b1971790005 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleDoc.java @@ -30,9 +30,9 @@ import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.db.rule.RuleDescriptionSectionDto; import org.sonar.db.rule.RuleDto; @@ -273,13 +273,13 @@ public class RuleDoc extends BaseDoc { return this; } - private RuleDoc setCharacteristic(CodeCharacteristic characteristic) { + private RuleDoc setCharacteristic(RuleCharacteristic characteristic) { setField(RuleIndexDefinition.FIELD_RULE_CHARACTERISTIC, characteristic.name()); return this; } - public CodeCharacteristic characteristic() { - return CodeCharacteristic.valueOf(getField(RuleIndexDefinition.FIELD_RULE_CHARACTERISTIC)); + public RuleCharacteristic characteristic() { + return RuleCharacteristic.valueOf(getField(RuleIndexDefinition.FIELD_RULE_CHARACTERISTIC)); } public long createdAt() { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java index 1677902a4ac..d3b99c11514 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleIndex.java @@ -50,9 +50,9 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortOrder; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.System2; import org.sonar.core.util.stream.MoreCollectors; @@ -298,9 +298,9 @@ public class RuleIndex { QueryBuilders.termsQuery(FIELD_RULE_TYPE, typeNames)); } - Collection<CodeCharacteristic> characteristics = query.getCharacteristics(); + Collection<RuleCharacteristic> characteristics = query.getCharacteristics(); if (isNotEmpty(characteristics)) { - List<String> characteristicNames = characteristics.stream().map(CodeCharacteristic::name).toList(); + List<String> characteristicNames = characteristics.stream().map(RuleCharacteristic::name).toList(); filters.put(FIELD_RULE_CHARACTERISTIC, QueryBuilders.termsQuery(FIELD_RULE_CHARACTERISTIC, characteristicNames)); } @@ -469,7 +469,7 @@ public class RuleIndex { (types == null) ? (new String[0]) : types.toArray())); } if (options.getFacets().contains(FACET_CHARACTERISTICS)) { - Collection<CodeCharacteristic> characteristics = query.getCharacteristics(); + Collection<RuleCharacteristic> characteristics = query.getCharacteristics(); aggregations.put(FACET_CHARACTERISTICS, stickyFacetBuilder.buildStickyFacet(FIELD_RULE_CHARACTERISTIC, FACET_CHARACTERISTICS, (characteristics == null) ? (new String[0]) : characteristics.toArray())); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java index 3a90f1b6ba2..48e5e8b297f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleQuery.java @@ -23,9 +23,9 @@ import com.google.common.base.Preconditions; import java.util.Collection; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.db.qualityprofile.QProfileDto; @@ -41,7 +41,7 @@ public class RuleQuery { private Collection<RuleStatus> statuses; private Collection<String> tags; private Collection<RuleType> types; - private Collection<CodeCharacteristic> characteristics; + private Collection<RuleCharacteristic> characteristics; private Boolean activation; private QProfileDto profile; private QProfileDto compareToQProfile; @@ -177,11 +177,11 @@ public class RuleQuery { } @CheckForNull - public Collection<CodeCharacteristic> getCharacteristics() { + public Collection<RuleCharacteristic> getCharacteristics() { return characteristics; } - public RuleQuery setCharacteristics(@Nullable Collection<CodeCharacteristic> characteristics) { + public RuleQuery setCharacteristics(@Nullable Collection<RuleCharacteristic> characteristics) { this.characteristics = characteristics; return this; } diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java index 7d4708b1d1a..5c1a155175b 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java @@ -23,9 +23,9 @@ import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.Date; import java.util.HashMap; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.resources.Scopes; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.core.util.Uuids; import org.sonar.db.component.ComponentDto; @@ -75,7 +75,7 @@ public class IssueDocTesting { doc.setKey(Uuids.createFast()); doc.setRuleUuid(Uuids.createFast()); doc.setType(RuleType.CODE_SMELL); - doc.setCharacteristic(CodeCharacteristic.COMPLIANT); + doc.setCharacteristic(RuleCharacteristic.COMPLIANT); doc.setAssigneeUuid("assignee_uuid_" + randomAlphabetic(26)); doc.setAuthorLogin("author_" + randomAlphabetic(5)); doc.setScope(IssueScope.MAIN); diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java index f18d5619d0a..6cf042a4273 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/rule/RegisterRules.java @@ -39,11 +39,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.sonar.api.Startable; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleScope; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.rule.RulesDefinition; @@ -209,7 +209,7 @@ public class RegisterRules implements Startable { RuleDto rule = dbRulesByRuleUuid.get(ruleUuid); if (rule == null) { LOG.warn("Could not retrieve rule with uuid %s referenced by a deprecated rule key. " + - "The following deprecated rule keys seem to be referencing a non-existing rule", + "The following deprecated rule keys seem to be referencing a non-existing rule", ruleUuid, entry.getValue()); } else { entry.getValue().forEach(d -> rulesByKey.put(d.getOldRuleKeyAsRuleKey(), rule)); @@ -268,10 +268,10 @@ public class RegisterRules implements Startable { private Stream<RuleDto> getAllModified() { return Stream.of( - created.stream(), - updated.stream(), - removed.stream(), - renamed.keySet().stream()) + created.stream(), + updated.stream(), + removed.stream(), + renamed.keySet().stream()) .flatMap(s -> s); } @@ -492,7 +492,7 @@ public class RegisterRules implements Startable { dto.setType(type); changed = true; } - CodeCharacteristic characteristic = def.characteristic(); + RuleCharacteristic characteristic = def.characteristic(); if (!Objects.equals(dto.getCharacteristic(), characteristic)) { dto.setCharacteristic(characteristic); changed = true; @@ -670,9 +670,9 @@ public class RegisterRules implements Startable { changed = true; } else if (dto.getSystemTags().size() != ruleDef.tags().size() || !dto.getSystemTags().containsAll(ruleDef.tags())) { - dto.setSystemTags(ruleDef.tags()); - changed = true; - } + dto.setSystemTags(ruleDef.tags()); + changed = true; + } return changed; } @@ -684,9 +684,9 @@ public class RegisterRules implements Startable { changed = true; } else if (dto.getSecurityStandards().size() != ruleDef.securityStandards().size() || !dto.getSecurityStandards().containsAll(ruleDef.securityStandards())) { - dto.setSecurityStandards(ruleDef.securityStandards()); - changed = true; - } + dto.setSecurityStandards(ruleDef.securityStandards()); + changed = true; + } return changed; } @@ -818,8 +818,8 @@ public class RegisterRules implements Startable { private static Set<String> getExistingAndRenamedRepositories(RegisterRulesContext recorder, Collection<RulesDefinition.Repository> context) { return Stream.concat( - context.stream().map(RulesDefinition.ExtendedRepository::key), - recorder.getRenamed().map(Map.Entry::getValue).map(RuleKey::repository)) + context.stream().map(RulesDefinition.ExtendedRepository::key), + recorder.getRenamed().map(Map.Entry::getValue).map(RuleKey::repository)) .collect(toSet()); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 8ce51cdd4de..ff98036da12 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -36,20 +36,20 @@ import org.jetbrains.annotations.Nullable; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.impl.utils.TestSystem2; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleScope; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.rule.Context; import org.sonar.api.server.rule.RuleDescriptionSection; import org.sonar.api.server.rule.RulesDefinition; -import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.DateUtils; +import org.sonar.api.testfixtures.log.LogTester; import org.sonar.core.util.UuidFactory; import org.sonar.core.util.UuidFactoryFast; import org.sonar.db.DbClient; @@ -210,7 +210,7 @@ public class RegisterRulesTest { assertThat(hotspotRule.getCreatedAt()).isEqualTo(RegisterRulesTest.DATE1.getTime()); assertThat(hotspotRule.getUpdatedAt()).isEqualTo(RegisterRulesTest.DATE1.getTime()); assertThat(hotspotRule.getType()).isEqualTo(RuleType.SECURITY_HOTSPOT.getDbConstant()); - assertThat(hotspotRule.getCharacteristic()).isEqualTo(CodeCharacteristic.SECURE); + assertThat(hotspotRule.getCharacteristic()).isEqualTo(RuleCharacteristic.SECURE); assertThat(hotspotRule.getSecurityStandards()).containsExactly("cwe:1", "cwe:123", "cwe:863", "owaspTop10-2021:a1", "owaspTop10-2021:a3"); } @@ -237,7 +237,7 @@ public class RegisterRulesTest { private void verifyExternalRule(RuleDto rule) { verifyCommonsFields(rule); - assertThat(rule.getCharacteristic()).isEqualTo(CodeCharacteristic.COMPLIANT); + assertThat(rule.getCharacteristic()).isEqualTo(RuleCharacteristic.COMPLIANT); } private void verifyCommonsFields(RuleDto rule) { @@ -422,7 +422,7 @@ public class RegisterRulesTest { assertThat(rule1.getNoteUserUuid()).isEqualTo("marius"); assertThat(rule1.getStatus()).isEqualTo(READY); assertThat(rule1.getType()).isEqualTo(RuleType.BUG.getDbConstant()); - assertThat(rule1.getCharacteristic()).isEqualTo(CodeCharacteristic.PORTABLE); + assertThat(rule1.getCharacteristic()).isEqualTo(RuleCharacteristic.PORTABLE); assertThat(rule1.getCreatedAt()).isEqualTo(DATE1.getTime()); assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2.getTime()); assertThat(rule1.getEducationPrinciples()).containsOnly("concept1", "concept4"); @@ -1170,7 +1170,7 @@ public class RegisterRulesTest { .setInternalKey("config1") .setTags("tag1", "tag2", "tag3") .setType(RuleType.CODE_SMELL) - .setCharacteristic(CodeCharacteristic.ROBUST) + .setCharacteristic(RuleCharacteristic.ROBUST) .setStatus(RuleStatus.BETA); } @@ -1182,7 +1182,7 @@ public class RegisterRulesTest { .setHtmlDescription("Description of One") .setSeverity(BLOCKER) .setType(RuleType.CODE_SMELL) - .setCharacteristic(CodeCharacteristic.TESTED) + .setCharacteristic(RuleCharacteristic.TESTED) .setStatus(RuleStatus.BETA); Arrays.stream(consumers).forEach(c -> c.accept(newRule)); @@ -1220,7 +1220,7 @@ public class RegisterRulesTest { .setTags("tag1", "tag2", "tag3") .setScope(RuleScope.ALL) .setType(RuleType.CODE_SMELL) - .setCharacteristic(CodeCharacteristic.CLEAR) + .setCharacteristic(RuleCharacteristic.CLEAR) .setStatus(RuleStatus.BETA) .setGapDescription("java.S115.effortToFix") .addEducationPrincipleKeys("concept1", "concept2", "concept3"); @@ -1233,7 +1233,7 @@ public class RegisterRulesTest { .setName("Hotspot") .setHtmlDescription("Minimal hotspot") .setType(RuleType.SECURITY_HOTSPOT) - .setCharacteristic(CodeCharacteristic.SECURE) + .setCharacteristic(RuleCharacteristic.SECURE) .addOwaspTop10(Y2021, OwaspTop10.A1, OwaspTop10.A3) .addCwe(1, 123, 863); @@ -1261,7 +1261,7 @@ public class RegisterRulesTest { // tag2 and tag3 removed, tag4 added .setTags("tag1", "tag4") .setType(RuleType.BUG) - .setCharacteristic(CodeCharacteristic.PORTABLE) + .setCharacteristic(RuleCharacteristic.PORTABLE) .setStatus(READY) .setGapDescription("java.S115.effortToFix.v2") .addEducationPrincipleKeys("concept1", "concept4"); @@ -1303,7 +1303,7 @@ public class RegisterRulesTest { .setTags("tag1", "tag2", "tag3") .setScope(RuleScope.ALL) .setType(RuleType.CODE_SMELL) - .setCharacteristic(CodeCharacteristic.COMPLIANT) + .setCharacteristic(RuleCharacteristic.COMPLIANT) .setStatus(RuleStatus.BETA) .addEducationPrincipleKeys("concept1", "concept2", "concept3"); @@ -1311,7 +1311,7 @@ public class RegisterRulesTest { .setName("Hotspot") .setHtmlDescription("Minimal hotspot") .setType(RuleType.SECURITY_HOTSPOT) - .setCharacteristic(CodeCharacteristic.SECURE) + .setCharacteristic(RuleCharacteristic.SECURE) .addOwaspTop10(Y2021, OwaspTop10.A1, OwaspTop10.A3) .addCwe(1, 123, 863); diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 59e714acd23..b9c055fa309 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -64,9 +64,9 @@ import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.sort.FieldSortBuilder; import org.joda.time.Duration; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.issue.Issue; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.server.rule.RulesDefinition.OwaspTop10Version; @@ -118,7 +118,6 @@ import static org.sonar.server.es.searchrequest.TopAggregationHelper.NO_OTHER_SU import static org.sonar.server.issue.index.IssueIndex.Facet.ASSIGNED_TO_ME; import static org.sonar.server.issue.index.IssueIndex.Facet.ASSIGNEES; import static org.sonar.server.issue.index.IssueIndex.Facet.AUTHOR; -import static org.sonar.server.issue.index.IssueIndex.Facet.CHARACTERISTICS; import static org.sonar.server.issue.index.IssueIndex.Facet.CREATED_AT; import static org.sonar.server.issue.index.IssueIndex.Facet.CWE; import static org.sonar.server.issue.index.IssueIndex.Facet.DIRECTORIES; @@ -139,6 +138,7 @@ import static org.sonar.server.issue.index.IssueIndex.Facet.SONARSOURCE_SECURITY import static org.sonar.server.issue.index.IssueIndex.Facet.STATUSES; import static org.sonar.server.issue.index.IssueIndex.Facet.TAGS; import static org.sonar.server.issue.index.IssueIndex.Facet.TYPES; +import static org.sonar.server.issue.index.IssueIndex.Facet.CHARACTERISTICS; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE_UUID; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_AUTHOR_LOGIN; import static org.sonar.server.issue.index.IssueIndexDefinition.FIELD_ISSUE_BRANCH_UUID; @@ -245,7 +245,7 @@ public class IssueIndex { // Resolutions facet returns one more element than the number of resolutions to take into account unresolved issues RESOLUTIONS(PARAM_RESOLUTIONS, FIELD_ISSUE_RESOLUTION, STICKY, Issue.RESOLUTIONS.size() + 1), TYPES(PARAM_TYPES, FIELD_ISSUE_TYPE, STICKY, RuleType.values().length), - CHARACTERISTICS(PARAM_CHARACTERISTICS, FIELD_ISSUE_CHARACTERISTIC, STICKY, CodeCharacteristic.values().length), + CHARACTERISTICS(PARAM_CHARACTERISTICS, FIELD_ISSUE_CHARACTERISTIC, STICKY, RuleCharacteristic.values().length), SCOPES(PARAM_SCOPES, FIELD_ISSUE_SCOPE, STICKY, MAX_FACET_SIZE), LANGUAGES(PARAM_LANGUAGES, FIELD_ISSUE_LANGUAGE, STICKY, MAX_FACET_SIZE), RULES(PARAM_RULES, FIELD_ISSUE_RULE_UUID, STICKY, MAX_FACET_SIZE), @@ -492,6 +492,7 @@ public class IssueIndex { } } + private static Set<String> calculateRequirementsForOwaspAsvs40Params(IssueQuery query) { int level = query.getOwaspAsvsLevel().orElse(3); List<String> levelRequirements = OWASP_ASVS_40_REQUIREMENTS_BY_LEVEL.get(level); @@ -520,8 +521,10 @@ public class IssueIndex { /** * <p>Builds the Elasticsearch boolean query to filter the PCI DSS categories.</p> + * * <p>The PCI DSS security report handles all the subcategories as one level. This means that subcategory 1.1 doesn't include the issues from 1.1.1. * Taking this into account, the search filter follows the same logic and uses prefix matching for top-level categories and exact matching for subcategories</p> + * * <p>Example</p> * <p>List of PCI DSS categories in issues: {1.5.8, 1.5.9, 1.6.7} * <ul> @@ -982,7 +985,7 @@ public class IssueIndex { t -> // add sub-aggregation to return issue count for current user aggregationHelper.getSubAggregationHelper() - .buildSelectedItemsAggregation(ASSIGNED_TO_ME.getName(), ASSIGNED_TO_ME.getTopAggregationDef(), new String[] {uuid}) + .buildSelectedItemsAggregation(ASSIGNED_TO_ME.getName(), ASSIGNED_TO_ME.getTopAggregationDef(), new String[]{uuid}) .ifPresent(t::subAggregation)); esRequest.aggregation(aggregation); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java index 219c87abaef..b756c0e3cbd 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/SearchActionIT.java @@ -35,10 +35,10 @@ import java.util.stream.Stream; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ws.WebService; import org.sonar.api.utils.Durations; @@ -95,8 +95,8 @@ import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; import static org.sonar.api.issue.Issue.STATUS_OPEN; import static org.sonar.api.issue.Issue.STATUS_RESOLVED; import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE; +import static org.sonar.api.rules.RuleType.*; import static org.sonar.api.rules.RuleType.CODE_SMELL; -import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT; import static org.sonar.api.server.ws.WebService.Param.FACETS; import static org.sonar.api.utils.DateUtils.formatDateTime; import static org.sonar.api.utils.DateUtils.parseDate; @@ -519,8 +519,8 @@ public class SearchActionIT { @Test public void search_by_characteristic_when_characteristic_set() { - RuleDto rule1 = newIssueRule(XOO_X1, r -> r.setCharacteristic(CodeCharacteristic.PORTABLE)); - RuleDto rule2 = newIssueRule(XOO_X2, r -> r.setCharacteristic(CodeCharacteristic.TESTED)); + RuleDto rule1 = newIssueRule(XOO_X1, r -> r.setCharacteristic(RuleCharacteristic.PORTABLE)); + RuleDto rule2 = newIssueRule(XOO_X2, r -> r.setCharacteristic(RuleCharacteristic.TESTED)); ComponentDto project = db.components().insertPublicProject("PROJECT_ID", c -> c.setKey("PROJECT_KEY").setLanguage("java")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("java")); @@ -534,7 +534,7 @@ public class SearchActionIT { indexPermissions(); SearchWsResponse searchWsResponse = ws.newRequest() - .setParam(PARAM_CHARACTERISTICS, CodeCharacteristic.PORTABLE.name() + "," + CodeCharacteristic.TESTED.name()) + .setParam(PARAM_CHARACTERISTICS, RuleCharacteristic.PORTABLE.name() + "," + RuleCharacteristic.TESTED.name()) .executeProtobuf(SearchWsResponse.class); List<Issue> issuesList = searchWsResponse.getIssuesList(); diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/SearchActionIT.java index 41a3f301336..9b8c6a27327 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/rule/ws/SearchActionIT.java @@ -29,11 +29,11 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; import org.junit.Before; import org.junit.Test; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.ws.WebService; @@ -403,12 +403,12 @@ public class SearchActionIT { @Test public void characteristics_shouldFilterOnCharacteristics() { - RuleDto rule1 = db.rules().insert(r -> r.setCharacteristic(CodeCharacteristic.ROBUST)); - RuleDto rule2 = db.rules().insert(r -> r.setCharacteristic(CodeCharacteristic.COMPLIANT)); + RuleDto rule1 = db.rules().insert(r -> r.setCharacteristic(RuleCharacteristic.ROBUST)); + RuleDto rule2 = db.rules().insert(r -> r.setCharacteristic(RuleCharacteristic.COMPLIANT)); indexRules(); Consumer<TestRequest> populator = r -> r - .setParam(PARAM_CHARACTERISTICS, CodeCharacteristic.ROBUST.name()); + .setParam(PARAM_CHARACTERISTICS, RuleCharacteristic.ROBUST.name()); TestRequest request = ws.newRequest(); populator.accept(request); @@ -419,11 +419,12 @@ public class SearchActionIT { assertThat(rulesList.get(0).getKey()).isEqualTo(rule1.getKey().toString()); } + @Test public void characteristics_shouldGroupCharacteristicsInTheFacets() { - RuleDto rule1 = db.rules().insert(r -> r.setCharacteristic(CodeCharacteristic.ROBUST)); - RuleDto rule2 = db.rules().insert(r -> r.setCharacteristic(CodeCharacteristic.COMPLIANT)); - RuleDto rule3 = db.rules().insert(r -> r.setCharacteristic(CodeCharacteristic.COMPLIANT)); + RuleDto rule1 = db.rules().insert(r -> r.setCharacteristic(RuleCharacteristic.ROBUST)); + RuleDto rule2 = db.rules().insert(r -> r.setCharacteristic(RuleCharacteristic.COMPLIANT)); + RuleDto rule3 = db.rules().insert(r -> r.setCharacteristic(RuleCharacteristic.COMPLIANT)); indexRules(); SearchResponse result = ws.newRequest() @@ -433,15 +434,15 @@ public class SearchActionIT { Common.Facet facets = result.getFacets().getFacets(0); int valuesCount = facets.getValuesCount(); - assertThat(valuesCount).isEqualTo(CodeCharacteristic.values().length); + assertThat(valuesCount).isEqualTo(RuleCharacteristic.values().length); List<Common.FacetValue> valuesList = facets.getValuesList(); Common.FacetValue compliantFacetValue = valuesList.get(0); - assertThat(compliantFacetValue.getVal()).isEqualTo(CodeCharacteristic.COMPLIANT.name()); + assertThat(compliantFacetValue.getVal()).isEqualTo(RuleCharacteristic.COMPLIANT.name()); assertThat(compliantFacetValue.getCount()).isEqualTo(2); Common.FacetValue robustFacetValue = valuesList.get(1); - assertThat(robustFacetValue.getVal()).isEqualTo(CodeCharacteristic.ROBUST.name()); + assertThat(robustFacetValue.getVal()).isEqualTo(RuleCharacteristic.ROBUST.name()); assertThat(robustFacetValue.getCount()).isEqualTo(1); } @@ -1028,10 +1029,10 @@ public class SearchActionIT { indexRules(); ws.newRequest() - .setParam(WebService.Param.PAGE, "2") - .setParam(WebService.Param.PAGE_SIZE, "9") - .execute() - .assertJson(this.getClass(), "paging.json"); + .setParam(WebService.Param.PAGE, "2") + .setParam(WebService.Param.PAGE_SIZE, "9") + .execute() + .assertJson(this.getClass(), "paging.json"); } @Test @@ -1083,6 +1084,7 @@ public class SearchActionIT { assertThat(actualSections).hasSameElementsAs(expected); } + private void verifyNoResults(Consumer<TestRequest> requestPopulator) { verify(requestPopulator); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java index 6d19ee80964..bd4bc6ab469 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchAction.java @@ -32,8 +32,8 @@ import javax.annotation.Nullable; import org.apache.lucene.search.TotalHits; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.search.SearchHit; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -283,12 +283,12 @@ public class SearchAction implements IssuesWsAction { action.createParam(PARAM_CHARACTERISTICS) .setDescription("Comma-separated list of characteristics.") .setSince("10.1") - .setPossibleValues(Arrays.stream(CodeCharacteristic.values()).map(Enum::name).toList()) - .setExampleValue(format(COMMA_SEPERATED_PARAMS_FORMAT, CodeCharacteristic.CLEAR, CodeCharacteristic.COMPLIANT)); + .setPossibleValues(Arrays.stream(RuleCharacteristic.values()).map(Enum::name).toList()) + .setExampleValue(format(COMMA_SEPERATED_PARAMS_FORMAT, RuleCharacteristic.CLEAR, RuleCharacteristic.COMPLIANT)); action.createParam(PARAM_OWASP_ASVS_LEVEL) .setDescription("Level of OWASP ASVS categories.") .setSince("9.7") - .setPossibleValues(1, 2, 3); + .setPossibleValues(1,2,3); action.createParam(PARAM_PCI_DSS_32) .setDescription("Comma-separated list of PCI DSS v3.2 categories.") .setSince("9.6") diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java index 09c9a67c742..6b00fd00a30 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleQueryFactory.java @@ -21,8 +21,8 @@ package org.sonar.server.rule.ws; import java.util.Date; import java.util.List; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleStatus; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; import org.sonar.api.server.ws.Request; @@ -67,7 +67,7 @@ public class RuleQueryFactory { /** * Similar to {@link #createRuleQuery(DbSession, Request)} but sets additional fields which are only used - * for the rule search WS. + * for the rule search WS. */ public RuleQuery createRuleSearchQuery(DbSession dbSession, Request request) { RuleQuery query = createRuleQuery(dbSession, request); @@ -100,7 +100,7 @@ public class RuleQueryFactory { query.setIsTemplate(request.paramAsBoolean(PARAM_IS_TEMPLATE)); query.setTemplateKey(request.param(PARAM_TEMPLATE_KEY)); query.setTypes(toEnums(request.paramAsStrings(PARAM_TYPES), RuleType.class)); - query.setCharacteristics(toEnums(request.paramAsStrings(PARAM_CHARACTERISTICS), CodeCharacteristic.class)); + query.setCharacteristics(toEnums(request.paramAsStrings(PARAM_CHARACTERISTICS), RuleCharacteristic.class)); query.setKey(request.param(PARAM_RULE_KEY)); query.setCwe(request.paramAsStrings(PARAM_CWE)); query.setOwaspTop10(request.paramAsStrings(PARAM_OWASP_TOP_10)); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java index b0460af9149..e1e7874ddb1 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/RuleWsSupport.java @@ -24,9 +24,9 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; import org.sonar.api.server.ws.WebService; @@ -177,8 +177,8 @@ public class RuleWsSupport { .createParam(PARAM_CHARACTERISTICS) .setSince("10.1") .setDescription("Comma-separated list of characteristics. Returned rules match any of the characteristics (OR operator)") - .setPossibleValues(CodeCharacteristic.values()) - .setExampleValue(CodeCharacteristic.CLEAR); + .setPossibleValues(RuleCharacteristic.values()) + .setExampleValue(RuleCharacteristic.CLEAR); action .createParam(PARAM_ACTIVATION) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java index 48fdac1ee23..d9ea1155b47 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/rule/ws/SearchAction.java @@ -38,8 +38,8 @@ import java.util.Set; import java.util.stream.Collectors; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; @@ -103,7 +103,7 @@ public class SearchAction implements RulesWsAction { public static final String ACTION = "search"; private static final Collection<String> DEFAULT_FACETS = Set.of(PARAM_LANGUAGES, PARAM_REPOSITORIES, "tags"); - private static final String[] POSSIBLE_FACETS = new String[] { + private static final String[] POSSIBLE_FACETS = new String[]{ FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS, @@ -325,7 +325,7 @@ public class SearchAction implements RulesWsAction { addMandatoryFacetValues(results, FACET_ACTIVE_SEVERITIES, Severity.ALL); addMandatoryFacetValues(results, FACET_TAGS, request.getTags()); addMandatoryFacetValues(results, FACET_TYPES, RuleType.names()); - addMandatoryFacetValues(results, FACET_CHARACTERISTICS, Arrays.stream(CodeCharacteristic.values()).map(Enum::name).toList()); + addMandatoryFacetValues(results, FACET_CHARACTERISTICS, Arrays.stream(RuleCharacteristic.values()).map(Enum::name).toList()); addMandatoryFacetValues(results, FACET_CWE, request.getCwe()); addMandatoryFacetValues(results, FACET_OWASP_TOP_10, request.getOwaspTop10()); addMandatoryFacetValues(results, FACET_OWASP_TOP_10_2021, request.getOwaspTop10For2021()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/RuleMapperTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/RuleMapperTest.java index 19ea3fcbbac..022914b12c2 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/RuleMapperTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/rule/ws/RuleMapperTest.java @@ -22,13 +22,15 @@ package org.sonar.server.rule.ws; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; +import java.util.List; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.resources.Languages; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.db.rule.RuleDto; +import org.sonar.server.platform.db.migration.version.DatabaseVersion; import org.sonarqube.ws.Common; import org.sonarqube.ws.Rules; @@ -40,7 +42,7 @@ public class RuleMapperTest { @Test @UseDataProvider("pluginApiEnumsMappedToProtobufEnums") - public void toWsRule_shouldMapCharacteristicEnumToProtobuf(CodeCharacteristic pluginApiEnum, Common.RuleCharacteristic protoEnum) { + public void toWsRule_shouldMapCharacteristicEnumToProtobuf(RuleCharacteristic pluginApiEnum, Common.RuleCharacteristic protoEnum) { RuleMapper ruleMapper = new RuleMapper(mock(Languages.class), mock(), mock()); RuleDto ruleDto = new RuleDto(); @@ -55,14 +57,14 @@ public class RuleMapperTest { @DataProvider public static Object[][] pluginApiEnumsMappedToProtobufEnums() { return new Object[][] { - {CodeCharacteristic.CLEAR, Common.RuleCharacteristic.CLEAR}, - {CodeCharacteristic.TESTED, Common.RuleCharacteristic.TESTED}, - {CodeCharacteristic.ROBUST, Common.RuleCharacteristic.ROBUST}, - {CodeCharacteristic.SECURE, Common.RuleCharacteristic.SECURE}, - {CodeCharacteristic.CONSISTENT, Common.RuleCharacteristic.CONSISTENT}, - {CodeCharacteristic.COMPLIANT, Common.RuleCharacteristic.COMPLIANT}, - {CodeCharacteristic.STRUCTURED, Common.RuleCharacteristic.STRUCTURED}, - {CodeCharacteristic.PORTABLE, Common.RuleCharacteristic.PORTABLE} + {RuleCharacteristic.CLEAR, Common.RuleCharacteristic.CLEAR}, + {RuleCharacteristic.TESTED, Common.RuleCharacteristic.TESTED}, + {RuleCharacteristic.ROBUST, Common.RuleCharacteristic.ROBUST}, + {RuleCharacteristic.SECURE, Common.RuleCharacteristic.SECURE}, + {RuleCharacteristic.CONSISTENT, Common.RuleCharacteristic.CONSISTENT}, + {RuleCharacteristic.COMPLIANT, Common.RuleCharacteristic.COMPLIANT}, + {RuleCharacteristic.STRUCTURED, Common.RuleCharacteristic.STRUCTURED}, + {RuleCharacteristic.PORTABLE, Common.RuleCharacteristic.PORTABLE} }; } }
\ No newline at end of file diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java index 8f1654751c0..c00af6fddbb 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java @@ -45,6 +45,7 @@ import org.sonar.api.issue.Issue; import org.sonar.api.issue.IssueComment; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; import org.sonar.core.issue.tracking.Trackable; @@ -55,7 +56,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. private String key = null; private RuleType type = null; - private CodeCharacteristic characteristic = null; + private RuleCharacteristic characteristic = null; private String componentUuid = null; private String componentKey = null; @@ -159,11 +160,11 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. @CheckForNull @Override - public CodeCharacteristic characteristic() { + public RuleCharacteristic characteristic() { return characteristic; } - public DefaultIssue setCharacteristic(CodeCharacteristic characteristic) { + public DefaultIssue setCharacteristic(RuleCharacteristic characteristic) { this.characteristic = characteristic; return this; } @@ -429,6 +430,7 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + public DefaultIssue setNew(boolean b) { isNew = b; return this; diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java index 2cc4937bc63..d2e606bee1a 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssue.java @@ -26,8 +26,8 @@ import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.issue.ExternalIssue; import org.sonar.api.batch.sensor.issue.NewExternalIssue; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static java.lang.String.format; @@ -39,7 +39,7 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs private Long effort; private Severity severity; private RuleType type; - private CodeCharacteristic characteristic; + private RuleCharacteristic characteristic; private String engineId; private String ruleId; @@ -101,7 +101,7 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs } @CheckForNull - public CodeCharacteristic characteristic() { + public RuleCharacteristic characteristic() { return characteristic; } @@ -133,7 +133,7 @@ public class DefaultExternalIssue extends AbstractDefaultIssue<DefaultExternalIs } @Override - public DefaultExternalIssue characteristic(CodeCharacteristic characteristic) { + public DefaultExternalIssue characteristic(RuleCharacteristic characteristic) { this.characteristic = characteristic; return this; } diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java index d9027741d44..aefa37f67e7 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRule.java @@ -26,7 +26,7 @@ import org.sonar.api.batch.sensor.internal.DefaultStorable; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.rule.AdHocRule; import org.sonar.api.batch.sensor.rule.NewAdHocRule; -import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static org.apache.commons.lang.StringUtils.isNotBlank; @@ -36,7 +36,7 @@ public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewA private Severity severity; private RuleType type; - private CodeCharacteristic characteristic; + private RuleCharacteristic characteristic; private String name; private String description; private String engineId; @@ -99,7 +99,7 @@ public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewA @CheckForNull @Override - public CodeCharacteristic characteristic() { + public RuleCharacteristic characteristic() { return characteristic; } @@ -134,7 +134,7 @@ public class DefaultAdHocRule extends DefaultStorable implements AdHocRule, NewA } @Override - public DefaultAdHocRule characteristic(CodeCharacteristic characteristic) { + public DefaultAdHocRule characteristic(RuleCharacteristic characteristic) { this.characteristic = characteristic; return this; } diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java index bb3dfba0f20..46a9b8e8e46 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java @@ -30,8 +30,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.SensorStorage; -import org.sonar.api.code.CodeCharacteristic; import org.sonar.api.rule.RuleKey; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static org.assertj.core.api.Assertions.assertThat; @@ -54,6 +54,7 @@ public class DefaultExternalIssueTest { .setWorkDir(temp.newFolder())); } + private DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php") .initMetadata("Foo\nBar\n") .build(); @@ -70,7 +71,7 @@ public class DefaultExternalIssueTest { .remediationEffortMinutes(10L) .type(RuleType.BUG) .severity(Severity.BLOCKER) - .characteristic(CodeCharacteristic.SECURE); + .characteristic(RuleCharacteristic.SECURE); assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_repo", "rule")); @@ -80,7 +81,7 @@ public class DefaultExternalIssueTest { assertThat(issue.remediationEffort()).isEqualTo(10L); assertThat(issue.type()).isEqualTo(RuleType.BUG); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); - assertThat(issue.characteristic()).isEqualTo(CodeCharacteristic.SECURE); + assertThat(issue.characteristic()).isEqualTo(RuleCharacteristic.SECURE); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); issue.save(); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java index 1a0807032b1..6ba0c8dde7b 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/rule/internal/DefaultAdHocRuleTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.sonar.api.batch.rule.Severity; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.rule.NewAdHocRule; -import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleCharacteristic; import org.sonar.api.rules.RuleType; import static org.assertj.core.api.Assertions.assertThat; @@ -44,7 +44,7 @@ public class DefaultAdHocRuleTest { .description("desc") .severity(Severity.BLOCKER) .type(RuleType.CODE_SMELL) - .characteristic(CodeCharacteristic.COMPLIANT); + .characteristic(RuleCharacteristic.COMPLIANT); rule.save(); assertThat(rule.engineId()).isEqualTo("engine"); @@ -53,7 +53,7 @@ public class DefaultAdHocRuleTest { assertThat(rule.description()).isEqualTo("desc"); assertThat(rule.severity()).isEqualTo(Severity.BLOCKER); assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL); - assertThat(rule.characteristic()).isEqualTo(CodeCharacteristic.COMPLIANT); + assertThat(rule.characteristic()).isEqualTo(RuleCharacteristic.COMPLIANT); verify(storage).store(any(DefaultAdHocRule.class)); } |