aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-20 15:21:36 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-20 15:21:50 +0100
commit112de14fe80756a66dd8bbe7bd37b15260365441 (patch)
tree6ab269fab951b64c1624e37a48a8c07d33775792 /sonar-core
parent83d06f75616789706f5fb546a8aec7c51ecc1be1 (diff)
downloadsonarqube-112de14fe80756a66dd8bbe7bd37b15260365441.tar.gz
sonarqube-112de14fe80756a66dd8bbe7bd37b15260365441.zip
SONAR-5056 Create restore from provided model action
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java13
-rw-r--r--sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelRepository.java1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml7
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java10
-rw-r--r--sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java3
-rw-r--r--sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_overriding_debt_rules.xml31
8 files changed, 65 insertions, 4 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
index 9afcd8014ee..2f5e0441f3d 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java
@@ -76,6 +76,19 @@ public class RuleDao implements BatchComponent, ServerComponent {
return getMapper(session).selectByCharacteristicOrSubCharacteristicId(characteristicOrSubCharacteristicId);
}
+ public List<RuleDto> selectOverridingDebt() {
+ SqlSession session = mybatis.openSession();
+ try {
+ return selectOverridingDebt(session);
+ } finally {
+ MyBatis.closeQuietly(session);
+ }
+ }
+
+ public List<RuleDto> selectOverridingDebt(SqlSession session) {
+ return getMapper(session).selectOverridingDebt();
+ }
+
@CheckForNull
public RuleDto selectById(Integer id, SqlSession session) {
return getMapper(session).selectById(id);
diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
index 8733b199d02..5fd2b2f3658 100644
--- a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java
@@ -32,6 +32,8 @@ public interface RuleMapper {
List<RuleDto> selectByCharacteristicOrSubCharacteristicId(int id);
+ List<RuleDto> selectOverridingDebt();
+
RuleDto selectById(Integer id);
RuleDto selectByName(String name);
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelRepository.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelRepository.java
index f9cc46262a0..89031c8304e 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelRepository.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtModelRepository.java
@@ -44,6 +44,7 @@ import static com.google.common.collect.Lists.newArrayList;
* they must be named "<pluginKey>-model.xml".
* </p>
*/
+// TODO move it to sonar-server and rename it DebtModelPluginRepository when it will be no more used by the SQALE plugin
public class TechnicalDebtModelRepository implements ServerExtension, Startable {
public static final String DEFAULT_MODEL = "technical-debt";
diff --git a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
index 17ddab71423..aa93b05e472 100644
--- a/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/rule/RuleMapper.xml
@@ -65,6 +65,13 @@
</where>
</select>
+ <select id="selectOverridingDebt" resultType="Rule">
+ SELECT <include refid="selectColumns"/> FROM rules
+ <where>
+ AND (characteristic_id is NOT NULL or remediation_function IS NOT NULL)
+ </where>
+ </select>
+
<update id="update" parameterType="Rule">
UPDATE rules SET
plugin_rule_key=#{ruleKey},
diff --git a/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml b/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
index 495ef37d1b1..5a600667933 100644
--- a/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
@@ -107,7 +107,7 @@
<insert id="insert" parameterType="Characteristic" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
INSERT INTO characteristics (kee, name, parent_id, characteristic_order, enabled, created_at, updated_at)
- VALUES (#{kee}, #{name}, #{parentId}, #{characteristicOrder}, #{enabled}, current_timestamp, current_timestamp)
+ VALUES (#{kee}, #{name}, #{parentId}, #{characteristicOrder}, #{enabled}, #{createdAt}, #{updatedAt})
</insert>
<update id="update" parameterType="Characteristic">
diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
index 7e90f6aeb9c..c7f0fa4c3fc 100644
--- a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java
@@ -50,7 +50,8 @@ public class RuleDaoTest extends AbstractDaoTestCase {
setupData("selectAll");
List<RuleDto> ruleDtos = dao.selectAll();
- assertThat(ruleDtos.size()).isEqualTo(1);
+ assertThat(ruleDtos).hasSize(1);
+
RuleDto ruleDto = ruleDtos.get(0);
assertThat(ruleDto.getId()).isEqualTo(1);
assertThat(ruleDto.getName()).isEqualTo("Avoid Null");
@@ -154,6 +155,13 @@ public class RuleDaoTest extends AbstractDaoTestCase {
}
@Test
+ public void select_overriding_debt_rules() throws Exception {
+ setupData("select_overriding_debt_rules");
+
+ assertThat(dao.selectOverridingDebt()).hasSize(3);
+ }
+
+ @Test
public void update() {
setupData("update");
diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
index 6a05a8c5599..1f76fe6327d 100644
--- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
@@ -31,8 +31,7 @@ import static org.fest.assertions.Assertions.assertThat;
public class CharacteristicDaoTest extends AbstractDaoTestCase {
- private static final String[] EXCLUDED_COLUMNS = new String[]{"id", "root_id", "rule_id", "function_key", "factor_unit", "factor_value", "offset_unit", "offset_value",
- "created_at", "updated_at"};
+ private static final String[] EXCLUDED_COLUMNS = new String[]{"id", "root_id", "rule_id", "function_key", "factor_unit", "factor_value", "offset_unit", "offset_value"};
CharacteristicDao dao;
diff --git a/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_overriding_debt_rules.xml b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_overriding_debt_rules.xml
new file mode 100644
index 00000000000..2e4d2271b40
--- /dev/null
+++ b/sonar-core/src/test/resources/org/sonar/core/rule/RuleDaoTest/select_overriding_debt_rules.xml
@@ -0,0 +1,31 @@
+<dataset>
+
+ <!-- Rule overriding debt and with default debt should be returned -->
+ <rules id="1" plugin_rule_key="UselessImportCheck" plugin_name="squid" name="UselessImportCheck" description="Useless imports should be removed" status="READY"
+ characteristic_id="2" default_characteristic_id="50"
+ remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5d"
+ remediation_offset="10h" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Rule only overriding debt should be returned -->
+ <rules id="2" plugin_rule_key="LeftCurlyBraceStartLineCheck" plugin_name="squid" name="LeftCurlyBraceStartLineCheck" description="Left curly braces should be located at the beginning of lines of code" status="READY"
+ characteristic_id="3" default_characteristic_id="[null]"
+ remediation_function="LINEAR_OFFSET" default_remediation_function="[null]"
+ remediation_factor="5d" default_remediation_factor="[null]"
+ remediation_offset="10h" default_remediation_offset="[null]" updated_at="2014-02-19"/>
+
+ <!-- Rule with only default debt should be returned -->
+ <rules id="3" plugin_rule_key="CallToFileDeleteOnExitMethod" plugin_name="squid" name="CallToFileDeleteOnExitMethod" description="CallToFileDeleteOnExitMethod" status="READY"
+ characteristic_id="[null]" default_characteristic_id="50"
+ remediation_function="[null]" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="[null]" default_remediation_factor="5d"
+ remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+ <!-- Removed rule overriding debt : should be returned -->
+ <rules id="4" plugin_rule_key="ObjectFinalizeOverridenCallsSuperFinalizeCheck" plugin_name="squid" name="ObjectFinalizeOverridenCallsSuperFinalizeCheck" description="super.finalize() should be called at the end of Object.finalize() implementations" status="REMOVED"
+ characteristic_id="3" default_characteristic_id="50"
+ remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
+ remediation_factor="5d" default_remediation_factor="5min"
+ remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"/>
+
+</dataset>