diff options
37 files changed, 204 insertions, 482 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java index 359f348cc7c..b274eeb6915 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java @@ -142,7 +142,7 @@ public final class TechnicalDebtDecorator implements Decorator { // BUT we don't want to save zero-values for non top-characteristics (see SQALE-147) if (value > 0.0) { org.sonar.api.rules.Rule oldRule = toOldRule(rule); - RuleMeasure measure = new RuleMeasure(CoreMetrics.TECHNICAL_DEBT, oldRule, oldRule.getSeverity(), null); + RuleMeasure measure = new RuleMeasure(CoreMetrics.TECHNICAL_DEBT, oldRule, null, null); saveMeasure(context, measure, value, inMemory); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java index cc98836f049..158713b6507 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java @@ -287,12 +287,6 @@ public class TechnicalDebtDecoratorTest { this.value = value; } - public IsCharacteristicMeasure(Metric metric, Double value) { - this.metric = metric; - this.characteristic = null; - this.value = value; - } - @Override public boolean matches(Object o) { if (!(o instanceof Measure)) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java index 237bfa3d93b..a8a061faa9a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java @@ -52,7 +52,7 @@ public class DebtModelProvider extends ProviderAdapter { private TechnicalDebtModel load(CharacteristicDao dao) { DefaultTechnicalDebtModel model = new DefaultTechnicalDebtModel(); - List<CharacteristicDto> dtos = dao.selectCharacteristics(); + List<CharacteristicDto> dtos = dao.selectEnabledCharacteristics(); Map<Integer, DefaultCharacteristic> characteristicsById = newHashMap(); addRootCharacteristics(model, dtos, characteristicsById); @@ -72,7 +72,7 @@ public class DebtModelProvider extends ProviderAdapter { private void addCharacteristics(List<CharacteristicDto> dtos, Map<Integer, DefaultCharacteristic> characteristicsById) { for (CharacteristicDto dto : dtos) { - if (dto.getParentId() != null && dto.getRuleId() == null) { + if (dto.getParentId() != null) { DefaultCharacteristic parent = characteristicsById.get(dto.getParentId()); DefaultCharacteristic characteristic = dto.toCharacteristic(parent); characteristicsById.put(dto.getId(), characteristic); diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java index 50e08fc793c..5bed2d878c0 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java @@ -25,8 +25,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rules.Rule; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel; import org.sonar.core.technicaldebt.db.CharacteristicDao; @@ -63,20 +61,7 @@ public class DebtModelProviderTest { .setName("Efficiency") .setParentId(1); - CharacteristicDto requirementDto = new CharacteristicDto() - .setId(3) - .setParentId(2) - .setRuleId(100) - .setFunction("linear") - .setFactorValue(2d) - .setFactorUnit(CharacteristicDto.DAYS) - .setOffsetValue(0d) - .setOffsetUnit(CharacteristicDto.MINUTES); - - RuleKey ruleKey = RuleKey.of("checkstyle", "Regexp"); - Rule rule = Rule.create(ruleKey.repository(), ruleKey.rule()); - rule.setId(100); - when(dao.selectCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto, characteristicDto, requirementDto)); + when(dao.selectEnabledCharacteristics()).thenReturn(newArrayList(rootCharacteristicDto, characteristicDto)); DefaultTechnicalDebtModel result = (DefaultTechnicalDebtModel) provider.provide(dao); assertThat(result.rootCharacteristics()).hasSize(1); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index c7c6fa7bb11..a5dd5961d36 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 520; + public static final int LAST_VERSION = 522; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java index 8a65bbe586c..cdc9d4ae1e2 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java @@ -83,8 +83,7 @@ public class DefaultTechnicalDebtManager implements TechnicalDebtManager { .setKey(dto.getKey()) .setName(dto.getName()) .setOrder(dto.getOrder()) - .setParentId(dto.getParentId()) - .setRootId(dto.getRootId()); + .setParentId(dto.getParentId()); } } diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java index 491d77d17ed..71ca2f170e3 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java @@ -40,20 +40,22 @@ public class CharacteristicDao implements BatchComponent, ServerComponent { /** * @return enabled root characteristics, characteristics and requirements * - * @deprecated since 4.3 (used by SQALE plugin) */ - @Deprecated public List<CharacteristicDto> selectEnabledCharacteristics() { SqlSession session = mybatis.openSession(); try { - return session.getMapper(CharacteristicMapper.class).selectEnabledCharacteristics(); + return selectEnabledCharacteristics(session); } finally { MyBatis.closeQuietly(session); } } + public List<CharacteristicDto> selectEnabledCharacteristics(SqlSession session) { + return session.getMapper(CharacteristicMapper.class).selectEnabledCharacteristics(); + } + /** - * @return enabled root characteristics, and characteristics + * @return all characteristics * */ public List<CharacteristicDto> selectCharacteristics() { @@ -104,17 +106,6 @@ public class CharacteristicDao implements BatchComponent, ServerComponent { } } - @CheckForNull - public CharacteristicDto selectByRuleId(Integer ruleId) { - SqlSession session = mybatis.openSession(); - CharacteristicMapper mapper = session.getMapper(CharacteristicMapper.class); - try { - return mapper.selectByRuleId(ruleId); - } finally { - MyBatis.closeQuietly(session); - } - } - public void insert(CharacteristicDto dto, SqlSession session) { session.getMapper(CharacteristicMapper.class).insert(dto); } diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java index 18a1bb9034d..cfd0e1466d4 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java @@ -20,10 +20,7 @@ package org.sonar.core.technicaldebt.db; -import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; -import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.internal.WorkDuration; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -41,14 +38,7 @@ public class CharacteristicDto implements Serializable { private String kee; private String name; private Integer parentId; - private Integer rootId; private Integer characteristicOrder; - private Integer ruleId; - private String functionKey; - private Double factorValue; - private String factorUnit; - private Double offsetValue; - private String offsetUnit; private Date createdAt; private Date updatedAt; private boolean enabled; @@ -93,16 +83,6 @@ public class CharacteristicDto implements Serializable { } @CheckForNull - public Integer getRootId() { - return rootId; - } - - public CharacteristicDto setRootId(@Nullable Integer rootId) { - this.rootId = rootId; - return this; - } - - @CheckForNull public Integer getOrder() { return characteristicOrder; } @@ -112,66 +92,6 @@ public class CharacteristicDto implements Serializable { return this; } - @CheckForNull - public Integer getRuleId() { - return ruleId; - } - - public CharacteristicDto setRuleId(@Nullable Integer ruleId) { - this.ruleId = ruleId; - return this; - } - - @CheckForNull - public String getFunction() { - return functionKey; - } - - public CharacteristicDto setFunction(@Nullable String function) { - this.functionKey = function; - return this; - } - - @CheckForNull - public Double getFactorValue() { - return factorValue; - } - - public CharacteristicDto setFactorValue(Double factor) { - this.factorValue = factor; - return this; - } - - @CheckForNull - public String getFactorUnit() { - return factorUnit; - } - - public CharacteristicDto setFactorUnit(@Nullable String factorUnit) { - this.factorUnit = factorUnit; - return this; - } - - @CheckForNull - public Double getOffsetValue() { - return offsetValue; - } - - public CharacteristicDto setOffsetValue(@Nullable Double offset) { - this.offsetValue = offset; - return this; - } - - @CheckForNull - public String getOffsetUnit() { - return offsetUnit; - } - - public CharacteristicDto setOffsetUnit(@Nullable String offsetUnit) { - this.offsetUnit = offsetUnit; - return this; - } - public Date getCreatedAt() { return createdAt; } @@ -218,68 +138,9 @@ public class CharacteristicDto implements Serializable { .setName(characteristic.name()) .setOrder(characteristic.order()) .setParentId(parentId) - .setRootId(parentId) .setEnabled(true) .setCreatedAt(characteristic.createdAt()) .setUpdatedAt(characteristic.updatedAt()); } - public DefaultRequirement toRequirement(RuleKey ruleKey, DefaultCharacteristic characteristic, DefaultCharacteristic rootCharacteristic) { - return new DefaultRequirement() - .setId(id) - .setRuleKey(ruleKey) - .setCharacteristic(characteristic) - .setRootCharacteristic(rootCharacteristic) - .setFunction(functionKey) - .setFactorValue(factorValue.intValue()) - .setFactorUnit(toUnit(factorUnit)) - .setOffsetValue(offsetValue.intValue()) - .setOffsetUnit(toUnit(offsetUnit)) - .setCreatedAt(createdAt) - .setUpdatedAt(updatedAt); - } - - public static CharacteristicDto toDto(DefaultRequirement requirement, Integer characteristicId, Integer rootCharacteristicId, Integer ruleId) { - return new CharacteristicDto() - .setRuleId(ruleId) - .setParentId(characteristicId) - .setRootId(rootCharacteristicId) - .setFunction(requirement.function()) - .setFactorValue((double) requirement.factorValue()) - .setFactorUnit(fromUnit(requirement.factorUnit())) - .setOffsetValue((double) requirement.offsetValue()) - .setOffsetUnit(fromUnit(requirement.offsetUnit())) - .setEnabled(true) - .setCreatedAt(requirement.createdAt()) - .setUpdatedAt(requirement.updatedAt()); - } - - private static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) { - if (requirementUnit != null) { - if (DAYS.equals(requirementUnit)) { - return WorkDuration.UNIT.DAYS; - } else if (HOURS.equals(requirementUnit)) { - return WorkDuration.UNIT.HOURS; - } else if (MINUTES.equals(requirementUnit)) { - return WorkDuration.UNIT.MINUTES; - } - throw new IllegalStateException("Invalid unit : " + requirementUnit); - } - return null; - } - - private static String fromUnit(@Nullable WorkDuration.UNIT unit) { - if (unit != null) { - if (WorkDuration.UNIT.DAYS.equals(unit)) { - return DAYS; - } else if (WorkDuration.UNIT.HOURS.equals(unit)) { - return HOURS; - } else if (WorkDuration.UNIT.MINUTES.equals(unit)) { - return MINUTES; - } - throw new IllegalStateException("Invalid unit : " + unit); - } - return null; - } - } diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java index 7ab1b291874..7439389021c 100644 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java @@ -34,8 +34,6 @@ public interface CharacteristicMapper { CharacteristicDto selectById(int id); - CharacteristicDto selectByRuleId(Integer ruleId); - void insert(CharacteristicDto characteristic); int update(CharacteristicDto characteristic); diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 01b91d42ffc..1761f27ecec 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -218,6 +218,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('517'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('518'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('519'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('520'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('521'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('522'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 7292b42d6d9..058641b81da 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -27,13 +27,6 @@ CREATE TABLE "CHARACTERISTICS" ( "KEE" VARCHAR(100), "NAME" VARCHAR(100), "PARENT_ID" INTEGER, - "ROOT_ID" INTEGER, - "RULE_ID" INTEGER, - "FUNCTION_KEY" VARCHAR(100), - "FACTOR_VALUE" DOUBLE, - "FACTOR_UNIT" VARCHAR(100), - "OFFSET_VALUE" DOUBLE, - "OFFSET_UNIT" VARCHAR(100), "CHARACTERISTIC_ORDER" INTEGER, "ENABLED" BOOLEAN, "CREATED_AT" TIMESTAMP, 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 2988115ae16..4cf3ea98e7f 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 @@ -9,14 +9,7 @@ c.kee as kee, c.name as name, c.parent_id as parentId, - c.root_id as rootId, c.characteristic_order as characteristicOrder, - c.rule_id as ruleId, - c.function_key as functionKey, - c.factor_value as factorValue, - c.factor_unit as factorUnit, - c.offset_value as offsetValue, - c.offset_unit as offsetUnit, c.enabled as enabled, c.created_at as createdAt, c.updated_at as updatedAt @@ -33,10 +26,6 @@ <select id="selectCharacteristics" parameterType="map" resultType="Characteristic"> select <include refid="characteristicColumns"/> from characteristics c - <where> - and c.rule_id is null - and c.enabled=${_true} - </where> </select> <select id="selectEnabledRootCharacteristics" parameterType="map" resultType="Characteristic"> @@ -44,7 +33,6 @@ from characteristics c <where> and c.parent_id is null - and c.rule_id is null and c.enabled=${_true} </where> order by characteristic_order asc @@ -68,36 +56,16 @@ </where> </select> - <select id="selectByRuleId" parameterType="Integer" resultType="Characteristic"> - select <include refid="characteristicColumns"/> - from characteristics c - <where> - and c.rule_id=#{ruleId} - and c.enabled=${_true} - </where> - </select> - <insert id="insert" parameterType="Characteristic" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> - INSERT INTO characteristics (kee, name, parent_id, root_id, characteristic_order, - rule_id, function_key, factor_value, factor_unit, offset_value, offset_unit, - enabled, created_at, updated_at) - VALUES (#{kee}, #{name}, #{parentId}, #{rootId}, #{characteristicOrder}, - #{ruleId}, #{functionKey}, #{factorValue}, #{factorUnit}, #{offsetValue}, #{offsetUnit}, - #{enabled}, current_timestamp, current_timestamp) + INSERT INTO characteristics (kee, name, parent_id, characteristic_order, enabled, created_at, updated_at) + VALUES (#{kee}, #{name}, #{parentId}, #{characteristicOrder}, #{enabled}, current_timestamp, current_timestamp) </insert> <update id="update" parameterType="Characteristic"> update characteristics set name=#{name}, parent_id=#{parentId}, - root_id=#{rootId}, characteristic_order=#{characteristicOrder}, - rule_id=#{ruleId}, - function_key=#{functionKey}, - factor_value=#{factorValue}, - factor_unit=#{factorUnit}, - offset_value=#{offsetValue}, - offset_unit=#{offsetUnit}, enabled=#{enabled}, updated_at=current_timestamp where id=#{id} diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java index 99c83b33dd7..89b71be51bf 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java @@ -73,13 +73,12 @@ public class DefaultTechnicalDebtManagerTest { rule.setId(1); when(dao.selectById(2)).thenReturn( - new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setName("Compiler").setParentId(1).setRootId(1)); + new CharacteristicDto().setId(2).setKey("COMPILER_RELATED_PORTABILITY").setName("Compiler").setParentId(1)); Characteristic result = finder.findCharacteristicById(2); assertThat(result.id()).isEqualTo(2); assertThat(result.parentId()).isEqualTo(1); - assertThat(result.rootId()).isEqualTo(1); assertThat(result.key()).isEqualTo("COMPILER_RELATED_PORTABILITY"); assertThat(result.name()).isEqualTo("Compiler"); } 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 0e4341ab81c..03f62c5cae5 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,7 +31,7 @@ import static org.fest.assertions.Assertions.assertThat; public class CharacteristicDaoTest extends AbstractDaoTestCase { - private static final String[] EXCLUDED_COLUMNS = new String[]{"id", "depth", "description", "quality_model_id", "created_at", "updated_at"}; + private static final String[] EXCLUDED_COLUMNS = new String[]{"id", "created_at", "updated_at"}; CharacteristicDao dao; @@ -46,15 +46,13 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { List<CharacteristicDto> dtos = dao.selectEnabledCharacteristics(); - assertThat(dtos).hasSize(3); + assertThat(dtos).hasSize(2); CharacteristicDto rootCharacteristic = dtos.get(0); assertThat(rootCharacteristic.getId()).isEqualTo(1); assertThat(rootCharacteristic.getKey()).isEqualTo("PORTABILITY"); assertThat(rootCharacteristic.getName()).isEqualTo("Portability"); assertThat(rootCharacteristic.getParentId()).isNull(); - assertThat(rootCharacteristic.getRootId()).isNull(); - assertThat(rootCharacteristic.getRuleId()).isNull(); assertThat(rootCharacteristic.getOrder()).isEqualTo(1); assertThat(rootCharacteristic.isEnabled()).isTrue(); assertThat(rootCharacteristic.getCreatedAt()).isNotNull(); @@ -65,60 +63,17 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { assertThat(characteristic.getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY"); assertThat(characteristic.getName()).isEqualTo("Compiler related portability"); assertThat(characteristic.getParentId()).isEqualTo(1); - assertThat(characteristic.getRootId()).isEqualTo(1); - assertThat(characteristic.getRuleId()).isNull(); assertThat(characteristic.getOrder()).isNull(); assertThat(characteristic.isEnabled()).isTrue(); assertThat(characteristic.getCreatedAt()).isNotNull(); assertThat(characteristic.getUpdatedAt()).isNotNull(); - - CharacteristicDto requirement = dtos.get(2); - assertThat(requirement.getId()).isEqualTo(3); - assertThat(requirement.getKey()).isNull(); - assertThat(requirement.getName()).isNull(); - assertThat(requirement.getParentId()).isEqualTo(2); - assertThat(requirement.getRootId()).isEqualTo(1); - assertThat(requirement.getRuleId()).isEqualTo(1); - assertThat(requirement.getOrder()).isNull(); - assertThat(requirement.getFunction()).isEqualTo("linear_offset"); - assertThat(requirement.getFactorValue()).isEqualTo(20.0); - assertThat(requirement.getFactorUnit()).isEqualTo("mn"); - assertThat(requirement.getOffsetValue()).isEqualTo(30.0); - assertThat(requirement.getOffsetUnit()).isEqualTo("h"); - assertThat(requirement.isEnabled()).isTrue(); - assertThat(requirement.getCreatedAt()).isNotNull(); - assertThat(requirement.getUpdatedAt()).isNull(); } @Test public void select_characteristics() { setupData("shared"); - List<CharacteristicDto> dtos = dao.selectCharacteristics(); - - assertThat(dtos).hasSize(2); - - CharacteristicDto rootCharacteristic = dtos.get(0); - assertThat(rootCharacteristic.getId()).isEqualTo(1); - assertThat(rootCharacteristic.getKey()).isEqualTo("PORTABILITY"); - assertThat(rootCharacteristic.getName()).isEqualTo("Portability"); - assertThat(rootCharacteristic.getParentId()).isNull(); - assertThat(rootCharacteristic.getRootId()).isNull(); - assertThat(rootCharacteristic.getOrder()).isEqualTo(1); - assertThat(rootCharacteristic.isEnabled()).isTrue(); - assertThat(rootCharacteristic.getCreatedAt()).isNotNull(); - assertThat(rootCharacteristic.getUpdatedAt()).isNotNull(); - - CharacteristicDto characteristic = dtos.get(1); - assertThat(characteristic.getId()).isEqualTo(2); - assertThat(characteristic.getKey()).isEqualTo("COMPILER_RELATED_PORTABILITY"); - assertThat(characteristic.getName()).isEqualTo("Compiler related portability"); - assertThat(characteristic.getParentId()).isEqualTo(1); - assertThat(characteristic.getRootId()).isEqualTo(1); - assertThat(characteristic.getOrder()).isNull(); - assertThat(characteristic.isEnabled()).isTrue(); - assertThat(characteristic.getCreatedAt()).isNotNull(); - assertThat(characteristic.getUpdatedAt()).isNotNull(); + assertThat(dao.selectCharacteristics()).hasSize(4); } @Test @@ -147,18 +102,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { } @Test - public void select_requirement() { - setupData("shared"); - - CharacteristicDto dto = dao.selectByRuleId(1); - - assertThat(dto).isNotNull(); - assertThat(dto.getId()).isEqualTo(3); - assertThat(dto.getParentId()).isEqualTo(2); - assertThat(dto.getRootId()).isEqualTo(1); - } - - @Test public void select_characteristic_by_key() { setupData("shared"); @@ -166,13 +109,11 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { assertThat(dto).isNotNull(); assertThat(dto.getId()).isEqualTo(2); assertThat(dto.getParentId()).isEqualTo(1); - assertThat(dto.getRootId()).isEqualTo(1); dto = dao.selectByKey("PORTABILITY"); assertThat(dto).isNotNull(); assertThat(dto.getId()).isEqualTo(1); assertThat(dto.getParentId()).isNull(); - assertThat(dto.getRootId()).isNull(); assertThat(dao.selectByKey("UNKNOWN")).isNull(); } @@ -202,25 +143,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { } @Test - public void insert_requirement() throws Exception { - CharacteristicDto dto = new CharacteristicDto() - .setParentId(2) - .setRootId(1) - .setRuleId(1) - .setFunction("linear_offset") - .setFactorValue(20.0) - .setFactorUnit("mn") - .setOffsetValue(30.0) - .setOffsetUnit("h") - .setCreatedAt(DateUtils.parseDate("2013-11-20")) - .setEnabled(true); - - dao.insert(dto); - - checkTables("insert_requirement", EXCLUDED_COLUMNS, "characteristics"); - } - - @Test public void update_characteristic() throws Exception { setupData("update_characteristic"); @@ -240,29 +162,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase { } @Test - public void update_requirement() throws Exception { - setupData("update_requirement"); - - CharacteristicDto dto = new CharacteristicDto() - .setId(1) - .setParentId(3) - .setRootId(1) - .setRuleId(2) - .setFunction("linear") - .setFactorValue(21.0) - .setFactorUnit("h") - .setOffsetValue(null) - .setOffsetUnit(null) - // Created date should not changed - .setCreatedAt(DateUtils.parseDate("2013-11-22")) - .setEnabled(false); - - dao.update(dto); - - checkTables("update_requirement", EXCLUDED_COLUMNS, "characteristics"); - } - - @Test public void disable() throws Exception { setupData("disable"); diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java index f6730185360..75c6a2f8cf0 100644 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java @@ -21,10 +21,7 @@ package org.sonar.core.technicaldebt.db; import org.junit.Test; -import org.sonar.api.rule.RuleKey; import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; -import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; -import org.sonar.api.utils.internal.WorkDuration; import java.util.Date; @@ -33,64 +30,57 @@ import static org.fest.assertions.Assertions.assertThat; public class CharacteristicDtoTest { @Test - public void to_dto_from_requirement() throws Exception { - DefaultRequirement requirement = new DefaultRequirement() - .setFunction("constant_issue") - .setFactorValue(10) - .setFactorUnit(WorkDuration.UNIT.DAYS) - .setOffsetValue(5) - .setOffsetUnit(WorkDuration.UNIT.MINUTES) + public void to_dto_from_characteristic() throws Exception { + DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic() + .setId(1) + .setKey("MEMORY_EFFICIENCY") + .setName("Memory use"); + + DefaultCharacteristic characteristic = new DefaultCharacteristic() + .setId(2) + .setKey("EFFICIENCY") + .setName("Efficiency") + .setParent(rootCharacteristic) + .setOrder(5) .setCreatedAt(new Date()) .setUpdatedAt(new Date()); - CharacteristicDto dto = CharacteristicDto.toDto(requirement, 2, 1, 10); - assertThat(dto.getRuleId()).isEqualTo(10); - assertThat(dto.getParentId()).isEqualTo(2); - assertThat(dto.getRootId()).isEqualTo(1); - assertThat(dto.getFunction()).isEqualTo("constant_issue"); - assertThat(dto.getFactorValue()).isEqualTo(10d); - assertThat(dto.getFactorUnit()).isEqualTo(CharacteristicDto.DAYS); - assertThat(dto.getOffsetValue()).isEqualTo(5d); - assertThat(dto.getOffsetUnit()).isEqualTo(CharacteristicDto.MINUTES); + CharacteristicDto dto = CharacteristicDto.toDto(characteristic, 1); + assertThat(dto.getId()).isNull(); + assertThat(dto.getParentId()).isEqualTo(1); + assertThat(dto.getKey()).isEqualTo("EFFICIENCY"); + assertThat(dto.getName()).isEqualTo("Efficiency"); + assertThat(dto.getOrder()).isEqualTo(5); assertThat(dto.isEnabled()).isTrue(); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); } @Test - public void to_requirement() throws Exception { - CharacteristicDto requirementDto = new CharacteristicDto() - .setId(3) - .setParentId(2) - .setRuleId(100) - .setFunction("linear") - .setFactorValue(2d) - .setFactorUnit(CharacteristicDto.DAYS) - .setOffsetValue(0d) - .setOffsetUnit(CharacteristicDto.MINUTES) - .setCreatedAt(new Date()) - .setUpdatedAt(new Date()); - + public void to_characteristic() throws Exception { DefaultCharacteristic rootCharacteristic = new DefaultCharacteristic() + .setId(1) .setKey("MEMORY_EFFICIENCY") .setName("Memory use"); - DefaultCharacteristic characteristic = new DefaultCharacteristic() + + CharacteristicDto dto = new CharacteristicDto() + .setId(2) + .setParentId(1) .setKey("EFFICIENCY") .setName("Efficiency") - .setParent(rootCharacteristic); - - DefaultRequirement requirement = requirementDto.toRequirement(RuleKey.of("squid", "S106"), characteristic, rootCharacteristic); - assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("squid", "S106")); - assertThat(requirement.characteristic()).isEqualTo(characteristic); - assertThat(requirement.rootCharacteristic()).isEqualTo(rootCharacteristic); - assertThat(requirement.function()).isEqualTo("linear"); - assertThat(requirement.factorValue()).isEqualTo(2); - assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.DAYS); - assertThat(requirement.offsetValue()).isEqualTo(0); - assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.MINUTES); - assertThat(requirement.createdAt()).isNotNull(); - assertThat(requirement.updatedAt()).isNotNull(); + .setOrder(5) + .setEnabled(false) + .setCreatedAt(new Date()) + .setUpdatedAt(new Date()); + DefaultCharacteristic characteristic = dto.toCharacteristic(rootCharacteristic); + assertThat(characteristic.id()).isEqualTo(2); + assertThat(characteristic.parent()).isEqualTo(rootCharacteristic); + assertThat(characteristic.key()).isEqualTo("EFFICIENCY"); + assertThat(characteristic.name()).isEqualTo("Efficiency"); + assertThat(characteristic.order()).isEqualTo(5); + assertThat(characteristic.createdAt()).isNotNull(); + assertThat(characteristic.updatedAt()).isNotNull(); } } diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml index d5ad7fc62d4..81249826cc2 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml @@ -10,9 +10,9 @@ worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"/> - <characteristics id="1" kee="M1C1" name="M1C1" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" enabled="[true]"/> - <characteristics id="2" kee="M1C2" name="M1C1" parent_id="1" root_id="1" rule_id="[null]" characteristic_order="[null]" enabled="[true]"/> - <characteristics id="3" kee="M1C3" name="M1C3" parent_id="2" root_id="1" rule_id="333" characteristic_order="[null]" enabled="[true]"/> + <characteristics id="1" kee="M1C1" name="M1C1" parent_id="[null]" characteristic_order="1" enabled="[true]"/> + <characteristics id="2" kee="M1C2" name="M1C1" parent_id="1" characteristic_order="[null]" enabled="[true]"/> + <characteristics id="3" kee="M1C3" name="M1C3" parent_id="2" characteristic_order="[null]" enabled="[true]"/> <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml index 23ec5986e5b..83204ee61d6 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml @@ -10,9 +10,9 @@ worst_value="0" optimized_best_value="[true]" best_value="100" direction="1" hidden="[false]"/> - <characteristics id="1" kee="M1C1" name="M1C1" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" enabled="[true]"/> - <characteristics id="2" kee="M1C2" name="M1C1" parent_id="1" root_id="1" rule_id="[null]" characteristic_order="[null]" enabled="[true]"/> - <characteristics id="3" kee="M1C3" name="M1C3" parent_id="2" root_id="1" rule_id="333" characteristic_order="[null]" enabled="[true]"/> + <characteristics id="1" kee="M1C1" name="M1C1" parent_id="[null]" characteristic_order="1" enabled="[true]"/> + <characteristics id="2" kee="M1C2" name="M1C1" parent_id="1" characteristic_order="[null]" enabled="[true]"/> + <characteristics id="3" kee="M1C3" name="M1C3" parent_id="2" characteristic_order="[null]" enabled="[true]"/> <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml index 81b97e0b518..04d1f65ac3e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml @@ -1,7 +1,6 @@ <dataset> - <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[false]" + <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[false]" created_at="2013-11-20" updated_at="[null]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml index a970b324456..dd69c61296d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml @@ -1,7 +1,6 @@ <dataset> - <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_characteristic-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_characteristic-result.xml index b6e2d5df640..51d29ef914a 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_characteristic-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_characteristic-result.xml @@ -1,7 +1,6 @@ <dataset> - <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="[null]"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_requirement-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_requirement-result.xml deleted file mode 100644 index 2b1ccb8fd6b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_requirement-result.xml +++ /dev/null @@ -1,7 +0,0 @@ -<dataset> - - <characteristics id="1" kee="[null]" name="[null]" parent_id="2" root_id="1" rule_id="1" characteristic_order="[null]" - function_key="linear_offset" factor_value="20.0" factor_unit="mn" offset_value="30.0" offset_unit="h" enabled="[true]" - created_at="2013-11-20" updated_at="[null]"/> - -</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics.xml index c8200af2825..ed75d063f9f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics.xml @@ -1,29 +1,21 @@ <dataset> - <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> - <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" root_id="1" rule_id="[null]" characteristic_order="[null]" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" characteristic_order="[null]" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> <!-- requirement --> - <characteristics id="3" kee="[null]" name="[null]" parent_id="2" root_id="1" rule_id="1" + <characteristics id="3" kee="[null]" name="[null]" parent_id="2" rule_id="1" function_key="linear_offset" factor_value="20.0" factor_unit="mn" offset_value="30.0" offset_unit="h" enabled="[true]" created_at="2013-11-20" updated_at="[null]"/> <!-- disabled characteristics --> - <characteristics id="4" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="1" root_id="1" rule_id="[null]" characteristic_order="2" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[false]" + <characteristics id="4" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="1" characteristic_order="2" + enabled="[false]" created_at="2013-11-20" updated_at="2013-11-22"/> - <!-- disabled requirement --> - <characteristics id="5" kee="[null]" name="[null]" parent_id="4" root_id="4" rule_id="1" - function_key="linear_offset" factor_value="30.0" factor_unit="mn" offset_value="20.0" offset_unit="h" enabled="[false]" - created_at="2013-11-20" updated_at="2013-11-22"/> - - - <rules id="1" plugin_rule_key="import" plugin_config_key="regexp" plugin_name="checkstyle" description="[null]" priority="3" status="READY" cardinality="SINGLE" parent_id="[null]" name="Regular exp"/> - </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml index 00a47fd34cc..59f106fe411 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml @@ -1,15 +1,15 @@ <dataset> - <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="2" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="2" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> - <characteristics id="2" kee="TESTABILITY" name="Testability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="2" kee="TESTABILITY" name="Testability" parent_id="[null]" characteristic_order="1" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> - <characteristics id="3" kee="MAINTAINABILITY" name="Maintainability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="4" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="3" kee="MAINTAINABILITY" name="Maintainability" parent_id="[null]" characteristic_order="4" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/shared.xml index d84c39d5d41..e8c52c0a142 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/shared.xml @@ -1,36 +1,23 @@ <dataset> <!-- Root characteristic --> - <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="PORTABILITY" name="Portability" parent_id="[null]" characteristic_order="1" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> <!-- Characteristic --> - <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" root_id="1" rule_id="[null]" characteristic_order="[null]" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="2" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="1" root_id="1" characteristic_order="[null]" + enabled="[true]" created_at="2013-11-20" updated_at="2013-11-22"/> - <!-- Requirement --> - <characteristics id="3" kee="[null]" name="[null]" parent_id="2" root_id="1" rule_id="1" - function_key="linear_offset" factor_value="20.0" factor_unit="mn" offset_value="30.0" offset_unit="h" enabled="[true]" - created_at="2013-11-20" updated_at="[null]"/> - <!-- Disabled root characteristic --> - <characteristics id="4" kee="DISABLED_ROOT_CHARACTERISTIC" name="Disabled root characteristic" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="2" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[false]" + <characteristics id="4" kee="DISABLED_ROOT_CHARACTERISTIC" name="Disabled root characteristic" parent_id="[null]" characteristic_order="2" + enabled="[false]" created_at="2013-11-20" updated_at="2013-11-22"/> <!-- Disabled characteristic --> - <characteristics id="5" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="4" root_id="4" rule_id="[null]" characteristic_order="[null]" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[false]" - created_at="2013-11-20" updated_at="2013-11-22"/> - - <!-- Disabled requirement --> - <characteristics id="6" kee="[null]" name="[null]" parent_id="5" root_id="4" rule_id="1" - function_key="linear_offset" factor_value="30.0" factor_unit="mn" offset_value="20.0" offset_unit="h" enabled="[false]" + <characteristics id="5" kee="DISABLED_CHARACTERISTIC" name="Disabled characteristic" parent_id="4" root_id="4" characteristic_order="[null]" + enabled="[false]" created_at="2013-11-20" updated_at="2013-11-22"/> - - <rules id="1" plugin_rule_key="import" plugin_config_key="regexp" plugin_name="checkstyle" description="[null]" priority="3" status="READY" cardinality="SINGLE" parent_id="[null]" name="Regular exp"/> - </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml index 026a50563e0..1ecd594caba 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml @@ -1,7 +1,6 @@ <dataset> - <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="New name" parent_id="[null]" rule_id="[null]" root_id="[null]" characteristic_order="2" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[false]" + <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="New name" parent_id="[null]" characteristic_order="2" enabled="[false]" created_at="2013-11-20" updated_at="2013-11-22"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic.xml index b4817ece8fa..b7d53e45565 100644 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic.xml +++ b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic.xml @@ -1,7 +1,6 @@ <dataset> - <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" root_id="[null]" rule_id="[null]" characteristic_order="1" - function_key="[null]" factor_value="[null]" factor_unit="[null]" offset_value="[null]" offset_unit="[null]" enabled="[true]" + <characteristics id="1" kee="COMPILER_RELATED_PORTABILITY" name="Compiler related portability" parent_id="[null]" characteristic_order="1" enabled="[true]" created_at="2013-11-20" updated_at="2013-11-20"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement-result.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement-result.xml deleted file mode 100644 index 71c4150f0cf..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement-result.xml +++ /dev/null @@ -1,7 +0,0 @@ -<dataset> - - <characteristics id="1" kee="[null]" name="[null]" parent_id="3" root_id="1" rule_id="2" characteristic_order="[null]" - function_key="linear" factor_value="21.0" factor_unit="h" offset_value="[null]" offset_unit="[null]" enabled="[false]" - created_at="2013-11-20" updated_at="2013-11-22"/> - -</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement.xml b/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement.xml deleted file mode 100644 index 2b1ccb8fd6b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement.xml +++ /dev/null @@ -1,7 +0,0 @@ -<dataset> - - <characteristics id="1" kee="[null]" name="[null]" parent_id="2" root_id="1" rule_id="1" characteristic_order="[null]" - function_key="linear_offset" factor_value="20.0" factor_unit="mn" offset_value="30.0" offset_unit="h" enabled="[true]" - created_at="2013-11-20" updated_at="[null]"/> - -</dataset> diff --git a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java index 7e66966c775..9175a47e8a2 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java @@ -97,7 +97,7 @@ public class RuleRegistration implements Startable { try { RuleDefinitions.Context context = defLoader.load(); Buffer buffer = new Buffer(system.now()); - List<CharacteristicDto> characteristicDtos = characteristicDao.selectCharacteristics(); + List<CharacteristicDto> characteristicDtos = characteristicDao.selectEnabledCharacteristics(); selectRulesFromDb(buffer, sqlSession); enableRuleDefinitions(context, buffer, characteristicDtos, sqlSession); List<RuleDto> removedRules = processRemainingDbRules(buffer, sqlSession); diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/521_copy_debt_to_rules.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/521_copy_debt_to_rules.rb new file mode 100644 index 00000000000..5f6ed481448 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/521_copy_debt_to_rules.rb @@ -0,0 +1,64 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# Sonar 4.3 +# SONAR-5056 +# +class CopyDebtToRules < ActiveRecord::Migration + + class Characteristic < ActiveRecord::Base + end + + class Rule < ActiveRecord::Base + end + + def self.up + Rule.reset_column_information + + requirements = Characteristic.all( + :conditions => ['rule_id IS NOT NULL AND function_key IS NOT NULL AND enabled=?', true] + ) + requirements.each do |requirement| + rule = Rule.find_by_id(requirement.rule_id) + if rule + rule.characteristic_id = requirement.parent_id + # functions are now store in upper case + rule.remediation_function = requirement.function_key.upcase + rule.remediation_factor = to_new_remediation(requirement.factor_value, requirement.factor_unit) + rule.remediation_offset = to_new_remediation(requirement.offset_value, requirement.offset_unit) + rule.save + end + end + end + + def self.to_new_remediation(old_value, old_unit) + if old_value + unit = old_unit || 'd' + unit = unit == 'mn' ? 'min' : unit + # As value is stored in double, we have to round it in order to have an integer (for instance, if it was 1.6, we'll use 2) + old_value.to_f.ceil.to_s + unit + else + '0d' + end + end + +end + diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/522_delete_requirements.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/522_delete_requirements.rb new file mode 100644 index 00000000000..c7312af1c16 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/522_delete_requirements.rb @@ -0,0 +1,46 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2013 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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. +# + +# +# Sonar 4.3 +# SONAR-5056 +# +class DeleteRequirements < ActiveRecord::Migration + + class Characteristic < ActiveRecord::Base + end + + def self.up + Characteristic.reset_column_information + + Characteristic.delete_all('rule_id IS NOT NULL') + + # Remove columns on debt + remove_column('characteristics', 'root_id') + remove_column('characteristics', 'rule_id') + remove_column('characteristics', 'function_key') + remove_column('characteristics', 'factor_value') + remove_column('characteristics', 'factor_unit') + remove_column('characteristics', 'offset_value') + remove_column('characteristics', 'offset_unit') + end + +end + diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml index 8c99f5e4404..3a010942f21 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml @@ -1,6 +1,6 @@ <dataset> - <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Efficiency" root_id="[null]" characteristic_order="[null]" enabled="[true]"/> + <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Efficiency" parent_id="[null]" characteristic_order="[null]" enabled="[true]"/> <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description" status="READY" priority="2" cardinality="SINGLE" parent_id="[null]" diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/remove_rule_debt_definitions_if_characteristic_not_found.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/remove_rule_debt_definitions_if_characteristic_not_found.xml index f926443c2de..6de51e77092 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/remove_rule_debt_definitions_if_characteristic_not_found.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/remove_rule_debt_definitions_if_characteristic_not_found.xml @@ -1,6 +1,6 @@ <dataset> - <characteristics id="999" kee="NEW" name="New" root_id="1" characteristic_order="1" enabled="[true]"/> + <characteristics id="999" kee="NEW" name="New" parent_id="1" characteristic_order="1" enabled="[true]"/> <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description" status="READY" priority="2" cardinality="SINGLE" parent_id="[null]" diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/shared.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/shared.xml index f652085767c..d74823494b0 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/shared.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/shared.xml @@ -1,6 +1,6 @@ <dataset> - <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" parent_id="1" root_id="1" characteristic_order="1" enabled="[true]"/> + <characteristics id="2" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" parent_id="1" characteristic_order="1" enabled="[true]"/> <rules id="1" plugin_rule_key="deprecated-key" plugin_name="deprecated-repo" plugin_config_key="[null]" name="Deprecated" description="[null]" status="READY" priority="4" cardinality="SINGLE" parent_id="[null]"/> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml index 52e585b5fe9..6ab04c32b61 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml @@ -1,6 +1,6 @@ <dataset> - <characteristics id="200" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" parent_id="1" characteristic_order="1" enabled="[true]"/> + <characteristics id="200" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" parent_id="1" characteristic_order="1" enabled="[true]"/> <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description" status="READY" priority="2" cardinality="SINGLE" parent_id="[null]" diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml index 210511b46e1..7821240a5c7 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml @@ -1,23 +1,3 @@ -<!-- - ~ SonarQube, open source software quality management tool. - ~ Copyright (C) 2008-2013 SonarSource - ~ mailto:contact AT sonarsource DOT com - ~ - ~ SonarQube 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. - ~ - ~ SonarQube 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. - --> - <dataset> <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="config1" name="One" description="Description of One" diff --git a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml index a4f65e79ca4..51e70c311d4 100644 --- a/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml +++ b/sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml @@ -1,6 +1,6 @@ <dataset> - <characteristics id="100" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" root_id="1" parent_id="1" characteristic_order="1" enabled="[true]"/> + <characteristics id="100" kee="MEMORY_EFFICIENCY" name="Memory Efficiency" parent_id="1" characteristic_order="1" enabled="[true]"/> <rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="[null]" name="Rule one" description="[null]" status="READY" priority="4" cardinality="MULTIPLE" parent_id="[null]" language="[null]" |