public NewRule setRemediationFactor(@Nullable String remediationFactor) {
// TODO validate format
- this.remediationFactor = remediationFactor;
+ this.remediationFactor = StringUtils.deleteWhitespace(remediationFactor);
return this;
}
public NewRule setRemediationOffset(@Nullable String remediationOffset) {
// TODO validate format
- this.remediationOffset = remediationOffset;
+ this.remediationOffset = StringUtils.deleteWhitespace(remediationOffset);
return this;
}
*/
package org.sonar.api.server.rule;
+import org.junit.Ignore;
import org.junit.Test;
import org.sonar.api.rule.RemediationFunction;
import org.sonar.api.rule.RuleStatus;
assertThat(rule.name()).isEqualTo("NullPointer");
}
+ @Test
+ public void sanitize_remediation_factor_and_offset() {
+ RuleDefinitions.NewRepository newFindbugs = context.newRepository("findbugs", "java");
+ newFindbugs.newRule("NPE")
+ .setName("Detect NPE")
+ .setHtmlDescription("NPE")
+ .setRemediationFactor(" 1 h ")
+ .setRemediationOffset(" 10 mi n ");
+ newFindbugs.done();
+
+ RuleDefinitions.Rule npeRule = context.repository("findbugs").rule("NPE");
+ assertThat(npeRule.remediationFactor()).isEqualTo("1h");
+ assertThat(npeRule.remediationOffset()).isEqualTo("10min");
+ }
+
@Test
public void extend_repository() {
assertThat(context.extendedRepositories()).isEmpty();
assertThat(e).hasMessage("Status 'REMOVED' is not accepted on rule '[repository=findbugs, key=NPE]'");
}
}
+
+ @Test
+ @Ignore("TODO")
+ public void fail_if_bad_remediation_factor_or_offset() {
+ try {
+ context.newRepository("findbugs", "java").newRule("NPE").setRemediationFactor("ten hours");
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Duration 'ten hours' is invalid, it should use the following sample format : 2d 10h 15min");
+ }
+
+ try {
+ context.newRepository("findbugs", "java").newRule("NPE").setRemediationOffset("ten hours");
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Duration 'ten hours' is invalid, it should use the following sample format : 2d 10h 15min");
+ }
+ }
+
}
dto.setStatus(status);
changed = true;
}
+ if (!StringUtils.equals(dto.getLanguage(), def.repository().language())) {
+ dto.setLanguage(def.repository().language());
+ changed = true;
+ }
+ changed = mergeDebtRule(def, dto) || changed;
+ if (changed) {
+ dto.setUpdatedAt(buffer.now());
+ }
+ return changed;
+ }
+
+ private boolean mergeDebtRule(RuleDefinitions.Rule def, RuleDto dto){
+ boolean changed = false;
// TODO add characteristic id change verification
dto.setEffortToFixL10nKey(def.effortToFixL10nKey());
changed = true;
}
-
- if (!StringUtils.equals(dto.getLanguage(), def.repository().language())) {
- dto.setLanguage(def.repository().language());
- changed = true;
- }
- if (changed) {
- dto.setUpdatedAt(buffer.now());
- }
return changed;
}