]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8838 insert and return tags from projects DB table
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Fri, 24 Feb 2017 17:53:45 +0000 (18:53 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 28 Feb 2017 10:29:29 +0000 (11:29 +0100)
17 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentDaoTest/insert-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentDaoTest/insert_disabled_component-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentDaoWithDuplicatedKeysTest/schema.sql
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shared.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKey-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldBulkUpdateKeyOnOnlyOneSubmodule-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldNotUpdateAllSubmodules.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ComponentKeyUpdaterDaoTest/shouldUpdateKey-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ResourceDaoTest/update_authorization_date-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/component/ResourceDaoTest/update_authorization_date.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml
server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml

index 959d0a3838187528efbf363ba94f95a9ec53039a..3c85c7a9625c3b6d2c0359d0ea793d6446057999 100644 (file)
  * 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.db.component;
 
+import com.google.common.base.Joiner;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import java.util.Date;
@@ -30,6 +32,7 @@ import org.sonar.api.component.Component;
 import org.sonar.api.resources.Scopes;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Collections.emptyList;
 import static org.sonar.db.component.ComponentValidator.checkComponentKey;
 import static org.sonar.db.component.ComponentValidator.checkComponentName;
 
@@ -39,6 +42,10 @@ public class ComponentDto implements Component {
   public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR;
   private static final Splitter UUID_PATH_SPLITTER = Splitter.on(UUID_PATH_SEPARATOR).omitEmptyStrings();
 
+  private static final char TAGS_SEPARATOR = ',';
+  private static final Joiner TAGS_JOINER = Joiner.on(TAGS_SEPARATOR).skipNulls();
+  private static final Splitter TAGS_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings();
+
   /**
    * ID generated by database. Do not use.
    */
@@ -113,11 +120,18 @@ public class ComponentDto implements Component {
   private String longName;
   private String language;
   private String description;
+  private String tags;
   private boolean enabled = true;
 
   private Date createdAt;
   private Long authorizationUpdatedAt;
 
+  public static String formatUuidPathFromParent(ComponentDto parent) {
+    checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath()));
+    checkArgument(!Strings.isNullOrEmpty(parent.uuid()));
+    return parent.getUuidPath() + parent.uuid() + UUID_PATH_SEPARATOR;
+  }
+
   public Long getId() {
     return id;
   }
@@ -149,6 +163,11 @@ public class ComponentDto implements Component {
     return uuidPath;
   }
 
+  public ComponentDto setUuidPath(String s) {
+    this.uuidPath = s;
+    return this;
+  }
+
   /**
    * List of ancestor UUIDs, ordered by depth in tree.
    */
@@ -156,11 +175,6 @@ public class ComponentDto implements Component {
     return UUID_PATH_SPLITTER.splitToList(uuidPath);
   }
 
-  public ComponentDto setUuidPath(String s) {
-    this.uuidPath = s;
-    return this;
-  }
-
   @Override
   public String key() {
     return kee;
@@ -360,6 +374,28 @@ public class ComponentDto implements Component {
     return moduleUuid == null && Scopes.PROJECT.equals(scope);
   }
 
+  public List<String> getTags() {
+    return tags == null ? emptyList() : TAGS_SPLITTER.splitToList(tags);
+  }
+
+  public ComponentDto setTags(List<String> tags) {
+    setTagsString(TAGS_JOINER.join(tags));
+    return this;
+  }
+
+  /**
+   * Used by MyBatis
+   */
+  @CheckForNull
+  public String getTagsString() {
+    return tags;
+  }
+
+  public ComponentDto setTagsString(@Nullable String tags) {
+    this.tags = tags;
+    return this;
+  }
+
   @Override
   public boolean equals(Object o) {
     if (this == o) {
@@ -402,10 +438,4 @@ public class ComponentDto implements Component {
       .append("authorizationUpdatedAt", authorizationUpdatedAt)
       .toString();
   }
-
-  public static String formatUuidPathFromParent(ComponentDto parent) {
-    checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath()));
-    checkArgument(!Strings.isNullOrEmpty(parent.uuid()));
-    return parent.getUuidPath() + parent.uuid() + UUID_PATH_SEPARATOR;
-  }
 }
index 3f3f8bb34f643071cfe8bcf0e75686a356da644b..e20ed6318bfaeadda2a26d52921e6bed9b5c679c 100644 (file)
@@ -15,6 +15,7 @@
     p.name as name,
     p.long_name as longName,
     p.description as description,
+    p.tags as tagsString,
     p.qualifier as qualifier,
     p.scope as scope,
     p.language as language,
     scope,
     language,
     description,
+    tags,
     root_uuid,
     path,
     copy_component_uuid,
     #{scope,jdbcType=VARCHAR},
     #{language,jdbcType=VARCHAR},
     #{description,jdbcType=VARCHAR},
+    #{tagsString, jdbcType=VARCHAR},
     #{rootUuid,jdbcType=VARCHAR},
     #{path,jdbcType=VARCHAR},
     #{copyComponentUuid,jdbcType=VARCHAR},
index 5e88b5687d1540730544fd7a1e605f016904771e..e2fc063c2ea0fad1592a9f30248ac140a8e6fa5f 100644 (file)
@@ -696,7 +696,9 @@ public class ComponentDaoTest {
       .setDeveloperUuid("uuid_7")
       .setEnabled(true)
       .setCreatedAt(DateUtils.parseDate("2014-06-18"))
-      .setAuthorizationUpdatedAt(123456789L);
+      .setAuthorizationUpdatedAt(123456789L)
+      .setTags(newArrayList("platform", "analyzers"))
+      ;
 
     underTest.insert(dbSession, componentDto);
     dbSession.commit();
@@ -1107,7 +1109,7 @@ public class ComponentDaoTest {
     ComponentDto project1 = db.components().insertComponent(newProjectDto(organizationDto).setName("project1"));
     ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setName("module1"));
     ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module1).setName("subModule1"));
-    ComponentDto file = db.components().insertComponent(newFileDto(subModule1).setName("file"));
+    db.components().insertComponent(newFileDto(subModule1).setName("file"));
     ComponentDto project2 = db.components().insertComponent(newProjectDto(organizationDto).setName("project2"));
     ComponentDto project3 = db.components().insertComponent(newProjectDto(organizationDto).setName("project3"));
 
index 85e0a295d99d532690c92d0b942d596767a2aee5..280502a5ea86427cc51583c1f824dfad6085fa0a 100644 (file)
@@ -17,6 +17,7 @@
             path="src/org/struts/RequestContext.java"
             root_uuid="uuid_3"
             description="description"
+            tags="platform,analyzers"
             enabled="[true]"
             copy_component_uuid="uuid_5"
             developer_uuid="uuid_7"
index e938c80ac16b2a7cab29342c277980b8921a724e..7f24dbc859377b271ca90eccd18dffad7d2c30f3 100644 (file)
@@ -16,6 +16,7 @@
             path="src/org/struts/RequestContext.java"
             root_uuid="uuid_3"
             description="[null]"
+            tags="[null]"
             enabled="[false]"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
index f1420ae723a254d64e8d545302e395247a228ab8..e2f822f02d768fb1382423155c451ce932f969c0 100644 (file)
@@ -25,6 +25,7 @@ CREATE TABLE "PROJECTS" (
   "MODULE_UUID_PATH" VARCHAR(1500),
   "NAME" VARCHAR(2000),
   "DESCRIPTION" VARCHAR(2000),
+  "TAGS" VARCHAR(4000),
   "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
   "SCOPE" VARCHAR(3),
   "QUALIFIER" VARCHAR(10),
index 10784d93cc5d891ced0ac538fce2b9d1bf4d26d2..8a85d6953856c3ac187b222e68bbc54ab5a7436f 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -51,6 +52,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
@@ -86,6 +88,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Foo Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
index 7abbcfc4c3a80e00aec6f58360d877f65c147df6..c734f270dde9548593aecb0b8887fb9e45c8a8a3 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -53,6 +54,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
@@ -90,6 +92,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             qualifier="BRC"
             long_name="Foo Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
index 8eed6e70baa3db4322f5d30c8f3d5d505f7d92e6..f0ca1fc2d8f0498fc8ecf083570025a6c957eb3a 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -53,6 +54,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
@@ -90,6 +92,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
             qualifier="BRC"
             long_name="Foo Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             copy_component_uuid="[null]"
index fd717059b49652b539db32978814904dad3fc590..c233d66e2fc4f0bd0ab353f303a7480e6ceec70c 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -53,6 +54,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
@@ -88,6 +90,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
index ca5465808002d3d36ad1b28378b713ce303428e3..b16db8645503295456a3174b0b74309f43defb2c 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -51,6 +52,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
@@ -85,6 +87,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
index 2a39e7a002dc13136d8f3baaa02ea798d6cfcc12..eb73a95d604b4b85e4c255b3873f255b7f1ad6f8 100644 (file)
@@ -14,6 +14,7 @@
             module_uuid="[null]"
             module_uuid_path="."
             description="[null]"
+            tags="[null]"
             long_name="Apache Struts"
             enabled="[true]"
             language="java"
@@ -55,6 +56,7 @@
             qualifier="BRC"
             long_name="Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
@@ -90,6 +92,7 @@
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="B"
             module_uuid_path=".A.B."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Struts UI"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             module_uuid="[null]"
             module_uuid_path=".E."
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
             qualifier="BRC"
             long_name="Foo Struts Core"
             description="[null]"
+            tags="[null]"
             enabled="[true]"
             language="java"
             created_at="[null]"
index c2025d9f8bf2977af814a076492ee7568cbebbf4..8d088b90489073c3a4aa7aeb2906c43c59e90138 100644 (file)
@@ -13,6 +13,7 @@
             kee="old key"
             name="old name"
             description="old name"
+            tags="[null]"
             long_name="old long name"
             enabled="[false]"
             language="old"
index ddc021ff65698e7e90c214effe68745f2a3b8914..a0977901d53eddf4888ff98dba8fe231fe18c06b 100644 (file)
@@ -13,6 +13,7 @@
             kee="old key"
             name="old name"
             description="old name"
+            tags="[null]"
             long_name="old long name"
             enabled="[false]"
             language="old"
index c215f710ae89dcbfb979221e57afc513e4fba42b..5faf33d30fe2f3d754cce920c751fe9f42b81b82 100644 (file)
@@ -22,6 +22,7 @@ What has been changed :
             kee="project"
             name="project"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
@@ -58,6 +59,7 @@ What has been changed :
             kee="project:my/dir"
             name="my/dir"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
@@ -94,6 +96,7 @@ What has been changed :
             kee="project:my/dir/File.java"
             name="my/dir/File.java"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
index 50363033280d7b349d7f915fd30904dfeb57fe84..25ebc3a8a454f25a1b9bed473e9f3a00e20471e5 100644 (file)
@@ -20,6 +20,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6
             kee="project"
             name="project"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
@@ -57,6 +58,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6
             kee="project:my/dir"
             name="my/dir"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
@@ -94,6 +96,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6
             kee="project:my/dir/File.java"
             name="my/dir/File.java"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"
index da4577aa3eaa85f4116b5601a5653f40ad8fb7c6..4a779c3b667d4c8717da0f08122dddd1a58bc4d7 100644 (file)
@@ -16,6 +16,7 @@
             name="project"
             root_uuid="P1"
             description="[null]"
+            tags="[null]"
             language="java"
             copy_component_uuid="[null]"
             developer_uuid="[null]"