From 1579738e5bf05a0a1e8d230585762eb75ea5cb7b Mon Sep 17 00:00:00 2001 From: Godin Date: Tue, 30 Nov 2010 15:40:42 +0000 Subject: [PATCH] SONAR-1450: Add support for incremental review of incoming violations --- .../PurgeUtilsTest/purgeSnapshots-result.xml | 8 +++--- .../api/PurgeUtilsTest/purgeSnapshots.xml | 8 +++--- .../purgeDeletedResources-result.xml | 8 +++--- .../purgeDeletedResources.xml | 8 +++--- .../purgeDeprecatedLast-result.xml | 8 +++--- .../purgeDeprecatedLast.xml | 8 +++--- .../purgeEntities-result.xml | 16 ++++++------ .../PurgeEntitiesTest/purgeEntities.xml | 16 ++++++------ .../purgeUnprocessed-result.xml | 16 ++++++------ .../PurgeUnprocessedTest/purgeUnprocessed.xml | 16 ++++++------ .../sonar/batch/index/ViolationPersister.java | 14 ++++++++-- .../batch/index/ViolationPersisterTest.java | 4 +-- .../index/ViolationPersisterTest/shared.xml | 1 + .../shouldInsertViolations-result.xml | 7 ++--- .../shouldUpdateViolation-result.xml | 3 ++- .../org/sonar/jpa/entity/SchemaMigration.java | 4 +-- ...160_add_rule_failures_created_at_column.rb | 26 +++++++++++++++++++ 17 files changed, 104 insertions(+), 67 deletions(-) create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml index f5039b0e8ec..3eb482305b8 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml @@ -56,10 +56,10 @@ - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + --> - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + models = session.getResults(RuleFailureModel.class, "snapshotId", previousLastSnapshot.getId(), "line", violation.getLineId(), "message", violation.getMessage()); + if (models != null && !models.isEmpty()) { + return models.get(0); + } + return null; } public void saveOrUpdateViolation(Project project, Violation violation) { @@ -61,7 +71,7 @@ public final class ViolationPersister { } else { // insert model = createModel(violation); - model.setCreatedAt(project.getAnalysisDate()); + model.setCreatedAt(snapshot.getCreatedAt()); } model.setSnapshotId(snapshot.getId()); session.save(model); diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java index 238d6e4ab57..61e60f7e613 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java @@ -39,8 +39,6 @@ import org.sonar.api.rules.Violation; import org.sonar.core.components.DefaultRuleFinder; import org.sonar.jpa.test.AbstractDbUnitTestCase; -import java.sql.Date; - public class ViolationPersisterTest extends AbstractDbUnitTestCase { private ViolationPersister violationPersister; @@ -68,7 +66,7 @@ public class ViolationPersisterTest extends AbstractDbUnitTestCase { .setPriority(RulePriority.CRITICAL).setLineId(50).setCost(80.0); Violation violation2 = Violation.create(rule2, javaFile) .setPriority(RulePriority.MINOR); - Project project = new Project("project").setAnalysisDate(Date.valueOf("2010-09-01")); + Project project = new Project("project"); violationPersister.saveViolation(project, violation1a); violationPersister.saveViolation(project, violation1b); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml index e32d3cbd7b5..1e7edba42a5 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml @@ -20,4 +20,5 @@ status="U" islast="false" depth="3" /> + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml index 1266940fe0d..d9b10b4d1c6 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml @@ -19,7 +19,8 @@ status="U" islast="false" depth="3" /> - - - + + + + \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml index 0025c82b089..e84072b474d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldUpdateViolation-result.xml @@ -19,4 +19,5 @@ status="U" islast="false" depth="3" /> - \ No newline at end of file + + diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index 5a6ec38be20..862666ab539 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -30,7 +30,7 @@ import java.sql.Statement; public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 152; + public static final int LAST_VERSION = 160; public final static String TABLE_NAME = "schema_migrations"; @@ -92,4 +92,4 @@ public class SchemaMigration { } } } -} \ No newline at end of file +} diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb new file mode 100644 index 00000000000..cf9d3189187 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/160_add_rule_failures_created_at_column.rb @@ -0,0 +1,26 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2009 SonarSource SA +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +class AddRuleFailuresCreatedAtColumn < ActiveRecord::Migration + + def self.up + add_column 'rule_failures', 'created_at', :datetime, :null => true + end + +end -- 2.39.5