diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-09 14:37:47 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-10-09 14:39:18 +0200 |
commit | b0903c3790a72643840e147501a739604e3083de (patch) | |
tree | 089f2d23b8fd1338b1b50400190644680448e63e /sonar-core | |
parent | 8918e980c528553baf9c5ca015d3dbeeaf8132a7 (diff) | |
download | sonarqube-b0903c3790a72643840e147501a739604e3083de.tar.gz sonarqube-b0903c3790a72643840e147501a739604e3083de.zip |
SONAR-5575 Fix missing parameter when creating and updating custom rule with empty parameter
Diffstat (limited to 'sonar-core')
9 files changed, 328 insertions, 3 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index dcb5e436527..af91a6ae928 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 600; + public static final int LAST_VERSION = 601; public static enum Status { UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 3e9c9d2f5f4..58cf793f0e1 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -53,6 +53,7 @@ import org.sonar.core.notification.db.NotificationQueueDto; import org.sonar.core.notification.db.NotificationQueueMapper; import org.sonar.core.permission.*; import org.sonar.core.persistence.migration.v44.Migration44Mapper; +import org.sonar.core.persistence.migration.v45.Migration45Mapper; import org.sonar.core.properties.PropertiesMapper; import org.sonar.core.properties.PropertyDto; import org.sonar.core.purge.PurgeMapper; @@ -170,7 +171,8 @@ public class MyBatis implements BatchComponent, ServerComponent { org.sonar.api.database.model.MeasureMapper.class, SnapshotDataMapper.class, SnapshotSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class, NotificationQueueMapper.class, CharacteristicMapper.class, GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, - MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, ProjectQgateAssociationMapper.class + MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, ProjectQgateAssociationMapper.class, + Migration45Mapper.class }; loadMappers(conf, mappers); configureLogback(mappers); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java new file mode 100644 index 00000000000..4f78491095a --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Migration45Mapper.java @@ -0,0 +1,61 @@ +/* + * 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.core.persistence.migration.v45; + +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Select; + +import java.util.Date; +import java.util.List; + +public interface Migration45Mapper { + + @Select("SELECT rules_parameters.id, rules_parameters.rule_id as \"ruleId\", rules_parameters.name as \"name\", rules_parameters.param_type as \"type\", " + + " rules_parameters.default_value as \"defaultValue\", rules_parameters.description, rules.template_id as \"ruleTemplateId\" " + + "FROM rules_parameters " + + " INNER JOIN rules ON rules.id = rules_parameters.rule_id " + + "WHERE rules.is_template = ${_true}") + @Result(javaType = RuleParameter.class) + List<RuleParameter> selectAllTemplateRuleParameters(); + + @Select("SELECT rules_parameters.id, rules_parameters.rule_id as \"ruleId\", rules_parameters.name as \"name\", rules_parameters.param_type as \"type\", " + + " rules_parameters.default_value as \"defaultValue\", rules_parameters.description, rules.template_id as \"ruleTemplateId\" " + + "FROM rules_parameters " + + " INNER JOIN rules ON rules.id = rules_parameters.rule_id " + + "WHERE rules.template_id IS NOT NULL") + @Result(javaType = RuleParameter.class) + List<RuleParameter> selectAllCustomRuleParameters(); + + @Select("SELECT id, plugin_rule_key as \"ruleKey\", plugin_name as \"repositoryKey\", is_template as \"isTemplate\", template_id as \"templateId\"" + + "FROM rules " + + "WHERE rules.template_id IS NOT NULL") + @Result(javaType = Rule.class) + List<Rule> selectAllCustomRules(); + + @Insert("INSERT INTO rules_parameters (rule_id, name, param_type, default_value, description)" + + " VALUES (#{ruleId}, #{name}, #{type}, #{defaultValue}, #{description})") + void insertRuleParameter(RuleParameter ruleParameter); + + @Insert("UPDATE rules SET updated_at=#{date} WHERE id=#{id}") + void updateRuleUpdateAt(@Param("id") Integer ruleId, @Param("date") Date updatedAt); + +} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Rule.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Rule.java new file mode 100644 index 00000000000..a54d2f3cf61 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/Rule.java @@ -0,0 +1,113 @@ +/* + * 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.core.persistence.migration.v45; + +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +/** + * SONAR-5575 + * <p/> + * Used in the Active Record Migration 601. + * + * @since 4.5 + */ +public final class Rule { + + private Integer id; + private String repositoryKey; + private String ruleKey; + private boolean isTemplate; + private Integer templateId; + + public Integer getId() { + return id; + } + + public Rule setId(Integer id) { + this.id = id; + return this; + } + + public String getRepositoryKey() { + return repositoryKey; + } + + public Rule setRepositoryKey(String repositoryKey) { + this.repositoryKey = repositoryKey; + return this; + } + + public String getRuleKey() { + return ruleKey; + } + + public Rule setRuleKey(String ruleKey) { + this.ruleKey = ruleKey; + return this; + } + + public boolean isTemplate() { + return isTemplate; + } + + public Rule setIsTemplate(boolean isTemplate) { + this.isTemplate = isTemplate; + return this; + } + + @CheckForNull + public Integer getTemplateId() { + return templateId; + } + + public Rule setTemplateId(@Nullable Integer templateId) { + this.templateId = templateId; + return this; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Rule)) { + return false; + } + if (this == obj) { + return true; + } + Rule other = (Rule) obj; + return new EqualsBuilder() + .append(repositoryKey, other.getRepositoryKey()) + .append(ruleKey, other.getRuleKey()) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(repositoryKey) + .append(ruleKey) + .toHashCode(); + } + + +} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/RuleParameter.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/RuleParameter.java new file mode 100644 index 00000000000..c930518ab81 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/RuleParameter.java @@ -0,0 +1,114 @@ +/* + * 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.core.persistence.migration.v45; + +import org.apache.commons.lang.builder.ReflectionToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +/** + * SONAR-5575 + * <p/> + * Used in the Active Record Migration 601. + * + * @since 4.5 + */ +public class RuleParameter { + + private Integer id; + private Integer ruleId; + private Integer ruleTemplateId; + private String name; + private String type; + private String defaultValue; + private String description; + + public Integer getId() { + return id; + } + + public RuleParameter setId(Integer id) { + this.id = id; + return this; + } + + public Integer getRuleId() { + return ruleId; + } + + public RuleParameter setRuleId(Integer ruleId) { + this.ruleId = ruleId; + return this; + } + + @CheckForNull + public Integer getRuleTemplateId() { + return ruleTemplateId; + } + + public RuleParameter setRuleTemplateId(@Nullable Integer ruleTemplateId) { + this.ruleTemplateId = ruleTemplateId; + return this; + } + + public String getName() { + return name; + } + + public RuleParameter setName(String name) { + this.name = name; + return this; + } + + public String getType() { + return type; + } + + public RuleParameter setType(String type) { + this.type = type; + return this; + } + + @CheckForNull + public String getDefaultValue() { + return defaultValue; + } + + public RuleParameter setDefaultValue(@Nullable String defaultValue) { + this.defaultValue = defaultValue; + return this; + } + + public String getDescription() { + return description; + } + + public RuleParameter setDescription(String description) { + this.description = description; + return this; + } + + @Override + public String toString() { + return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/package-info.java b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/package-info.java new file mode 100644 index 00000000000..4e661d78b28 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/persistence/migration/v45/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.core.persistence.migration.v45; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleParamDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleParamDto.java index 7d1436974bc..ddddb819bed 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleParamDto.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleParamDto.java @@ -23,6 +23,9 @@ package org.sonar.core.rule; import org.apache.commons.lang.builder.ReflectionToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + public class RuleParamDto { private Integer id; @@ -68,11 +71,12 @@ public class RuleParamDto { return this; } + @CheckForNull public String getDefaultValue() { return defaultValue; } - public RuleParamDto setDefaultValue(String defaultValue) { + public RuleParamDto setDefaultValue(@Nullable String defaultValue) { this.defaultValue = defaultValue; return this; } diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/migration/v45/Migration45Mapper.xml b/sonar-core/src/main/resources/org/sonar/core/persistence/migration/v45/Migration45Mapper.xml new file mode 100644 index 00000000000..ea7778ed475 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/migration/v45/Migration45Mapper.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + +<mapper namespace="org.sonar.core.persistence.migration.v45.Migration45Mapper"> + +</mapper> + diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 687099904a9..53b8dcc9d12 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -255,6 +255,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('582'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('583'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('584'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('600'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('601'); INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; |