From 93ee3f6ef943d0573c7d15298f6f4a3b402e0a84 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 22 May 2014 19:36:09 +0200 Subject: [PATCH] SONAR-5335 When upgrading from SonarQube 4.2 with PMD 2.1, searching for some Java rules is failing --- ...equirementsFromCharacteristicsToRules.java | 7 ++++++ ...rementsFromCharacteristicsToRulesTest.java | 16 +++++++++++++ ...th_coeff_to_constant_issue_with_offset.xml | 24 +++++++++++++++++++ ...onstant_issue_with_offset_requirements.xml | 19 +++++++++++++++ ...f_to_constant_issue_with_offset_result.xml | 24 +++++++++++++++++++ ...irements_from_characteristics_to_rules.xml | 4 ++-- ...s_from_characteristics_to_rules_result.xml | 4 ++-- 7 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements.xml create mode 100644 sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml diff --git a/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java b/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java index 4f6ea91372a..e5aa88fc897 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java @@ -214,6 +214,13 @@ public class CopyRequirementsFromCharacteristicsToRules { ruleRow.setCoefficient(convertDuration(enabledRequirement.getCoefficientValue(), enabledRequirement.getCoefficientUnit())); ruleRow.setOffset(convertDuration(enabledRequirement.getOffsetValue(), enabledRequirement.getOffsetUnit())); + // Constant/issue with coefficient is replaced by Constant/issue with offset (with no coefficient) + if (DebtRemediationFunction.Type.CONSTANT_ISSUE.name().equals(ruleRow.getFunction()) + && ruleRow.getCoefficient() != null) { + ruleRow.setOffset(ruleRow.getCoefficient()); + ruleRow.setCoefficient(null); + } + // If the coefficient of a linear or linear with offset function is null, it should be replaced by 0 if ((DebtRemediationFunction.Type.LINEAR.name().equals(ruleRow.getFunction()) || DebtRemediationFunction.Type.LINEAR_OFFSET.name().equals(ruleRow.getFunction())) diff --git a/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java index 1c7f5b37dc5..f9e886b6eb6 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java @@ -87,6 +87,22 @@ public class CopyRequirementsFromCharacteristicsToRulesTest extends AbstractDaoT verify(ruleRegistry).reindex(); } + /** + * SONAR-5335 + */ + @Test + public void convert_constant_issue_with_coeff_to_constant_issue_with_offset() throws Exception { + setupData("convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements"); + db.prepareDbUnit(getClass(), "convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml"); + + when(status.isUpgraded()).thenReturn(true); + when(status.getInitialDbVersion()).thenReturn(498); + + service.start(); + + db.assertDbUnit(getClass(), "convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml", "rules"); + } + @Test public void convert_duration() throws Exception { assertThat(CopyRequirementsFromCharacteristicsToRules.convertDuration(1.0, "h")).isEqualTo("1h"); diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml new file mode 100644 index 00000000000..3007042e182 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements.xml b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements.xml new file mode 100644 index 00000000000..104fd458667 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml new file mode 100644 index 00000000000..c5c054d724c --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules.xml b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules.xml index 05fb8c17653..fd5eaddf708 100644 --- a/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules.xml +++ b/sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules.xml @@ -42,7 +42,7 @@ remediation_coeff="[null]" default_remediation_coeff="5d" remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/> - + + remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/> - + + remediation_offset="0h" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>