]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5007 add RULES_PROFILES.CREATED_AT, UPDATED_AT and RULES_UPDATED_AT
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 Jun 2014 22:44:14 +0000 (00:44 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 Jun 2014 22:45:34 +0000 (00:45 +0200)
41 files changed:
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/java/org/sonar/core/persistence/migration/v44/Migration44Mapper.java
sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileDto.java
sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QualityProfileMapper.java
sonar-core/src/main/resources/org/sonar/core/persistence/migration/v44/Migration44Mapper.xml
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-core/src/test/java/org/sonar/core/persistence/migration/v44/ProfileMeasureTest.java [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/delete-result.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/inheritance.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/insert-result.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/projects.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/select_all_is_sorted_by_profile_name.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/select_by_language.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/qualityprofile/db/QualityProfileDaoTest/update-result.xml
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldCountNumberOfRulesOfACategoryForGivenPlugins.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleParams.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleWithRuleKeyAndPluginKey.xml [deleted file]
sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRules.xml [deleted file]
sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java [new file with mode: 0644]
sonar-server/src/main/java/org/sonar/server/db/migrations/v44/QProfileKeyMigration.java [deleted file]
sonar-server/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/549_set_qprofile_keys.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/db/migrate/550_convert_profile_measures.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/551_update_logs_to_activities.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/552_add_qprofile_dates.rb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at_result.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/schema.sql [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes.xml [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes_result.xml [new file with mode: 0644]

index 0a449c778c4db7031f6bc695ab1fea76213ed6d7..e873c66cd809ca8363d11d792958e5573d2af407 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 551;
+  public static final int LAST_VERSION = 553;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 2a514ff2d541849974ac4ec4f4573eece6947386..d27b8c95c4e99a579d8a104524e4fbdf2e29a448 100644 (file)
@@ -30,12 +30,13 @@ public interface Migration44Mapper {
   // migration of measures "profile" and "profile_version"
   List<ProfileMeasure> selectProfileMeasures();
   int selectProfileVersion(long snapshotId);
-  @CheckForNull Date selectProfileVersionDate(@Param("profileId") long profileId, @Param("profileVersion") int profileVersion);
+  @CheckForNull Date selectProfileVersionDate(@Param("profileId") int profileId, @Param("profileVersion") int profileVersion);
   void updateProfileMeasure(@Param("measureId") long measureId, @Param("json") String json);
 
   // creation of columns RULES_PROFILES.CREATED_AT and UPDATED_AT
-  @CheckForNull Date selectProfileCreatedAt(long profileId);
-  @CheckForNull Date selectProfileUpdatedAt(long profileId);
+  @CheckForNull Date selectProfileCreatedAt(int profileId);
+  @CheckForNull Date selectProfileUpdatedAt(int profileId);
+  void updateProfileDates(@Param("profileId") int profileId, @Param("createdAt") Date createdAt, @Param("updatedAt") Date updatedAt);
 
   // migrate changeLog to Activities
   List<ChangeLog> selectActiveRuleChange(@Param("enabled") Boolean enabled);
index 992b8a7f57acf2bf8ce4d16583467a4cb2c04b16..bc7224a5fc3f44fb6778424cb06051543e37c2f5 100644 (file)
@@ -24,6 +24,7 @@ import org.sonar.core.persistence.Dto;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
+import java.util.Date;
 
 public class QualityProfileDto extends Dto<String> {
 
@@ -32,6 +33,7 @@ public class QualityProfileDto extends Dto<String> {
   private String name;
   private String language;
   private String parentKee;
+  private Date createdAt, updatedAt, rulesUpdatedAt;
 
   /**
    * @deprecated use {@link #createFor(String)}
@@ -96,6 +98,22 @@ public class QualityProfileDto extends Dto<String> {
     return this;
   }
 
+  public Date getCreatedAt() {
+    return createdAt;
+  }
+
+  public void setCreatedAt(Date createdAt) {
+    this.createdAt = createdAt;
+  }
+
+  public Date getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public void setUpdatedAt(Date updatedAt) {
+    this.updatedAt = updatedAt;
+  }
+
   public static QualityProfileDto createFor(String key) {
     return new QualityProfileDto().setKee(key);
   }
index 3acfe87172761c781b14680661ce108e60bd7585..cef07f9a24ad9617f2b60775bb3a74747d08f4e4 100644 (file)
@@ -33,7 +33,7 @@ public interface QualityProfileMapper {
 
   void update(QualityProfileDto dto);
 
-  void delete(Integer id);
+  void delete(int id);
 
   List<QualityProfileDto> selectAll();
 
index 150df88078d7387c8816d2f52c23d2ef78c0c71c..4484a1111e601f08be704b68bdc90f95dcbe3d3a 100644 (file)
     where id=#{measureId}
   </update>
 
-  <select id="selectProfileUpdateAt" resultType="date" parameterType="long">
+  <select id="selectProfileUpdatedAt" resultType="date" parameterType="int">
     select max(change_date) from active_rule_changes
     where profile_id=#{id}
   </select>
 
-  <select id="selectProfileCreatedAt" resultType="date" parameterType="long">
+  <select id="selectProfileCreatedAt" resultType="date" parameterType="int">
     select min(change_date) from active_rule_changes
     where profile_id=#{id}
   </select>
 
+  <update id="updateProfileDates" parameterType="map">
+    update rules_profiles
+    set created_at=#{createdAt}, updated_at=#{updatedAt}, rules_updated_at=#{updatedAt}
+    where id=#{profileId}
+  </update>
+
   <select id="selectActiveRuleChange" parameterType="Boolean"
           resultType="org.sonar.core.persistence.migration.v44.ChangeLog">
     select
index 8b36b94db46edaba562f85d9b93488ec795d9b9b..0485e75a9762a48477d690f4349b8b13db3b6599 100644 (file)
@@ -244,6 +244,8 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('547');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('548');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('549');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('551');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('552');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('553');
 
 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;
index 3d5c02849c5823d93c754fc7debd53af2c4decca..bea3a332c6260a766afabab8a6ea4d2dd710cfb2 100644 (file)
@@ -50,7 +50,10 @@ CREATE TABLE "RULES_PROFILES" (
   "NAME" VARCHAR(100) NOT NULL,
   "LANGUAGE" VARCHAR(20),
   "KEE" VARCHAR(1000) NOT NULL,
-  "PARENT_KEE" VARCHAR(1000)
+  "PARENT_KEE" VARCHAR(1000),
+  "RULES_UPDATED_AT" TIMESTAMP,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
 );
 
 CREATE TABLE "WIDGETS" (
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/migration/v44/ProfileMeasureTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/migration/v44/ProfileMeasureTest.java
new file mode 100644 (file)
index 0000000..9e31505
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.v44;
+
+import org.junit.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.*;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ProfileMeasureTest {
+
+  @Test
+  public void getId() throws Exception {
+    assertThat(ProfileMeasure.class, allOf(
+      hasValidBeanConstructor(),
+      hasValidGettersAndSetters()
+      ));
+  }
+}
index fb2afaf6b07b3e953b9da84557f33569c4464fbe..f8ed2f0f6fb73e074fb5b50d4629ada1daf3b72a 100644 (file)
@@ -1,5 +1,6 @@
 <dataset>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 </dataset>
index 6936254ea4b8e577af8d7eacb759b6149b0f0078..85979c32a29c829015a656de5e770cd322f14481 100644 (file)
@@ -1,17 +1,23 @@
 <dataset>
 
-  <rules_profiles id="1" name="Child1" language="java" parent_kee="java_parent" kee="java_child1"/>
+  <rules_profiles id="1" name="Child1" language="java" parent_kee="java_parent" kee="java_child1"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Child2" language="java" parent_kee="java_parent" kee="java_child2"/>
+  <rules_profiles id="2" name="Child2" language="java" parent_kee="java_parent" kee="java_child2"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="3" name="Parent" language="java" parent_kee="[null]" kee="java_parent"/>
+  <rules_profiles id="3" name="Parent" language="java" parent_kee="[null]" kee="java_parent"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
   <!-- Same profile for another language -->
 
-  <rules_profiles id="4" name="Child1" language="js" parent_kee="js_parent" kee="js_child1"/>
+  <rules_profiles id="4" name="Child1" language="js" parent_kee="js_parent" kee="js_child1"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="5" name="Child2" language="js" parent_kee="js_parent" kee="js_child2"/>
+  <rules_profiles id="5" name="Child2" language="js" parent_kee="js_parent" kee="js_child2"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="6" name="Parent" language="js" parent_kee="[null]" kee="js_parent"/>
+  <rules_profiles id="6" name="Parent" language="js" parent_kee="[null]" kee="js_parent"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 </dataset>
index 2e66e8d4e86b9a89f32dc603075c4654b292ac4d..ee041878cd8b51875de44967c931e31d4d5c7cdc 100644 (file)
@@ -1,10 +1,13 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde"/>
+  <rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 
 </dataset>
index 9cda069147499f5e0f926181eda5a08c43983261..a380d4288a746c4ea612080ff8e9f26a96366b2f 100644 (file)
@@ -1,7 +1,9 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
   <projects id="1" kee="org.codehaus.sonar:sonar" name="SonarQube"/>
   <projects id="2" kee="org.codehaus.sonar-plugins.java:java" name="SonarQube Java"/>
index d43fbf5aa4d23a78d2318f2537955009f82fcdf6..eb5e56d051753b750ca019233dc9c2045a37135e 100644 (file)
@@ -1,10 +1,13 @@
 <dataset>
 
-  <rules_profiles id="3" name="Third" language="js" parent_kee="[null]" kee="js_third"/>
+  <rules_profiles id="3" name="Third" language="js" parent_kee="[null]" kee="js_third"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="1" name="First" language="js" parent_kee="[null]" kee="js_first"/>
+  <rules_profiles id="1" name="First" language="js" parent_kee="[null]" kee="js_first"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Second" language="js" parent_kee="[null]" kee="js_second"/>
+  <rules_profiles id="2" name="Second" language="js" parent_kee="[null]" kee="js_second"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 
 </dataset>
index 552995b1dfb0605173ab7c8f0de113a2fbfd354b..b3313d4178457ea5f1dac4c01b3f840a5a54f6f0 100644 (file)
@@ -1,10 +1,12 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way 1" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+  <rules_profiles id="1" name="Sonar Way 1" language="java" parent_kee="[null]" kee="java_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
   <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
-                  used_profile="[false]"/>
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="3" name="Sonar Way 2" language="java" parent_kee="[null]" kee="java_sonar_way2"/>
+  <rules_profiles id="3" name="Sonar Way 2" language="java" parent_kee="[null]" kee="java_sonar_way2"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 </dataset>
index bfa61fc45bc94651447f201e3a9a0a9ad2cc021a..9cb3d667d5fdc91205b7e59fef88903445a636df 100644 (file)
@@ -1,8 +1,10 @@
 <dataset>
 
-  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"/>
+  <rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
   <properties id="1" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="[null]"/>
   <properties id="2" prop_key="sonar.profile.java" text_value="Sonar Way" resource_id="1"/>
index e24553488919ff6be30d15fd1a866f375573ac95..9ec70d75713e875d1506ad145df7fde7557030c7 100644 (file)
@@ -1,8 +1,10 @@
 <dataset>
 
-  <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way"/>
+  <rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
-  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"/>
+  <rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
 
 
 </dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldCountNumberOfRulesOfACategoryForGivenPlugins.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldCountNumberOfRulesOfACategoryForGivenPlugins.xml
deleted file mode 100644 (file)
index 43f9ba1..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="rule one" description="desc" plugin_config_key="config"
-         plugin_rule_key="rule_one" plugin_name="plugin1" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <rules tags="[null]" system_tags="[null]" id="2" name="rule two" description="desc" plugin_config_key="config"
-         plugin_rule_key="rule_two" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="3" name="rule three" description="desc" plugin_config_key="config"
-         plugin_rule_key="rule_three" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <rules tags="[null]" system_tags="[null]" id="4" name="rule 4" description="desc" plugin_config_key="config"
-         plugin_rule_key="rule_4" plugin_name="plugin2" status="READY" is_template="[false]" template_id="[null]"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter-result.xml
deleted file mode 100644 (file)
index c9466ae..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="rule1" description="desc" plugin_config_key="config"
-         plugin_rule_key="key1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <rules_parameters id="1" rule_id="1" name="param1" description="[null]" param_type="REGULAR_EXPRESSION"/>
-  <rules_parameters id="2" rule_id="1" name="param2" description="[null]" param_type="REGULAR_EXPRESSION"/>
-
-  <rules_profiles id="1" name="profile1" language="java"/>
-  <rules_profiles id="2" name="profile2" language="OTHER"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="1" failure_level="2"/>
-
-  <!-- deleted -->
-  <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>-->
-  <!--<active_rule_parameters id="2" active_rule_id="2" rules_parameter_id="1" value="15"/>-->
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="2" value="15"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRuleParametersFromARuleParameter.xml
deleted file mode 100644 (file)
index 09b9dc7..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="rule1" description="desc" plugin_config_key="config"
-         plugin_rule_key="key1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <rules_parameters id="1" rule_id="1" name="param1" description="foo" param_type="REGULAR_EXPRESSION"/>
-  <rules_parameters id="2" rule_id="1" name="param2" description="foo" param_type="REGULAR_EXPRESSION"/>
-
-  <rules_profiles id="1" name="profile1" language="java"/>
-  <rules_profiles id="2" name="profile2" language="OTHER"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="1" failure_level="2"/>
-
-  <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" value="20"/>
-  <active_rule_parameters id="2" active_rule_id="2" rules_parameter_id="1" value="15"/>
-  <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="2" value="15"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules-result.xml
deleted file mode 100644 (file)
index 8beeb39..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<dataset>
-
-  <rules_profiles id="1" name="profile one" language="java"/>
-  <rules_profiles id="2" name="profile two" language="java"/>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
-         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
-         plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
-         plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldDeleteActiveRules.xml
deleted file mode 100644 (file)
index 8174c81..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<dataset>
-
-  <rules_profiles id="1" name="profile one" language="java" />
-  <rules_profiles id="2" name="profile two" language="java" />
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
-         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
-         plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
-         plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="4" profile_id="2" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="5" profile_id="2" rule_id="2" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="6" profile_id="2" rule_id="3" failure_level="2"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetActiveRules.xml
deleted file mode 100644 (file)
index db8f5e5..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<dataset>
-
-  <rules_profiles id="1" name="profile one" language="java" />
-  <rules_profiles id="2" name="profile two" language="java" />
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
-         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="2" name="bar" description="test" plugin_config_key="checker/bar"
-         plugin_rule_key="checkstyle.rule2" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="3" name="baz" description="test" plugin_config_key="checker/baz"
-         plugin_rule_key="checkstyle.rule3" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="1" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="1" rule_id="2" failure_level="2"/>
-  <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="1" rule_id="3" failure_level="2"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleParams.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleParams.xml
deleted file mode 100644 (file)
index 320cd40..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<dataset>
-
-  <!-- Rules -->
-  <rules tags="[null]" system_tags="[null]" id="1" name="new1" description="test1" plugin_config_key="checker/new1"
-         plugin_rule_key="checkstyle.new1" plugin_name="PLUGIN_KEY" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="2" name="new2" description="test2" plugin_config_key="checker/new2"
-         plugin_rule_key="checkstyle.new2" plugin_name="PLUGIN_KEY" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <!-- Rules parameters -->
-  <rules_parameters id="1" rule_id="1" name="rule1_param1" description="rule1_desc1" param_type="REGULAR_EXPRESSION"
-      />
-  <rules_parameters id="2" rule_id="1" name="rule1_param2" description="rule1_desc2" param_type="REGULAR_EXPRESSION"
-      />
-  <rules_parameters id="3" rule_id="2" name="rule2_param1" description="rule2_desc1" param_type="REGULAR_EXPRESSION"
-      />
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleWithRuleKeyAndPluginKey.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRuleWithRuleKeyAndPluginKey.xml
deleted file mode 100644 (file)
index 5aa92b9..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="foo" description="test" plugin_config_key="checker/foo"
-         plugin_rule_key="checkstyle.rule1" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-</dataset>
diff --git a/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRules.xml b/sonar-core/src/test/resources/org/sonar/jpa/dao/RulesDaoTest/shouldGetRules.xml
deleted file mode 100644 (file)
index e1fc311..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-<dataset>
-
-  <rules tags="[null]" system_tags="[null]" id="1" name="rule one" description="desc" plugin_config_key="other config"
-         plugin_rule_key="rule_one" plugin_name="plugin" status="READY" is_template="[false]" template_id="[null]"/>
-  <rules tags="[null]" system_tags="[null]" id="2" name="rule two" description="desc" plugin_config_key="config"
-         plugin_rule_key="rule_two" plugin_name="other plugin" status="READY" is_template="[false]" template_id="[null]"/>
-
-  <rules_parameters id="1" rule_id="1" name="rule1_param1" description="rule1_desc1" param_type="REGULAR_EXPRESSION"
-      />
-  <rules_parameters id="2" rule_id="2" name="rule2_param1" description="rule2_desc1" param_type="REGULAR_EXPRESSION"
-      />
-
-</dataset>
index ab24194d507d3e71837d273d815a3229ca12b04a..bc1e543c2d1313a00d3cf1b668d9cabe607f9803 100644 (file)
@@ -31,9 +31,10 @@ import org.sonar.server.db.migrations.v43.RequirementMeasuresMigration;
 import org.sonar.server.db.migrations.v43.TechnicalDebtMeasuresMigration;
 import org.sonar.server.db.migrations.v44.ChangeLogMigration;
 import org.sonar.server.db.migrations.v44.ConvertProfileMeasures;
+import org.sonar.server.db.migrations.v44.FeedQProfileDatesMigration;
+import org.sonar.server.db.migrations.v44.FeedQProfileKeysMigration;
 import org.sonar.server.db.migrations.v44.IssueActionPlanKeyMigration;
 import org.sonar.server.db.migrations.v44.MeasureDataMigration;
-import org.sonar.server.db.migrations.v44.QProfileKeyMigration;
 
 import java.util.List;
 
@@ -57,7 +58,8 @@ public interface DatabaseMigrations {
     // 4.4
     IssueActionPlanKeyMigration.class,
     MeasureDataMigration.class,
-    QProfileKeyMigration.class,
+    FeedQProfileKeysMigration.class,
+    FeedQProfileDatesMigration.class,
     ChangeLogMigration.class,
     ConvertProfileMeasures.class
   );
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigration.java
new file mode 100644 (file)
index 0000000..23b87f1
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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.server.db.migrations.v44;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.commons.lang.ObjectUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.migration.v44.Migration44Mapper;
+import org.sonar.core.qualityprofile.db.QualityProfileDto;
+import org.sonar.core.qualityprofile.db.QualityProfileMapper;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import java.util.Date;
+
+/**
+ * Feed the new columns RULES_PROFILES.CREATED_AT and UPDATED_AT
+ * 
+ * @since 4.4
+ */
+public class FeedQProfileDatesMigration implements DatabaseMigration {
+
+  private final DbClient db;
+  private final System2 system;
+
+  @VisibleForTesting
+  FeedQProfileDatesMigration(DbClient db, System2 system) {
+    this.db = db;
+    this.system = system;
+  }
+
+  public FeedQProfileDatesMigration(DbClient db) {
+    this(db, System2.INSTANCE);
+  }
+
+  @Override
+  public void execute() {
+    DbSession session = db.openSession(false);
+    try {
+      Date now = new Date(system.now());
+      int i = 0;
+      QualityProfileMapper profileMapper = session.getMapper(QualityProfileMapper.class);
+      Migration44Mapper migrationMapper = session.getMapper(Migration44Mapper.class);
+      for (QualityProfileDto profile : profileMapper.selectAll()) {
+        Date createdAt = migrationMapper.selectProfileCreatedAt(profile.getId());
+        Date updatedAt = migrationMapper.selectProfileUpdatedAt(profile.getId());
+        migrationMapper.updateProfileDates(profile.getId(),
+          (Date) ObjectUtils.defaultIfNull(createdAt, now), (Date) ObjectUtils.defaultIfNull(updatedAt, now));
+        if (i % 100 == 0) {
+          session.commit();
+          i++;
+        }
+      }
+      session.commit();
+    } finally {
+      session.close();
+    }
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/FeedQProfileKeysMigration.java
new file mode 100644 (file)
index 0000000..f2b1b5e
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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.server.db.migrations.v44;
+
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.DatabaseMigration;
+import org.sonar.server.db.migrations.MassUpdater;
+import org.sonar.server.db.migrations.SqlUtil;
+import org.sonar.server.util.Slug;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Feed the new columns RULES_PROFILES.KEE and PARENT_KEE.
+ * 
+ * @since 4.4
+ */
+public class FeedQProfileKeysMigration implements DatabaseMigration {
+
+  private final Database db;
+
+  public FeedQProfileKeysMigration(Database database) {
+    this.db = database;
+  }
+
+  @Override
+  public void execute() {
+    updateKeys();
+    updateParentKeys();
+  }
+
+  private void updateKeys() {
+    new MassUpdater(db, 100).execute(
+      new MassUpdater.InputLoader<Row>() {
+        @Override
+        public String selectSql() {
+          return "SELECT id,language,name FROM rules_profiles";
+        }
+
+        @Override
+        public Row load(ResultSet rs) throws SQLException {
+          Row row = new Row();
+          row.id = SqlUtil.getLong(rs, 1);
+          row.lang = rs.getString(2);
+          row.name = rs.getString(3);
+          return row;
+        }
+      },
+      new MassUpdater.InputConverter<Row>() {
+
+        @Override
+        public String updateSql() {
+          return "UPDATE rules_profiles SET kee=? WHERE id=?";
+        }
+
+        @Override
+        public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
+          updateStatement.setString(1, Slug.slugify(String.format("%s %s", row.lang, row.name)));
+          updateStatement.setLong(2, row.id);
+          return true;
+        }
+      }
+      );
+  }
+
+  private void updateParentKeys() {
+    new MassUpdater(db, 100).execute(
+      new MassUpdater.InputLoader<Row>() {
+        @Override
+        public String selectSql() {
+          return "SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " +
+            "and child.language=parent.language AND child.parent_name IS NOT NULL";
+        }
+
+        @Override
+        public Row load(ResultSet rs) throws SQLException {
+          Row row = new Row();
+          row.id = SqlUtil.getLong(rs, 1);
+          row.parentKey = rs.getString(2);
+          return row;
+        }
+      },
+      new MassUpdater.InputConverter<Row>() {
+
+        @Override
+        public String updateSql() {
+          return "UPDATE rules_profiles SET parent_kee=? WHERE id=?";
+        }
+
+        @Override
+        public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
+          updateStatement.setString(1, row.parentKey);
+          updateStatement.setLong(2, row.id);
+          return true;
+        }
+      }
+      );
+  }
+
+  private static class Row {
+    private Long id;
+    private String lang, name, parentKey;
+  }
+}
diff --git a/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/QProfileKeyMigration.java b/sonar-server/src/main/java/org/sonar/server/db/migrations/v44/QProfileKeyMigration.java
deleted file mode 100644 (file)
index 444c6bd..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.server.db.migrations.v44;
-
-import org.sonar.core.persistence.Database;
-import org.sonar.server.db.migrations.DatabaseMigration;
-import org.sonar.server.db.migrations.MassUpdater;
-import org.sonar.server.db.migrations.SqlUtil;
-import org.sonar.server.util.Slug;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-/**
- * Feed the new columns RULES_PROFILE.KEE and PARENT_KEE.
- * 
- * @since 4.4
- */
-public class QProfileKeyMigration implements DatabaseMigration {
-
-  private final Database db;
-
-  public QProfileKeyMigration(Database database) {
-    this.db = database;
-  }
-
-  @Override
-  public void execute() {
-    updateKeys();
-    updateParentKeys();
-  }
-
-  private void updateKeys() {
-    new MassUpdater(db, 100).execute(
-      new MassUpdater.InputLoader<Row>() {
-        @Override
-        public String selectSql() {
-          return "SELECT id,language,name FROM rules_profiles";
-        }
-
-        @Override
-        public Row load(ResultSet rs) throws SQLException {
-          Row row = new Row();
-          row.id = SqlUtil.getLong(rs, 1);
-          row.lang = rs.getString(2);
-          row.name = rs.getString(3);
-          return row;
-        }
-      },
-      new MassUpdater.InputConverter<Row>() {
-
-        @Override
-        public String updateSql() {
-          return "UPDATE rules_profiles SET kee=? WHERE id=?";
-        }
-
-        @Override
-        public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
-          updateStatement.setString(1, Slug.slugify(String.format("%s %s", row.lang, row.name)));
-          updateStatement.setLong(2, row.id);
-          return true;
-        }
-      }
-      );
-  }
-
-  private void updateParentKeys() {
-    new MassUpdater(db, 100).execute(
-      new MassUpdater.InputLoader<Row>() {
-        @Override
-        public String selectSql() {
-          return "SELECT child.id,parent.kee FROM rules_profiles child, rules_profiles parent WHERE child.parent_name=parent.name " +
-            "and child.language=parent.language AND child.parent_name IS NOT NULL";
-        }
-
-        @Override
-        public Row load(ResultSet rs) throws SQLException {
-          Row row = new Row();
-          row.id = SqlUtil.getLong(rs, 1);
-          row.parentKey = rs.getString(2);
-          return row;
-        }
-      },
-      new MassUpdater.InputConverter<Row>() {
-
-        @Override
-        public String updateSql() {
-          return "UPDATE rules_profiles SET parent_kee=? WHERE id=?";
-        }
-
-        @Override
-        public boolean convert(Row row, PreparedStatement updateStatement) throws SQLException {
-          updateStatement.setString(1, row.parentKey);
-          updateStatement.setLong(2, row.id);
-          return true;
-        }
-      }
-      );
-  }
-
-  private static class Row {
-    private Long id;
-    private String lang, name, parentKey;
-  }
-}
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/549_feed_qprofile_keys.rb
new file mode 100644 (file)
index 0000000..0f76dc6
--- /dev/null
@@ -0,0 +1,39 @@
+#
+# 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.
+#
+
+#
+# SonarQube 4.4
+# SONAR-5384
+#
+class FeedQprofileKeys < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v44.FeedQProfileKeysMigration')
+
+    # set as non-null and unique
+    change_column :rules_profiles, :kee, :string, :limit => 1000, :null => false
+    add_index :rules_profiles, :kee, :name => 'uniq_qprof_key', :unique => true
+
+    remove_column :rules_profiles, :parent_name
+    remove_column :rules_profiles, :version
+    remove_column :rules_profiles, :used_profile
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/549_set_qprofile_keys.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/549_set_qprofile_keys.rb
deleted file mode 100644 (file)
index c0f092b..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# 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.
-#
-
-#
-# SonarQube 4.4
-# SONAR-5384
-#
-class SetQprofileKeys < ActiveRecord::Migration
-
-  def self.up
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.QProfileKeyMigration')
-
-    # set as non-null and unique
-    change_column :rules_profiles, :kee, :string, :limit => 1000, :null => false
-    add_index :rules_profiles, :kee, :name => 'uniq_qprof_key', :unique => true
-
-    remove_column :rules_profiles, :parent_name
-    remove_column :rules_profiles, :version
-    remove_column :rules_profiles, :used_profile
-  end
-
-end
index 19a4c8e87ae41cf2f8683f02e9e94780f7bd7ec4..427a7703a4a3439fe93b9ee1b9327ecca17b244c 100644 (file)
@@ -28,7 +28,7 @@ class ConvertProfileMeasures < ActiveRecord::Migration
   end
 
   def self.up
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.ConvertProfileMeasures')
+    execute_java_migration('org.sonar.server.db.migrations.v44.ConvertProfileMeasures')
 
     Metric.reset_column_information
     metric = Metric.find_by_name('profile')
index 5dc87440153f38c5994bace0c02bdf065262d6f1..0244e5730122e667803c7d0059b289bffc2030e1 100644 (file)
@@ -25,7 +25,7 @@
 class UpdateLogsToActivities < ActiveRecord::Migration
 
   def self.up
-    Java::OrgSonarServerUi::JRubyFacade.getInstance().databaseMigrator().executeMigration('org.sonar.server.db.migrations.v44.ChangeLogMigration')
+    execute_java_migration('org.sonar.server.db.migrations.v44.ChangeLogMigration')
   end
 
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/552_add_qprofile_dates.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/552_add_qprofile_dates.rb
new file mode 100644 (file)
index 0000000..5090e1b
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+#
+# SonarQube 4.4
+#
+class AddQprofileDates < ActiveRecord::Migration
+
+  def self.up
+    add_column :rules_profiles, :rules_updated_at, :datetime, :null => true
+    add_column :rules_profiles, :created_at, :datetime, :null => true
+    add_column :rules_profiles, :updated_at, :datetime, :null => true
+  end
+
+end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/553_feed_qprofile_dates.rb
new file mode 100644 (file)
index 0000000..2fe4f23
--- /dev/null
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+#
+# SonarQube 4.4
+#
+class FeedQprofileDates < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration 'org.sonar.server.db.migrations.v44.FeedQProfileDatesMigration'
+  end
+
+end
diff --git a/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java b/sonar-server/src/test/java/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest.java
new file mode 100644 (file)
index 0000000..7eee036
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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.server.db.migrations.v44;
+
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.DbClient;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FeedQProfileDatesMigrationTest {
+
+  @ClassRule
+  public static TestDatabase db = new TestDatabase().schema(FeedQProfileDatesMigrationTest.class, "schema.sql");
+
+  FeedQProfileDatesMigration migration;
+
+  @Before
+  public void setUp() throws Exception {
+    DbClient dbClient = new DbClient(db.database(), db.myBatis());
+    System2 system = mock(System2.class);
+    when(system.now()).thenReturn(DateUtils.parseDate("2014-07-03").getTime());
+    migration = new FeedQProfileDatesMigration(dbClient, system);
+  }
+
+  @Test
+  public void feed_created_at_and_updated_at() throws Exception {
+    db.prepareDbUnit(getClass(), "feed_created_at_and_updated_at.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "feed_created_at_and_updated_at_result.xml", "rules_profiles");
+  }
+
+  @Test
+  public void use_default_dates_when_no_changes() throws Exception {
+    db.prepareDbUnit(getClass(), "use_default_dates_when_no_changes.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "use_default_dates_when_no_changes_result.xml", "rules_profiles");
+  }
+
+}
diff --git a/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at.xml b/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at.xml
new file mode 100644 (file)
index 0000000..5f0a7a8
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+  <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+
+  <!-- oldest to newest changes -->
+  <active_rule_changes id="122" profile_id="10" profile_version="2" rule_id="1" change_date="2011-12-25 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="robert"/>
+
+  <active_rule_changes id="123" profile_id="10" profile_version="2" rule_id="1" change_date="2013-05-18 10:20:05.158"
+                       enabled="[null]" old_severity="1" new_severity="4" username="lucie"/>
+
+  <active_rule_changes id="126" profile_id="10" profile_version="3" rule_id="1" change_date="2014-01-24 20:20:05.158"
+                       enabled="[null]" old_severity="[null]" new_severity="[null]" username="tatiana"/>
+
+  <!-- another profile -->
+  <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at_result.xml b/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/feed_created_at_and_updated_at_result.xml
new file mode 100644 (file)
index 0000000..b8edf93
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+  <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+                  rules_updated_at="2014-01-24 20:20:05.158" created_at="2011-12-25 20:20:05.158" updated_at="2014-01-24 20:20:05.158"/>
+
+  <!-- oldest to newest changes -->
+  <active_rule_changes id="122" profile_id="10" profile_version="2" rule_id="1" change_date="2011-12-25 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="robert"/>
+
+  <active_rule_changes id="123" profile_id="10" profile_version="2" rule_id="1" change_date="2013-05-18 10:20:05.158"
+                       enabled="[null]" old_severity="1" new_severity="4" username="lucie"/>
+
+  <active_rule_changes id="126" profile_id="10" profile_version="3" rule_id="1" change_date="2014-01-24 20:20:05.158"
+                       enabled="[null]" old_severity="[null]" new_severity="[null]" username="tatiana"/>
+
+  <!-- another profile -->
+  <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/schema.sql b/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/schema.sql
new file mode 100644 (file)
index 0000000..36fce32
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE TABLE "RULES_PROFILES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "NAME" VARCHAR(100) NOT NULL,
+  "LANGUAGE" VARCHAR(20),
+  "KEE" VARCHAR(1000) NOT NULL,
+  "PARENT_KEE" VARCHAR(1000),
+  "RULES_UPDATED_AT" TIMESTAMP,
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
+
+CREATE TABLE "ACTIVE_RULE_CHANGES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "USERNAME" VARCHAR(255),
+  "PROFILE_ID" INTEGER NOT NULL,
+  "PROFILE_VERSION" INTEGER NOT NULL,
+  "RULE_ID" INTEGER NOT NULL,
+  "CHANGE_DATE" TIMESTAMP NOT NULL,
+  "ENABLED" BOOLEAN,
+  "OLD_SEVERITY" INTEGER,
+  "NEW_SEVERITY" INTEGER
+);
+
+CREATE TABLE "ACTIVE_RULE_PARAM_CHANGES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "ACTIVE_RULE_CHANGE_ID" INTEGER NOT NULL,
+  "RULES_PARAMETER_ID" INTEGER NOT NULL,
+  "OLD_VALUE" VARCHAR(4000),
+  "NEW_VALUE" VARCHAR(4000)
+  );
diff --git a/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes.xml b/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes.xml
new file mode 100644 (file)
index 0000000..4c01980
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+  <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+                  rules_updated_at="[null]" created_at="[null]" updated_at="[null]"/>
+
+
+  <!-- another profile -->
+  <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>
diff --git a/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes_result.xml b/sonar-server/src/test/resources/org/sonar/server/db/migrations/v44/FeedQProfileDatesMigrationTest/use_default_dates_when_no_changes_result.xml
new file mode 100644 (file)
index 0000000..e1cf4eb
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+
+  <rules_profiles id="10" name="Sonar Way" language="java" kee="java-sw" parent_kee="[null]"
+                  rules_updated_at="2014-07-03" created_at="2014-07-03" updated_at="2014-07-03"/>
+
+
+  <!-- another profile -->
+  <active_rule_changes id="124" profile_id="11" profile_version="1" rule_id="2" change_date="2011-12-05 20:20:05.158"
+                       enabled="true" old_severity="[null]" new_severity="1" username="Administrator"/>
+
+</dataset>