]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 Move batch DebtRemediationFunction from rule to debt package
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 3 Apr 2014 16:17:20 +0000 (18:17 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 3 Apr 2014 16:17:28 +0000 (18:17 +0200)
12 files changed:
sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
sonar-batch/src/main/java/org/sonar/batch/rule/RulesProvider.java
sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
sonar-batch/src/test/java/org/sonar/batch/rule/RulesProviderTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/DefaultRule.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/internal/NewRule.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java [new file with mode: 0644]
sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DefaultDebtRemediationFunctionTest.java [deleted file]
sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/internal/RulesBuilderTest.java

index 5eaa0726038f59afcbf415d4d4c46f147dff48a8..c0a49d68671e6e43b617a40d3aa4dd5dbb8c14ec 100644 (file)
@@ -21,7 +21,11 @@ package org.sonar.batch.issue;
 
 import com.google.common.base.Objects;
 import com.google.common.base.Strings;
-import org.sonar.api.batch.rule.*;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
+import org.sonar.api.batch.rule.ActiveRule;
+import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.rule.Rule;
+import org.sonar.api.batch.rule.Rules;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.resources.Project;
 import org.sonar.api.rule.RuleKey;
index ef479b27f00efaf603f9c0304346ff7a5b4ac352..49b4cf95986051ff71b308e8d51f35aeca08ed08 100644 (file)
@@ -27,8 +27,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.debt.DebtCharacteristic;
 import org.sonar.api.batch.debt.DebtModel;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.batch.debt.internal.DefaultDebtModel;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
 import org.sonar.api.batch.rule.Rules;
 import org.sonar.api.batch.rule.internal.NewRule;
 import org.sonar.api.batch.rule.internal.RulesBuilder;
index 6be76b5d95dbf40bf30389417551cd32f8902796..3df87485b74fe1ff80d6eaa3b6c716a10d792c19 100644 (file)
@@ -26,7 +26,7 @@ import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
 import org.sonar.api.batch.rule.internal.RulesBuilder;
 import org.sonar.api.issue.internal.DefaultIssue;
index 5ec693d2bc1205587c6dfb6d6a6378a217af93ad..3bf623aab5a9871bb476d9034284d9a7010fff04 100644 (file)
@@ -25,9 +25,9 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic;
 import org.sonar.api.batch.debt.internal.DefaultDebtModel;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
 import org.sonar.api.batch.rule.Rule;
 import org.sonar.api.batch.rule.RuleParam;
 import org.sonar.api.batch.rule.Rules;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/debt/DebtRemediationFunction.java
new file mode 100644 (file)
index 0000000..97fd9e0
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+package org.sonar.api.batch.debt;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.utils.Duration;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
+/**
+ * @since 4.3
+ */
+public class DebtRemediationFunction {
+
+  public static enum Type {
+    LINEAR, LINEAR_OFFSET, CONSTANT_ISSUE
+  }
+
+  private Type type;
+  private Duration coefficient;
+  private Duration offset;
+
+  private DebtRemediationFunction(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
+    this.type = type;
+    this.coefficient = coefficient;
+    this.offset = offset;
+  }
+
+  public static DebtRemediationFunction create(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
+    return new DebtRemediationFunction(type, coefficient, offset);
+  }
+
+  public static DebtRemediationFunction createLinear(Duration coefficient) {
+    return new DebtRemediationFunction(Type.LINEAR, coefficient, null);
+  }
+
+  public static DebtRemediationFunction createLinearWithOffset(Duration coefficient, Duration offset) {
+    return new DebtRemediationFunction(Type.LINEAR_OFFSET, coefficient, offset);
+  }
+
+  public static DebtRemediationFunction createConstantPerIssue(Duration offset) {
+    return new DebtRemediationFunction(Type.CONSTANT_ISSUE, null, offset);
+  }
+
+  public Type type() {
+    return type;
+  }
+
+  @CheckForNull
+  public Duration coefficient() {
+    return coefficient;
+  }
+
+  @CheckForNull
+  public Duration offset() {
+    return offset;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+    DebtRemediationFunction that = (DebtRemediationFunction) o;
+    return new EqualsBuilder()
+      .append(type, that.type())
+      .append(coefficient, that.coefficient())
+      .append(offset, that.offset())
+      .isEquals();
+  }
+
+  @Override
+  public int hashCode() {
+    return new HashCodeBuilder(15, 31)
+      .append(type)
+      .append(coefficient)
+      .append(offset)
+      .toHashCode();
+  }
+
+  @Override
+  public String toString() {
+    return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+  }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java
deleted file mode 100644 (file)
index 5ce0a5e..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.
- */
-
-package org.sonar.api.batch.rule;
-
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ReflectionToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.utils.Duration;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
-/**
- * @since 4.3
- */
-public class DebtRemediationFunction {
-
-  public static enum Type {
-    LINEAR, LINEAR_OFFSET, CONSTANT_ISSUE
-  }
-
-  private Type type;
-  private Duration coefficient;
-  private Duration offset;
-
-  private DebtRemediationFunction(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
-    this.type = type;
-    this.coefficient = coefficient;
-    this.offset = offset;
-  }
-
-  public static DebtRemediationFunction create(Type type, @Nullable Duration coefficient, @Nullable Duration offset) {
-    return new DebtRemediationFunction(type, coefficient, offset);
-  }
-
-  public static DebtRemediationFunction createLinear(Duration coefficient) {
-    return new DebtRemediationFunction(Type.LINEAR, coefficient, null);
-  }
-
-  public static DebtRemediationFunction createLinearWithOffset(Duration coefficient, Duration offset) {
-    return new DebtRemediationFunction(Type.LINEAR_OFFSET, coefficient, offset);
-  }
-
-  public static DebtRemediationFunction createConstantPerIssue(Duration offset) {
-    return new DebtRemediationFunction(Type.CONSTANT_ISSUE, null, offset);
-  }
-
-  public Type type() {
-    return type;
-  }
-
-  @CheckForNull
-  public Duration coefficient() {
-    return coefficient;
-  }
-
-  @CheckForNull
-  public Duration offset() {
-    return offset;
-  }
-
-  @Override
-  public boolean equals(Object o) {
-    if (this == o) {
-      return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
-      return false;
-    }
-    DebtRemediationFunction that = (DebtRemediationFunction) o;
-    return new EqualsBuilder()
-      .append(type, that.type())
-      .append(coefficient, that.coefficient())
-      .append(offset, that.offset())
-      .isEquals();
-  }
-
-  @Override
-  public int hashCode() {
-    return new HashCodeBuilder(15, 31)
-      .append(type)
-      .append(coefficient)
-      .append(offset)
-      .toHashCode();
-  }
-
-  @Override
-  public String toString() {
-    return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
-  }
-}
index 475d8e7b6008eb606bc9a4e55f456b9db1841a01..66d42e2be5cce6da62a07f0877cee489e77c4d03 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.api.batch.rule;
 
 import com.google.common.annotations.Beta;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 
index cd93c077d60556f0715f78b0b458a296f1af2f89..7e311e2901cc1a83bbdef75aa39866a644b8ff00 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.api.batch.rule.internal;
 
 import com.google.common.collect.ImmutableMap;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.batch.rule.Rule;
 import org.sonar.api.batch.rule.RuleParam;
 import org.sonar.api.rule.RuleKey;
index c921a41ecc4c060d626fdb2548aa5e859f0ff6b2..5843672ade05ac4494ac3d1c008fabf144d962df 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.api.batch.rule.internal;
 
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.RuleStatus;
 import org.sonar.api.rule.Severity;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/debt/DebtRemediationFunctionTest.java
new file mode 100644 (file)
index 0000000..dfbd2d2
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.
+ */
+
+package org.sonar.api.batch.debt;
+
+import org.junit.Test;
+import org.sonar.api.utils.Duration;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DebtRemediationFunctionTest {
+
+  @Test
+  public void create_linear() throws Exception {
+    DebtRemediationFunction function = DebtRemediationFunction.createLinear(Duration.create(10));
+    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
+    assertThat(function.coefficient()).isEqualTo(Duration.create(10));
+    assertThat(function.offset()).isNull();
+  }
+
+  @Test
+  public void create_linear_with_offset() throws Exception {
+    DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
+    assertThat(function.coefficient()).isEqualTo(Duration.create(10));
+    assertThat(function.offset()).isEqualTo(Duration.create(5));
+  }
+
+  @Test
+  public void create_constant_per_issue() throws Exception {
+    DebtRemediationFunction function = DebtRemediationFunction.createConstantPerIssue(Duration.create(10));
+    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
+    assertThat(function.coefficient()).isNull();
+    assertThat(function.offset()).isEqualTo(Duration.create(10));
+  }
+
+  @Test
+  public void test_equals_and_hashcode() throws Exception {
+    DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+    DebtRemediationFunction functionWithSameValue = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+    DebtRemediationFunction functionWithDifferentType = DebtRemediationFunction.createConstantPerIssue(Duration.create(5));
+
+    assertThat(function).isEqualTo(function);
+    assertThat(function).isEqualTo(functionWithSameValue);
+    assertThat(function).isNotEqualTo(functionWithDifferentType);
+    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(11), Duration.create(5)));
+    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(6)));
+    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinear(Duration.create(10)));
+    assertThat(function).isNotEqualTo(DebtRemediationFunction.createConstantPerIssue(Duration.create(6)));
+
+    assertThat(function.hashCode()).isEqualTo(function.hashCode());
+    assertThat(function.hashCode()).isEqualTo(functionWithSameValue.hashCode());
+    assertThat(function.hashCode()).isNotEqualTo(functionWithDifferentType.hashCode());
+  }
+
+  @Test
+  public void test_to_string() throws Exception {
+    assertThat(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5)).toString()).isNotNull();
+  }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DefaultDebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DefaultDebtRemediationFunctionTest.java
deleted file mode 100644 (file)
index 4bcb659..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 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.
- */
-
-package org.sonar.api.batch.rule;
-
-import org.junit.Test;
-import org.sonar.api.utils.Duration;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class DefaultDebtRemediationFunctionTest {
-
-  @Test
-  public void create_linear() throws Exception {
-    DebtRemediationFunction function = DebtRemediationFunction.createLinear(Duration.create(10));
-    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
-    assertThat(function.coefficient()).isEqualTo(Duration.create(10));
-    assertThat(function.offset()).isNull();
-  }
-
-  @Test
-  public void create_linear_with_offset() throws Exception {
-    DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
-    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
-    assertThat(function.coefficient()).isEqualTo(Duration.create(10));
-    assertThat(function.offset()).isEqualTo(Duration.create(5));
-  }
-
-  @Test
-  public void create_constant_per_issue() throws Exception {
-    DebtRemediationFunction function = DebtRemediationFunction.createConstantPerIssue(Duration.create(10));
-    assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
-    assertThat(function.coefficient()).isNull();
-    assertThat(function.offset()).isEqualTo(Duration.create(10));
-  }
-
-  @Test
-  public void test_equals_and_hashcode() throws Exception {
-    DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
-    DebtRemediationFunction functionWithSameValue = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
-    DebtRemediationFunction functionWithDifferentType = DebtRemediationFunction.createConstantPerIssue(Duration.create(5));
-
-    assertThat(function).isEqualTo(function);
-    assertThat(function).isEqualTo(functionWithSameValue);
-    assertThat(function).isNotEqualTo(functionWithDifferentType);
-    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(11), Duration.create(5)));
-    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(6)));
-    assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinear(Duration.create(10)));
-    assertThat(function).isNotEqualTo(DebtRemediationFunction.createConstantPerIssue(Duration.create(6)));
-
-    assertThat(function.hashCode()).isEqualTo(function.hashCode());
-    assertThat(function.hashCode()).isEqualTo(functionWithSameValue.hashCode());
-    assertThat(function.hashCode()).isNotEqualTo(functionWithDifferentType.hashCode());
-  }
-
-  @Test
-  public void test_to_string() throws Exception {
-    assertThat(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5)).toString()).isNotNull();
-  }
-}
index 074fe58aef7dd113ac1c8fb4eaad09cc3008533a..e7a445bf90429f5c6611b78ab38f4e1f4437c96c 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.api.batch.rule.internal;
 
 import org.junit.Test;
-import org.sonar.api.batch.rule.DebtRemediationFunction;
+import org.sonar.api.batch.debt.DebtRemediationFunction;
 import org.sonar.api.batch.rule.Rule;
 import org.sonar.api.batch.rule.Rules;
 import org.sonar.api.rule.RuleKey;