aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-03 17:29:23 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-07-03 17:51:11 +0200
commit5b9dfc041ae3355dc68dcc4cb0a97b76d33dc106 (patch)
tree99472a4ac8eac0b272c0941a9765c1ba977fd8e6 /plugins
parent10244be8668b4adba0dbdfcb9488a235eedabb6e (diff)
downloadsonarqube-5b9dfc041ae3355dc68dcc4cb0a97b76d33dc106.tar.gz
sonarqube-5b9dfc041ae3355dc68dcc4cb0a97b76d33dc106.zip
SONAR-5432 Remove RCI and Weighted issues metrics
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java94
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java1
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssuesDensityDecorator.java94
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java124
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssuesDensityDecoratorTest.java107
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/WeightedIssuesDecoratorTest.java95
6 files changed, 9 insertions, 506 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 44e3b343aa0..114597c0ae4 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -20,11 +20,7 @@
package org.sonar.plugins.core;
import com.google.common.collect.ImmutableList;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
-import org.sonar.api.PropertyType;
-import org.sonar.api.SonarPlugin;
+import org.sonar.api.*;
import org.sonar.api.checks.NoSonarFilter;
import org.sonar.core.timemachine.Periods;
import org.sonar.plugins.core.batch.IndexProjectPostJob;
@@ -32,88 +28,18 @@ import org.sonar.plugins.core.charts.DistributionAreaChart;
import org.sonar.plugins.core.charts.DistributionBarChart;
import org.sonar.plugins.core.charts.XradarChart;
import org.sonar.plugins.core.colorizers.JavaColorizerFormat;
-import org.sonar.plugins.core.dashboards.GlobalDefaultDashboard;
-import org.sonar.plugins.core.dashboards.ProjectDefaultDashboard;
-import org.sonar.plugins.core.dashboards.ProjectHotspotDashboard;
-import org.sonar.plugins.core.dashboards.ProjectIssuesDashboard;
-import org.sonar.plugins.core.dashboards.ProjectTimeMachineDashboard;
-import org.sonar.plugins.core.issue.CountFalsePositivesDecorator;
-import org.sonar.plugins.core.issue.CountUnresolvedIssuesDecorator;
-import org.sonar.plugins.core.issue.InitialOpenIssuesSensor;
-import org.sonar.plugins.core.issue.InitialOpenIssuesStack;
-import org.sonar.plugins.core.issue.IssueHandlers;
-import org.sonar.plugins.core.issue.IssueTracking;
-import org.sonar.plugins.core.issue.IssueTrackingDecorator;
-import org.sonar.plugins.core.issue.IssuesDensityDecorator;
-import org.sonar.plugins.core.issue.WeightedIssuesDecorator;
-import org.sonar.plugins.core.issue.notification.ChangesOnMyIssueNotificationDispatcher;
-import org.sonar.plugins.core.issue.notification.IssueChangesEmailTemplate;
-import org.sonar.plugins.core.issue.notification.NewFalsePositiveNotificationDispatcher;
-import org.sonar.plugins.core.issue.notification.NewIssuesEmailTemplate;
-import org.sonar.plugins.core.issue.notification.NewIssuesNotificationDispatcher;
-import org.sonar.plugins.core.issue.notification.SendIssueNotificationsPostJob;
+import org.sonar.plugins.core.dashboards.*;
+import org.sonar.plugins.core.issue.*;
+import org.sonar.plugins.core.issue.notification.*;
import org.sonar.plugins.core.measurefilters.MyFavouritesFilter;
import org.sonar.plugins.core.measurefilters.ProjectFilter;
import org.sonar.plugins.core.notifications.alerts.NewAlerts;
import org.sonar.plugins.core.security.ApplyProjectRolesDecorator;
-import org.sonar.plugins.core.sensors.BranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.CommentDensityDecorator;
-import org.sonar.plugins.core.sensors.CoverageDecorator;
-import org.sonar.plugins.core.sensors.CoverageMeasurementFilter;
-import org.sonar.plugins.core.sensors.DirectoriesDecorator;
-import org.sonar.plugins.core.sensors.FileHashSensor;
-import org.sonar.plugins.core.sensors.FilesDecorator;
-import org.sonar.plugins.core.sensors.ItBranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.ItCoverageDecorator;
-import org.sonar.plugins.core.sensors.ItLineCoverageDecorator;
-import org.sonar.plugins.core.sensors.LineCoverageDecorator;
-import org.sonar.plugins.core.sensors.ManualMeasureDecorator;
-import org.sonar.plugins.core.sensors.OverallBranchCoverageDecorator;
-import org.sonar.plugins.core.sensors.OverallCoverageDecorator;
-import org.sonar.plugins.core.sensors.OverallLineCoverageDecorator;
-import org.sonar.plugins.core.sensors.ProjectLinksSensor;
-import org.sonar.plugins.core.sensors.UnitTestDecorator;
-import org.sonar.plugins.core.sensors.VersionEventsSensor;
-import org.sonar.plugins.core.timemachine.NewCoverageAggregator;
-import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.NewOverallCoverageFileAnalyzer;
-import org.sonar.plugins.core.timemachine.TendencyDecorator;
-import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister;
-import org.sonar.plugins.core.timemachine.VariationDecorator;
-import org.sonar.plugins.core.widgets.AlertsWidget;
-import org.sonar.plugins.core.widgets.BubbleChartWidget;
-import org.sonar.plugins.core.widgets.ComplexityWidget;
-import org.sonar.plugins.core.widgets.CoverageWidget;
-import org.sonar.plugins.core.widgets.CustomMeasuresWidget;
-import org.sonar.plugins.core.widgets.DescriptionWidget;
-import org.sonar.plugins.core.widgets.DocumentationCommentsWidget;
-import org.sonar.plugins.core.widgets.DuplicationsWidget;
-import org.sonar.plugins.core.widgets.EventsWidget;
-import org.sonar.plugins.core.widgets.HotspotMetricWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget;
-import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget;
-import org.sonar.plugins.core.widgets.ItCoverageWidget;
-import org.sonar.plugins.core.widgets.ProjectFileCloudWidget;
-import org.sonar.plugins.core.widgets.SizeWidget;
-import org.sonar.plugins.core.widgets.TechnicalDebtPyramidWidget;
-import org.sonar.plugins.core.widgets.TimeMachineWidget;
-import org.sonar.plugins.core.widgets.TimelineWidget;
-import org.sonar.plugins.core.widgets.TreemapWidget;
-import org.sonar.plugins.core.widgets.WelcomeWidget;
-import org.sonar.plugins.core.widgets.issues.ActionPlansWidget;
-import org.sonar.plugins.core.widgets.issues.FalsePositiveIssuesWidget;
-import org.sonar.plugins.core.widgets.issues.IssueFilterWidget;
-import org.sonar.plugins.core.widgets.issues.IssuesWidget;
-import org.sonar.plugins.core.widgets.issues.MyUnresolvedIssuesWidget;
-import org.sonar.plugins.core.widgets.issues.UnresolvedIssuesPerAssigneeWidget;
-import org.sonar.plugins.core.widgets.issues.UnresolvedIssuesStatusesWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterAsBubbleChartWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterAsCloudWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterAsHistogramWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterAsPieChartWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterListWidget;
-import org.sonar.plugins.core.widgets.measures.MeasureFilterTreemapWidget;
+import org.sonar.plugins.core.sensors.*;
+import org.sonar.plugins.core.timemachine.*;
+import org.sonar.plugins.core.widgets.*;
+import org.sonar.plugins.core.widgets.issues.*;
+import org.sonar.plugins.core.widgets.measures.*;
import java.util.List;
@@ -322,8 +248,6 @@ public final class CorePlugin extends SonarPlugin {
IssueHandlers.class,
CountUnresolvedIssuesDecorator.class,
CountFalsePositivesDecorator.class,
- WeightedIssuesDecorator.class,
- IssuesDensityDecorator.class,
InitialOpenIssuesSensor.class,
InitialOpenIssuesStack.class,
HotspotMostViolatedResourcesWidget.class,
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java
index ae4f75d12e1..cf7b3ab6a5a 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/dashboards/ProjectTimeMachineDashboard.java
@@ -91,7 +91,6 @@ public final class ProjectTimeMachineDashboard extends DashboardTemplate {
rulesTimeMachineWidget.setProperty(METRIC4, CoreMetrics.MAJOR_VIOLATIONS_KEY);
rulesTimeMachineWidget.setProperty(METRIC5, CoreMetrics.MINOR_VIOLATIONS_KEY);
rulesTimeMachineWidget.setProperty(METRIC6, CoreMetrics.INFO_VIOLATIONS_KEY);
- rulesTimeMachineWidget.setProperty(METRIC7, CoreMetrics.WEIGHTED_VIOLATIONS_KEY);
Widget complexityTimeMachineWidget = addTimeMachineWidgetOnSecondColumn(dashboard);
complexityTimeMachineWidget.setProperty(METRIC1, CoreMetrics.COMPLEXITY_KEY);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssuesDensityDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssuesDensityDecorator.java
deleted file mode 100644
index a804bbd9a42..00000000000
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssuesDensityDecorator.java
+++ /dev/null
@@ -1,94 +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.plugins.core.issue;
-
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorBarriers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @since 3.6
- */
-@DependsUpon(DecoratorBarriers.END_OF_VIOLATION_TRACKING)
-public class IssuesDensityDecorator implements Decorator {
-
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @DependsUpon
- public List<Metric> dependsUponWeightedIissuesAndNcloc() {
- return Arrays.<Metric>asList(CoreMetrics.WEIGHTED_VIOLATIONS, CoreMetrics.NCLOC);
- }
-
- @DependedUpon
- public Metric generatesIssuesDensity() {
- return CoreMetrics.VIOLATIONS_DENSITY;
- }
-
- public void decorate(Resource resource, DecoratorContext context) {
- if (shouldDecorateResource(context)) {
- decorateDensity(context);
- }
- }
-
- protected boolean shouldDecorateResource(DecoratorContext context) {
- return context.getMeasure(CoreMetrics.VIOLATIONS_DENSITY) == null;
- }
-
- private void decorateDensity(DecoratorContext context) {
- Measure ncloc = context.getMeasure(CoreMetrics.NCLOC);
- if (MeasureUtils.hasValue(ncloc) && ncloc.getValue() > 0.0) {
- saveDensity(context, ncloc.getValue().intValue());
- }
- }
-
- private void saveDensity(DecoratorContext context, int ncloc) {
- Measure debt = context.getMeasure(CoreMetrics.WEIGHTED_VIOLATIONS);
- Integer debtValue = 0;
- if (MeasureUtils.hasValue(debt)) {
- debtValue = debt.getValue().intValue();
- }
- double density = calculate(debtValue, ncloc);
- context.saveMeasure(CoreMetrics.VIOLATIONS_DENSITY, density);
- }
-
- protected static double calculate(int debt, int ncloc) {
- double rci = (1.0 - ((double) debt / (double) ncloc)) * 100.0;
- rci = Math.max(rci, 0.0);
- return rci;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java
deleted file mode 100644
index a7af9d3ff29..00000000000
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/WeightedIssuesDecorator.java
+++ /dev/null
@@ -1,124 +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.plugins.core.issue;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.TreeMultiset;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.Properties;
-import org.sonar.api.Property;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.config.Settings;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.utils.KeyValueFormat;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-@Properties(@Property(
- key = CoreProperties.CORE_RULE_WEIGHTS_PROPERTY,
- defaultValue = CoreProperties.CORE_RULE_WEIGHTS_DEFAULT_VALUE,
- name = "Rules weight",
- description = "A weight is associated to each severity to emphasize the most critical issues.",
- project = false,
- global = true,
- category = CoreProperties.CATEGORY_GENERAL))
-public class WeightedIssuesDecorator implements Decorator {
-
- private Settings settings;
- private Map<RulePriority, Integer> weightsBySeverity;
-
- public WeightedIssuesDecorator(Settings settings) {
- this.settings = settings;
- }
-
- @DependsUpon
- public List<Metric> dependsUponIssues() {
- return Arrays.<Metric>asList(CoreMetrics.BLOCKER_VIOLATIONS, CoreMetrics.CRITICAL_VIOLATIONS,
- CoreMetrics.MAJOR_VIOLATIONS, CoreMetrics.MINOR_VIOLATIONS, CoreMetrics.INFO_VIOLATIONS);
- }
-
- @DependedUpon
- public Metric generatesWeightedIssues() {
- return CoreMetrics.WEIGHTED_VIOLATIONS;
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- public void start() {
- weightsBySeverity = getWeights(settings);
- }
-
- Map<RulePriority, Integer> getWeightsBySeverity() {
- return weightsBySeverity;
- }
-
- static Map<RulePriority, Integer> getWeights(final Settings settings) {
- String value = settings.getString(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY);
-
- Map<RulePriority, Integer> weights = KeyValueFormat.parse(value, KeyValueFormat.newPriorityConverter(), KeyValueFormat.newIntegerConverter());
-
- for (RulePriority priority : RulePriority.values()) {
- if (!weights.containsKey(priority)) {
- weights.put(priority, 1);
- }
- }
- return weights;
- }
-
- @Override
- public void decorate(Resource resource, DecoratorContext context) {
- decorate(context);
- }
-
- void decorate(DecoratorContext context) {
- double debt = 0.0;
- Multiset<RulePriority> distribution = TreeMultiset.create();
-
- for (RulePriority severity : RulePriority.values()) {
- Measure measure = context.getMeasure(SeverityUtils.severityToIssueMetric(severity));
- if (measure != null && MeasureUtils.hasValue(measure)) {
- distribution.add(severity, measure.getIntValue());
- double add = weightsBySeverity.get(severity) * measure.getIntValue();
- debt += add;
- }
- }
-
- String distributionFormatted = KeyValueFormat.format(distribution);
- // SONAR-4987 We should store store an empty string for the distribution value
- Measure debtMeasure = new Measure(CoreMetrics.WEIGHTED_VIOLATIONS, debt, Strings.emptyToNull(distributionFormatted));
- context.saveMeasure(debtMeasure);
- }
-
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssuesDensityDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssuesDensityDecoratorTest.java
deleted file mode 100644
index 9d97903f22c..00000000000
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssuesDensityDecoratorTest.java
+++ /dev/null
@@ -1,107 +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.plugins.core.issue;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.Scopes;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-
-public class IssuesDensityDecoratorTest {
-
- private IssuesDensityDecorator decorator;
- private Resource resource;
-
- @Before
- public void before() {
- resource = mock(Resource.class);
- when(resource.getScope()).thenReturn(Scopes.PROJECT);
- decorator = new IssuesDensityDecorator();
- }
-
- @Test
- public void calculate_density() {
- assertThat(IssuesDensityDecorator.calculate(4000, 200)).isEqualTo(0.0);
- assertThat(IssuesDensityDecorator.calculate(200, 200)).isEqualTo(0.0);
- assertThat(IssuesDensityDecorator.calculate(50, 200)).isEqualTo(75.0);
- assertThat(IssuesDensityDecorator.calculate(0, 200)).isEqualTo(100.0);
- }
-
- @Test
- public void decorate_density() {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0));
- when(context.getMeasure(CoreMetrics.WEIGHTED_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.WEIGHTED_VIOLATIONS, 50.0));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.VIOLATIONS_DENSITY, 75.0);
- }
-
- @Test
- public void no_density_if_no_ncloc() {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 0.0));
- when(context.getMeasure(CoreMetrics.WEIGHTED_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.WEIGHTED_VIOLATIONS, 50.0));
-
- decorator.decorate(resource, context);
-
- verify(context, never()).saveMeasure(Matchers.eq(CoreMetrics.VIOLATIONS_DENSITY), Matchers.anyDouble());
- }
-
- @Test
- public void save_density_if_value_is_zero() {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0));
- when(context.getMeasure(CoreMetrics.WEIGHTED_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.WEIGHTED_VIOLATIONS, 5000.0));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.VIOLATIONS_DENSITY, 0.0);
- }
-
- @Test
- public void density_is_hundred_when_no_debt() {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.VIOLATIONS_DENSITY, 100.0);
- }
-
- @Test
- public void density_is_hundred_when_debt_is_zero() {
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.NCLOC)).thenReturn(new Measure(CoreMetrics.NCLOC, 200.0));
- when(context.getMeasure(CoreMetrics.WEIGHTED_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.WEIGHTED_VIOLATIONS, 0.0));
-
- decorator.decorate(resource, context);
-
- verify(context).saveMeasure(CoreMetrics.VIOLATIONS_DENSITY, 100.0);
- }
-}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/WeightedIssuesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/WeightedIssuesDecoratorTest.java
deleted file mode 100644
index 81a19376779..00000000000
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/WeightedIssuesDecoratorTest.java
+++ /dev/null
@@ -1,95 +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.plugins.core.issue;
-
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.config.Settings;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.test.IsMeasure;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
-
-
-public class WeightedIssuesDecoratorTest {
-
- @Test
- public void test_weighted_VIOLATIONS() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY, "BLOCKER=10;CRITICAL=5;MAJOR=2;MINOR=1;INFO=0");
- WeightedIssuesDecorator decorator = new WeightedIssuesDecorator(settings);
- DecoratorContext context = mock(DecoratorContext.class);
- when(context.getMeasure(CoreMetrics.INFO_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.INFO_VIOLATIONS, 50.0));
- when(context.getMeasure(CoreMetrics.CRITICAL_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.CRITICAL_VIOLATIONS, 80.0));
- when(context.getMeasure(CoreMetrics.BLOCKER_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.BLOCKER_VIOLATIONS, 100.0));
-
- decorator.start();
- decorator.decorate(context);
-
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.WEIGHTED_VIOLATIONS, (double) (100 * 10 + 80 * 5 + 50 * 0))));
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.WEIGHTED_VIOLATIONS, "INFO=50;CRITICAL=80;BLOCKER=100")));
- }
-
- // SONAR-3092
- @Test
- public void do_save_zero() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY, "BLOCKER=10;CRITICAL=5;MAJOR=2;MINOR=1;INFO=0");
- DecoratorContext context = mock(DecoratorContext.class);
-
- WeightedIssuesDecorator decorator = new WeightedIssuesDecorator(settings);
- decorator.start();
- decorator.decorate(context);
-
- verify(context).saveMeasure(any(Measure.class));
- // SONAR-4987
- verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.WEIGHTED_VIOLATIONS, "")));
- }
-
- @Test
- public void should_load_severity_weights_at_startup() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY, "BLOCKER=2;CRITICAL=1;MAJOR=0;MINOR=0;INFO=0");
-
- WeightedIssuesDecorator decorator = new WeightedIssuesDecorator(settings);
- decorator.start();
-
- assertThat(decorator.getWeightsBySeverity().get(RulePriority.BLOCKER)).isEqualTo(2);
- assertThat(decorator.getWeightsBySeverity().get(RulePriority.CRITICAL)).isEqualTo(1);
- assertThat(decorator.getWeightsBySeverity().get(RulePriority.MAJOR)).isEqualTo(0);
- }
-
- @Test
- public void weights_setting_should_be_optional() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.CORE_RULE_WEIGHTS_PROPERTY, "BLOCKER=2");
-
- WeightedIssuesDecorator decorator = new WeightedIssuesDecorator(settings);
- decorator.start();
-
- assertThat(decorator.getWeightsBySeverity().get(RulePriority.MAJOR)).isEqualTo(1);
- }
-}