]> source.dussan.org Git - sonarqube.git/commitdiff
Do not use anymore deprecated WorkUnit
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Feb 2014 09:18:32 +0000 (10:18 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 17 Feb 2014 09:18:32 +0000 (10:18 +0100)
22 files changed:
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
sonar-batch/src/test/java/org/sonar/batch/debt/DebtModelLoaderTest.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManager.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporter.java
sonar-core/src/main/java/org/sonar/core/technicaldebt/db/CharacteristicDto.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtManagerTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtModelSynchronizerTest.java
sonar-core/src/test/java/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest.java
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/ignore_requirement_on_root_characteristics.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldImportXML_badly-formatted.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldImportXML_with_deprecated_constant_per_file.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldImportXML_with_deprecated_linear_with_threshold.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldImportXML_with_linear.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldImportXML_with_linear_with_offset.xml
sonar-core/src/test/resources/org/sonar/core/technicaldebt/TechnicalDebtXMLImporterTest/shouldLogWarningIfRuleNotFound.xml
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirement.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java
sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristic.java
sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java
sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java

index 196d647bf79a759acfd5f766a8a3c5decac11679..1d0dca11f8fcbb467b000e00d0fbc22686f13dbf 100644 (file)
@@ -260,13 +260,13 @@ public class CountUnresolvedIssuesDecorator implements Decorator {
   }
 
   @VisibleForTesting
-  int countIssuesAfterDate(Collection<Issue> issues, @Nullable Date targetDate) {
+  int countIssuesAfterDate(Collection<Issue> issues, @Nullable Date date) {
     if (issues == null) {
       return 0;
     }
     int count = 0;
     for (Issue issue : issues) {
-      if (isAfter(issue, targetDate)) {
+      if (isAfter(issue, date)) {
         count++;
       }
     }
index 1640363b8ef4dc1ea05853358cf031d41c7bba0c..faa25f1d1a987ce1995d1123823ea95e443f151d 100644 (file)
@@ -31,6 +31,7 @@ import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
@@ -108,8 +109,10 @@ public class DebtModelLoaderTest {
     DefaultRequirement requirement = result.requirementsByRule(ruleKey);
     assertThat(requirement.ruleKey()).isEqualTo(ruleKey);
     assertThat(requirement.function()).isEqualTo("linear");
-    assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.DAYS));
-    assertThat(requirement.offset()).isEqualTo(WorkUnit.create(0d, WorkUnit.DAYS));
+    assertThat(requirement.factorValue()).isEqualTo(2);
+    assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
+    assertThat(requirement.offsetValue()).isEqualTo(0);
+    assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
   }
 
 }
index 78d3157cd2410d465b5510ff953991b084f9f017..823064f62042a43ad861c48416876f4cad48e83a 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.technicaldebt.server.Characteristic;
 import org.sonar.api.technicaldebt.server.TechnicalDebtManager;
 import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
-import org.sonar.api.utils.WorkUnit;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
@@ -92,6 +91,8 @@ public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
   }
 
   private static Characteristic toCharacteristic(CharacteristicDto dto, @Nullable RuleKey ruleKey) {
+    Double factorValue = dto.getFactorValue();
+    Double offsetValue = dto.getOffsetValue();
     return new DefaultCharacteristic()
       .setId(dto.getId())
       .setKey(dto.getKey())
@@ -101,8 +102,10 @@ public class DefaultTechnicalDebtManager implements TechnicalDebtManager {
       .setRootId(dto.getRootId())
       .setRuleKey(ruleKey)
       .setFunction(dto.getFunction())
-      .setFactor(WorkUnit.create(dto.getFactorValue(), dto.getFactorUnit()))
-      .setOffset(WorkUnit.create(dto.getOffsetValue(), dto.getOffsetUnit()));
+      .setFactorValue(factorValue != null ? factorValue.intValue() : null)
+      .setFactorUnit(DefaultCharacteristic.toUnit(dto.getFactorUnit()))
+      .setOffsetValue(offsetValue != null ? offsetValue.intValue() : null)
+      .setOffsetUnit(DefaultCharacteristic.toUnit(dto.getOffsetUnit()));
   }
 
 }
index 33ea98e5b7d37919f99f5a848bf6fce945ca1083..817fe76a6ca29b6ddd689c97477fa6dcd67cfee5 100644 (file)
@@ -36,8 +36,10 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import org.sonar.api.utils.ValidationMessages;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
+import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
+import javax.annotation.CheckForNull;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 
@@ -184,7 +186,7 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
   private Property processProperty(SMInputCursor cursor, ValidationMessages messages) throws XMLStreamException {
     SMInputCursor c = cursor.childElementCursor();
     String key = null;
-    Double value = null;
+    int value = 0;
     String textValue = null;
     while (c.getNext() != null) {
       String node = c.getLocalName();
@@ -194,7 +196,9 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
       } else if (StringUtils.equals(node, PROPERTY_VALUE)) {
         String s = c.collectDescendantText().trim();
         try {
-          value = NumberUtils.createDouble(s);
+          // The value is still a double for the moment
+          Double valueDouble = NumberUtils.createDouble(s);
+          value = valueDouble.intValue();
         } catch (NumberFormatException ex) {
           messages.addErrorText(String.format("Cannot import value '%s' for field %s - Expected a numeric value instead", s, key));
         }
@@ -205,16 +209,24 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
     return new Property(key, value, textValue);
   }
 
+  @CheckForNull
   private DefaultRequirement processFunctionsOnRequirement(DefaultRequirement requirement, Properties properties, ValidationMessages messages) {
     Property function = properties.function();
     Property factor = properties.factor();
     Property offset = properties.offset();
 
     if (function != null) {
+      // Requirements should always have values, so we init it with default values
+      requirement.setFactorValue(0);
+      requirement.setFactorUnit(WorkDuration.UNIT.DAYS);
+      requirement.setOffsetValue(0);
+      requirement.setOffsetUnit(WorkDuration.UNIT.DAYS);
+
       String functionKey = function.getTextValue();
       if ("linear_threshold".equals(functionKey)) {
         function.setTextValue(DefaultRequirement.FUNCTION_LINEAR);
-        offset.setValue(0d);
+        offset.setValue(0);
+        offset.setTextValue(CharacteristicDto.DAYS);
         messages.addWarningText(String.format("Linear with threshold function is no more used, function of the requirement '%s' is replaced by linear.", requirement.ruleKey()));
       } else if ("constant_resource".equals(functionKey)) {
         messages.addWarningText(String.format("Constant/file function is no more used, requirements '%s' are ignored.", requirement.ruleKey()));
@@ -223,10 +235,12 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
 
       requirement.setFunction(function.getTextValue());
       if (factor != null) {
-        requirement.setFactor(WorkUnit.create(factor.getValue(), factor.getTextValue()));
+        requirement.setFactorValue(factor.getValue());
+        requirement.setFactorUnit(DefaultRequirement.toUnit(factor.getTextValue()));
       }
       if (offset != null) {
-        requirement.setOffset(WorkUnit.create(offset.getValue(), offset.getTextValue()));
+        requirement.setOffsetValue(offset.getValue());
+        requirement.setOffsetUnit(DefaultRequirement.toUnit(offset.getTextValue()));
       }
       return requirement;
     }
@@ -270,16 +284,16 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
 
   private static class Property {
     String key;
-    Double value;
+    int value;
     String textValue;
 
-    private Property(String key, Double value, String textValue) {
+    private Property(String key, int value, String textValue) {
       this.key = key;
       this.value = value;
       this.textValue = textValue;
     }
 
-    private Property setValue(Double value) {
+    private Property setValue(int value) {
       this.value = value;
       return this;
     }
@@ -293,7 +307,7 @@ public class TechnicalDebtXMLImporter implements ServerExtension {
       return key;
     }
 
-    private Double getValue() {
+    private int getValue() {
       return value;
     }
 
index 86357657a2e5a85f95597534f893a1a4d4665c6b..ae72bbf0e817c8335c6e63c3bc3bc2c6cdaca2a8 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.core.technicaldebt.db;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -33,6 +33,10 @@ import java.util.Date;
 
 public class CharacteristicDto implements Serializable {
 
+  public static final String DAYS = "d";
+  public static final String MINUTES = "mn";
+  public static final String HOURS = "h";
+
   private Integer id;
   private String kee;
   private String name;
@@ -227,8 +231,10 @@ public class CharacteristicDto implements Serializable {
       .setCharacteristic(characteristic)
       .setRootCharacteristic(rootCharacteristic)
       .setFunction(functionKey)
-      .setFactor(WorkUnit.create(factorValue, factorUnit))
-      .setOffset(WorkUnit.create(offsetValue, offsetUnit))
+      .setFactorValue(factorValue.intValue())
+      .setFactorUnit(toUnit(factorUnit))
+      .setOffsetValue(offsetValue.intValue())
+      .setOffsetUnit(toUnit(offsetUnit))
       .setCreatedAt(createdAt)
       .setUpdatedAt(updatedAt);
   }
@@ -239,13 +245,41 @@ public class CharacteristicDto implements Serializable {
       .setParentId(characteristicId)
       .setRootId(rootCharacteristicId)
       .setFunction(requirement.function())
-      .setFactorValue(requirement.factor().getValue())
-      .setFactorUnit(requirement.factor().getUnit())
-      .setOffsetValue(requirement.offset().getValue())
-      .setOffsetUnit(requirement.offset().getUnit())
+      .setFactorValue((double) requirement.factorValue())
+      .setFactorUnit(fromUnit(requirement.factorUnit()))
+      .setOffsetValue((double) requirement.offsetValue())
+      .setOffsetUnit(fromUnit(requirement.offsetUnit()))
       .setEnabled(true)
       .setCreatedAt(requirement.createdAt())
       .setUpdatedAt(requirement.updatedAt());
   }
 
+  public static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) {
+    if (requirementUnit != null) {
+      if (requirementUnit.equals(DAYS)) {
+        return WorkDuration.UNIT.DAYS;
+      } else if (requirementUnit.equals(HOURS)) {
+        return WorkDuration.UNIT.HOURS;
+      } else if (requirementUnit.equals(MINUTES)) {
+        return WorkDuration.UNIT.MINUTES;
+      }
+      throw new IllegalStateException("Invalid unit : " + requirementUnit);
+    }
+    return null;
+  }
+
+  public static String fromUnit(@Nullable WorkDuration.UNIT unit) {
+    if (unit != null) {
+      if (unit.equals(WorkDuration.UNIT.DAYS)) {
+        return DAYS;
+      } else if (unit.equals(WorkDuration.UNIT.HOURS)) {
+        return HOURS;
+      } else if (unit.equals(WorkDuration.UNIT.MINUTES)) {
+        return MINUTES;
+      }
+      throw new IllegalStateException("Invalid unit : " + unit);
+    }
+    return null;
+  }
+
 }
index 2e66f1ebd55818e4c4c2d8cbfc49c516809df860..f6369fe9209dd72a379dbec30badfb2e04255a04 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
 import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 
@@ -80,7 +80,10 @@ public class DefaultTechnicalDebtManagerTest {
     rule.setId(1);
 
     when(dao.selectByRuleId(rule.getId())).thenReturn(
-      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear").setFactorValue(30.0).setFactorUnit("mn"));
+      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear")
+        .setFactorValue(30.0).setFactorUnit("mn")
+        .setOffsetValue(0.0).setOffsetUnit("d")
+    );
 
     Characteristic result = finder.findRequirementByRule(rule);
 
@@ -89,8 +92,10 @@ public class DefaultTechnicalDebtManagerTest {
     assertThat(result.rootId()).isEqualTo(1);
     assertThat(result.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
     assertThat(result.function()).isEqualTo("linear");
-    assertThat(result.factor()).isEqualTo(WorkUnit.create(30d, WorkUnit.MINUTES));
-    assertThat(result.offset()).isEqualTo(WorkUnit.create(0d, WorkUnit.DAYS));
+    assertThat(result.factorValue()).isEqualTo(30);
+    assertThat(result.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
+    assertThat(result.offsetValue()).isEqualTo(0);
+    assertThat(result.offsetUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
   }
 
   @Test
@@ -140,7 +145,10 @@ public class DefaultTechnicalDebtManagerTest {
     when(ruleFinder.findById(1)).thenReturn(rule);
 
     when(dao.selectByRuleId(rule.getId())).thenReturn(
-      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear").setFactorValue(30.0).setFactorUnit("mn"));
+      new CharacteristicDto().setId(3).setRuleId(10).setParentId(2).setRootId(1).setFunction("linear")
+        .setFactorValue(30.0).setFactorUnit("mn")
+        .setOffsetValue(0.0).setOffsetUnit("d")
+    );
 
     Characteristic result = finder.findRequirementByRuleId(1);
 
@@ -149,8 +157,11 @@ public class DefaultTechnicalDebtManagerTest {
     assertThat(result.rootId()).isEqualTo(1);
     assertThat(result.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
     assertThat(result.function()).isEqualTo("linear");
-    assertThat(result.factor()).isEqualTo(WorkUnit.create(30d, WorkUnit.MINUTES));
-    assertThat(result.offset()).isEqualTo(WorkUnit.create(0d, WorkUnit.DAYS));
+    assertThat(result.factorValue()).isEqualTo(30);
+    assertThat(result.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
+    assertThat(result.offsetValue()).isEqualTo(0);
+    assertThat(result.offsetUnit()).isEqualTo(WorkDuration.UNIT.DAYS);
+
   }
 
   @Test
index dcf61654fc317a882dc706c60189ae308dd1ab86..246269c48c3f5b30035db44238fcd2e2b6c6a7ce 100644 (file)
@@ -25,7 +25,7 @@ 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.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -92,8 +92,10 @@ public class DefaultTechnicalDebtModelTest {
       .setCharacteristic(characteristic)
       .setRuleKey(ruleKey)
       .setFunction("linear")
-      .setFactor(WorkUnit.create(2d, WorkUnit.HOURS))
-      .setOffset(WorkUnit.create(0d, WorkUnit.HOURS));
+      .setFactorValue(2)
+      .setFactorUnit(WorkDuration.UNIT.HOURS)
+      .setOffsetValue(0)
+      .setOffsetUnit(WorkDuration.UNIT.HOURS);
 
     sqaleModel.addRootCharacteristic(rootCharacteristic);
 
index 774f80d890d43590c3c2c998ea16b85f8a8fc50c..9baa526ce67fe3944a6c3687596eff1af2692116 100644 (file)
@@ -35,7 +35,7 @@ import org.sonar.api.rules.Rule;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import org.sonar.api.utils.ValidationMessages;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
@@ -142,7 +142,11 @@ public class TechnicalDebtModelSynchronizerTest {
     RuleKey ruleKey = RuleKey.of("checkstyle", "import");
     when(ruleCache.getByRuleKey(ruleKey)).thenReturn(rule);
     new DefaultRequirement().setRuleKey(ruleKey)
-      .setFunction("linear").setFactor(WorkUnit.create(30d, WorkUnit.MINUTES)).setCharacteristic(javaCharacteristic).setRootCharacteristic(javaRootCharacteristic);
+      .setFunction("linear")
+      .setFactorValue(30)
+      .setFactorUnit(WorkDuration.UNIT.MINUTES)
+      .setCharacteristic(javaCharacteristic)
+      .setRootCharacteristic(javaRootCharacteristic);
 
     Reader javaModelReader = mock(Reader.class);
     when(xmlImporter.importXML(eq(javaModelReader), any(ValidationMessages.class), eq(ruleCache))).thenReturn(javaModel);
@@ -195,7 +199,11 @@ public class TechnicalDebtModelSynchronizerTest {
 
     // New requirement
     new DefaultRequirement().setRuleKey(ruleKey2)
-      .setFunction("linear").setFactor(WorkUnit.create(1d, WorkUnit.HOURS)).setCharacteristic(javaCharacteristic).setRootCharacteristic(javaRootCharacteristic);
+      .setFunction("linear")
+      .setFactorValue(1)
+      .setFactorUnit(WorkDuration.UNIT.HOURS)
+      .setCharacteristic(javaCharacteristic)
+      .setRootCharacteristic(javaRootCharacteristic);
 
     Reader javaModelReader = mock(Reader.class);
     when(technicalDebtModelRepository.createReaderForXMLFile("java")).thenReturn(javaModelReader);
index 5dad54e04308c83a48e62ae39e8543b26591e734..05138280dbf911d7fe9d78a74539e7f590743833 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.api.rules.RuleQuery;
 import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic;
 import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement;
 import org.sonar.api.utils.ValidationMessages;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
 
 import java.io.IOException;
 
@@ -89,7 +89,7 @@ public class TechnicalDebtXMLImporterTest {
     ValidationMessages messages = ValidationMessages.create();
     DefaultTechnicalDebtModel sqale = new TechnicalDebtXMLImporter().importXML(xml, messages, technicalDebtRuleCache);
 
-    checkXmlCorrectlyImported(sqale, WorkUnit.create(1.0, "h"), messages);
+    checkXmlCorrectlyImported(sqale, 1, WorkDuration.UNIT.HOURS, messages);
   }
 
   @Test
@@ -101,7 +101,7 @@ public class TechnicalDebtXMLImporterTest {
     ValidationMessages messages = ValidationMessages.create();
     DefaultTechnicalDebtModel sqale = new TechnicalDebtXMLImporter().importXML(xml, messages, technicalDebtRuleCache);
 
-    checkXmlCorrectlyImported(sqale, WorkUnit.create(0.0, "h"), messages);
+    checkXmlCorrectlyImported(sqale, 0, WorkDuration.UNIT.DAYS, messages);
     assertThat(messages.getWarnings()).hasSize(1);
   }
 
@@ -189,10 +189,10 @@ public class TechnicalDebtXMLImporterTest {
   }
 
   private void checkXmlCorrectlyImported(DefaultTechnicalDebtModel sqale, ValidationMessages messages) {
-    checkXmlCorrectlyImported(sqale, WorkUnit.create(0d, WorkUnit.DAYS), messages);
+    checkXmlCorrectlyImported(sqale, 0, WorkDuration.UNIT.DAYS, messages);
   }
 
-  private void checkXmlCorrectlyImported(DefaultTechnicalDebtModel sqale, WorkUnit offset, ValidationMessages messages) {
+  private void checkXmlCorrectlyImported(DefaultTechnicalDebtModel sqale, Integer offsetValue, WorkDuration.UNIT offsetUnit, ValidationMessages messages) {
     assertThat(messages.getErrors()).isEmpty();
 
     // characteristics
@@ -211,8 +211,10 @@ public class TechnicalDebtXMLImporterTest {
     assertThat(requirement.ruleKey().repository()).isEqualTo("checkstyle");
     assertThat(requirement.ruleKey().rule()).isEqualTo("Regexp");
     assertThat(requirement.function()).isEqualTo("linear");
-    assertThat(requirement.factor()).isEqualTo(WorkUnit.create(3.2, "h"));
-    assertThat(requirement.offset()).isEqualTo(offset);
+    assertThat(requirement.factorValue()).isEqualTo(3);
+    assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
+    assertThat(requirement.offsetValue()).isEqualTo(offsetValue);
+    assertThat(requirement.offsetUnit()).isEqualTo(offsetUnit);
     assertThat(requirement.characteristic().key()).isEqualTo("MEMORY_EFFICIENCY");
     assertThat(requirement.rootCharacteristic().key()).isEqualTo("EFFICIENCY");
   }
index af9e9f4748e51c5a9567a5e0f9cfbd4772487b85..bcf3ed867d3b3e13c129bb6c652ebc04f9652029 100644 (file)
@@ -7,7 +7,7 @@
       <rule-key>Regexp</rule-key>
       <prop>
         <key>remediationFactor</key>
-        <val>3.2</val>
+        <val>3.0</val>
         <txt>h</txt>
       </prop>
       <prop>
index db64d45ba5fdf0ae0fe5d7ac451d6ca762c3fbf8..6c7d153992c504b45599d7ee59de2237204a6d04 100644 (file)
@@ -25,7 +25,7 @@
         <prop>
           <key>remediationFactor
           </key>
-          <val>3.2
+          <val>3.0
           </val>
           <txt>h
           </txt>
index ca49d873ca552ad0223045d2d78df70282fa3cab..4b8ae3f647581bc85b61de3c37cc7189ac24267b 100644 (file)
@@ -11,7 +11,7 @@
         <rule-key>Regexp</rule-key>
         <prop>
           <key>remediationFactor</key>
-          <val>3.2</val>
+          <val>3.0</val>
           <txt>h</txt>
         </prop>
         <prop>
index 1a9fbfd0c6a0e8499b2bf62fa267045129c6774d..9ebc69b94a6373da310cee3a49c7a238cc5df78f 100644 (file)
@@ -20,7 +20,7 @@
         </prop>
         <prop>
           <key>remediationFactor</key>
-          <val>3.2</val>
+          <val>3.0</val>
           <txt>h</txt>
         </prop>
         <!-- Should be ignored -->
index 554df10e6404c753e5be4b43524c68bef27b8ec1..f641a5185ecc54fc7a2cb259c059d241a09d43b3 100644 (file)
@@ -15,7 +15,7 @@
         <rule-key>Regexp</rule-key>
         <prop>
           <key>remediationFactor</key>
-          <val>3.2</val>
+          <val>3.0</val>
           <txt>h</txt>
         </prop>
         <prop>
index b20a3afd2792fe03a8c6fa00099d946fe9d66783..d12f70d0e2dd06a9e8d4550e3132a2940b574417 100644 (file)
@@ -15,7 +15,7 @@
         <rule-key>Regexp</rule-key>
         <prop>
           <key>remediationFactor</key>
-          <val>3.2</val>
+          <val>3.0</val>
           <txt>h</txt>
         </prop>
         <prop>
index cf4edb394e5d35fcf8e89e5c178c0849dfe5e25b..2898f458e3f2c633e1a4c369955e8cf553df4214 100644 (file)
@@ -10,7 +10,7 @@
         <rule-key>Foo</rule-key>
         <prop>
           <key>remediationFactor</key>
-          <val>3.2</val>
+          <val>3.0</val>
           <txt>h</txt>
         </prop>
         <prop>
index 6e4116edc637e050bb73f8e8a055011cb92536bf..60e41eb5e9603bf93cd556e3f749c5cec9f01466 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.api.technicaldebt.batch;
 
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
 import java.util.Date;
@@ -40,10 +41,38 @@ public interface Requirement {
 
   String function();
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   WorkUnit factor();
 
+  /**
+   * @since 4.2
+   */
+  int factorValue();
+
+  /**
+   * @since 4.2
+   */
+  WorkDuration.UNIT factorUnit();
+
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   WorkUnit offset();
 
+  /**
+   * @since 4.2
+   */
+  int offsetValue();
+
+  /**
+   * @since 4.2
+   */
+  WorkDuration.UNIT offsetUnit();
+
   Date createdAt();
 
   Date updatedAt();
index d8fca31d1f27efb0d477e51e8c4c211c4ff128e7..c8828e61eb9c51fb6a879bfede459818035ff8ed 100644 (file)
@@ -22,11 +22,14 @@ package org.sonar.api.technicaldebt.batch.internal;
 
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
+import org.picocontainer.annotations.Nullable;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.technicaldebt.batch.Requirement;
 import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
+import javax.annotation.CheckForNull;
+
 import java.util.Date;
 
 public class DefaultRequirement implements Requirement {
@@ -45,17 +48,10 @@ public class DefaultRequirement implements Requirement {
   private WorkDuration.UNIT factorUnit;
   private int offsetValue;
   private WorkDuration.UNIT offsetUnit;
-  private WorkUnit factor;
-  private WorkUnit offset;
 
   private Date createdAt;
   private Date updatedAt;
 
-  public DefaultRequirement() {
-    this.factor = WorkUnit.create(0d, WorkUnit.DAYS);
-    this.offset = WorkUnit.create(0d, WorkUnit.DAYS);
-  }
-
   public Integer id() {
     return id;
   }
@@ -107,8 +103,7 @@ public class DefaultRequirement implements Requirement {
    */
   @Deprecated
   public WorkUnit factor() {
-    return factor;
-//    return WorkUnit.create((double) factorValue, fromUnit(factorUnit));
+    return WorkUnit.create((double) factorValue, fromUnit(factorUnit));
   }
 
   /**
@@ -116,24 +111,8 @@ public class DefaultRequirement implements Requirement {
    */
   @Deprecated
   public DefaultRequirement setFactor(WorkUnit factor) {
-    this.factor = factor;
-    return this;
-  }
-
-  /**
-   * @deprecated since 4.2
-   */
-  @Deprecated
-  public WorkUnit offset() {
-    return offset;
-  }
-
-  /**
-   * @deprecated since 4.2
-   */
-  @Deprecated
-  public DefaultRequirement setOffset(WorkUnit offset) {
-    this.offset = offset;
+    this.factorValue = (int) factor.getValue();
+    this.factorUnit = toUnit(factor.getUnit());
     return this;
   }
 
@@ -146,15 +125,34 @@ public class DefaultRequirement implements Requirement {
     return this;
   }
 
+  @CheckForNull
   public WorkDuration.UNIT factorUnit() {
     return factorUnit;
   }
 
-  public DefaultRequirement setFactorUnit(WorkDuration.UNIT factorUnit) {
+  public DefaultRequirement setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) {
     this.factorUnit = factorUnit;
     return this;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
+  public WorkUnit offset() {
+    return WorkUnit.create((double) offsetValue, fromUnit(offsetUnit));
+  }
+
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
+  public DefaultRequirement setOffset(WorkUnit offset) {
+    this.offsetValue = (int) offset.getValue();
+    this.offsetUnit = toUnit(offset.getUnit());
+    return this;
+  }
+
   public int offsetValue() {
     return offsetValue;
   }
@@ -164,11 +162,12 @@ public class DefaultRequirement implements Requirement {
     return this;
   }
 
+  @CheckForNull
   public WorkDuration.UNIT offsetUnit() {
     return offsetUnit;
   }
 
-  public DefaultRequirement setOffsetUnit(WorkDuration.UNIT offsetUnit) {
+  public DefaultRequirement setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) {
     this.offsetUnit = offsetUnit;
     return this;
   }
@@ -191,7 +190,7 @@ public class DefaultRequirement implements Requirement {
     return this;
   }
 
-  private static WorkDuration.UNIT toUnit(String requirementUnit){
+  public static WorkDuration.UNIT toUnit(String requirementUnit){
     if (requirementUnit.equals(WorkUnit.DAYS)) {
       return WorkDuration.UNIT.DAYS;
     } else if (requirementUnit.equals(WorkUnit.HOURS)) {
index dc227360496cd546cfea080139436423a8682fc5..0b016e172bc3c971e3bc2cd999ae1227101144bc 100644 (file)
@@ -21,6 +21,7 @@
 package org.sonar.api.technicaldebt.server;
 
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
 import javax.annotation.CheckForNull;
@@ -48,10 +49,44 @@ public interface Characteristic {
 
   String function();
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
+  @CheckForNull
   WorkUnit factor();
 
+  /**
+   * @since 4.2
+   */
+  @CheckForNull
+  Integer factorValue();
+
+  /**
+   * @since 4.2
+   */
+  @CheckForNull
+  WorkDuration.UNIT factorUnit();
+
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
+  @CheckForNull
   WorkUnit offset();
 
+  /**
+   * @since 4.2
+   */
+  @CheckForNull
+  Integer offsetValue();
+
+  /**
+   * @since 4.2
+   */
+  @CheckForNull
+  WorkDuration.UNIT offsetUnit();
+
   boolean isRoot();
 
   boolean isRequirement();
index 3bac7310762400cf6cd2afd319d2da84e804432a..c27f94cab74bbba2caa2d9325e1cdbdf71f1f825 100644 (file)
@@ -24,6 +24,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.technicaldebt.server.Characteristic;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
 import javax.annotation.CheckForNull;
@@ -42,8 +43,10 @@ public class DefaultCharacteristic implements Characteristic {
   private Integer rootId;
   private RuleKey ruleKey;
   private String function;
-  private WorkUnit factor;
-  private WorkUnit offset;
+  private Integer factorValue;
+  private WorkDuration.UNIT factorUnit;
+  private Integer offsetValue;
+  private WorkDuration.UNIT offsetUnit;
 
   public Integer id() {
     return id;
@@ -124,26 +127,118 @@ public class DefaultCharacteristic implements Characteristic {
     return this;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   @CheckForNull
   public WorkUnit factor() {
-    return factor;
+    if (factorValue!= null && factorUnit!= null) {
+      return WorkUnit.create((double) factorValue, fromUnit(factorUnit));
+    }
+    return null;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   public DefaultCharacteristic setFactor(@Nullable WorkUnit factor) {
-    this.factor = factor;
+    if (factor != null) {
+      this.factorValue = (int) factor.getValue();
+      this.factorUnit = toUnit(factor.getUnit());
+    }
     return this;
   }
 
   @CheckForNull
+  public Integer factorValue() {
+    return factorValue;
+  }
+
+  public DefaultCharacteristic setFactorValue(@Nullable Integer factorValue) {
+    this.factorValue = factorValue;
+    return this;
+  }
+
+  @CheckForNull
+  public WorkDuration.UNIT factorUnit() {
+    return factorUnit;
+  }
+
+  public DefaultCharacteristic setFactorUnit(@Nullable WorkDuration.UNIT factorUnit) {
+    this.factorUnit = factorUnit;
+    return this;
+  }
+
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   public WorkUnit offset() {
-    return offset;
+    if (offsetValue!= null && offsetUnit!= null) {
+    return WorkUnit.create((double) offsetValue, fromUnit(offsetUnit));
+    }
+    return null;
   }
 
+  /**
+   * @deprecated since 4.2
+   */
+  @Deprecated
   public DefaultCharacteristic setOffset(@Nullable WorkUnit offset) {
-    this.offset = offset;
+    if (offset != null) {
+      this.offsetValue = (int) offset.getValue();
+      this.offsetUnit = toUnit(offset.getUnit());
+    }
     return this;
   }
 
+  @CheckForNull
+  public Integer offsetValue() {
+    return offsetValue;
+  }
+
+  public DefaultCharacteristic setOffsetValue(@Nullable Integer offsetValue) {
+    this.offsetValue = offsetValue;
+    return this;
+  }
+
+  @CheckForNull
+  public WorkDuration.UNIT offsetUnit() {
+    return offsetUnit;
+  }
+
+  public DefaultCharacteristic setOffsetUnit(@Nullable WorkDuration.UNIT offsetUnit) {
+    this.offsetUnit = offsetUnit;
+    return this;
+  }
+
+  public static WorkDuration.UNIT toUnit(@Nullable String requirementUnit) {
+    if (requirementUnit != null) {
+      if (requirementUnit.equals(WorkUnit.DAYS)) {
+        return WorkDuration.UNIT.DAYS;
+      } else if (requirementUnit.equals(WorkUnit.HOURS)) {
+        return WorkDuration.UNIT.HOURS;
+      } else if (requirementUnit.equals(WorkUnit.MINUTES)) {
+        return WorkDuration.UNIT.MINUTES;
+      }
+      throw new IllegalStateException("Invalid unit : " + requirementUnit);
+    }
+    return null;
+  }
+
+  private static String fromUnit(WorkDuration.UNIT unit){
+    if (unit.equals(WorkDuration.UNIT.DAYS)) {
+      return WorkUnit.DAYS;
+    } else if (unit.equals(WorkDuration.UNIT.HOURS)) {
+      return WorkUnit.HOURS;
+    } else if (unit.equals(WorkDuration.UNIT.MINUTES)) {
+      return WorkUnit.MINUTES;
+    }
+    throw new IllegalStateException("Invalid unit : " + unit);
+  }
+
   public boolean isRoot() {
     return parentId == null;
   }
index 918b5918f183a921996ca02b31e42ab2d1d959ef..343ec3285cc8b8338203a7c8d08935416a90ef03 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.api.technicaldebt.batch.internal;
 
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
 import java.text.SimpleDateFormat;
@@ -47,8 +48,10 @@ public class DefaultRequirementTest {
       .setCharacteristic(characteristic)
       .setRootCharacteristic(root)
       .setFunction("linear_offset")
-      .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
-      .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
+      .setFactorValue(2)
+      .setFactorUnit(WorkDuration.UNIT.MINUTES)
+      .setOffsetValue(1)
+      .setOffsetUnit(WorkDuration.UNIT.HOURS)
       .setCreatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"))
       .setUpdatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
 
@@ -57,7 +60,11 @@ public class DefaultRequirementTest {
     assertThat(requirement.characteristic()).isEqualTo(characteristic);
     assertThat(requirement.rootCharacteristic()).isEqualTo(root);
     assertThat(requirement.function()).isEqualTo("linear_offset");
+    assertThat(requirement.factorValue()).isEqualTo(2);
+    assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
     assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+    assertThat(requirement.offsetValue()).isEqualTo(1);
+    assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
     assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
     assertThat(requirement.createdAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
     assertThat(requirement.updatedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
index 6cdb209c18fec05a71836831a16b21328038324f..193e5c5b145201f21529e64a342454e2f6857e83 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.api.technicaldebt.server.internal;
 
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.WorkDuration;
 import org.sonar.api.utils.WorkUnit;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -44,7 +45,11 @@ public class DefaultCharacteristicTest {
     assertThat(characteristic.order()).isEqualTo(5);
     assertThat(characteristic.ruleKey()).isNull();
     assertThat(characteristic.function()).isNull();
+    assertThat(characteristic.factorValue()).isNull();
+    assertThat(characteristic.factorUnit()).isNull();
     assertThat(characteristic.factor()).isNull();
+    assertThat(characteristic.offsetValue()).isNull();
+    assertThat(characteristic.offsetUnit()).isNull();
     assertThat(characteristic.offset()).isNull();
     assertThat(characteristic.parentId()).isEqualTo(2);
     assertThat(characteristic.rootId()).isEqualTo(2);
@@ -56,8 +61,10 @@ public class DefaultCharacteristicTest {
       .setId(1)
       .setRuleKey(RuleKey.of("repo", "rule"))
       .setFunction("linear_offset")
-      .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
-      .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
+      .setFactorValue(2)
+      .setFactorUnit(WorkDuration.UNIT.MINUTES)
+      .setOffsetValue(1)
+      .setOffsetUnit(WorkDuration.UNIT.HOURS)
       .setRootId(3)
       .setParentId(2);
 
@@ -67,7 +74,11 @@ public class DefaultCharacteristicTest {
     assertThat(requirement.order()).isNull();
     assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
     assertThat(requirement.function()).isEqualTo("linear_offset");
+    assertThat(requirement.factorValue()).isEqualTo(2);
+    assertThat(requirement.factorUnit()).isEqualTo(WorkDuration.UNIT.MINUTES);
     assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+    assertThat(requirement.offsetValue()).isEqualTo(1);
+    assertThat(requirement.offsetUnit()).isEqualTo(WorkDuration.UNIT.HOURS);
     assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
     assertThat(requirement.parentId()).isEqualTo(2);
     assertThat(requirement.rootId()).isEqualTo(3);
@@ -92,15 +103,16 @@ public class DefaultCharacteristicTest {
       .setId(1)
       .setRuleKey(RuleKey.of("repo", "rule"))
       .setFunction("linear_offset")
-      .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
-      .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
+      .setFactorValue(2)
+      .setFactorUnit(WorkDuration.UNIT.MINUTES)
+      .setOffsetValue(1)
+      .setOffsetUnit(WorkDuration.UNIT.HOURS)
       .setRootId(3)
       .setParentId(2);
 
     assertThat(requirement.isRequirement()).isTrue();
   }
 
-
   @Test
   public void test_equals() throws Exception {
     assertThat(new DefaultCharacteristic().setKey("NETWORK_USE")).isEqualTo(new DefaultCharacteristic().setKey("NETWORK_USE"));