diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-04 14:25:21 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-12-04 14:26:32 +0100 |
commit | 9df8ed37f34ceb5d26045bf2d75a56b2fe80e172 (patch) | |
tree | 15b9d5a4d484ccc809f745a243fd7becf0a05166 | |
parent | 58d45c1b7a60280949d5a3da512cde645e19e1bc (diff) | |
download | sonarqube-9df8ed37f34ceb5d26045bf2d75a56b2fe80e172.tar.gz sonarqube-9df8ed37f34ceb5d26045bf2d75a56b2fe80e172.zip |
Fix quality flaws
10 files changed, 31 insertions, 25 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java index 513711c6f79..1b5ad14e6e2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java +++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/BarChart.java @@ -178,7 +178,7 @@ public class BarChart extends BaseChartWeb implements DeprecatedChart { // Series String seriesParam = params.get(BaseChartWeb.CHART_PARAM_SERIES); - String[] seriesSplit = null; + String[] seriesSplit; if (seriesParam != null && seriesParam.length() > 0) { seriesSplit = seriesParam.split(","); } else { diff --git a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java index 064df390a3c..51f5fa3a94c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java +++ b/server/sonar-server/src/main/java/org/sonar/server/charts/deprecated/CustomBarChart.java @@ -109,7 +109,7 @@ public class CustomBarChart extends BarChart { // Categories String categoriesParam = params.get(CHART_PARAM_CATEGORIES); - String[] categoriesSplit = null; + String[] categoriesSplit; if (categoriesParam != null && categoriesParam.length() > 0) { categoriesSplit = categoriesParam.split(","); } else { diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java index f6d30a2ae02..fdde7ba5f40 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorContext.java @@ -96,7 +96,7 @@ public class DefaultSensorContext implements SensorContext { @Override public <G extends Serializable> NewMeasure<G> newMeasure() { - return new DefaultMeasure<G>(sensorStorage); + return new DefaultMeasure<>(sensorStorage); } @Override diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardMapper.java b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardMapper.java index a6222c6fcb8..e39494acca0 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/DashboardMapper.java @@ -45,6 +45,6 @@ public interface DashboardMapper { @Insert("INSERT INTO dashboards (user_id, name, description, column_layout, shared, is_global, created_at, " + "updated_at) VALUES (#{userId}, #{name}, #{description}, #{columnLayout}, #{shared}, " + "#{global}, #{createdAt}, #{updatedAt})") - @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void insert(DashboardDto dashboardDto); } diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetMapper.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetMapper.java index c82e1b4c924..dcf00a6bf9c 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetMapper.java @@ -31,7 +31,7 @@ public interface WidgetMapper { " values (#{dashboardId,jdbcType=INTEGER}, #{widgetKey,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, " + " #{description,jdbcType=VARCHAR}, #{columnIndex,jdbcType=INTEGER}, " + " #{rowIndex,jdbcType=INTEGER}, #{configured,jdbcType=BOOLEAN}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{resourceId,jdbcType=INTEGER})") - @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void insert(WidgetDto widgetDto); WidgetDto selectById(long widgetId); diff --git a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyMapper.java b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyMapper.java index 46432fba6b8..3b26323b7d2 100644 --- a/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/dashboard/WidgetPropertyMapper.java @@ -31,7 +31,7 @@ public interface WidgetPropertyMapper { String COLUMNS = "wp.id, wp.widget_id as \"widgetId\", wp.kee as \"propertyKey\", wp.text_value as \"textValue\""; @Insert("insert into widget_properties (widget_id, kee, text_value) values (#{widgetId}, #{propertyKey}, #{textValue})") - @Options(keyColumn = "id", useGeneratedKeys = true, keyProperty = "id") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") void insert(WidgetPropertyDto dto); @CheckForNull diff --git a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java index 8b94ef241bd..32f6ae890b4 100644 --- a/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java @@ -61,6 +61,7 @@ public class CeActivityDaoTest { assertThat(saved.get().getStartedAt()).isEqualTo(1_500_000_000_000L); assertThat(saved.get().getExecutedAt()).isEqualTo(1_500_000_000_500L); assertThat(saved.get().getExecutionTimeMs()).isEqualTo(500L); + assertThat(saved.get().toString()).isNotEmpty(); } @Test diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java index 16b780739e7..4e88bc085cc 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileExporter.java @@ -66,7 +66,7 @@ public abstract class ProfileExporter { } protected final ProfileExporter setSupportedLanguages(String... languages) { - supportedLanguages = (languages != null ? languages : new String[0]); + supportedLanguages = (languages != null) ? languages : new String[0]; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java index afe3d17e748..d0eeb1ac824 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/ProfileImporter.java @@ -64,7 +64,7 @@ public abstract class ProfileImporter { } protected final ProfileImporter setSupportedLanguages(String... languages) { - supportedLanguages = (languages != null ? languages : new String[0]); + supportedLanguages = (languages != null) ? languages : new String[0]; return this; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java index 8ecc91898dd..60e24c08174 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java @@ -264,51 +264,51 @@ public class RulesDefinitionXmlLoader { String nodeName = cursor.getLocalName(); if (equalsIgnoreCase("name", nodeName)) { - name = trim(cursor.collectDescendantText(false)); + name = nodeValue(cursor); } else if (equalsIgnoreCase("description", nodeName)) { - description = trim(cursor.collectDescendantText(false)); + description = nodeValue(cursor); } else if (equalsIgnoreCase("descriptionFormat", nodeName)) { - descriptionFormat = trim(cursor.collectDescendantText(false)); + descriptionFormat = nodeValue(cursor); } else if (equalsIgnoreCase("key", nodeName)) { - key = trim(cursor.collectDescendantText(false)); + key = nodeValue(cursor); } else if (equalsIgnoreCase("configKey", nodeName)) { // deprecated field, replaced by internalKey - internalKey = trim(cursor.collectDescendantText(false)); + internalKey = nodeValue(cursor); } else if (equalsIgnoreCase("internalKey", nodeName)) { - internalKey = trim(cursor.collectDescendantText(false)); + internalKey = nodeValue(cursor); } else if (equalsIgnoreCase("priority", nodeName)) { // deprecated field, replaced by severity - severity = trim(cursor.collectDescendantText(false)); + severity = nodeValue(cursor); } else if (equalsIgnoreCase("severity", nodeName)) { - severity = trim(cursor.collectDescendantText(false)); + severity = nodeValue(cursor); } else if (equalsIgnoreCase("cardinality", nodeName)) { - template = Cardinality.MULTIPLE == Cardinality.valueOf(trim(cursor.collectDescendantText(false))); + template = Cardinality.MULTIPLE == Cardinality.valueOf(nodeValue(cursor)); } else if (equalsIgnoreCase("effortToFixDescription", nodeName)) { - effortToFixDescription = trim(cursor.collectDescendantText(false)); + effortToFixDescription = nodeValue(cursor); } else if (equalsIgnoreCase("debtRemediationFunction", nodeName)) { - debtRemediationFunction = trim(cursor.collectDescendantText(false)); + debtRemediationFunction = nodeValue(cursor); } else if (equalsIgnoreCase("debtRemediationFunctionOffset", nodeName)) { - debtRemediationFunctionOffset = trim(cursor.collectDescendantText(false)); + debtRemediationFunctionOffset = nodeValue(cursor); } else if (equalsIgnoreCase("debtRemediationFunctionCoefficient", nodeName)) { - debtRemediationFunctionCoeff = trim(cursor.collectDescendantText(false)); + debtRemediationFunctionCoeff = nodeValue(cursor); } else if (equalsIgnoreCase("debtSubCharacteristic", nodeName)) { - debtSubCharacteristic = trim(cursor.collectDescendantText(false)); + debtSubCharacteristic = nodeValue(cursor); } else if (equalsIgnoreCase("status", nodeName)) { - String s = trim(cursor.collectDescendantText(false)); + String s = nodeValue(cursor); if (s != null) { status = RuleStatus.valueOf(s); } @@ -317,7 +317,7 @@ public class RulesDefinitionXmlLoader { params.add(processParameter(cursor)); } else if (equalsIgnoreCase("tag", nodeName)) { - tags.add(trim(cursor.collectDescendantText(false))); + tags.add(nodeValue(cursor)); } } @@ -371,7 +371,12 @@ public class RulesDefinitionXmlLoader { } } + private static String nodeValue(SMInputCursor cursor) throws XMLStreamException { + return trim(cursor.collectDescendantText(false)); + } + private static class ParamStruct { + String key; String description; String defaultValue; @@ -396,7 +401,7 @@ public class RulesDefinitionXmlLoader { SMInputCursor paramC = ruleC.childElementCursor(); while (paramC.getNext() != null) { String propNodeName = paramC.getLocalName(); - String propText = trim(paramC.collectDescendantText(false)); + String propText = nodeValue(paramC); if (equalsIgnoreCase("key", propNodeName)) { param.key = propText; |