]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10544 add IS_EXTERNAL and DESCRIPTION_URL column to RULES table
authorGuillaume Jambet <guillaume.jambet@sonarsource.com>
Tue, 10 Apr 2018 07:33:09 +0000 (09:33 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 26 Apr 2018 18:20:50 +0000 (20:20 +0200)
server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDefinitionDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/rule/RuleMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/DbVersion72Test.java
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql [new file with mode: 0644]

index d15982719de2daed119759e2c478bdaf0fc96068..4306a0d22f619685d4e4e95c13cbc7b32f8745a5 100644 (file)
@@ -186,8 +186,10 @@ CREATE TABLE "RULES" (
   "PLUGIN_NAME" VARCHAR(255) NOT NULL,
   "DESCRIPTION" VARCHAR(16777215),
   "DESCRIPTION_FORMAT" VARCHAR(20),
+  "DESCRIPTION_URL" VARCHAR(256),
   "PRIORITY" INTEGER,
   "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
+  "IS_EXTERNAL" BOOLEAN DEFAULT FALSE,
   "TEMPLATE_ID" INTEGER,
   "PLUGIN_CONFIG_KEY" VARCHAR(200),
   "NAME" VARCHAR(200),
index c291d134b972f4dba9f3f7587b7fc7bcc76b3141..1b072c4659492cdd1352c8b3771d33ec74d84826 100644 (file)
@@ -42,11 +42,13 @@ public class RuleDefinitionDto {
   private String ruleKey;
   private String description;
   private RuleDto.Format descriptionFormat;
+  private String descriptionURL;
   private RuleStatus status;
   private String name;
   private String configKey;
   private Integer severity;
   private boolean isTemplate;
+  private boolean isExternal;
   private String language;
   private Integer templateId;
   private String defRemediationFunction;
@@ -120,6 +122,15 @@ public class RuleDefinitionDto {
     return this;
   }
 
+  public String getDescriptionURL() {
+    return descriptionURL;
+  }
+
+  public RuleDefinitionDto setDescriptionURL(String descriptionURL) {
+    this.descriptionURL = descriptionURL;
+    return this;
+  }
+
   public RuleDto.Format getDescriptionFormat() {
     return descriptionFormat;
   }
@@ -185,6 +196,16 @@ public class RuleDefinitionDto {
     return this;
   }
 
+
+  public boolean isExternal() {
+    return isExternal;
+  }
+
+  public RuleDefinitionDto setIsExternal(boolean isExternal) {
+    this.isExternal = isExternal;
+    return this;
+  }
+
   @CheckForNull
   public String getLanguage() {
     return language;
index 44b4ecf66a531d9d885718ad0e031cc46935424e..0d5acbf4bba4d85c3a23bcfc14c8bf2bc35cf4fb 100644 (file)
@@ -9,11 +9,13 @@
     r.plugin_name as "repositoryKey",
     r.description,
     r.description_format as "descriptionFormat",
+    r.description_url as "descriptionURL",
     r.status,
     r.name,
     r.plugin_config_key as "configKey",
     r.priority as "severity",
     r.is_template as "isTemplate",
+    r.is_external as "isExternal",
     r.language as "language",
     r.template_id as "templateId",
     r.def_remediation_function as "defRemediationFunction",
       plugin_name,
       description,
       description_format,
+      description_url,
       status,
       name,
       plugin_config_key,
       priority,
       is_template,
+      is_external,
       language,
       template_id,
       def_remediation_function,
       #{repositoryKey,jdbcType=VARCHAR},
       #{description,jdbcType=VARCHAR},
       #{descriptionFormat,jdbcType=VARCHAR},
+      #{descriptionURL,jdbcType=VARCHAR},
       #{status,jdbcType=VARCHAR},
       #{name,jdbcType=VARCHAR},
       #{configKey,jdbcType=VARCHAR},
       #{severity,jdbcType=INTEGER},
       #{isTemplate,jdbcType=BOOLEAN},
+      #{isExternal,jdbcType=BOOLEAN},
       #{language,jdbcType=VARCHAR},
       #{templateId,jdbcType=INTEGER},
       #{defRemediationFunction,jdbcType=VARCHAR},
       plugin_name=#{repositoryKey,jdbcType=VARCHAR},
       description=#{description,jdbcType=VARCHAR},
       description_format=#{descriptionFormat,jdbcType=VARCHAR},
+      description_url=#{descriptionURL,jdbcType=VARCHAR},
       status=#{status,jdbcType=VARCHAR},
       name=#{name,jdbcType=VARCHAR},
       plugin_config_key=#{configKey,jdbcType=VARCHAR},
       priority=#{severity,jdbcType=INTEGER},
       is_template=#{isTemplate,jdbcType=BOOLEAN},
+      is_external=#{isExternal,jdbcType=BOOLEAN},
       language=#{language,jdbcType=VARCHAR},
       template_id=#{templateId,jdbcType=INTEGER},
       def_remediation_function=#{defRemediationFunction,jdbcType=VARCHAR},
index b585954a785699760d324f59d8cb059abc9ac183..44e469219f9dabe73f01f4a3de8b32c5386e514f 100644 (file)
@@ -476,10 +476,12 @@ public class RuleDaoTest {
       .setName("new name")
       .setDescription("new description")
       .setDescriptionFormat(RuleDto.Format.MARKDOWN)
+      .setDescriptionURL("https://eslint.org/docs/rules/no-cond-assign")
       .setStatus(RuleStatus.DEPRECATED)
       .setConfigKey("NewConfigKey")
       .setSeverity(Severity.INFO)
       .setIsTemplate(true)
+      .setIsExternal(true)
       .setLanguage("dart")
       .setTemplateId(3)
       .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
@@ -499,6 +501,7 @@ public class RuleDaoTest {
     assertThat(ruleDto.getName()).isEqualTo("new name");
     assertThat(ruleDto.getDescription()).isEqualTo("new description");
     assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN);
+    assertThat(ruleDto.getDescriptionURL()).isEqualTo("https://eslint.org/docs/rules/no-cond-assign");
     assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED);
     assertThat(ruleDto.getRuleKey()).isEqualTo("NewRuleKey");
     assertThat(ruleDto.getRepositoryKey()).isEqualTo("plugin");
@@ -506,6 +509,7 @@ public class RuleDaoTest {
     assertThat(ruleDto.getSeverity()).isEqualTo(0);
     assertThat(ruleDto.getLanguage()).isEqualTo("dart");
     assertThat(ruleDto.isTemplate()).isTrue();
+    assertThat(ruleDto.isExternal()).isTrue();
     assertThat(ruleDto.getTemplateId()).isEqualTo(3);
     assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET");
     assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d");
@@ -529,10 +533,12 @@ public class RuleDaoTest {
       .setName("new name")
       .setDescription("new description")
       .setDescriptionFormat(RuleDto.Format.MARKDOWN)
+      .setDescriptionURL("https://eslint.org/docs/rules/no-cond-assign")
       .setStatus(RuleStatus.DEPRECATED)
       .setConfigKey("NewConfigKey")
       .setSeverity(Severity.INFO)
       .setIsTemplate(true)
+      .setIsExternal(true)
       .setLanguage("dart")
       .setTemplateId(3)
       .setDefRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString())
@@ -551,6 +557,7 @@ public class RuleDaoTest {
     assertThat(ruleDto.getName()).isEqualTo("new name");
     assertThat(ruleDto.getDescription()).isEqualTo("new description");
     assertThat(ruleDto.getDescriptionFormat()).isEqualTo(RuleDto.Format.MARKDOWN);
+    assertThat(ruleDto.getDescriptionURL()).isEqualTo("https://eslint.org/docs/rules/no-cond-assign");
     assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.DEPRECATED);
     assertThat(ruleDto.getRuleKey()).isEqualTo("NewRuleKey");
     assertThat(ruleDto.getRepositoryKey()).isEqualTo("plugin");
@@ -558,6 +565,7 @@ public class RuleDaoTest {
     assertThat(ruleDto.getSeverity()).isEqualTo(0);
     assertThat(ruleDto.getLanguage()).isEqualTo("dart");
     assertThat(ruleDto.isTemplate()).isTrue();
+    assertThat(ruleDto.isExternal()).isTrue();
     assertThat(ruleDto.getTemplateId()).isEqualTo(3);
     assertThat(ruleDto.getDefRemediationFunction()).isEqualTo("LINEAR_OFFSET");
     assertThat(ruleDto.getDefRemediationGapMultiplier()).isEqualTo("5d");
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternal.java
new file mode 100644 (file)
index 0000000..236f2bb
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v72;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import java.sql.SQLException;
+
+public class AddRuleExternal extends DdlChange {
+
+  public AddRuleExternal(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddColumnsBuilder(getDialect(), "rules")
+      .addColumn(BooleanColumnDef.newBooleanColumnDefBuilder()
+        .setColumnName("is_external")
+        .setIsNullable(true)
+        .setDefaultValue(false)
+        .build())
+      .addColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+        .setColumnName("description_url")
+        .setIsNullable(true)
+        .setLimit(256)
+        .build())
+      .build());
+  }
+
+}
index 2303e9e1d89b20dd84aa78dc4207fe4abdbb08f4..dbbb14df39bedab2ec2696ad9063323a329e8c9b 100644 (file)
@@ -30,6 +30,6 @@ public class DbVersion72 implements DbVersion {
       .add(2100, "Increase size of USERS.CRYPTED_PASSWORD", IncreaseCryptedPasswordSize.class)
       .add(2101, "Add HASH_METHOD to table users", AddHashMethodToUsersTable.class)
       .add(2102, "Populate HASH_METHOD on table users", PopulateHashMethodOnUsers.class)
-    ;
+      .add(2103, "Add isExternal boolean and description_url to rules", AddRuleExternal.class);
   }
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest.java
new file mode 100644 (file)
index 0000000..850bf0c
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.platform.db.migration.version.v72;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import java.sql.SQLException;
+
+import static java.sql.Types.BOOLEAN;
+import static java.sql.Types.VARCHAR;
+import static org.junit.rules.ExpectedException.none;
+import static org.sonar.db.CoreDbTester.createForSchema;
+
+public class AddRuleExternalTest {
+  @Rule
+  public final CoreDbTester dbTester = createForSchema(AddRuleExternalTest.class, "rules.sql");
+
+  @Rule
+  public ExpectedException expectedException = none();
+
+  private AddRuleExternal underTest = new AddRuleExternal(dbTester.database());
+
+  @Test
+  public void column_are_added_to_table() throws SQLException {
+    underTest.execute();
+    dbTester.assertColumnDefinition("rules", "is_external", BOOLEAN, null, true);
+    dbTester.assertColumnDefinition("rules", "description_url", VARCHAR, 256, true);
+  }
+
+  @Test
+  public void migration_is_not_reentrant() throws SQLException {
+    underTest.execute();
+
+    expectedException.expect(IllegalStateException.class);
+
+    underTest.execute();
+  }
+}
index 9af6646d5a1f8aa80ea2e2c71b08b2c5691d4cff..31fa3c4f6eeb056db007892e46ced40e3c9e6ddb 100644 (file)
@@ -28,13 +28,13 @@ public class DbVersion72Test {
   private DbVersion72 underTest = new DbVersion72();
 
   @Test
-  public void migrationNumber_starts_at_2100() {
+  public void migrationNumber_starts_at_2000() {
     verifyMinimumMigrationNumber(underTest, 2100);
   }
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 3);
+    verifyMigrationCount(underTest, 4);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v72/AddRuleExternalTest/rules.sql
new file mode 100644 (file)
index 0000000..f661e2f
--- /dev/null
@@ -0,0 +1,25 @@
+CREATE TABLE "RULES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PLUGIN_KEY" VARCHAR(200),
+  "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+  "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+  "DESCRIPTION" VARCHAR(16777215),
+  "DESCRIPTION_FORMAT" VARCHAR(20),
+  "PRIORITY" INTEGER,
+  "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
+  "TEMPLATE_ID" INTEGER,
+  "PLUGIN_CONFIG_KEY" VARCHAR(200),
+  "NAME" VARCHAR(200),
+  "STATUS" VARCHAR(40),
+  "LANGUAGE" VARCHAR(20),
+  "SCOPE" VARCHAR(20) NOT NULL,
+  "DEF_REMEDIATION_FUNCTION" VARCHAR(20),
+  "DEF_REMEDIATION_GAP_MULT" VARCHAR(20),
+  "DEF_REMEDIATION_BASE_EFFORT" VARCHAR(20),
+  "GAP_DESCRIPTION" VARCHAR(4000),
+  "SYSTEM_TAGS" VARCHAR(4000),
+  "RULE_TYPE" TINYINT,
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT
+);
+CREATE UNIQUE INDEX "RULES_REPO_KEY" ON "RULES" ("PLUGIN_NAME", "PLUGIN_RULE_KEY");