From: Lukasz Jarocki Date: Mon, 24 Apr 2023 07:15:32 +0000 (+0200) Subject: SONAR-19050 consistent use of CodeCharacteristic term X-Git-Tag: 10.1.0.73491~413 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eba174a010c3b24fa5d28cf5588f50d696041bba;p=sonarqube.git SONAR-19050 consistent use of CodeCharacteristic term --- 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..abbef0bc7f2 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 @@ -42,11 +42,12 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.db.component.ComponentDto; import org.sonar.db.protobuf.DbIssues; import org.sonar.db.rule.RuleDto; +import org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter; import static com.google.common.base.Preconditions.checkArgument; import static org.sonar.api.utils.DateUtils.dateToLong; import static org.sonar.api.utils.DateUtils.longToDate; -import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic; +import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic; public final class IssueDto implements Serializable { @@ -728,7 +729,7 @@ public final class IssueDto implements Serializable { @CheckForNull public CodeCharacteristic getEffectiveRuleCharacteristic() { - return ruleCharacteristic != null ? ruleCharacteristic : convertToRuleCharacteristic(ruleType); + return ruleCharacteristic != null ? ruleCharacteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(ruleType); } public int getRuleType() { 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..01fe39ea256 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 @@ -403,7 +403,7 @@ public class RuleDto { } public CodeCharacteristic getEffectiveCharacteristic() { - return characteristic != null ? characteristic : RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(type); + return characteristic != null ? characteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(type); } public RuleDto setCharacteristic(@Nullable CodeCharacteristic characteristic) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java new file mode 100644 index 00000000000..76165c2c06c --- /dev/null +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db.rule; + +import org.sonar.api.code.CodeCharacteristic; +import org.sonar.api.rules.RuleType; + +public class RuleTypeToCodeCharacteristicConverter { + + private RuleTypeToCodeCharacteristicConverter() { + } + + public static CodeCharacteristic convertToCodeCharacteristic(int ruleType) { + if (ruleType == 0) { + return CodeCharacteristic.CLEAR; + } + return convertToCodeCharacteristic(RuleType.valueOf(ruleType)); + } + + public static CodeCharacteristic convertToCodeCharacteristic(RuleType ruleType) { + return switch (ruleType) { + case BUG -> CodeCharacteristic.ROBUST; + case CODE_SMELL -> CodeCharacteristic.CLEAR; + case SECURITY_HOTSPOT, VULNERABILITY -> CodeCharacteristic.SECURE; + }; + } + +} 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 deleted file mode 100644 index 38f8b643900..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.db.rule; - -import org.sonar.api.code.CodeCharacteristic; -import org.sonar.api.rules.RuleType; - -public class RuleTypeToRuleCharacteristicConverter { - - private RuleTypeToRuleCharacteristicConverter() { - } - - public static CodeCharacteristic convertToRuleCharacteristic(int ruleType) { - if (ruleType == 0) { - return CodeCharacteristic.CLEAR; - } - return convertToRuleCharacteristic(RuleType.valueOf(ruleType)); - } - - public static CodeCharacteristic convertToRuleCharacteristic(RuleType ruleType) { - return switch (ruleType) { - case BUG -> CodeCharacteristic.ROBUST; - case CODE_SMELL -> CodeCharacteristic.CLEAR; - case SECURITY_HOTSPOT, VULNERABILITY -> CodeCharacteristic.SECURE; - }; - } - -} 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..f805010721a 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 @@ -189,7 +189,7 @@ public class RuleDtoTest { assertThat(characteristic).isNull(); CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic(); - CodeCharacteristic expected = RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(RuleType.BUG); + CodeCharacteristic expected = RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(RuleType.BUG); assertThat(effectiveCharacteristic).isEqualTo(expected); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java new file mode 100644 index 00000000000..b6d8073e43d --- /dev/null +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 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.db.rule; + +import com.tngtech.java.junit.dataprovider.DataProvider; +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.RuleType; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic; + +@RunWith(DataProviderRunner.class) +public class RuleTypeToCodeCharacteristicConverterTest { + + @Test + @UseDataProvider("ruleTypeToCodeCharacteristicData") + public void convertToCodeCharacteristic_when_receivedNonNullRuleType_should_convertToCorrespondingDefaultCharacteristic(RuleType type, + CodeCharacteristic expectedCharacteristic) { + assertThat(convertToCodeCharacteristic(type)).isEqualTo(expectedCharacteristic); + } + + @DataProvider + public static Object[][] ruleTypeToCodeCharacteristicData() { + return new Object[][] { + {RuleType.CODE_SMELL, CodeCharacteristic.CLEAR}, + {RuleType.BUG, CodeCharacteristic.ROBUST}, + {RuleType.VULNERABILITY, CodeCharacteristic.SECURE}, + {RuleType.SECURITY_HOTSPOT, CodeCharacteristic.SECURE} + }; + } + +} 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 deleted file mode 100644 index 508b40744b4..00000000000 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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.db.rule; - -import com.tngtech.java.junit.dataprovider.DataProvider; -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.RuleType; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic; - -@RunWith(DataProviderRunner.class) -public class RuleTypeToRuleCharacteristicConverterTest { - - @Test - @UseDataProvider("ruleTypeToRulCharacteristicData") - public void convertToRuleCharacteristic_when_receivedNonNullRuleType_should_convertToCorrespondingDefaultCharacteristic(RuleType type, - CodeCharacteristic 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} - }; - } - -} diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java index 94f6523dceb..28b9d5e522f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java @@ -38,6 +38,7 @@ import org.sonar.db.DatabaseUtils; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.ResultSetIterator; +import org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter; import org.sonar.server.security.SecurityStandards; import static com.google.common.base.Preconditions.checkArgument; @@ -45,7 +46,7 @@ import static org.elasticsearch.common.Strings.isNullOrEmpty; import static org.sonar.api.utils.DateUtils.longToDate; import static org.sonar.db.DatabaseUtils.getLong; import static org.sonar.db.rule.RuleDto.deserializeSecurityStandardsString; -import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic; +import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic; import static org.sonar.server.security.SecurityStandards.fromSecurityStandards; /** @@ -244,7 +245,7 @@ class IssueIteratorForSingleChunk implements IssueIterator { doc.setIsNewCodeReference(!isNullOrEmpty(rs.getString(24))); String characteristic = rs.getString(25); - doc.setCharacteristic(characteristic != null ? characteristic : convertToRuleCharacteristic(rs.getInt(26)).name()); + doc.setCharacteristic(characteristic != null ? characteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(rs.getInt(26)).name()); return doc; }