]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5335 When upgrading from SonarQube 4.2 with PMD 2.1, searching for some Java...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 May 2014 17:36:09 +0000 (19:36 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 22 May 2014 17:36:09 +0000 (19:36 +0200)
sonar-server/src/main/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRules.java
sonar-server/src/test/java/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest.java
sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_requirements.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/convert_constant_issue_with_coeff_to_constant_issue_with_offset_result.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules.xml
sonar-server/src/test/resources/org/sonar/server/startup/CopyRequirementsFromCharacteristicsToRulesTest/copy_requirements_from_characteristics_to_rules_result.xml

index 4f6ea91372ad1356dee458a011532a8578f04e34..e5aa88fc8970badc44312a28c8762c4eacfa0e1b 100644 (file)
@@ -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()))
index 1c7f5b37dc5bf5947501f1d8cb7ea91baccb389a..f9e886b6eb6b81c311f972a8157364188508050a 100644 (file)
@@ -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 (file)
index 0000000..3007042
--- /dev/null
@@ -0,0 +1,24 @@
+<dataset>
+
+  <!-- Constant/issue with coefficient -> Update rule to Constant/issue with offset -->
+  <rules id="1" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
+         characteristic_id="[null]" default_characteristic_id="10"
+         remediation_function="[null]" default_remediation_function="LINEAR"
+         remediation_coeff="[null]" default_remediation_coeff="5d"
+         remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+  <!-- Constant/issue with coefficient and offset -> Update rule to Constant/issue with only offset -->
+  <rules id="2" plugin_rule_key="HiddenFieldCheck" plugin_name="squid" name="HiddenFieldCheck" description="HiddenFieldCheck" status="READY"
+         characteristic_id="[null]" default_characteristic_id="10"
+         remediation_function="[null]" default_remediation_function="LINEAR"
+         remediation_coeff="[null]" default_remediation_coeff="5d"
+         remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+  <!-- Constant/issue with coefficient but having same value as default -> No update -->
+  <rules id="3" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
+         characteristic_id="[null]" default_characteristic_id="10"
+         remediation_function="[null]" default_remediation_function="CONSTANT_ISSUE"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="5min" updated_at="2014-02-19"/>
+
+</dataset>
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 (file)
index 0000000..104fd45
--- /dev/null
@@ -0,0 +1,19 @@
+
+<dataset>
+
+  <!-- Requirements of rule 1 -->
+  <characteristics id="1" parent_id="10" rule_id="1"
+                   function_key="constant_issue" factor_value="20.0" factor_unit="mn" offset_value="0.0" offset_unit="h" enabled="[true]"
+                   created_at="2013-11-20" updated_at="[null]"/>
+
+  <!-- Requirements of rule 2 -->
+  <characteristics id="2" parent_id="10" rule_id="2"
+                   function_key="constant_issue" factor_value="30.0" factor_unit="mn" offset_value="20.0" offset_unit="h" enabled="[true]"
+                   created_at="2013-11-20" updated_at="[null]"/>
+
+  <!-- Requirements of rule 3 -->
+  <characteristics id="3" parent_id="10" rule_id="3"
+                   function_key="constant_issue" factor_value="5.0" factor_unit="mn" offset_value="0.0" offset_unit="h" enabled="[true]"
+                   created_at="2013-11-20" updated_at="[null]"/>
+
+</dataset>
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 (file)
index 0000000..c5c054d
--- /dev/null
@@ -0,0 +1,24 @@
+<dataset>
+
+  <!-- Constant/issue with coefficient -> Update rule to Constant/issue with offset -->
+  <rules id="1" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
+         characteristic_id="10" default_characteristic_id="10"
+         remediation_function="CONSTANT_ISSUE" default_remediation_function="LINEAR"
+         remediation_coeff="[null]" default_remediation_coeff="5d"
+         remediation_offset="20min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
+
+  <!-- Constant/issue with coefficient and offset -> Update rule to Constant/issue with only offset -->
+  <rules id="2" plugin_rule_key="HiddenFieldCheck" plugin_name="squid" name="HiddenFieldCheck" description="HiddenFieldCheck" status="READY"
+         characteristic_id="10" default_characteristic_id="10"
+         remediation_function="CONSTANT_ISSUE" default_remediation_function="LINEAR"
+         remediation_coeff="[null]" default_remediation_coeff="5d"
+         remediation_offset="30min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
+
+  <!-- Constant/issue with coefficient but having same value as default -> No update -->
+  <rules id="3" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
+         characteristic_id="[null]" default_characteristic_id="10"
+         remediation_function="[null]" default_remediation_function="CONSTANT_ISSUE"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="5min" updated_at="2014-02-19"/>
+
+</dataset>
index 05fb8c1765333a21de0d2eea323388587ba0f133..fd5eaddf70829f8d2ed33ae91902e7f7c598e51f 100644 (file)
@@ -42,7 +42,7 @@
          remediation_coeff="[null]" default_remediation_coeff="5d"
          remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"/>
 
-  <!-- Rule linked to one enable requirement on Linear function (with a coeeficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
+  <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
   <rules id="7" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
          characteristic_id="[null]" default_characteristic_id="20"
          remediation_function="[null]" default_remediation_function="LINEAR"
@@ -54,7 +54,7 @@
          characteristic_id="[null]" default_characteristic_id="20"
          remediation_function="[null]" default_remediation_function="LINEAR"
          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"/>
 
   <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0d -> should keep 0d), with different value of debt -> Update rule -->
   <rules id="9" plugin_rule_key="SwitchLastCaseIsDefaultCheck" plugin_name="squid" name="SwitchLastCaseIsDefaultCheck" description="SwitchLastCaseIsDefaultCheck" status="READY"
index b7557ad1c88d165a743773613ad1cf525f1d4bb7..9506b6274d86d9599ce239c0420647191bf769c1 100644 (file)
@@ -42,7 +42,7 @@
          remediation_coeff="[null]" default_remediation_coeff="5d"
          remediation_offset="15min" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
 
-  <!-- Rule linked to one enable requirement on Linear function (with a coeeficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
+  <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0min -> to be replaced by null), with different value of debt -> Update rule -->
   <rules id="7" plugin_rule_key="ForLoopCounterChangedCheck" plugin_name="squid" name="ForLoopCounterChangedCheck" description="ForLoopCounterChangedCheck" status="READY"
          characteristic_id="10" default_characteristic_id="20"
          remediation_function="LINEAR" default_remediation_function="LINEAR"
@@ -54,7 +54,7 @@
          characteristic_id="10" default_characteristic_id="20"
          remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR"
          remediation_coeff="5d" default_remediation_coeff="5d"
-         remediation_offset="0h" default_remediation_offset="[null" updated_at="2014-03-13 19:10:03.0"/>
+         remediation_offset="0h" default_remediation_offset="[null]" updated_at="2014-03-13 19:10:03.0"/>
 
   <!-- Rule linked to one enable requirement on Linear function (with a coefficient of 0d -> should keep 0d), with different value of debt -> Update rule -->
   <rules id="9" plugin_rule_key="SwitchLastCaseIsDefaultCheck" plugin_name="squid" name="SwitchLastCaseIsDefaultCheck" description="SwitchLastCaseIsDefaultCheck" status="READY"