// 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);
}
}
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)) {
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);
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);
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;
.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);
*/
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
.setKey(dto.getKey())
.setName(dto.getName())
.setOrder(dto.getOrder())
- .setParentId(dto.getParentId())
- .setRootId(dto.getRootId());
+ .setParentId(dto.getParentId());
}
}
/**
* @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() {
}
}
- @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);
}
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;
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;
return this;
}
- @CheckForNull
- public Integer getRootId() {
- return rootId;
- }
-
- public CharacteristicDto setRootId(@Nullable Integer rootId) {
- this.rootId = rootId;
- return this;
- }
-
@CheckForNull
public Integer getOrder() {
return characteristicOrder;
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;
}
.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;
- }
-
}
CharacteristicDto selectById(int id);
- CharacteristicDto selectByRuleId(Integer ruleId);
-
void insert(CharacteristicDto characteristic);
int update(CharacteristicDto characteristic);
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;
"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,
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
<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">
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
</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}
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");
}
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;
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();
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
assertThat(dtos.get(2).getKey()).isEqualTo("MAINTAINABILITY");
}
- @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");
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();
}
checkTables("insert_characteristic", EXCLUDED_COLUMNS, "characteristics");
}
- @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");
checkTables("update_characteristic", new String[]{"id", "depth", "description", "quality_model_id", "updated_at"}, "characteristics");
}
- @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");
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;
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();
}
}
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]"
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]"
<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>
<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>
<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>
+++ /dev/null
-<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>
<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>
<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>
<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>
<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>
<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>
+++ /dev/null
-<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>
+++ /dev/null
-<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>
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);
--- /dev/null
+#
+# 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
+
--- /dev/null
+#
+# 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
+
<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]"
<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]"
<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]"/>
<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]"
-<!--
- ~ 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"
<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]"