From: David Gageot Date: Fri, 5 Oct 2012 08:58:44 +0000 (+0200) Subject: Fix violations X-Git-Tag: 3.3~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3b491638221796e517421d401d23b16e1589eabc;p=sonarqube.git Fix violations --- diff --git a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java index 98d63538619..4530c57fdaa 100644 --- a/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java +++ b/plugins/sonar-jacoco-plugin/src/test/java/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest.java @@ -23,11 +23,11 @@ import com.google.common.io.Files; import org.junit.Test; import org.sonar.api.batch.SensorContext; import org.sonar.api.measures.CoreMetrics; -import org.sonar.api.measures.Measure; import org.sonar.api.resources.JavaFile; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectFileSystem; import org.sonar.api.resources.Resource; +import org.sonar.api.test.IsMeasure; import org.sonar.test.TestUtils; import java.io.File; @@ -35,17 +35,19 @@ import java.io.IOException; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; public class JaCoCoOverallSensorTest { - private final JacocoConfiguration configuration= mock(JacocoConfiguration.class); + private final JacocoConfiguration configuration = mock(JacocoConfiguration.class); private final SensorContext context = mock(SensorContext.class); private final ProjectFileSystem pfs = mock(ProjectFileSystem.class); private final Project project = mock(Project.class); - private final JaCoCoOverallSensor sensor = new JaCoCoOverallSensor(configuration); + private final JaCoCoOverallSensor sensor = new JaCoCoOverallSensor(configuration); @Test public void should_execute_on_project() { @@ -83,9 +85,13 @@ public class JaCoCoOverallSensorTest { sensor.analyse(project, context); verify(context).getResource(resource); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, 5.0)); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_UNCOVERED_LINES, 0.0)); - verify(context).saveMeasure(resource, new Measure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, "3=1;6=1;7=1;10=1;11=1")); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_LINES_TO_COVER, 12.0))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_UNCOVERED_LINES, 2.0))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA, "3=1;6=1;7=1;10=1;11=1;14=1;15=1;17=1;18=1;20=1;23=0;24=0"))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_CONDITIONS_TO_COVER, 2.0))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, 0.0))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_CONDITIONS_BY_LINE, "14=2"))); + verify(context).saveMeasure(eq(resource), argThat(new IsMeasure(CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE, (String) null))); verifyNoMoreInteractions(context); } diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/HelloWorld.class.toCopy b/plugins/sonar-jacoco-plugin/src/test/resources/HelloWorld.class.toCopy index e9d34004571..5965c3d25af 100644 Binary files a/plugins/sonar-jacoco-plugin/src/test/resources/HelloWorld.class.toCopy and b/plugins/sonar-jacoco-plugin/src/test/resources/HelloWorld.class.toCopy differ diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec index ce2421df376..3a75745c380 100644 Binary files a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec and b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/it.exec differ diff --git a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec index 09d84373641..bf1248b02f6 100644 Binary files a/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec and b/plugins/sonar-jacoco-plugin/src/test/resources/org/sonar/plugins/jacoco/JaCoCoOverallSensorTest/ut.exec differ diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java index 6025d79bd44..c829cd4ac17 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyDefinition.java @@ -19,6 +19,7 @@ */ package org.sonar.api.config; +import com.google.common.collect.ImmutableList; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; @@ -27,6 +28,8 @@ import org.sonar.api.PropertyType; import javax.annotation.Nullable; +import java.util.List; + /** * @since 3.0 */ @@ -56,19 +59,19 @@ public final class PropertyDefinition { } } - private String key; - private String defaultValue; - private String name; - private PropertyType type = PropertyType.STRING; - private String[] options; - private String description; - private String category; - private boolean onProject = false; - private boolean onModule = false; - private boolean isGlobal = true; - private boolean multiValues; - private String propertySetKey; - private PropertyFieldDefinition[] fields; + private final String key; + private final String defaultValue; + private final String name; + private final PropertyType type; + private final String[] options; + private final String description; + private final String category; + private final boolean onProject; + private final boolean onModule; + private final boolean isGlobal; + private final boolean multiValues; + private final String propertySetKey; + private final List fields; private PropertyDefinition(Property annotation) { this.key = annotation.key(); @@ -82,8 +85,24 @@ public final class PropertyDefinition { this.type = fixType(annotation.key(), annotation.type()); this.options = annotation.options(); this.multiValues = annotation.multiValues(); - propertySetKey = annotation.propertySetKey(); - this.fields = PropertyFieldDefinition.create(annotation.fields()); + this.propertySetKey = annotation.propertySetKey(); + this.fields = ImmutableList.copyOf(PropertyFieldDefinition.create(annotation.fields())); + } + + private PropertyDefinition(String key, PropertyType type, String[] options) { + this.key = key; + this.name = null; + this.defaultValue = null; + this.description = null; + this.isGlobal = true; + this.onProject = false; + this.onModule = false; + this.category = null; + this.type = type; + this.options = options; + this.multiValues = false; + this.propertySetKey = null; + this.fields = null; } private static PropertyType fixType(String key, PropertyType type) { @@ -99,12 +118,6 @@ public final class PropertyDefinition { return type; } - private PropertyDefinition(String key, PropertyType type, String[] options) { - this.key = key; - this.type = type; - this.options = options; - } - public static PropertyDefinition create(Property annotation) { return new PropertyDefinition(annotation); } @@ -199,7 +212,7 @@ public final class PropertyDefinition { /** * @since 3.3 */ - public PropertyFieldDefinition[] getFields() { + public List getFields() { return fields; } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java index dfa4171792a..05fbea9cf7e 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/PropertyFieldDefinition.java @@ -47,12 +47,12 @@ public final class PropertyFieldDefinition { this.options = annotation.options(); } - public static PropertyFieldDefinition[] create(PropertyField[] fields) { + public static List create(PropertyField[] fields) { List definitions = Lists.newArrayList(); for (PropertyField field : fields) { definitions.add(new PropertyFieldDefinition(field)); } - return definitions.toArray(new PropertyFieldDefinition[definitions.size()]); + return definitions; } public String getKey() { 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 7e3adbf5073..fd65fb460a0 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 @@ -973,13 +973,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_COVERAGE = new Metric.Builder(OVERALL_COVERAGE_KEY, "Overall coverage", Metric.ValueType.PERCENT) - .setDescription("Overall test coverage") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .create(); + .setDescription("Overall test coverage") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .create(); /** * @since 3.3 @@ -990,14 +990,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_COVERAGE = new Metric.Builder(NEW_OVERALL_COVERAGE_KEY, "Overall new coverage", Metric.ValueType.PERCENT) - .setDescription("Overall coverage of new/changed code") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall coverage of new/changed code") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1008,14 +1008,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_LINES_TO_COVER = new Metric.Builder(OVERALL_LINES_TO_COVER_KEY, "Overall lines to cover", Metric.ValueType.INT) - .setDescription("Overall lines to cover by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setDomain(DOMAIN_OVERALL_TESTS) - .setQualitative(false) - .setFormula(new SumChildValuesFormula(false)) - .setHidden(true) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall lines to cover by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setDomain(DOMAIN_OVERALL_TESTS) + .setQualitative(false) + .setFormula(new SumChildValuesFormula(false)) + .setHidden(true) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1026,13 +1026,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_LINES_TO_COVER = new Metric.Builder(NEW_OVERALL_LINES_TO_COVER_KEY, "Overall new lines to cover", Metric.ValueType.INT) - .setDescription("New lines to cover by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New lines to cover by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1043,12 +1043,12 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_UNCOVERED_LINES = new Metric.Builder(OVERALL_UNCOVERED_LINES_KEY, "Overall uncovered lines", Metric.ValueType.INT) - .setDescription("Uncovered lines by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .create(); + .setDescription("Uncovered lines by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .create(); /** * @since 3.3 @@ -1059,13 +1059,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_UNCOVERED_LINES = new Metric.Builder(NEW_OVERALL_UNCOVERED_LINES_KEY, "Overall new lines uncovered", Metric.ValueType.INT) - .setDescription("New lines that are not covered by any tests") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setBestValue(0.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New lines that are not covered by any tests") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setBestValue(0.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1076,11 +1076,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_LINE_COVERAGE = new Metric.Builder(OVERALL_LINE_COVERAGE_KEY, "Overall line coverage", Metric.ValueType.PERCENT) - .setDescription("Line coverage by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .create(); + .setDescription("Line coverage by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .create(); /** * @since 3.3 @@ -1091,14 +1091,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_LINE_COVERAGE = new Metric.Builder(NEW_OVERALL_LINE_COVERAGE_KEY, "Overall new line coverage", Metric.ValueType.PERCENT) - .setDescription("Line coverage of added/changed code by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Line coverage of added/changed code by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1109,12 +1109,12 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_COVERAGE_LINE_HITS_DATA = new Metric.Builder(OVERALL_COVERAGE_LINE_HITS_DATA_KEY, "Overall coverage hits by line", Metric.ValueType.DATA) - .setDescription("Coverage hits by all tests and by line") - .setDirection(Metric.DIRECTION_NONE) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Coverage hits by all tests and by line") + .setDirection(Metric.DIRECTION_NONE) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1125,14 +1125,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(OVERALL_CONDITIONS_TO_COVER_KEY, "Overall branches to cover", Metric.ValueType.INT) - .setDescription("Branches to cover by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(false) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setHidden(true) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Branches to cover by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(false) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setHidden(true) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1143,11 +1143,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_CONDITIONS_TO_COVER = new Metric.Builder(NEW_OVERALL_CONDITIONS_TO_COVER_KEY, "Overall new branches to cover", Metric.ValueType.INT) - .setDescription("New branches to cover by all tests") - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New branches to cover by all tests") + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1158,11 +1158,11 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall uncovered branches", Metric.ValueType.INT) - .setDescription("Uncovered branches by all tests") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .create(); + .setDescription("Uncovered branches by all tests") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .create(); /** * @since 3.3 @@ -1173,13 +1173,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_UNCOVERED_CONDITIONS = new Metric.Builder(NEW_OVERALL_UNCOVERED_CONDITIONS_KEY, "Overall new branches uncovered", Metric.ValueType.INT) - .setDescription("New branches that are not covered by any test") - .setDirection(Metric.DIRECTION_WORST) - .setDomain(DOMAIN_OVERALL_TESTS) - .setFormula(new SumChildValuesFormula(false)) - .setBestValue(0.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("New branches that are not covered by any test") + .setDirection(Metric.DIRECTION_WORST) + .setDomain(DOMAIN_OVERALL_TESTS) + .setFormula(new SumChildValuesFormula(false)) + .setBestValue(0.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1190,13 +1190,13 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_BRANCH_COVERAGE = new Metric.Builder(OVERALL_BRANCH_COVERAGE_KEY, "Overall branch coverage", Metric.ValueType.PERCENT) - .setDescription("Branch coverage by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .create(); + .setDescription("Branch coverage by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .create(); /** * @since 3.3 @@ -1207,14 +1207,14 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric NEW_OVERALL_BRANCH_COVERAGE = new Metric.Builder(NEW_OVERALL_BRANCH_COVERAGE_KEY, "Overall new branch coverage", Metric.ValueType.PERCENT) - .setDescription("Branch coverage of new/changed code by all tests") - .setDirection(Metric.DIRECTION_BETTER) - .setQualitative(true) - .setDomain(DOMAIN_OVERALL_TESTS) - .setWorstValue(0.0) - .setBestValue(100.0) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Branch coverage of new/changed code by all tests") + .setDirection(Metric.DIRECTION_BETTER) + .setQualitative(true) + .setDomain(DOMAIN_OVERALL_TESTS) + .setWorstValue(0.0) + .setBestValue(100.0) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1225,10 +1225,10 @@ public final class CoreMetrics { * @since 3.3 */ public static final Metric OVERALL_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_CONDITIONS_BY_LINE_KEY, "Overall branches by line", Metric.ValueType.DATA) - .setDescription("Overall branches by all tests and by line") - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); + .setDescription("Overall branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); /** * @since 3.3 @@ -1238,12 +1238,12 @@ public final class CoreMetrics { /** * @since 3.3 */ - public static final Metric OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line", Metric.ValueType.DATA) - .setDescription("Overall covered branches by all tests and by line") - .setDomain(DOMAIN_OVERALL_TESTS) - .setDeleteHistoricalData(true) - .create(); - + public static final Metric OVERALL_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(OVERALL_COVERED_CONDITIONS_BY_LINE_KEY, "Overall covered branches by line", + Metric.ValueType.DATA) + .setDescription("Overall covered branches by all tests and by line") + .setDomain(DOMAIN_OVERALL_TESTS) + .setDeleteHistoricalData(true) + .create(); // -------------------------------------------------------------------------------------------------------------------- // diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java index ce4bdbc814e..134a0b4f6ad 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java @@ -20,6 +20,9 @@ package org.sonar.api.rules; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; +import com.google.common.base.Functions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -93,15 +96,19 @@ public final class AnnotationRuleParser implements ServerComponent { } } + private static final Function, PropertyType> TYPE_FOR_CLASS = Functions.forMap( + ImmutableMap., PropertyType> builder() + .put(Integer.class, PropertyType.INTEGER) + .put(int.class, PropertyType.INTEGER) + .put(Float.class, PropertyType.FLOAT) + .put(float.class, PropertyType.FLOAT) + .put(Boolean.class, PropertyType.BOOLEAN) + .put(boolean.class, PropertyType.BOOLEAN) + .build(), + PropertyType.STRING); + @VisibleForTesting static PropertyType guessType(Class type) { - if ((type == Integer.class) || (type == int.class)) { - return PropertyType.INTEGER; - } else if ((type == Float.class) || (type == float.class)) { - return PropertyType.FLOAT; - } else if ((type == Boolean.class) || (type == boolean.class)) { - return PropertyType.BOOLEAN; - } - return PropertyType.STRING; + return TYPE_FOR_CLASS.apply(type); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java index bc76fcd7507..a0b2295f98b 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/PropertyDefinitionTest.java @@ -94,17 +94,17 @@ public class PropertyDefinitionTest { PropertyDefinition def = PropertyDefinition.create(prop); assertThat(def.getFields()).hasSize(2); - assertThat(def.getFields()[0].getKey()).isEqualTo("first"); - assertThat(def.getFields()[0].getName()).isEqualTo("First"); - assertThat(def.getFields()[0].getDescription()).isEqualTo("Description"); - assertThat(def.getFields()[0].getType()).isEqualTo(PropertyType.STRING); - assertThat(def.getFields()[0].getOptions()).containsOnly("A", "B"); - assertThat(def.getFields()[0].getIndicativeSize()).isEqualTo(20); - assertThat(def.getFields()[1].getKey()).isEqualTo("second"); - assertThat(def.getFields()[1].getName()).isEqualTo("Second"); - assertThat(def.getFields()[1].getType()).isEqualTo(PropertyType.INTEGER); - assertThat(def.getFields()[1].getOptions()).isEmpty(); - assertThat(def.getFields()[1].getIndicativeSize()).isEqualTo(5); + assertThat(def.getFields().get(0).getKey()).isEqualTo("first"); + assertThat(def.getFields().get(0).getName()).isEqualTo("First"); + assertThat(def.getFields().get(0).getDescription()).isEqualTo("Description"); + assertThat(def.getFields().get(0).getType()).isEqualTo(PropertyType.STRING); + assertThat(def.getFields().get(0).getOptions()).containsOnly("A", "B"); + assertThat(def.getFields().get(0).getIndicativeSize()).isEqualTo(20); + assertThat(def.getFields().get(1).getKey()).isEqualTo("second"); + assertThat(def.getFields().get(1).getName()).isEqualTo("Second"); + assertThat(def.getFields().get(1).getType()).isEqualTo(PropertyType.INTEGER); + assertThat(def.getFields().get(1).getOptions()).isEmpty(); + assertThat(def.getFields().get(1).getIndicativeSize()).isEqualTo(5); } @Properties(@Property(key = "hello", name = "Hello")) diff --git a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java index ec3c0852363..a279aa66bf3 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/DefaultPages.java @@ -21,7 +21,13 @@ package org.sonar.server.ui; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.web.*; +import org.sonar.api.web.DefaultTab; +import org.sonar.api.web.NavigationSection; +import org.sonar.api.web.RequiredMeasures; +import org.sonar.api.web.ResourceQualifier; +import org.sonar.api.web.RubyRailsPage; +import org.sonar.api.web.UserRole; +import org.sonar.api.web.View; /** * @since 2.7 @@ -44,7 +50,7 @@ public final class DefaultPages { @UserRole(UserRole.CODEVIEWER) private static final class SourceTab implements RubyRailsPage { public String getTemplate() { - //not used, hardcoded in BrowseController + // not used, hardcoded in BrowseController return "browse/index"; } @@ -57,15 +63,14 @@ public final class DefaultPages { } } - @NavigationSection(NavigationSection.RESOURCE_TAB) @ResourceQualifier({Qualifiers.FILE, Qualifiers.CLASS}) @DefaultTab(metrics = { - /* unit tests */ - CoreMetrics.COVERAGE_KEY, CoreMetrics.LINES_TO_COVER_KEY, CoreMetrics.UNCOVERED_LINES_KEY, CoreMetrics.LINE_COVERAGE_KEY, - CoreMetrics.CONDITIONS_TO_COVER_KEY, CoreMetrics.UNCOVERED_CONDITIONS_KEY, CoreMetrics.BRANCH_COVERAGE_KEY, - CoreMetrics.NEW_COVERAGE_KEY, CoreMetrics.NEW_UNCOVERED_LINES_KEY, CoreMetrics.NEW_LINE_COVERAGE_KEY, - CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY, + /* unit tests */ + CoreMetrics.COVERAGE_KEY, CoreMetrics.LINES_TO_COVER_KEY, CoreMetrics.UNCOVERED_LINES_KEY, CoreMetrics.LINE_COVERAGE_KEY, + CoreMetrics.CONDITIONS_TO_COVER_KEY, CoreMetrics.UNCOVERED_CONDITIONS_KEY, CoreMetrics.BRANCH_COVERAGE_KEY, + CoreMetrics.NEW_COVERAGE_KEY, CoreMetrics.NEW_UNCOVERED_LINES_KEY, CoreMetrics.NEW_LINE_COVERAGE_KEY, + CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY, /* integration tests */ CoreMetrics.IT_COVERAGE_KEY, CoreMetrics.IT_LINES_TO_COVER_KEY, CoreMetrics.IT_UNCOVERED_LINES_KEY, CoreMetrics.IT_LINE_COVERAGE_KEY, @@ -77,13 +82,14 @@ public final class DefaultPages { CoreMetrics.OVERALL_COVERAGE_KEY, CoreMetrics.OVERALL_LINES_TO_COVER_KEY, CoreMetrics.OVERALL_UNCOVERED_LINES_KEY, CoreMetrics.OVERALL_LINE_COVERAGE_KEY, CoreMetrics.OVERALL_CONDITIONS_TO_COVER_KEY, CoreMetrics.OVERALL_UNCOVERED_CONDITIONS_KEY, CoreMetrics.OVERALL_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_UNCOVERED_LINES_KEY, CoreMetrics.NEW_OVERALL_LINE_COVERAGE_KEY, - CoreMetrics.NEW_OVERALL_LINES_TO_COVER_KEY, CoreMetrics.NEW_OVERALL_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER_KEY, CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS_KEY - }) + CoreMetrics.NEW_OVERALL_LINES_TO_COVER_KEY, CoreMetrics.NEW_OVERALL_BRANCH_COVERAGE_KEY, CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER_KEY, + CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS_KEY + }) @RequiredMeasures(anyOf = {CoreMetrics.COVERAGE_KEY, CoreMetrics.IT_COVERAGE_KEY, CoreMetrics.OVERALL_COVERAGE_KEY}) @UserRole(UserRole.CODEVIEWER) private static final class CoverageTab implements RubyRailsPage { public String getTemplate() { - //not used, hardcoded in BrowseController + // not used, hardcoded in BrowseController return "browse/index"; } @@ -98,16 +104,16 @@ public final class DefaultPages { @NavigationSection(NavigationSection.RESOURCE_TAB) @DefaultTab(metrics = {CoreMetrics.VIOLATIONS_DENSITY_KEY, CoreMetrics.WEIGHTED_VIOLATIONS_KEY, CoreMetrics.VIOLATIONS_KEY, CoreMetrics.BLOCKER_VIOLATIONS_KEY, - CoreMetrics.CRITICAL_VIOLATIONS_KEY, CoreMetrics.MAJOR_VIOLATIONS_KEY, CoreMetrics.MINOR_VIOLATIONS_KEY, CoreMetrics.INFO_VIOLATIONS_KEY, - CoreMetrics.NEW_VIOLATIONS_KEY, CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY, CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY, CoreMetrics.NEW_MAJOR_VIOLATIONS_KEY, - CoreMetrics.NEW_MINOR_VIOLATIONS_KEY, CoreMetrics.NEW_INFO_VIOLATIONS_KEY, CoreMetrics.ACTIVE_REVIEWS_KEY, CoreMetrics.UNASSIGNED_REVIEWS_KEY, - CoreMetrics.UNPLANNED_REVIEWS_KEY, CoreMetrics.FALSE_POSITIVE_REVIEWS_KEY, CoreMetrics.UNREVIEWED_VIOLATIONS_KEY, CoreMetrics.NEW_UNREVIEWED_VIOLATIONS_KEY}) + CoreMetrics.CRITICAL_VIOLATIONS_KEY, CoreMetrics.MAJOR_VIOLATIONS_KEY, CoreMetrics.MINOR_VIOLATIONS_KEY, CoreMetrics.INFO_VIOLATIONS_KEY, + CoreMetrics.NEW_VIOLATIONS_KEY, CoreMetrics.NEW_BLOCKER_VIOLATIONS_KEY, CoreMetrics.NEW_CRITICAL_VIOLATIONS_KEY, CoreMetrics.NEW_MAJOR_VIOLATIONS_KEY, + CoreMetrics.NEW_MINOR_VIOLATIONS_KEY, CoreMetrics.NEW_INFO_VIOLATIONS_KEY, CoreMetrics.ACTIVE_REVIEWS_KEY, CoreMetrics.UNASSIGNED_REVIEWS_KEY, + CoreMetrics.UNPLANNED_REVIEWS_KEY, CoreMetrics.FALSE_POSITIVE_REVIEWS_KEY, CoreMetrics.UNREVIEWED_VIOLATIONS_KEY, CoreMetrics.NEW_UNREVIEWED_VIOLATIONS_KEY}) @ResourceQualifier({Qualifiers.VIEW, Qualifiers.SUBVIEW, Qualifiers.PROJECT, Qualifiers.MODULE, Qualifiers.PACKAGE, Qualifiers.DIRECTORY, Qualifiers.FILE, Qualifiers.CLASS, Qualifiers.UNIT_TEST_FILE}) @UserRole(UserRole.CODEVIEWER) private static final class ViolationsTab implements RubyRailsPage { public String getTemplate() { - //not used, hardcoded in BrowseController + // not used, hardcoded in BrowseController return "browse/index"; } @@ -126,7 +132,7 @@ public final class DefaultPages { @UserRole(UserRole.CODEVIEWER) private static final class DuplicationsTab implements RubyRailsPage { public String getTemplate() { - //not used, hardcoded in BrowseController + // not used, hardcoded in BrowseController return "browse/index"; }