aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-03-08 15:46:19 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-03-08 15:46:19 +0100
commit1cea549f87284f5705ebe575f911adf0cdaf34f3 (patch)
tree022352a60205637b6e6e61514f7eb77c6359a10b
parent0e7853d4c96f3af80ccda2917bf9bee980aaf490 (diff)
downloadsonarqube-1cea549f87284f5705ebe575f911adf0cdaf34f3.tar.gz
sonarqube-1cea549f87284f5705ebe575f911adf0cdaf34f3.zip
SONAR-3879 SONAR-4170 SONAR-3880 Add status, created_at and updated_at columns to Rules table
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties3
-rw-r--r--sonar-check-api/src/main/java/org/sonar/check/Rule.java6
-rw-r--r--sonar-check-api/src/main/java/org/sonar/check/Status.java28
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java54
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java23
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java34
-rw-r--r--sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java15
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/380_add_status_and_dates_to_rules.rb31
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java18
-rw-r--r--sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml4
14 files changed, 204 insertions, 21 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
index 4539d9429d3..ebd13865b40 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties
@@ -18,6 +18,7 @@ assignee=Assignee
author=Author
back=Back
backup_verb=Backup
+beta=Beta
blocker=Blocker
bold=Bold
build_date=Build date
@@ -34,6 +35,7 @@ closed=Closed
code=Code
color=Color
compare=Compare
+configurable=Configurable
configure=Configure
confirm=Confirm
copy=Copy
@@ -45,6 +47,7 @@ date=Date
days=Days
default=Default
delete=Delete
+deprecated=Deprecated
descending=Descending
description=Description
directories=Directories
diff --git a/sonar-check-api/src/main/java/org/sonar/check/Rule.java b/sonar-check-api/src/main/java/org/sonar/check/Rule.java
index 62742720f1a..3c92139c720 100644
--- a/sonar-check-api/src/main/java/org/sonar/check/Rule.java
+++ b/sonar-check-api/src/main/java/org/sonar/check/Rule.java
@@ -60,4 +60,10 @@ public @interface Rule {
IsoCategory isoCategory() default IsoCategory.NONE;
Cardinality cardinality() default Cardinality.SINGLE;
+
+ /**
+ * The rule status. Can be Normal, Beta or Deprecated
+ * @since 3.6
+ */
+ Status status() default Status.NORMAL;
}
diff --git a/sonar-check-api/src/main/java/org/sonar/check/Status.java b/sonar-check-api/src/main/java/org/sonar/check/Status.java
new file mode 100644
index 00000000000..e8a1fd159ee
--- /dev/null
+++ b/sonar-check-api/src/main/java/org/sonar/check/Status.java
@@ -0,0 +1,28 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+
+package org.sonar.check;
+
+/**
+ * @since 3.6
+ */
+public enum Status {
+ NORMAL, BETA, DEPRECATED
+}
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 1ec8a9fbe28..491e6dc2d7e 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
@@ -32,7 +32,7 @@ import java.util.List;
*/
public class DatabaseVersion implements BatchComponent, ServerComponent {
- public static final int LAST_VERSION = 370;
+ public static final int LAST_VERSION = 380;
public static enum Status {
UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
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 18f965622b9..fbc8eb61309 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
@@ -149,6 +149,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('361');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('362');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('363');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('370');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('380');
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;
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index aea283eb183..168b023238a 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -153,7 +153,10 @@ CREATE TABLE "RULES" (
"CARDINALITY" VARCHAR(10),
"PARENT_ID" INTEGER,
"PLUGIN_CONFIG_KEY" VARCHAR(500),
- "NAME" VARCHAR(200)
+ "NAME" VARCHAR(200),
+ "STATUS" VARCHAR(40),
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP,
);
CREATE TABLE "WIDGET_PROPERTIES" (
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
index 134a0b4f6ad..38f15ea804d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/AnnotationRuleParser.java
@@ -69,6 +69,7 @@ public final class AnnotationRuleParser implements ServerComponent {
rule.setDescription(description);
rule.setSeverity(RulePriority.fromCheckPriority(ruleAnnotation.priority()));
rule.setCardinality(ruleAnnotation.cardinality());
+ rule.setStatus(ruleAnnotation.status().name());
List<Field> fields = FieldUtils2.getFields(clazz, true);
for (Field field : fields) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
index efcc8dd3bfd..9c5f23cb49e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/Rule.java
@@ -27,9 +27,22 @@ import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.check.Cardinality;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
@Entity
@@ -73,6 +86,9 @@ public final class Rule {
@Column(name = "cardinality", updatable = true, nullable = false)
private Cardinality cardinality = Cardinality.SINGLE;
+ @Column(name = "status", updatable = true, nullable = true)
+ private String status;
+
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "parent_id", updatable = true, nullable = true)
private Rule parent = null;
@@ -81,6 +97,14 @@ public final class Rule {
@OneToMany(mappedBy = "rule")
private List<RuleParam> params = new ArrayList<RuleParam>();
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "created_at", updatable = true, nullable = true)
+ private Date createdAt;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ @Column(name = "updated_at", updatable = true, nullable = true)
+ private Date updatedAt;
+
/**
* @deprecated since 2.3. Use the factory method {@link #create()}
*/
@@ -356,6 +380,33 @@ public final class Rule {
return this;
}
+ public String getStatus() {
+ return status;
+ }
+
+ public Rule setStatus(String status) {
+ this.status = status;
+ return this;
+ }
+
+ public Date getCreatedAt() {
+ return createdAt;
+ }
+
+ public Rule setCreatedAt(Date created_at) {
+ this.createdAt = created_at;
+ return this;
+ }
+
+ public Date getUpdatedAt() {
+ return updatedAt;
+ }
+
+ public Rule setUpdatedAt(Date updatedAt) {
+ this.updatedAt = updatedAt;
+ return this;
+ }
+
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Rule)) {
@@ -391,6 +442,7 @@ public final class Rule {
.append("enabled", enabled)
.append("severity", priority)
.append("cardinality", cardinality)
+ .append("status", status)
.toString();
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
index 8339d272ce9..d43a0e64330 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
@@ -20,6 +20,7 @@
package org.sonar.api.rules;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.io.Closeables;
import org.apache.commons.io.FileUtils;
@@ -32,6 +33,7 @@ import org.sonar.api.PropertyType;
import org.sonar.api.ServerComponent;
import org.sonar.api.utils.SonarException;
import org.sonar.check.Cardinality;
+import org.sonar.check.Status;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
@@ -146,11 +148,15 @@ public final class XMLRuleParser implements ServerComponent {
} else if (StringUtils.equalsIgnoreCase("cardinality", nodeName)) {
rule.setCardinality(Cardinality.valueOf(StringUtils.trim(cursor.collectDescendantText(false))));
+ } else if (StringUtils.equalsIgnoreCase("status", nodeName)) {
+ String value = StringUtils.trim(cursor.collectDescendantText(false));
+ processStatus(rule, value);
+
} else if (StringUtils.equalsIgnoreCase("param", nodeName)) {
processParameter(rule, cursor);
}
}
- if (StringUtils.isEmpty(rule.getKey())) {
+ if (Strings.isNullOrEmpty(rule.getKey())) {
throw new SonarException("Node <key> is missing in <rule>");
}
}
@@ -187,7 +193,7 @@ public final class XMLRuleParser implements ServerComponent {
param.setDefaultValue(propText);
}
}
- if (StringUtils.isEmpty(param.getKey())) {
+ if (Strings.isNullOrEmpty(param.getKey())) {
throw new SonarException("Node <key> is missing in <param>");
}
}
@@ -218,4 +224,17 @@ public final class XMLRuleParser implements ServerComponent {
}
throw new SonarException("Invalid property type [" + type + "]");
}
+
+ private static void processStatus(Rule rule, String value) {
+ try {
+ if (!Strings.isNullOrEmpty(value)) {
+ Status status = Status.valueOf(value);
+ rule.setStatus(status.name());
+ } else {
+ rule.setStatus(Status.NORMAL.name());
+ }
+ } catch (IllegalArgumentException e) {
+ throw new SonarException("Node <status> can only contains : "+ Status.values(), e);
+ }
+ }
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
index ba04b6f7bb1..14213c64f7a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/rules/XMLRuleParserTest.java
@@ -24,6 +24,7 @@ import org.junit.Test;
import org.sonar.api.PropertyType;
import org.sonar.api.utils.SonarException;
import org.sonar.check.Cardinality;
+import org.sonar.check.Status;
import java.io.File;
import java.io.StringReader;
@@ -39,7 +40,7 @@ import static org.junit.Assert.assertThat;
public class XMLRuleParserTest {
@Test
- public void parseXml() throws Exception {
+ public void should_parse_xml() throws Exception {
File file = new File(getClass().getResource("/org/sonar/api/rules/XMLRuleParserTest/rules.xml").toURI());
List<Rule> rules = new XMLRuleParser().parse(file);
assertThat(rules.size(), is(2));
@@ -50,6 +51,7 @@ public class XMLRuleParserTest {
assertThat(rule.getSeverity(), Is.is(RulePriority.BLOCKER));
assertThat(rule.getCardinality(), Is.is(Cardinality.MULTIPLE));
assertThat(rule.getConfigKey(), is("Checker/TreeWalker/LocalVariableName"));
+ assertThat(rule.getStatus(), is(Status.NORMAL.name()));
assertThat(rule.getParams().size(), is(2));
RuleParam prop = rule.getParam("ignore");
@@ -64,18 +66,18 @@ public class XMLRuleParserTest {
}
@Test(expected = SonarException.class)
- public void failIfMissingRuleKey() {
+ public void should_fail_if_missing_rule_key() {
new XMLRuleParser().parse(new StringReader("<rules><rule><name>Foo</name></rule></rules>"));
}
@Test
- public void ruleNameShouldBeOptional() {
+ public void should_rule_name_should_be_optional() {
List<Rule> rules = new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key></rule></rules>"));
assertThat(rules.get(0).getName(), nullValue());
}
@Test(expected = SonarException.class)
- public void failIfMissingPropertyKey() {
+ public void should_fail_if_missing_property_key() {
new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"));
}
@@ -94,12 +96,12 @@ public class XMLRuleParserTest {
}
@Test(expected = SonarException.class)
- public void fail_on_invalid_rule_parameter_type() {
+ public void should_fail_on_invalid_rule_parameter_type() {
new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key><name>Foo</name><param><key>key</key><type>INVALID</type></param></rule></rules>"));
}
@Test
- public void testUtf8Encoding() {
+ public void test_utf8_encoding() {
List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/utf8.xml"));
assertThat(rules.size(), is(1));
Rule rule = rules.get(0);
@@ -111,7 +113,7 @@ public class XMLRuleParserTest {
}
@Test
- public void shouldSupportDeprecatedFormat() {
+ public void should_support_deprecated_format() {
// the deprecated format uses some attributes instead of nodes
List<Rule> rules = new XMLRuleParser().parse(getClass().getResourceAsStream("/org/sonar/api/rules/XMLRuleParserTest/deprecated.xml"));
assertThat(rules.size(), is(1));
@@ -120,4 +122,22 @@ public class XMLRuleParserTest {
assertThat(rule.getKey(), is("org.sonar.it.checkstyle.MethodsCountCheck"));
assertThat(rule.getParam("minMethodsCount"), not(nullValue()));
}
+
+ @Test(expected = SonarException.class)
+ public void should_fail_if_status_is_unknown() {
+ new XMLRuleParser().parse(new StringReader("<rules><rule><key>foo</key><name>Foo</name><status>UNKNOWN</status></rule></rules>"));
+ }
+
+ @Test
+ public void should_read_rule_status() {
+ List<Rule> rules = new XMLRuleParser().parse(new StringReader(
+ "<rules>"+
+ "<rule><key>foo</key><status>NORMAL</status></rule>"+
+ "<rule><key>foo</key><status>BETA</status></rule>"+
+ "<rule><key>foo</key><status>DEPRECATED</status></rule>"+
+ "</rules>"));
+ assertThat(rules.get(0).getStatus(), is(Status.NORMAL.name()));
+ assertThat(rules.get(1).getStatus(), is(Status.BETA.name()));
+ assertThat(rules.get(2).getStatus(), is(Status.DEPRECATED.name()));
+ }
}
diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
index f033f5deef5..1791b36e017 100644
--- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
+++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java
@@ -19,22 +19,26 @@
*/
package org.sonar.server.startup;
+import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.rules.ActiveRuleParam;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleParam;
import org.sonar.api.rules.RuleRepository;
-import org.sonar.api.utils.Logs;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
+import org.sonar.check.Status;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.jpa.session.DatabaseSessionFactory;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -42,6 +46,8 @@ import java.util.Map;
public final class RegisterRules {
+ private static final Logger LOG = LoggerFactory.getLogger(RegisterRules.class);
+
private final DatabaseSessionFactory sessionFactory;
private final List<RuleRepository> repositories;
private final RuleI18nManager ruleI18nManager;
@@ -104,7 +110,7 @@ public final class RegisterRules {
rule.setRepositoryKey(repository.getKey());
rulesByKey.put(rule.getKey(), rule);
}
- Logs.INFO.info(rulesByKey.size() + " rules");
+ LOG.info(rulesByKey.size() + " rules");
List<Rule> persistedRules = session.getResults(Rule.class, "pluginName", repository.getKey());
for (Rule persistedRule : persistedRules) {
@@ -140,6 +146,8 @@ public final class RegisterRules {
persistedRule.setSeverity(rule.getSeverity());
persistedRule.setEnabled(true);
persistedRule.setCardinality(rule.getCardinality());
+ persistedRule.setStatus(!Strings.isNullOrEmpty(rule.getStatus()) ? rule.getStatus() : Status.NORMAL.name());
+ persistedRule.setUpdatedAt(new Date());
// delete deprecated params
deleteDeprecatedParameters(persistedRule, rule, session);
@@ -182,7 +190,10 @@ public final class RegisterRules {
private void saveNewRules(Collection<Rule> rules, DatabaseSession session) {
for (Rule rule : rules) {
rule.setEnabled(true);
+ rule.setStatus(Status.NORMAL.name());
+ rule.setCreatedAt(new Date());
session.saveWithoutFlush(rule);
}
}
+
}
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/380_add_status_and_dates_to_rules.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/380_add_status_and_dates_to_rules.rb
new file mode 100644
index 00000000000..7d6952cb552
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/380_add_status_and_dates_to_rules.rb
@@ -0,0 +1,31 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# Sonar 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.
+#
+# Sonar 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 Sonar; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+#
+
+#
+# Sonar 3.6
+#
+class AddStatusAndDatesToRules < ActiveRecord::Migration
+ def self.up
+ add_column 'rules', 'status', :string, :null => true, :limit => 40
+ add_column 'rules', 'created_at', :datetime, :null => true
+ add_column 'rules', 'updated_at', :datetime, :null => true
+ end
+end
+
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java
index 2be99f6e3a6..4f38f512d2b 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterRulesTest.java
@@ -28,6 +28,7 @@ import org.sonar.api.rules.RuleParam;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.utils.SonarException;
+import org.sonar.check.Status;
import org.sonar.core.i18n.RuleI18nManager;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -38,6 +39,7 @@ import java.util.Locale;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -69,6 +71,8 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
assertThat(first.getKey(), is("rule1"));
assertThat(first.getRepositoryKey(), is("fake"));
assertThat(first.isEnabled(), is(true));
+ assertThat(first.getCreatedAt(), notNullValue());
+ assertThat(first.getStatus(), is(Status.NORMAL.name()));
assertThat(first.getParams().size(), is(2));
}
@@ -130,11 +134,14 @@ public class RegisterRulesTest extends AbstractDbUnitTestCase {
task.start();
// fields have been updated with new values
- Rule rule = getSession().getSingleResult(Rule.class, "id", 1);
- assertThat(rule.getName(), is("One"));
- assertThat(rule.getDescription(), is("Description of One"));
- assertThat(rule.getSeverity(), is(RulePriority.BLOCKER));
- assertThat(rule.getConfigKey(), is("config1"));
+ Rule rule1 = getSession().getSingleResult(Rule.class, "id", 1);
+ assertThat(rule1.getName(), is("One"));
+ assertThat(rule1.getDescription(), is("Description of One"));
+ assertThat(rule1.getSeverity(), is(RulePriority.BLOCKER));
+ assertThat(rule1.getConfigKey(), is("config1"));
+
+ Rule rule2 = getSession().getSingleResult(Rule.class, "id", 2);
+ assertThat(rule2.getStatus(), is(Status.DEPRECATED.name()));
}
@Test
@@ -293,6 +300,7 @@ class FakeRepository extends RuleRepository {
Rule rule2 = Rule.create("fake", "rule2", "Two");
rule2.setDescription("Description of Two");
rule2.setSeverity(RulePriority.INFO);
+ rule2.setStatus(Status.DEPRECATED.name());
return Arrays.asList(rule1, rule2);
}
diff --git a/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml b/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml
index 0ddafe20302..d12564071ba 100644
--- a/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml
+++ b/sonar-server/src/test/resources/org/sonar/server/startup/RegisterRulesTest/updadeRuleFields.xml
@@ -1,10 +1,10 @@
<dataset>
<rules id="1" plugin_rule_key="rule1" plugin_name="fake" plugin_config_key="old_config_key" name="old name" description="old description"
- enabled="true" priority="2" cardinality="SINGLE" parent_id="[null]"/>
+ enabled="true" priority="2" cardinality="SINGLE" parent_id="[null]" status="NORMAL"/>
<rules id="2" plugin_rule_key="rule2" plugin_name="fake" plugin_config_key="old_config_key2" name="old name2" description="old description2"
- enabled="true" priority="1" cardinality="SINGLE" parent_id="[null]"/>
+ enabled="true" priority="1" cardinality="SINGLE" parent_id="[null]" status="NORMAL"/>
<rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="STRING"/>