diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-28 18:46:26 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2013-11-28 18:47:39 +0100 |
commit | 32a20516bb3bcd67e08aa8136df68bfe2565aab6 (patch) | |
tree | b93d15b1d3664907a8095d28e9d2d1e09b6916d2 /sonar-plugin-api | |
parent | 9b0e7a93043f93e65181c9d152f06feceadc702f (diff) | |
download | sonarqube-32a20516bb3bcd67e08aa8136df68bfe2565aab6.tar.gz sonarqube-32a20516bb3bcd67e08aa8136df68bfe2565aab6.zip |
SONAR-4831 Refactored technical debt
Diffstat (limited to 'sonar-plugin-api')
9 files changed, 402 insertions, 57 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java index b6a78b582ba..c47dd1f17f6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java @@ -22,8 +22,8 @@ package org.sonar.api.measures; import com.google.common.annotations.Beta; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.math.NumberUtils; -import org.sonar.api.technicaldebt.Characteristic; -import org.sonar.api.technicaldebt.Requirement; +import org.sonar.api.technicaldebt.batch.Characteristic; +import org.sonar.api.technicaldebt.batch.Requirement; import javax.annotation.CheckForNull; import javax.annotation.Nullable; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java index 83e88e15a94..3b964a214e1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java @@ -20,8 +20,8 @@ package org.sonar.api.measures; import org.sonar.api.rules.Rule; -import org.sonar.api.technicaldebt.Characteristic; -import org.sonar.api.technicaldebt.Requirement; +import org.sonar.api.technicaldebt.batch.Characteristic; +import org.sonar.api.technicaldebt.batch.Requirement; import java.util.ArrayList; import java.util.Collection; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java new file mode 100644 index 00000000000..1ea0eb7960d --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Characteristic.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.sonar.api.technicaldebt.batch; + +import javax.annotation.CheckForNull; + +import java.util.Date; +import java.util.List; + +public interface Characteristic { + + Integer id(); + + String key(); + + String name(); + + Integer order(); + + @CheckForNull + Characteristic parent(); + + List<? extends Characteristic> children(); + + List<? extends Requirement> requirements(); + + boolean isRoot(); + + Date createdAt(); + + Date updatedAt(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java new file mode 100644 index 00000000000..080726b97af --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/Requirement.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.sonar.api.technicaldebt.batch; + +import org.sonar.api.rule.RuleKey; +import org.sonar.api.technicaldebt.WorkUnit; + +import java.util.Date; + +public interface Requirement { + + Integer id(); + + RuleKey ruleKey(); + + Characteristic characteristic(); + + Characteristic rootCharacteristic(); + + String function(); + + WorkUnit factor(); + + WorkUnit offset(); + + Date createdAt(); + + Date updatedAt(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java new file mode 100644 index 00000000000..10a5b832fc8 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/batch/TechnicalDebtModel.java @@ -0,0 +1,42 @@ +/* + * 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. + */ + +package org.sonar.api.technicaldebt.batch; + +import org.sonar.api.rule.RuleKey; + +import javax.annotation.CheckForNull; + +import java.util.List; + +public interface TechnicalDebtModel { + + @CheckForNull + Characteristic characteristicById(Integer id); + + @CheckForNull + Requirement requirementsByRule(RuleKey ruleKey); + + @CheckForNull + Requirement requirementsById(Integer id); + + List<? extends Requirement> requirements(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/internal/DefaultCharacteristic.java index e75baf264f3..6252ab59746 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/Characteristic.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/internal/DefaultCharacteristic.java @@ -18,11 +18,12 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.api.technicaldebt; +package org.sonar.api.technicaldebt.internal; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import org.sonar.api.technicaldebt.batch.Characteristic; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -32,21 +33,21 @@ import java.util.List; import static com.google.common.collect.Lists.newArrayList; -public class Characteristic { +public class DefaultCharacteristic implements Characteristic { private Integer id; private String key; private String name; private Integer order; - private Characteristic parent; - private Characteristic root; - private List<Characteristic> children; - private List<Requirement> requirements; + private DefaultCharacteristic parent; + private DefaultCharacteristic root; + private List<DefaultCharacteristic> children; + private List<DefaultRequirement> requirements; private Date createdAt; private Date updatedAt; - public Characteristic() { + public DefaultCharacteristic() { this.children = newArrayList(); this.requirements = newArrayList(); } @@ -55,7 +56,7 @@ public class Characteristic { return id; } - public Characteristic setId(Integer id) { + public DefaultCharacteristic setId(Integer id) { this.id = id; return this; } @@ -64,7 +65,7 @@ public class Characteristic { return key; } - public Characteristic setKey(String key) { + public DefaultCharacteristic setKey(String key) { this.key = StringUtils.trimToNull(key); return this; } @@ -73,8 +74,9 @@ public class Characteristic { return name; } - public Characteristic setName(String name) { - return setName(name, false); + public DefaultCharacteristic setName(String name) { + this.name = name; + return this; } public Characteristic setName(String s, boolean asKey) { @@ -90,17 +92,17 @@ public class Characteristic { return order; } - public Characteristic setOrder(Integer order) { + public DefaultCharacteristic setOrder(Integer order) { this.order = order; return this; } @CheckForNull - public Characteristic parent() { + public DefaultCharacteristic parent() { return parent; } - public Characteristic setParent(@Nullable Characteristic parent) { + public DefaultCharacteristic setParent(@Nullable DefaultCharacteristic parent) { if (parent != null) { this.parent = parent; parent.addChild(this); @@ -109,39 +111,34 @@ public class Characteristic { } @CheckForNull - public Characteristic getRoot() { + public DefaultCharacteristic getRoot() { return root; } - public Characteristic setRoot(@Nullable Characteristic root) { + public DefaultCharacteristic setRoot(@Nullable DefaultCharacteristic root) { this.root = root; return this; } - public List<Characteristic> children() { + public List<DefaultCharacteristic> children() { return children; } - private Characteristic addChild(Characteristic child){ + private DefaultCharacteristic addChild(DefaultCharacteristic child) { this.children.add(child); return this; } - public List<Requirement> requirements() { + public List<DefaultRequirement> requirements() { return requirements; } - protected Characteristic addRequirement(Requirement requirement){ + public DefaultCharacteristic addRequirement(DefaultRequirement requirement) { this.requirements.add(requirement); return this; } - public Characteristic removeRequirement(Requirement requirement){ - this.requirements.remove(requirement); - return this; - } - - public boolean isRoot(){ + public boolean isRoot() { return parent == null; } @@ -149,7 +146,7 @@ public class Characteristic { return createdAt; } - public Characteristic setCreatedAt(Date createdAt) { + public DefaultCharacteristic setCreatedAt(Date createdAt) { this.createdAt = createdAt; return this; } @@ -158,7 +155,7 @@ public class Characteristic { return updatedAt; } - public Characteristic setUpdatedAt(Date updatedAt) { + public DefaultCharacteristic setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; return this; } @@ -176,7 +173,7 @@ public class Characteristic { if (o == null || getClass() != o.getClass()) { return false; } - Characteristic that = (Characteristic) o; + DefaultCharacteristic that = (DefaultCharacteristic) o; return key.equals(that.key); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/Requirement.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/internal/DefaultRequirement.java index 47d9019d51d..6ae1551b4b8 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/Requirement.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/internal/DefaultRequirement.java @@ -18,28 +18,26 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package org.sonar.api.technicaldebt; +package org.sonar.api.technicaldebt.internal; -import com.google.common.collect.ImmutableList; 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.WorkUnit; +import org.sonar.api.technicaldebt.batch.Requirement; import java.util.Date; -import java.util.List; -public class Requirement { +public class DefaultRequirement implements Requirement { public static final String FUNCTION_LINEAR = "linear"; public static final String FUNCTION_LINEAR_WITH_OFFSET = "linear_offset"; public static final String CONSTANT_ISSUE = "constant_issue"; - public static final List<String> FUNCTIONS = ImmutableList.of(FUNCTION_LINEAR, FUNCTION_LINEAR_WITH_OFFSET, CONSTANT_ISSUE); - private Integer id; private RuleKey ruleKey; - private Characteristic characteristic; - private Characteristic rootCharacteristic; + private DefaultCharacteristic characteristic; + private DefaultCharacteristic rootCharacteristic; private String function; private WorkUnit factor; @@ -48,7 +46,7 @@ public class Requirement { private Date createdAt; private Date updatedAt; - public Requirement() { + public DefaultRequirement() { this.factor = WorkUnit.create(0d, WorkUnit.DEFAULT_UNIT); this.offset = WorkUnit.create(0d, WorkUnit.DEFAULT_UNIT); } @@ -57,7 +55,7 @@ public class Requirement { return id; } - public Requirement setId(Integer id) { + public DefaultRequirement setId(Integer id) { this.id = id; return this; } @@ -66,26 +64,26 @@ public class Requirement { return ruleKey; } - public Requirement setRuleKey(RuleKey ruleKey) { + public DefaultRequirement setRuleKey(RuleKey ruleKey) { this.ruleKey = ruleKey; return this; } - public Characteristic characteristic() { + public DefaultCharacteristic characteristic() { return characteristic; } - public Requirement setCharacteristic(Characteristic characteristic) { + public DefaultRequirement setCharacteristic(DefaultCharacteristic characteristic) { this.characteristic = characteristic; this.characteristic.addRequirement(this); return this; } - public Characteristic getRootCharacteristic() { + public DefaultCharacteristic rootCharacteristic() { return rootCharacteristic; } - public Requirement setRootCharacteristic(Characteristic rootCharacteristic) { + public DefaultRequirement setRootCharacteristic(DefaultCharacteristic rootCharacteristic) { this.rootCharacteristic = rootCharacteristic; return this; } @@ -94,10 +92,7 @@ public class Requirement { return function; } - public Requirement setFunction(String function) { - if (!FUNCTIONS.contains(function)) { - throw new IllegalArgumentException("Function '"+ function +"' is unknown."); - } + public DefaultRequirement setFunction(String function) { this.function = function; return this; } @@ -106,7 +101,7 @@ public class Requirement { return factor; } - public Requirement setFactor(WorkUnit factor) { + public DefaultRequirement setFactor(WorkUnit factor) { this.factor = factor; return this; } @@ -115,7 +110,7 @@ public class Requirement { return offset; } - public Requirement setOffset(WorkUnit offset) { + public DefaultRequirement setOffset(WorkUnit offset) { this.offset = offset; return this; } @@ -124,7 +119,7 @@ public class Requirement { return createdAt; } - public Requirement setCreatedAt(Date createdAt) { + public DefaultRequirement setCreatedAt(Date createdAt) { this.createdAt = createdAt; return this; } @@ -133,7 +128,7 @@ public class Requirement { return updatedAt; } - public Requirement setUpdatedAt(Date updatedAt) { + public DefaultRequirement setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; return this; } @@ -153,7 +148,7 @@ public class Requirement { return false; } - Requirement that = (Requirement) o; + DefaultRequirement that = (DefaultRequirement) o; if (!characteristic.equals(that.characteristic)) { return false; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java new file mode 100644 index 00000000000..05cbe32ceb6 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/Characteristic.java @@ -0,0 +1,177 @@ +/* + * 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. + */ + +package org.sonar.api.technicaldebt.server; + +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.WorkUnit; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class Characteristic { + + private Integer id; + private String key; + private String name; + private Integer order; + private Integer parentId; + private Integer rootId; + private RuleKey ruleKey; + private String function; + private WorkUnit factor; + private WorkUnit offset; + + public Integer id() { + return id; + } + + public Characteristic setId(Integer id) { + this.id = id; + return this; + } + + public String key() { + return key; + } + + public Characteristic setKey(String key) { + this.key = key; + return this; + } + + public String name() { + return name; + } + + public Characteristic setName(String name) { + this.name = name; + return this; + } + + public Integer order() { + return order; + } + + public Characteristic setOrder(Integer order) { + this.order = order; + return this; + } + + @CheckForNull + public Integer parentId() { + return parentId; + } + + public Characteristic setParentId(@Nullable Integer parentId) { + this.parentId = parentId; + return this; + } + + @CheckForNull + public Integer rootId() { + return rootId; + } + + public Characteristic setRootId(@Nullable Integer rootId) { + this.rootId = rootId; + return this; + } + + public RuleKey ruleKey() { + return ruleKey; + } + + public Characteristic setRuleKey(RuleKey ruleKey) { + this.ruleKey = ruleKey; + return this; + } + + public String function() { + return function; + } + + public Characteristic setFunction(String function) { + this.function = function; + return this; + } + + public WorkUnit factor() { + return factor; + } + + public Characteristic setFactor(WorkUnit factor) { + this.factor = factor; + return this; + } + + public WorkUnit offset() { + return offset; + } + + public Characteristic setOffset(WorkUnit offset) { + this.offset = offset; + return this; + } + + public boolean isRoot() { + return parentId == null; + } + + public boolean isRequirement() { + return ruleKey == null; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + Characteristic that = (Characteristic) o; + + if (key != null ? !key.equals(that.key) : that.key != null) { + return false; + } + if (ruleKey != null ? !ruleKey.equals(that.ruleKey) : that.ruleKey != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = key != null ? key.hashCode() : 0; + result = 31 * result + (ruleKey != null ? ruleKey.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java new file mode 100644 index 00000000000..acd3e33de4f --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/technicaldebt/server/TechnicalDebtManager.java @@ -0,0 +1,35 @@ +/* + * 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. + */ + +package org.sonar.api.technicaldebt.server; + +import org.sonar.api.ServerComponent; +import org.sonar.api.rules.Rule; + +import java.util.List; + +public interface TechnicalDebtManager extends ServerComponent { + + List<Characteristic> findRootCharacteristics(); + + Characteristic findRequirementByRule(Rule rule); + + Characteristic findCharacteristicById(Integer id); +} |