diff options
author | Jenkins CI <ci@sonarsource.com> | 2015-03-24 14:55:50 +0100 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2015-03-24 14:55:50 +0100 |
commit | 0ba459d0cce0e1f0f29e581286ccf3c189bc3257 (patch) | |
tree | a26205538b10a48a7d743f3e9ccb05770c5faa11 /server | |
parent | 472ec39ded1cea93fe9538afb72cebd72c239588 (diff) | |
parent | 9ea5ee4ea61f0311c4f1fa5d2cfa96896be9676c (diff) | |
download | sonarqube-0ba459d0cce0e1f0f29e581286ccf3c189bc3257.tar.gz sonarqube-0ba459d0cce0e1f0f29e581286ccf3c189bc3257.zip |
Automatic merge from branch-5.1
* origin/branch-5.1:
SONAR-6335 Fix file source migration to generate correct checksum on blank lines
Do not show the debt (sub)characteristic of a rule when it has been overloaded as removed
Diffstat (limited to 'server')
4 files changed, 67 insertions, 11 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java index 3a4e6a7d53e..ea3aa3ca172 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java @@ -37,11 +37,7 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; import java.io.StringReader; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; import static com.google.common.base.Charsets.UTF_8; @@ -110,7 +106,7 @@ class FileSourceDto { public static String lineChecksum(String line) { String reducedLine = StringUtils.replaceChars(line, SPACE_CHARS, ""); - if (line.isEmpty()) { + if (reducedLine.isEmpty()) { return ""; } return DigestUtils.md5Hex(reducedLine); diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java index edb54625e5e..77cf01ec5a2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleMapping.java @@ -106,8 +106,8 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> { map("defaultDebtChar", new IndexStringMapper("defaultDebtChar", RuleNormalizer.RuleField.DEFAULT_CHARACTERISTIC.field())); map("defaultDebtSubChar", new IndexStringMapper("defaultDebtSubChar", RuleNormalizer.RuleField.DEFAULT_SUB_CHARACTERISTIC.field())); - map("debtChar", new IndexStringMapper("debtChar", RuleNormalizer.RuleField.CHARACTERISTIC.field())); - map("debtSubChar", new IndexStringMapper("debtSubChar", RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field())); + map("debtChar", new CharacteristicMapper()); + map("debtSubChar", new SubCharacteristicMapper()); map("debtCharName", new CharacteristicNameMapper()); map("debtSubCharName", new SubCharacteristicNameMapper()); @@ -198,6 +198,34 @@ public class RuleMapping extends BaseMapping<RuleDoc, RuleMappingContext> { return context == null || context.getFieldsToReturn().contains("debtSubCharName"); } + private static class CharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> { + private CharacteristicMapper() { + super(RuleNormalizer.RuleField.CHARACTERISTIC.field()); + } + + @Override + public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { + String debtCharacteristicKey = rule.debtCharacteristicKey(); + if (debtCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtCharacteristicKey)) { + json.prop("debtChar", debtCharacteristicKey); + } + } + } + + private static class SubCharacteristicMapper extends IndexMapper<RuleDoc, RuleMappingContext> { + private SubCharacteristicMapper() { + super(RuleNormalizer.RuleField.SUB_CHARACTERISTIC.field()); + } + + @Override + public void write(JsonWriter json, RuleDoc rule, RuleMappingContext context) { + String debtSubCharacteristicKey = rule.debtSubCharacteristicKey(); + if (debtSubCharacteristicKey != null && !DebtCharacteristic.NONE.equals(debtSubCharacteristicKey)) { + json.prop("debtSubChar", debtSubCharacteristicKey); + } + } + } + private static class CharacteristicNameMapper extends IndexMapper<RuleDoc, RuleMappingContext> { private CharacteristicNameMapper() { super(RuleNormalizer.RuleField.CHARACTERISTIC.field()); @@ -237,7 +265,7 @@ class RuleMappingContext { private final Map<String, String> debtCharacteristicNamesByKey = Maps.newHashMap(); @CheckForNull - public String debtCharacteristicName(String key) { + public String debtCharacteristicName(@Nullable String key) { return debtCharacteristicNamesByKey.get(key); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FileSourceDtoTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FileSourceDtoTest.java new file mode 100644 index 00000000000..fc4090f8adf --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FileSourceDtoTest.java @@ -0,0 +1,34 @@ +/* + * 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.server.db.migrations.v50; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FileSourceDtoTest { + + @Test + public void checksumOfBlankLine() { + assertThat(FileSourceDto.lineChecksum("")).isEmpty(); + assertThat(FileSourceDto.lineChecksum(" \r\n")).isEmpty(); + } + +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_rule_with_overridden_disable_debt.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_rule_with_overridden_disable_debt.json index e4b2495aac3..10bb82b9b8a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_rule_with_overridden_disable_debt.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/ShowActionMediumTest/show_rule_with_overridden_disable_debt.json @@ -7,8 +7,6 @@ "severity": "MINOR", "status": "BETA", "isTemplate": false, - "debtChar": "NONE", - "debtSubChar": "NONE", "debtOverloaded": true, "lang": "xoo" } |