]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 23 Jan 2015 14:50:17 +0000 (15:50 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 23 Jan 2015 14:50:17 +0000 (15:50 +0100)
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ActiveRule.java
sonar-core/src/main/java/org/sonar/core/user/AuthorDao.java
sonar-core/src/test/java/org/sonar/core/user/AuthorDaoTest.java
sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/user/AuthorDaoTest/add_missing_module_uuid_path.xml [new file with mode: 0644]

index 26721ddb5a6ee5b34a812bd5de8de755c2ddb9b2..4b6cd2f96b21460bf1d7e4eb7b4a9975f9a3f4f8 100644 (file)
@@ -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<Duplication> {
+  static class DuplicationComparator implements Comparator<Duplication>, 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<Block> {
+  private static class BlockComparator implements Comparator<Block>, Serializable {
     private static final long serialVersionUID = 1;
 
     @Override
index 4fda09f8910363614212062c324c85c6dcd76f4e..d9bf2e3bea712f061f686f10ea98189f774a422c 100644 (file)
@@ -30,7 +30,7 @@ public class ActiveRule {
   private final String name, severity, internalKey, language;
   private final Map<String, String> params = new HashMap<String, String>();
 
-  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;
   }
index 24f5d440de3824a256a2b763290cd36bdf0c3295..224d7201cb306eb9d02ca6f9841144b0d06252c0 100644 (file)
@@ -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);
index a8296eebebe135b433937e39271387c34a9f2a99..8b547471fe20ac32233c8d84d55915572a21c450 100644 (file)
@@ -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 (file)
index 0000000..b8737c8
--- /dev/null
@@ -0,0 +1,7 @@
+<dataset>
+  <projects id="1" name="developer@company.net" qualifier="DEV" uuid="ABCD" project_uuid="ABCD" module_uuid="[null]" module_uuid_path="."/>
+  <authors id="1" person_id="1" login="developer@company.net"/>
+
+  <projects id="2" name="developer2@company.net" qualifier="DEV" uuid="BCDE" project_uuid="BCDE" module_uuid="[null]" module_uuid_path="."/>
+  <authors id="2" person_id="2" login="developer2@company.net"/>
+</dataset>
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 (file)
index 0000000..fb0854f
--- /dev/null
@@ -0,0 +1,2 @@
+<dataset>
+</dataset>