summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-11-25 09:57:42 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-11-25 09:57:42 +0100
commit36c7fe808ee079ae8ed82b6d55930666a71e8663 (patch)
treeb2f2bae7cf4e06a4edec6e195fbce47c66798699
parenta26fcb817d579ee813759ea6acd43a4d30388dd0 (diff)
downloadsonarqube-36c7fe808ee079ae8ed82b6d55930666a71e8663.tar.gz
sonarqube-36c7fe808ee079ae8ed82b6d55930666a71e8663.zip
Fix some violations
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/SeverityUtils.java48
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java22
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/WeightedViolationsDecorator.java20
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/SeverityUtilsTest.java35
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/Batch.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasuresFilters.java27
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java2
8 files changed, 102 insertions, 56 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/SeverityUtils.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/SeverityUtils.java
new file mode 100644
index 00000000000..3b81c55793c
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/SeverityUtils.java
@@ -0,0 +1,48 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.sensors;
+
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.rules.RulePriority;
+
+final class SeverityUtils {
+ private SeverityUtils() {
+ // only static methods
+ }
+
+ static Metric severityToViolationMetric(RulePriority severity) {
+ Metric metric;
+ if (severity.equals(RulePriority.BLOCKER)) {
+ metric = CoreMetrics.BLOCKER_VIOLATIONS;
+ } else if (severity.equals(RulePriority.CRITICAL)) {
+ metric = CoreMetrics.CRITICAL_VIOLATIONS;
+ } else if (severity.equals(RulePriority.MAJOR)) {
+ metric = CoreMetrics.MAJOR_VIOLATIONS;
+ } else if (severity.equals(RulePriority.MINOR)) {
+ metric = CoreMetrics.MINOR_VIOLATIONS;
+ } else if (severity.equals(RulePriority.INFO)) {
+ metric = CoreMetrics.INFO_VIOLATIONS;
+ } else {
+ throw new IllegalArgumentException("Unsupported severity: " + severity);
+ }
+ return metric;
+ }
+}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
index c349eac99ab..a270ecd8e59 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
@@ -80,7 +80,7 @@ public class ViolationsDecorator implements Decorator {
}
for (RulePriority severity : RulePriority.values()) {
- Metric metric = severityToMetric(severity);
+ Metric metric = SeverityUtils.severityToViolationMetric(severity);
if (context.getMeasure(metric) == null) {
Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.metric(metric));
int sum = MeasureUtils.sum(true, children).intValue() + severitiesBag.count(severity);
@@ -97,7 +97,7 @@ public class ViolationsDecorator implements Decorator {
}
for (RulePriority severity : RulePriority.values()) {
- Metric metric = severityToMetric(severity);
+ Metric metric = SeverityUtils.severityToViolationMetric(severity);
Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(metric));
for (Measure child : children) {
@@ -129,24 +129,6 @@ public class ViolationsDecorator implements Decorator {
return rulesBag;
}
- static Metric severityToMetric(RulePriority severity) {
- Metric metric;
- if (severity.equals(RulePriority.BLOCKER)) {
- metric = CoreMetrics.BLOCKER_VIOLATIONS;
- } else if (severity.equals(RulePriority.CRITICAL)) {
- metric = CoreMetrics.CRITICAL_VIOLATIONS;
- } else if (severity.equals(RulePriority.MAJOR)) {
- metric = CoreMetrics.MAJOR_VIOLATIONS;
- } else if (severity.equals(RulePriority.MINOR)) {
- metric = CoreMetrics.MINOR_VIOLATIONS;
- } else if (severity.equals(RulePriority.INFO)) {
- metric = CoreMetrics.INFO_VIOLATIONS;
- } else {
- throw new IllegalArgumentException("Unsupported severity: " + severity);
- }
- return metric;
- }
-
@Override
public String toString() {
return getClass().getSimpleName();
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/WeightedViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/WeightedViolationsDecorator.java
index c25f6415a3e..c6818f15912 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/WeightedViolationsDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/WeightedViolationsDecorator.java
@@ -66,7 +66,7 @@ public class WeightedViolationsDecorator implements Decorator {
Multiset<RulePriority> distribution = TreeMultiset.create();
for (RulePriority severity : RulePriority.values()) {
- Measure measure = context.getMeasure(severityToMetric(severity));
+ Measure measure = context.getMeasure(SeverityUtils.severityToViolationMetric(severity));
if (measure != null && MeasureUtils.hasValue(measure)) {
distribution.add(severity, measure.getIntValue());
double add = weights.get(severity) * measure.getIntValue();
@@ -78,24 +78,6 @@ public class WeightedViolationsDecorator implements Decorator {
saveMeasure(context, debtMeasure);
}
- static Metric severityToMetric(RulePriority severity) {
- Metric metric;
- if (severity.equals(RulePriority.BLOCKER)) {
- metric = CoreMetrics.BLOCKER_VIOLATIONS;
- } else if (severity.equals(RulePriority.CRITICAL)) {
- metric = CoreMetrics.CRITICAL_VIOLATIONS;
- } else if (severity.equals(RulePriority.MAJOR)) {
- metric = CoreMetrics.MAJOR_VIOLATIONS;
- } else if (severity.equals(RulePriority.MINOR)) {
- metric = CoreMetrics.MINOR_VIOLATIONS;
- } else if (severity.equals(RulePriority.INFO)) {
- metric = CoreMetrics.INFO_VIOLATIONS;
- } else {
- throw new IllegalArgumentException("Unsupported severity: " + severity);
- }
- return metric;
- }
-
private void saveMeasure(DecoratorContext context, Measure debtMeasure) {
if (debtMeasure.getValue() > 0.0) {
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/SeverityUtilsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/SeverityUtilsTest.java
new file mode 100644
index 00000000000..d0fc6e5ad36
--- /dev/null
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/SeverityUtilsTest.java
@@ -0,0 +1,35 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.plugins.core.sensors;
+
+import org.junit.Test;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.rules.RulePriority;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class SeverityUtilsTest {
+ @Test
+ public void shouldConvertToViolationMetric() {
+ assertThat(SeverityUtils.severityToViolationMetric(RulePriority.INFO), is(CoreMetrics.INFO_VIOLATIONS));
+ assertThat(SeverityUtils.severityToViolationMetric(RulePriority.BLOCKER), is(CoreMetrics.BLOCKER_VIOLATIONS));
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/Batch.java b/sonar-batch/src/main/java/org/sonar/batch/Batch.java
index ef964b991ac..13bc0827bda 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/Batch.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/Batch.java
@@ -66,7 +66,7 @@ public final class Batch {
/**
* Used by Gradle 1.0
*
- * @deprecated
+ * @deprecated in version 2.12
*/
@Deprecated
public static Batch create(ProjectReactor projectReactor, Configuration configuration, Object... bootstrapperComponents) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
index 5431a06c381..f0d6b2bc78a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
@@ -1423,7 +1423,7 @@ public final class CoreMetrics {
.setDomain(DOMAIN_GENERAL)
.create();
- public static List<Metric> metrics = Lists.newLinkedList();
+ private static final List<Metric> metrics = Lists.newLinkedList();
public static List<Metric> getMetrics() {
if (metrics.isEmpty()) {
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 6701e1c9b2f..5ec8e759dc8 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
@@ -21,7 +21,6 @@ package org.sonar.api.measures;
import org.sonar.api.qualitymodel.Characteristic;
import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
import java.util.ArrayList;
import java.util.Collection;
@@ -57,8 +56,8 @@ public final class MeasuresFilters {
}
for (Measure measure : measures) {
if (measure.getClass().equals(Measure.class) &&
- measure.getMetricKey().equals(metricKey) &&
- measure.getCharacteristic()==null) {
+ measure.getMetricKey().equals(metricKey) &&
+ measure.getCharacteristic() == null) {
return measure;
}
}
@@ -76,9 +75,9 @@ public final class MeasuresFilters {
}
for (Measure measure : measures) {
if (measure.getClass().equals(Measure.class) &&
- measure.getMetric().equals(metric) &&
- measure.getCharacteristic()!=null &&
- measure.getCharacteristic().equals(characteristic)) {
+ measure.getMetric().equals(metric) &&
+ measure.getCharacteristic() != null &&
+ measure.getCharacteristic().equals(characteristic)) {
return measure;
}
}
@@ -86,14 +85,14 @@ public final class MeasuresFilters {
}
};
}
-
+
/**
* @since 2.0
*/
public static MeasuresFilter<Measure> measure(final Measure measure) {
return new MeasuresFilter<Measure>() {
public Measure filter(Collection<Measure> measures) {
- if (measures==null) {
+ if (measures == null) {
return null;
}
for (Measure m : measures) {
@@ -107,7 +106,7 @@ public final class MeasuresFilters {
}
/**
- * @deprecated since 2.5. See http://jira.codehaus.org/browse/SONAR-2007
+ * @deprecated since 2.5. See http://jira.codehaus.org/browse/SONAR-2007
*/
@Deprecated
public static MeasuresFilter<RuleMeasure> ruleCategory(final Metric metric, final Integer category) {
@@ -136,8 +135,8 @@ public final class MeasuresFilters {
private boolean apply(Measure measure) {
return measure instanceof RuleMeasure
- && metric.equals(measure.getMetric())
- && ((RuleMeasure) measure).getRule() != null;
+ && metric.equals(measure.getMetric())
+ && ((RuleMeasure) measure).getRule() != null;
}
public Collection<RuleMeasure> filter(Collection<Measure> measures) {
@@ -181,8 +180,8 @@ public final class MeasuresFilters {
private boolean apply(Measure measure) {
return measure instanceof RuleMeasure
- && filterOnMetricKey().equals(measure.getMetricKey())
- && doApply((RuleMeasure) measure);
+ && filterOnMetricKey().equals(measure.getMetricKey())
+ && doApply((RuleMeasure) measure);
}
abstract boolean doApply(RuleMeasure ruleMeasure);
@@ -228,7 +227,7 @@ public final class MeasuresFilters {
@Override
boolean doApply(RuleMeasure measure) {
return measure.getRule() != null
- && rule.equals(measure.getRule());
+ && rule.equals(measure.getRule());
}
}
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
index 43cc7ccc162..17bad8d8c91 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
@@ -69,7 +69,7 @@ public class RegisterMetrics {
private void checkMetrics(Map<String, Metrics> metricsByRepository, Metrics metrics) {
for (Metric metric : metrics.getMetrics()) {
String metricKey = metric.getKey();
- if (CoreMetrics.metrics.contains(metric)) {
+ if (CoreMetrics.getMetrics().contains(metric)) {
throw new ServerStartException("The following metric is already defined in sonar: " + metricKey);
}
Metrics anotherRepository = metricsByRepository.get(metricKey);