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 {
@CheckForNull
public CodeCharacteristic getEffectiveRuleCharacteristic() {
- return ruleCharacteristic != null ? ruleCharacteristic : convertToRuleCharacteristic(ruleType);
+ return ruleCharacteristic != null ? ruleCharacteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(ruleType);
}
public int getRuleType() {
}
public CodeCharacteristic getEffectiveCharacteristic() {
- return characteristic != null ? characteristic : RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(type);
+ return characteristic != null ? characteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(type);
}
public RuleDto setCharacteristic(@Nullable CodeCharacteristic characteristic) {
--- /dev/null
+/*
+ * 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;
+ };
+ }
+
+}
+++ /dev/null
-/*
- * 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;
- };
- }
-
-}
assertThat(characteristic).isNull();
CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic();
- CodeCharacteristic expected = RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(RuleType.BUG);
+ CodeCharacteristic expected = RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(RuleType.BUG);
assertThat(effectiveCharacteristic).isEqualTo(expected);
}
--- /dev/null
+/*
+ * 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}
+ };
+ }
+
+}
+++ /dev/null
-/*
- * 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}
- };
- }
-
-}
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;
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;
/**
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;
}