From 8c16c2f0b3c3866d32ac35056f8ad7e305c00344 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 | 8 +++ ...rementsFromCharacteristicsToRulesTest.java | 15 ++++++ ...th_coeff_to_constant_issue_with_offset.xml | 54 +++++++++++++++++++ ...f_to_constant_issue_with_offset_result.xml | 39 ++++++++++++++ ...irements_from_characteristics_to_rules.xml | 2 +- ...s_from_characteristics_to_rules_result.xml | 2 +- .../requirements.xml | 4 -- 7 files changed, 118 insertions(+), 6 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_result.xml delete mode 100644 sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/requirements.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 117c5f55315..bd4e0d8b33b 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 @@ -42,6 +42,7 @@ import org.sonar.server.rule2.RegisterRules; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.Collection; import java.util.List; import java.util.Map; @@ -145,6 +146,13 @@ public class CopyRequirementsFromCharacteristicsToRules implements ServerCompone ruleRow.setRemediationCoefficient(convertDuration(enabledRequirement.getCoefficientValue(), enabledRequirement.getCoefficientUnit())); ruleRow.setRemediationOffset(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.getRemediationFunction()) + && ruleRow.getRemediationCoefficient() != null) { + ruleRow.setRemediationOffset(ruleRow.getRemediationCoefficient()); + ruleRow.setRemediationCoefficient(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.getRemediationFunction()) || DebtRemediationFunction.Type.LINEAR_OFFSET.name().equals(ruleRow.getRemediationFunction())) 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 9de4f367dab..26d2d7dc27c 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 @@ -69,6 +69,21 @@ public class CopyRequirementsFromCharacteristicsToRulesTest { db.assertDbUnit(getClass(), "copy_requirements_from_characteristics_to_rules_result.xml", "rules"); } + /** + * SONAR-5335 + */ + @Test + public void convert_constant_issue_with_coeff_to_constant_issue_with_offset() throws Exception { + 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 remove_requirements_data_from_characteristics() throws Exception { db.prepareDbUnit(getClass(), "remove_requirements_data_from_characteristics.xml"); 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..8e2d790f22a --- /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,54 @@ + + + + + + + + + + + + + + + + + + + + + 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..6a3fe70ac4e --- /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,39 @@ + + + + + + + + + + + + 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 1890f973d67..594b202c4a4 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 @@ -49,7 +49,7 @@ remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19" NOTE_CREATED_AT="[null]" NOTE_DATA="[null]" NOTE_UPDATED_AT="[null]" NOTE_USER_LOGIN="[null]" PARENT_ID="[null]" PLUGIN_CONFIG_KEY="[null]" PRIORITY="[null]" cardinality="[null]" created_at="[null]" language="[null]" effort_to_fix_description="[null]"/> - + - + - - - -- 2.39.5