]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5758 db migration to delete corrupted rows in ACTIVITIES
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 21 Oct 2014 17:44:22 +0000 (19:44 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 21 Oct 2014 17:44:22 +0000 (19:44 +0200)
30 files changed:
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/package-info.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/no_changes.xml [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/schema.sql [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/no_changes.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/schema.sql [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute-result.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/schema.sql [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/601_add_missing_custom_rule_parameters.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/602_remove_duplication_in_group_roles.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/603_add_enabled_to_projects_kee_index.rb
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/604_delete_unescaped_activities.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl

index d27f85f8344a8c063113e1a303d3162e84383ba6..8bc203035abdf0b40d989f31ed623034c0b5a7ad 100644 (file)
@@ -25,9 +25,10 @@ import org.sonar.server.db.migrations.v42.CompleteIssueMessageMigration;
 import org.sonar.server.db.migrations.v42.PackageKeysMigration;
 import org.sonar.server.db.migrations.v43.*;
 import org.sonar.server.db.migrations.v44.*;
-import org.sonar.server.db.migrations.v45.AddMissingCustomRuleParametersMigration;
+import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration;
 import org.sonar.server.db.migrations.v45.AddMissingRuleParameterDefaultValuesMigration;
 import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigration;
+import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities;
 
 import java.util.List;
 
@@ -59,7 +60,10 @@ public interface DatabaseMigrations {
     // 4.5
     AddMissingRuleParameterDefaultValuesMigration.class,
     DeleteMeasuresOnDeletedProfilesMigration.class,
-    AddMissingCustomRuleParametersMigration.class
+
+    // 4.5.1
+    AddMissingCustomRuleParametersMigration.class,
+    DeleteUnescapedActivities.class
   );
 
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigration.java
deleted file mode 100644 (file)
index 4df9123..0000000
+++ /dev/null
@@ -1,118 +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.v45;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Multimap;
-import org.sonar.api.utils.System2;
-import org.sonar.core.persistence.DbSession;
-import org.sonar.core.persistence.migration.v45.Migration45Mapper;
-import org.sonar.core.persistence.migration.v45.Rule;
-import org.sonar.core.persistence.migration.v45.RuleParameter;
-import org.sonar.server.db.DbClient;
-import org.sonar.server.db.migrations.DatabaseMigration;
-
-import javax.annotation.Nullable;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-/**
- * See http://jira.codehaus.org/browse/SONAR-5575
- *
- * Add missing parameters (with no value) on each custom rules
- *
- * @since 4.5
- */
-public class AddMissingCustomRuleParametersMigration implements DatabaseMigration {
-
-  private final DbClient db;
-  private final System2 system;
-
-  public AddMissingCustomRuleParametersMigration(DbClient db, System2 system) {
-    this.db = db;
-    this.system = system;
-  }
-
-  @Override
-  public void execute() {
-    DbSession session = db.openSession(false);
-    try {
-      Migration45Mapper mapper = session.getMapper(Migration45Mapper.class);
-
-      List<RuleParameter> templateRuleParams = mapper.selectAllTemplateRuleParameters();
-      Multimap<Integer, RuleParameter> templateRuleParamsByRuleId = ArrayListMultimap.create();
-      for (RuleParameter templateRuleParam : templateRuleParams) {
-        templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam);
-      }
-
-      List<Rule> customRules = mapper.selectAllCustomRules();
-      Multimap<Integer, Integer> customRuleIdsByTemplateRuleId = HashMultimap.create();
-      for (Rule customRule : customRules) {
-        customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId());
-      }
-
-      List<RuleParameter> customRuleParams = mapper.selectAllCustomRuleParameters();
-      Multimap<Integer, RuleParameter> customRuleParamsByRuleId = ArrayListMultimap.create();
-      for (RuleParameter customRuleParam : customRuleParams) {
-        customRuleParamsByRuleId.put(customRuleParam.getRuleId(), customRuleParam);
-      }
-
-      // For each parameters of template rules, verify that each custom rules has the parameter
-      for (Integer templateRuleId : templateRuleParamsByRuleId.keySet()) {
-        for (RuleParameter templateRuleParam : templateRuleParamsByRuleId.get(templateRuleId)) {
-          // Each custom rule should have this parameter
-          for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) {
-            if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) {
-              // Insert new custom rule parameter
-              mapper.insertRuleParameter(new RuleParameter()
-                .setRuleId(customRuleId)
-                .setRuleTemplateId(templateRuleId)
-                .setName(templateRuleParam.getName())
-                .setDescription(templateRuleParam.getDescription())
-                .setType(templateRuleParam.getType())
-              );
-
-              // Update updated at date of custom rule in order to allow E/S indexation
-              mapper.updateRuleUpdateAt(customRuleId, new Date(system.now()));
-            }
-          }
-        }
-      }
-
-      session.commit();
-    } finally {
-      session.close();
-    }
-  }
-
-  private boolean hasParameter(final String parameter, Collection<RuleParameter> customRuleParams) {
-    return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
-      @Override
-      public boolean apply(@Nullable RuleParameter input) {
-        return input != null && input.getName().equals(parameter);
-      }
-    });
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigration.java
new file mode 100644 (file)
index 0000000..48aad8f
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * 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.v451;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.migration.v45.Migration45Mapper;
+import org.sonar.core.persistence.migration.v45.Rule;
+import org.sonar.core.persistence.migration.v45.RuleParameter;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * See http://jira.codehaus.org/browse/SONAR-5575
+ *
+ * Add missing parameters (with no value) on each custom rules
+ *
+ * @since 4.5.1
+ */
+public class AddMissingCustomRuleParametersMigration implements DatabaseMigration {
+
+  private final DbClient db;
+  private final System2 system;
+
+  public AddMissingCustomRuleParametersMigration(DbClient db, System2 system) {
+    this.db = db;
+    this.system = system;
+  }
+
+  @Override
+  public void execute() {
+    DbSession session = db.openSession(false);
+    try {
+      Migration45Mapper mapper = session.getMapper(Migration45Mapper.class);
+
+      List<RuleParameter> templateRuleParams = mapper.selectAllTemplateRuleParameters();
+      Multimap<Integer, RuleParameter> templateRuleParamsByRuleId = ArrayListMultimap.create();
+      for (RuleParameter templateRuleParam : templateRuleParams) {
+        templateRuleParamsByRuleId.put(templateRuleParam.getRuleId(), templateRuleParam);
+      }
+
+      List<Rule> customRules = mapper.selectAllCustomRules();
+      Multimap<Integer, Integer> customRuleIdsByTemplateRuleId = HashMultimap.create();
+      for (Rule customRule : customRules) {
+        customRuleIdsByTemplateRuleId.put(customRule.getTemplateId(), customRule.getId());
+      }
+
+      List<RuleParameter> customRuleParams = mapper.selectAllCustomRuleParameters();
+      Multimap<Integer, RuleParameter> customRuleParamsByRuleId = ArrayListMultimap.create();
+      for (RuleParameter customRuleParam : customRuleParams) {
+        customRuleParamsByRuleId.put(customRuleParam.getRuleId(), customRuleParam);
+      }
+
+      // For each parameters of template rules, verify that each custom rules has the parameter
+      for (Integer templateRuleId : templateRuleParamsByRuleId.keySet()) {
+        for (RuleParameter templateRuleParam : templateRuleParamsByRuleId.get(templateRuleId)) {
+          // Each custom rule should have this parameter
+          for (Integer customRuleId : customRuleIdsByTemplateRuleId.get(templateRuleId)) {
+            if (!hasParameter(templateRuleParam.getName(), customRuleParamsByRuleId.get(customRuleId))) {
+              // Insert new custom rule parameter
+              mapper.insertRuleParameter(new RuleParameter()
+                .setRuleId(customRuleId)
+                .setRuleTemplateId(templateRuleId)
+                .setName(templateRuleParam.getName())
+                .setDescription(templateRuleParam.getDescription())
+                .setType(templateRuleParam.getType())
+              );
+
+              // Update updated at date of custom rule in order to allow E/S indexation
+              mapper.updateRuleUpdateAt(customRuleId, new Date(system.now()));
+            }
+          }
+        }
+      }
+
+      session.commit();
+    } finally {
+      session.close();
+    }
+  }
+
+  private boolean hasParameter(final String parameter, Collection<RuleParameter> customRuleParams) {
+    return Iterables.any(customRuleParams, new Predicate<RuleParameter>() {
+      @Override
+      public boolean apply(@Nullable RuleParameter input) {
+        return input != null && input.getName().equals(parameter);
+      }
+    });
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivities.java
new file mode 100644 (file)
index 0000000..5f9866d
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * 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.v451;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.Select;
+import org.sonar.server.db.migrations.SqlStatement;
+
+import java.sql.SQLException;
+
+/**
+ * See http://jira.codehaus.org/browse/SONAR-5758
+ *
+ * @since 4.5.1
+ */
+public class DeleteUnescapedActivities extends BaseDataChange {
+
+  public DeleteUnescapedActivities(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("select id,data_field from activities where log_type='QPROFILE'");
+    massUpdate.update("delete activities where id=?");
+    massUpdate.execute(new MassUpdate.Handler() {
+      @Override
+      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+        String csv = row.getString(2);
+        if (isUnescaped(csv)) {
+          update.setLong(1, row.getLong(1));
+          return true;
+        }
+        return false;
+      }
+    });
+  }
+
+  static boolean isUnescaped(String csv) {
+    String[] splits = csv.split(";");
+    for (String split : splits) {
+      if (StringUtils.countMatches(split, "=") != 1) {
+        return true;
+      }
+    }
+    return false;
+  }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v451/package-info.java
new file mode 100644 (file)
index 0000000..30ddbeb
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.server.db.migrations.v451;
+
+import javax.annotation.ParametersAreNonnullByDefault;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest.java
deleted file mode 100644 (file)
index f1db254..0000000
+++ /dev/null
@@ -1,78 +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.v45;
-
-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 org.sonar.server.db.migrations.DatabaseMigration;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class AddMissingCustomRuleParametersMigrationTest {
-
-  @ClassRule
-  public static TestDatabase db = new TestDatabase().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
-
-  DatabaseMigration migration;
-  System2 system = mock(System2.class);
-
-  @Before
-  public void setUp() throws Exception {
-    db.executeUpdateSql("truncate table rules");
-    db.executeUpdateSql("truncate table rules_parameters");
-    DbClient dbClient = new DbClient(db.database(), db.myBatis());
-    migration = new AddMissingCustomRuleParametersMigration(dbClient, system);
-    when(system.now()).thenReturn(DateUtils.parseDate("2014-10-09").getTime());
-  }
-
-  @Test
-  public void execute() throws Exception {
-    db.prepareDbUnit(getClass(), "execute.xml");
-
-    migration.execute();
-
-    db.assertDbUnit(getClass(), "execute-result.xml", "rules", "rules_parameters");
-  }
-
-  @Test
-  public void execute_when_custom_rule_have_no_parameter() throws Exception {
-    db.prepareDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter.xml");
-
-    migration.execute();
-
-    db.assertDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter-result.xml", "rules", "rules_parameters");
-  }
-
-  @Test
-  public void no_changes() throws Exception {
-    db.prepareDbUnit(getClass(), "no_changes.xml");
-
-    migration.execute();
-
-    db.assertDbUnit(getClass(), "no_changes.xml", "rules", "rules_parameters");
-  }
-
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest.java
new file mode 100644 (file)
index 0000000..e33bff9
--- /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.v451;
+
+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 org.sonar.server.db.migrations.DatabaseMigration;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AddMissingCustomRuleParametersMigrationTest {
+
+  @ClassRule
+  public static TestDatabase db = new TestDatabase().schema(AddMissingCustomRuleParametersMigrationTest.class, "schema.sql");
+
+  DatabaseMigration migration;
+  System2 system = mock(System2.class);
+
+  @Before
+  public void setUp() throws Exception {
+    db.executeUpdateSql("truncate table rules");
+    db.executeUpdateSql("truncate table rules_parameters");
+    DbClient dbClient = new DbClient(db.database(), db.myBatis());
+    migration = new AddMissingCustomRuleParametersMigration(dbClient, system);
+    when(system.now()).thenReturn(DateUtils.parseDate("2014-10-09").getTime());
+  }
+
+  @Test
+  public void execute() throws Exception {
+    db.prepareDbUnit(getClass(), "execute.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "execute-result.xml", "rules", "rules_parameters");
+  }
+
+  @Test
+  public void execute_when_custom_rule_have_no_parameter() throws Exception {
+    db.prepareDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "execute_when_custom_rule_have_no_parameter-result.xml", "rules", "rules_parameters");
+  }
+
+  @Test
+  public void no_changes() throws Exception {
+    db.prepareDbUnit(getClass(), "no_changes.xml");
+
+    migration.execute();
+
+    db.assertDbUnit(getClass(), "no_changes.xml", "rules", "rules_parameters");
+  }
+
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest.java
new file mode 100644 (file)
index 0000000..4f342cf
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.v451;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.core.persistence.TestDatabase;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DeleteUnescapedActivitiesTest {
+
+  @ClassRule
+  public static TestDatabase db = new TestDatabase().schema(DeleteUnescapedActivitiesTest.class, "schema.sql");
+
+  DatabaseMigration migration;
+
+  @Test
+  public void execute() throws Exception {
+    migration = new DeleteUnescapedActivities(db.database());
+    db.prepareDbUnit(getClass(), "execute.xml");
+    migration.execute();
+    db.assertDbUnit(getClass(), "execute-result.xml", "activities");
+  }
+
+  @Test
+  public void is_unescaped() throws Exception {
+    assertThat(DeleteUnescapedActivities.isUnescaped(
+      "ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;profileKey=java-findbugs-74105;severity=MAJOR;" +
+        "key=java-findbugs-74105:findbugs:PT_RELATIVE_PATH_TRAVERSAL"))
+      .isFalse();
+    assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo/bar")).isFalse();
+    assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo/bar;foo;ruleKey=S001")).isTrue();
+    assertThat(DeleteUnescapedActivities.isUnescaped("param_xpath=/foo=foo;ruleKey=S001")).isTrue();
+
+  }
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute-result.xml
deleted file mode 100644 (file)
index a4b4ab4..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-
-  <!-- Template rule -->
-  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
-  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
-
-  <!-- Custom rule, 2 parameters should be added -->
-  <rules id="2" plugin_rule_key="ArchitecturalConstraint_2" plugin_name="xoo" name="Architectural constraint 2" description="Architectural constraint 2" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-10-09"/>
-  <rules_parameters id="5" rule_id="2" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="6" rule_id="2" name="format" param_type="STRING" default_value="csv" description="[null]" />
-  <rules_parameters id="7" rule_id="2" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="8" rule_id="2" name="param" param_type="STRING" default_value="[null]" description="[null]" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute.xml
deleted file mode 100644 (file)
index 58b9732..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<dataset>
-
-  <!-- Template rule -->
-  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
-  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
-
-  <!-- Custom rule, 2 parameters are existing, 2 parameters should be added -->
-  <rules id="2" plugin_rule_key="ArchitecturalConstraint_2" plugin_name="xoo" name="Architectural constraint 2" description="Architectural constraint 2" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="5" rule_id="2" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="6" rule_id="2" name="format" param_type="STRING" default_value="csv" description="[null]" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml
deleted file mode 100644 (file)
index 76c7c18..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<dataset>
-
-  <!-- Template rule -->
-  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
-  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
-
-  <!-- Custom rule, 0 parameter are existing, 4 parameters should be added -->
-  <rules id="3" plugin_rule_key="ArchitecturalConstraint_3" plugin_name="xoo" name="Architectural constraint 3" description="Architectural constraint 3" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-10-09"/>
-  <rules_parameters id="5" rule_id="3" name="max" param_type="INT" default_value="[null]" description="[null]" />
-  <rules_parameters id="6" rule_id="3" name="format" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="7" rule_id="3" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="8" rule_id="3" name="param" param_type="STRING" default_value="[null]" description="[null]" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml
deleted file mode 100644 (file)
index dd676e5..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<dataset>
-
-  <!-- Template rule -->
-  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
-  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
-  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
-  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
-
-  <!-- Custom rule, 0 parameter are existing, 4 parameters should be added -->
-  <rules id="3" plugin_rule_key="ArchitecturalConstraint_3" plugin_name="xoo" name="Architectural constraint 3" description="Architectural constraint 3" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-01-01"/>
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/no_changes.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/no_changes.xml
deleted file mode 100644 (file)
index ed072ad..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<dataset>
-
-  <!-- Template rule -->
-  <rules id="10" plugin_rule_key="Rule2" plugin_name="xoo" name="Rule2" description="Rule2" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="10" rule_id="10" name="max" param_type="INT" default_value="10" description="[null]" />
-
-  <!-- Custom rule, no parameter should be added -->
-  <rules id="11" plugin_rule_key="Rule2_2" plugin_name="xoo" name="Rule2_2" description="Rule2_2" status="READY" priority="1" language="xoo"
-         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
-         characteristic_id="[null]" default_characteristic_id="[null]"
-         remediation_function="[null]" default_remediation_function="[null]"
-         remediation_coeff="[null]" default_remediation_coeff="[null]"
-         remediation_offset="[null]" default_remediation_offset="[null]"
-         effort_to_fix_description="[null]"
-         is_template="[false]" template_id="10" created_at="2014-01-01" updated_at="2014-01-01"/>
-  <rules_parameters id="11" rule_id="11" name="max" param_type="INT" default_value="10" description="[null]" />
-
-</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v45/AddMissingCustomRuleParametersMigrationTest/schema.sql
deleted file mode 100644 (file)
index 0bf3861..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-CREATE TABLE "RULES_PARAMETERS" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "RULE_ID" INTEGER NOT NULL,
-  "NAME" VARCHAR(128) NOT NULL,
-  "PARAM_TYPE" VARCHAR(512) NOT NULL,
-  "DEFAULT_VALUE" VARCHAR(4000),
-  "DESCRIPTION" VARCHAR(4000)
-);
-
-CREATE TABLE "RULES" (
-  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
-  "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
-  "PLUGIN_NAME" VARCHAR(255) NOT NULL,
-  "DESCRIPTION" VARCHAR(16777215),
-  "DESCRIPTION_FORMAT" VARCHAR(20),
-  "PRIORITY" INTEGER,
-  "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
-  "TEMPLATE_ID" INTEGER,
-  "PLUGIN_CONFIG_KEY" VARCHAR(500),
-  "NAME" VARCHAR(200),
-  "STATUS" VARCHAR(40),
-  "LANGUAGE" VARCHAR(20),
-  "NOTE_DATA" CLOB(2147483647),
-  "NOTE_USER_LOGIN" VARCHAR(255),
-  "NOTE_CREATED_AT" TIMESTAMP,
-  "NOTE_UPDATED_AT" TIMESTAMP,
-  "CHARACTERISTIC_ID" INTEGER,
-  "DEFAULT_CHARACTERISTIC_ID" INTEGER,
-  "REMEDIATION_FUNCTION" VARCHAR(20),
-  "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20),
-  "REMEDIATION_COEFF" VARCHAR(20),
-  "DEFAULT_REMEDIATION_COEFF" VARCHAR(20),
-  "REMEDIATION_OFFSET" VARCHAR(20),
-  "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20),
-  "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000),
-  "TAGS" VARCHAR(4000),
-  "SYSTEM_TAGS" VARCHAR(4000),
-  "CREATED_AT" TIMESTAMP,
-  "UPDATED_AT" TIMESTAMP
-);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute-result.xml
new file mode 100644 (file)
index 0000000..a4b4ab4
--- /dev/null
@@ -0,0 +1,31 @@
+<dataset>
+
+  <!-- Template rule -->
+  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
+  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
+
+  <!-- Custom rule, 2 parameters should be added -->
+  <rules id="2" plugin_rule_key="ArchitecturalConstraint_2" plugin_name="xoo" name="Architectural constraint 2" description="Architectural constraint 2" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-10-09"/>
+  <rules_parameters id="5" rule_id="2" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="6" rule_id="2" name="format" param_type="STRING" default_value="csv" description="[null]" />
+  <rules_parameters id="7" rule_id="2" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="8" rule_id="2" name="param" param_type="STRING" default_value="[null]" description="[null]" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute.xml
new file mode 100644 (file)
index 0000000..58b9732
--- /dev/null
@@ -0,0 +1,29 @@
+<dataset>
+
+  <!-- Template rule -->
+  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
+  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
+
+  <!-- Custom rule, 2 parameters are existing, 2 parameters should be added -->
+  <rules id="2" plugin_rule_key="ArchitecturalConstraint_2" plugin_name="xoo" name="Architectural constraint 2" description="Architectural constraint 2" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="5" rule_id="2" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="6" rule_id="2" name="format" param_type="STRING" default_value="csv" description="[null]" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter-result.xml
new file mode 100644 (file)
index 0000000..76c7c18
--- /dev/null
@@ -0,0 +1,31 @@
+<dataset>
+
+  <!-- Template rule -->
+  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
+  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
+
+  <!-- Custom rule, 0 parameter are existing, 4 parameters should be added -->
+  <rules id="3" plugin_rule_key="ArchitecturalConstraint_3" plugin_name="xoo" name="Architectural constraint 3" description="Architectural constraint 3" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-10-09"/>
+  <rules_parameters id="5" rule_id="3" name="max" param_type="INT" default_value="[null]" description="[null]" />
+  <rules_parameters id="6" rule_id="3" name="format" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="7" rule_id="3" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="8" rule_id="3" name="param" param_type="STRING" default_value="[null]" description="[null]" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/execute_when_custom_rule_have_no_parameter.xml
new file mode 100644 (file)
index 0000000..dd676e5
--- /dev/null
@@ -0,0 +1,27 @@
+<dataset>
+
+  <!-- Template rule -->
+  <rules id="1" plugin_rule_key="ArchitecturalConstraint" plugin_name="xoo" name="Architectural constraint" description="Architectural constraint" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="1" rule_id="1" name="max" param_type="INT" default_value="10" description="[null]" />
+  <rules_parameters id="2" rule_id="1" name="format" param_type="STRING" default_value="txt" description="[null]" />
+  <rules_parameters id="3" rule_id="1" name="type" param_type="STRING" default_value="[null]" description="[null]" />
+  <rules_parameters id="4" rule_id="1" name="param" param_type="STRING" default_value="" description="[null]" />
+
+  <!-- Custom rule, 0 parameter are existing, 4 parameters should be added -->
+  <rules id="3" plugin_rule_key="ArchitecturalConstraint_3" plugin_name="xoo" name="Architectural constraint 3" description="Architectural constraint 3" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[false]" template_id="1" created_at="2014-01-01" updated_at="2014-01-01"/>
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/no_changes.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/no_changes.xml
new file mode 100644 (file)
index 0000000..ed072ad
--- /dev/null
@@ -0,0 +1,25 @@
+<dataset>
+
+  <!-- Template rule -->
+  <rules id="10" plugin_rule_key="Rule2" plugin_name="xoo" name="Rule2" description="Rule2" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[true]" template_id="[null]" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="10" rule_id="10" name="max" param_type="INT" default_value="10" description="[null]" />
+
+  <!-- Custom rule, no parameter should be added -->
+  <rules id="11" plugin_rule_key="Rule2_2" plugin_name="xoo" name="Rule2_2" description="Rule2_2" status="READY" priority="1" language="xoo"
+         note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]" description_format="HTML" tags="[null]" system_tags="[null]" plugin_config_key="[null]"
+         characteristic_id="[null]" default_characteristic_id="[null]"
+         remediation_function="[null]" default_remediation_function="[null]"
+         remediation_coeff="[null]" default_remediation_coeff="[null]"
+         remediation_offset="[null]" default_remediation_offset="[null]"
+         effort_to_fix_description="[null]"
+         is_template="[false]" template_id="10" created_at="2014-01-01" updated_at="2014-01-01"/>
+  <rules_parameters id="11" rule_id="11" name="max" param_type="INT" default_value="10" description="[null]" />
+
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/AddMissingCustomRuleParametersMigrationTest/schema.sql
new file mode 100644 (file)
index 0000000..0bf3861
--- /dev/null
@@ -0,0 +1,40 @@
+CREATE TABLE "RULES_PARAMETERS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "RULE_ID" INTEGER NOT NULL,
+  "NAME" VARCHAR(128) NOT NULL,
+  "PARAM_TYPE" VARCHAR(512) NOT NULL,
+  "DEFAULT_VALUE" VARCHAR(4000),
+  "DESCRIPTION" VARCHAR(4000)
+);
+
+CREATE TABLE "RULES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL,
+  "PLUGIN_NAME" VARCHAR(255) NOT NULL,
+  "DESCRIPTION" VARCHAR(16777215),
+  "DESCRIPTION_FORMAT" VARCHAR(20),
+  "PRIORITY" INTEGER,
+  "IS_TEMPLATE" BOOLEAN DEFAULT FALSE,
+  "TEMPLATE_ID" INTEGER,
+  "PLUGIN_CONFIG_KEY" VARCHAR(500),
+  "NAME" VARCHAR(200),
+  "STATUS" VARCHAR(40),
+  "LANGUAGE" VARCHAR(20),
+  "NOTE_DATA" CLOB(2147483647),
+  "NOTE_USER_LOGIN" VARCHAR(255),
+  "NOTE_CREATED_AT" TIMESTAMP,
+  "NOTE_UPDATED_AT" TIMESTAMP,
+  "CHARACTERISTIC_ID" INTEGER,
+  "DEFAULT_CHARACTERISTIC_ID" INTEGER,
+  "REMEDIATION_FUNCTION" VARCHAR(20),
+  "DEFAULT_REMEDIATION_FUNCTION" VARCHAR(20),
+  "REMEDIATION_COEFF" VARCHAR(20),
+  "DEFAULT_REMEDIATION_COEFF" VARCHAR(20),
+  "REMEDIATION_OFFSET" VARCHAR(20),
+  "DEFAULT_REMEDIATION_OFFSET" VARCHAR(20),
+  "EFFORT_TO_FIX_DESCRIPTION" VARCHAR(4000),
+  "TAGS" VARCHAR(4000),
+  "SYSTEM_TAGS" VARCHAR(4000),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP
+);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute-result.xml
new file mode 100644 (file)
index 0000000..49462b9
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- ok -->
+  <activities id="1" log_key="abcde" created_at="2014-01-10" user_login="[null]" log_type="QPROFILE"
+              log_action="ACTIVATED" log_message="[null]"
+              data_field="ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;profileKey=java-findbugs-74105;severity=MAJOR"/>
+
+  <!-- ko - deleted -->
+  <!--<activities id="2" log_key="fghij" created_at="2014-01-10" user_login="[null]" log_type="QPROFILE"
+              log_action="ACTIVATED" log_message="[null]"
+              data_field="ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;param_xpath=foo;bar;baz"/>-->
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/execute.xml
new file mode 100644 (file)
index 0000000..4154847
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- ok -->
+  <activities id="1" log_key="abcde" created_at="2014-01-10" user_login="[null]" log_type="QPROFILE"
+              log_action="ACTIVATED" log_message="[null]"
+              data_field="ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;profileKey=java-findbugs-74105;severity=MAJOR"/>
+
+  <!-- ko -->
+  <activities id="2" log_key="fghij" created_at="2014-01-10" user_login="[null]" log_type="QPROFILE"
+              log_action="ACTIVATED" log_message="[null]"
+              data_field="ruleKey=findbugs:PT_RELATIVE_PATH_TRAVERSAL;param_xpath=foo;bar;baz"/>
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v451/DeleteUnescapedActivitiesTest/schema.sql
new file mode 100644 (file)
index 0000000..336e2fd
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "ACTIVITIES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "LOG_KEY" VARCHAR(250),
+  "CREATED_AT" TIMESTAMP,
+  "USER_LOGIN" VARCHAR(30),
+  "LOG_TYPE" VARCHAR(250),
+  "LOG_ACTION" VARCHAR(250),
+  "LOG_MESSAGE" VARCHAR(250),
+  "DATA_FIELD" CLOB(2147483647)
+);
index 55d04675c936c53bc940c0480e1963b472676d2e..68fc21af0553824d627b03cf55f4f3d278724bef 100644 (file)
@@ -25,6 +25,6 @@
 class AddMissingCustomRuleParameters < ActiveRecord::Migration
 
   def self.up
-    execute_java_migration 'org.sonar.server.db.migrations.v45.AddMissingCustomRuleParametersMigration'
+    execute_java_migration 'org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration'
   end
 end
index 168fa378ebb48285aed83d98083695b41be1d60a..069b9a3aff4be5f97cd4abeda54ee875992beb70 100644 (file)
@@ -19,7 +19,7 @@
 #
 
 #
-# SonarQube 4.5
+# SonarQube 4.5.1
 # SONAR-4950 Unique constraint cannot be created because it would be on resource_id that is nullable
 #
 class RemoveDuplicationInGroupRoles < ActiveRecord::Migration
index 6615bc274d21615c0725cbbae4e42e50ac75438b..6e80a8f8ee34046517c42b412be65810dc12fb9f 100644 (file)
@@ -19,7 +19,7 @@
 #
 
 #
-# SonarQube 4.5
+# SonarQube 4.5.1
 # SONAR-5625
 #
 class AddEnabledToProjectsKeeIndex < ActiveRecord::Migration
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/604_delete_unescaped_activities.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/604_delete_unescaped_activities.rb
new file mode 100644 (file)
index 0000000..6fe1d07
--- /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.5.1
+# SONAR-5758
+#
+class DeleteUnescapedActivities < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration 'org.sonar.server.db.migrations.v451.DeleteUnescapedActivities'
+  end
+end
index f8efc2cf9d3248f9f45a15d3efc5ac193c31da9d..6fdca61abb5c148078b5c262754df80affdaa08c 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 603;
+  public static final int LAST_VERSION = 604;
 
   public static enum Status {
     UP_TO_DATE, REQUIRES_UPGRADE, REQUIRES_DOWNGRADE, FRESH_INSTALL
index 1539b72a14292da0cb90c9fc6da382cc61df10e8..7cad5b16ff43a4e1869c3ad7891a729c203d6bb4 100644 (file)
@@ -258,6 +258,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('600');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('601');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('602');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('603');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('604');
 
 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 0afd7195b6eabbb6e2afe1a10581b6799075a170..608e80bc6dbc1c0fbc57e654c28935df9e5ea5ca 100644 (file)
@@ -537,6 +537,7 @@ CREATE TABLE "PERM_TEMPLATES_GROUPS" (
 
 
 CREATE TABLE "ACTIVITIES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
   "LOG_KEY" VARCHAR(250),
   "CREATED_AT" TIMESTAMP,
   "USER_LOGIN" VARCHAR(30),