From 51b8c91b138aab690921e647e30deabbaf61e75b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 23 Jan 2015 15:50:17 +0100 Subject: [PATCH] Fix quality flaws --- .../duplication/ws/DuplicationsParser.java | 5 +++-- .../sonar/batch/protocol/input/ActiveRule.java | 10 +++++++++- .../main/java/org/sonar/core/user/AuthorDao.java | 3 ++- .../java/org/sonar/core/user/AuthorDaoTest.java | 16 +++++++++++++++- .../add_missing_module_uuid_path-result.xml | 7 +++++++ .../add_missing_module_uuid_path.xml | 2 ++ 6 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path-result.xml create mode 100644 sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java index 26721ddb5a6..4b6cd2f96b2 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java +++ b/server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java @@ -35,6 +35,7 @@ import javax.annotation.Nullable; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; +import java.io.Serializable; import java.io.StringReader; import java.util.Collections; import java.util.Comparator; @@ -103,7 +104,7 @@ public class DuplicationsParser implements ServerComponent { } @VisibleForTesting - static class DuplicationComparator implements Comparator { + static class DuplicationComparator implements Comparator, Serializable { private static final long serialVersionUID = 1; private final ComponentDto component; @@ -146,7 +147,7 @@ public class DuplicationsParser implements ServerComponent { } } - private static class BlockComparator implements Comparator { + private static class BlockComparator implements Comparator, Serializable { private static final long serialVersionUID = 1; @Override diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java index 4fda09f8910..d9bf2e3bea7 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java @@ -30,7 +30,7 @@ public class ActiveRule { private final String name, severity, internalKey, language; private final Map params = new HashMap(); - public ActiveRule(String repositoryKey, String ruleKey, String name, String severity, @Nullable String internalKey, String language) { + public ActiveRule(String repositoryKey, String ruleKey, String name, @Nullable String severity, @Nullable String internalKey, @Nullable String language) { this.repositoryKey = repositoryKey; this.ruleKey = ruleKey; this.name = name; @@ -51,10 +51,18 @@ public class ActiveRule { return name; } + /** + * Is null on manual rules + */ + @CheckForNull public String severity() { return severity; } + /** + * Is null on manual rules + */ + @CheckForNull public String language() { return language; } diff --git a/sonar-core/src/main/java/org/sonar/core/user/AuthorDao.java b/sonar-core/src/main/java/org/sonar/core/user/AuthorDao.java index 24f5d440de3..224d7201cb3 100644 --- a/sonar-core/src/main/java/org/sonar/core/user/AuthorDao.java +++ b/sonar-core/src/main/java/org/sonar/core/user/AuthorDao.java @@ -19,6 +19,7 @@ */ package org.sonar.core.user; +import com.google.common.base.Strings; import org.apache.ibatis.session.SqlSession; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; @@ -78,7 +79,7 @@ public class AuthorDao implements BatchComponent, ServerComponent { SqlSession session = mybatis.openSession(false); try { // Hack in order to set "." on DEV - if (resourceDto.getModuleUuidPath() == null || resourceDto.getModuleUuidPath().isEmpty()) { + if (Strings.isNullOrEmpty(resourceDto.getModuleUuidPath())) { resourceDto.setModuleUuidPath(ComponentDto.MODULE_UUID_PATH_SEP); } resourceDao.insertUsingExistingSession(resourceDto, session); diff --git a/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java b/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java index a8296eebebe..8b547471fe2 100644 --- a/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java @@ -72,7 +72,7 @@ public class AuthorDaoTest extends AbstractDaoTestCase { setupData("shouldInsertAuthorAndDeveloper"); String login = "developer@company.net"; - ResourceDto resourceDto = new ResourceDto().setName(login).setQualifier("DEV").setUuid("ABCD").setProjectUuid("ABCD"); + ResourceDto resourceDto = new ResourceDto().setName(login).setQualifier("DEV").setUuid("ABCD").setProjectUuid("ABCD").setModuleUuidPath("."); dao.insertAuthorAndDeveloper(login, resourceDto); checkTables("shouldInsertAuthorAndDeveloper", @@ -81,6 +81,20 @@ public class AuthorDaoTest extends AbstractDaoTestCase { "authors", "projects"); } + @Test + public void add_missing_module_uuid_path() throws Exception { + setupData("add_missing_module_uuid_path"); + + dao.insertAuthorAndDeveloper("developer@company.net", new ResourceDto().setName("developer@company.net").setQualifier("DEV").setUuid("ABCD").setProjectUuid("ABCD") + .setModuleUuidPath("")); + dao.insertAuthorAndDeveloper("developer2@company.net", new ResourceDto().setName("developer2@company.net").setQualifier("DEV").setUuid("BCDE").setProjectUuid("BCDE")); + + checkTables("add_missing_module_uuid_path", + new String[] {"created_at", "updated_at", "copy_resource_id", "description", "enabled", "kee", "deprecated_kee", "path", "language", "long_name", "person_id", "root_id", + "scope", "authorization_updated_at"}, + "authors", "projects"); + } + @Test public void shouldPreventAuthorsDuplication() { setupData("shouldPreventAuthorsDuplication"); diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path-result.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path-result.xml new file mode 100644 index 00000000000..b8737c88118 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path-result.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path.xml b/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path.xml new file mode 100644 index 00000000000..fb0854fccbe --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path.xml @@ -0,0 +1,2 @@ + + -- 2.39.5