]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 Add migration to copy data on requirements from characteristics to rules...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 16:24:42 +0000 (17:24 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 16:24:53 +0000 (17:24 +0100)
37 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/TechnicalDebtDecoratorTest.java
sonar-batch/src/main/java/org/sonar/batch/debt/DebtModelProvider.java
sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelProviderTest.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDao.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicMapper.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/main/resources/org/sonar/core/technicaldebt/db/CharacteristicMapper.xml
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDaoTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/db/CharacteristicDtoTest.java
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable-result.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/disable.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_characteristic-result.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/insert_requirement-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/select_enabled_root_characteristics_order_by_characteristic_order.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic-result.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_characteristic.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/core/technicaldebt/db/CharacteristicDaoTest/update_requirement.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/rule/RuleRegistration.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/521_copy_debt_to_rules.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/522_delete_requirements.rb [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/ignore_rule_debt_definitions_if_rule_is_linked_on_root_characteristic.xml
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/remove_rule_debt_definitions_if_characteristic_not_found.xml
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/shared.xml
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_rule_fields.xml
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language-result.xml
sonar-server/src/test/resources/org/sonar/server/rule/RuleRegistrationTest/update_template_rule_language.xml

index 359f348cc7c0fc68e8841c5a001009277b44170c..b274eeb6915cd0eeafdfacaabfb59bad276fe40f 100644 (file)
@@ -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);
     }
   }
index cc98836f0493827ada3db67d2071afb9e828b220..158713b6507d992c2956cd753a7b47f9ce1aed86 100644 (file)
@@ -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)) {
index 237bfa3d93b4c4d7ed3167a3402eab216fd5ed83..a8a061faa9abce2ddeecbb55f7dc730ca701b25f 100644 (file)
@@ -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);
index 50e08fc793cd5c77f366fc2c4f5f7d6aba211ec8..5bed2d878c04a44b771ffe0ccdd82d33ab1c83e7 100644 (file)
@@ -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);
index c7c6fa7bb118ab96d2d9b1a4f4bd3b5b4dbd2604..a5dd5961d366af8e408a2032d69bb342b4495d54 100644 (file)
@@ -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
index 8a65bbe586cd288703e56e494ecf341cb0a424a1..cdc9d4ae1e25007654263c4554ed405c021a2bfe 100644 (file)
@@ -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());
   }
 
 }
index 491d77d17ed6c63b1ac20de8974224d28aa5c14d..71ca2f170e364428b3f328e8846d5af61e9a4044 100644 (file)
@@ -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);
   }
index 18a1bb9034dd87fe10ca84d62dabed9e32ae803e..cfd0e1466d4ebe18108b0626e6713d5e363d5f20 100644 (file)
 
 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;
@@ -92,16 +82,6 @@ public class CharacteristicDto implements Serializable {
     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;
@@ -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;
-  }
-
 }
index 7ab1b291874aacafeb4f47cac8111a6a9984e3a3..7439389021cc0004683898dbd078b5361170716f 100644 (file)
@@ -34,8 +34,6 @@ public interface CharacteristicMapper {
 
   CharacteristicDto selectById(int id);
 
-  CharacteristicDto selectByRuleId(Integer ruleId);
-
   void insert(CharacteristicDto characteristic);
 
   int update(CharacteristicDto characteristic);
index 01b91d42ffc6567401a8489ac649208dc40802d5..1761f27ecec5889419c44bd33697adff634d045c 100644 (file)
@@ -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;
index 7292b42d6d9760ca956d3fd562b6731fced4b6c2..058641b81da719831e00dc3d137e0f4117d95f3f 100644 (file)
@@ -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,
index 2988115ae1688f599b35d74c699cbb66e14fc1bc..4cf3ea98e7f92c6ea0ef116546fd7d711bf862ed 100644 (file)
@@ -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
   <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
     </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}
index 99c83b33dd7dba26b44ae8a4eb52fdfbbb3b29ad..89b71be51bff3cc5a8e428e3d4e43f7e80b85b7b 100644 (file)
@@ -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");
   }
index 0e4341ab81c77ecce792b12f050e879f64d39cd0..03f62c5cae501dfb3e31898014a0ec50278dae99 100644 (file)
@@ -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
@@ -146,18 +101,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
     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");
@@ -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();
   }
@@ -201,25 +142,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
     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");
@@ -239,29 +161,6 @@ public class CharacteristicDaoTest extends AbstractDaoTestCase {
     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");
index f6730185360bff6eac16bde64d936d6c3eceb873..75c6a2f8cf087574dae1fef5225a9de1ae1eaf71 100644 (file)
 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();
   }
 }
index d5ad7fc62d47a9da972056e03346e00c1f446c87..81249826cc2d4aaa0cf06ae00e7cc60585a143f0 100644 (file)
@@ -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]"
index 23ec5986e5ba4a1bccbd0a2d5a1507969d5d3580..83204ee61d6f9c1925ffd5f7500f9703e323369d 100644 (file)
@@ -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]"
index 81b97e0b518924208a0f3acab5f1e9ba29ea92f4..04d1f65ac3e73df03959e5d8a0a65ce0c64df1ff 100644 (file)
@@ -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>
index a970b3244569ad0c00ac58262af3c728c4ff20fb..dd69c61296d92db2dcdd13e8122e3ddaf7f5c218 100644 (file)
@@ -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>
index b6e2d5df640aaca04da97fb036a95a7a79ee9751..51d29ef914a2c9590c3b14c67f2e87b91bbe8a83 100644 (file)
@@ -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 (file)
index 2b1ccb8..0000000
+++ /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>
index c8200af28251434ae75ae8e3ec60374899d7a700..ed75d063f9f5d40cc23181a2cadacc878de86507 100644 (file)
@@ -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>
index 00a47fd34cc930e5c5ff245665470e7509faea70..59f106fe411f944d1f69a951d7dd392fe78732d0 100644 (file)
@@ -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>
index d84c39d5d41e6d4fa751bfcabe655707388e8dcf..e8c52c0a142f9bd87b739cb76f6cde9afd408b6f 100644 (file)
@@ -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>
index 026a50563e078a969fdeb7064778df4e901206b7..1ecd594caba147144c86458e51ebd70366dbb2da 100644 (file)
@@ -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>
index b4817ece8fa5c0b226708479c4545dc0320d8ce9..b7d53e4556564826023bb02ffef3772981cc62b3 100644 (file)
@@ -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 (file)
index 71c4150..0000000
+++ /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 (file)
index 2b1ccb8..0000000
+++ /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>
index 7e66966c7758297df1012815e90ee39bd5fe88e1..9175a47e8a24695875150386b672c3c46024b729 100644 (file)
@@ -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 (file)
index 0000000..5f6ed48
--- /dev/null
@@ -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 (file)
index 0000000..c7312af
--- /dev/null
@@ -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
+
index 8c99f5e44044b9a3a1a8cf0108b77cba61463863..3a010942f2118a8e1970cbac392057900ca6fbbd 100644 (file)
@@ -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]"
index f926443c2de86751677c6481864a8f11996c96fb..6de51e77092c773263616d834f6719488f61d844 100644 (file)
@@ -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]"
index f652085767c6eab5ce435491b25f65b26a6fc304..d74823494b094834f6e5ad7177cd0b050d390366 100644 (file)
@@ -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]"/>
index 52e585b5fe9e771555929e0d3353791f4b95ee05..6ab04c32b6104a2c3efd8c90125d09bc4e9b61a3 100644 (file)
@@ -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]"
index 210511b46e1ac2844a84587e8ab22283be95383d..7821240a5c7ce322bedcbb195e7e3b77650eb74a 100644 (file)
@@ -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"
index a4f65e79ca4f5ac661c5a3a8900a08cddb970265..51e70c311d47cc8a653cc38275494c0e91c7f79a 100644 (file)
@@ -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]"