diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-15 15:47:40 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-08-15 15:47:40 +0200 |
commit | 9ca86cd73f8807401910cf8610b7b37bfb528b10 (patch) | |
tree | b2a02ce2627facc14ce4209b835cb4a96c6dabab | |
parent | f6c065834cddaeb5e1072a4ac0032c8c13f7c857 (diff) | |
download | sonarqube-9ca86cd73f8807401910cf8610b7b37bfb528b10.tar.gz sonarqube-9ca86cd73f8807401910cf8610b7b37bfb528b10.zip |
SONAR-2707 Some dependencies might miss in the Libraries, Dependencies and Design services when running several sonar analysis at same time
4 files changed, 159 insertions, 2 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java index a05bd16bb02..65792f152aa 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java @@ -37,8 +37,10 @@ public final class PurgeDependencies extends Purge { public void purge(PurgeContext context) { Query query = getSession().createQuery("SELECT d.projectSnapshotId FROM " + DependencyDto.class.getSimpleName() + - " d WHERE NOT EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last)"); - query.setParameter("last", true); + " d WHERE EXISTS(FROM " + Snapshot.class.getSimpleName() + " s WHERE s.id=d.projectSnapshotId AND s.last=:last and s.status=:status)"); + query.setParameter("last", false); + query.setParameter("status", Snapshot.STATUS_PROCESSED); + final List<Integer> projectSnapshotIds = query.getResultList(); PurgeUtils.executeQuery(getSession(), "", projectSnapshotIds, "DELETE FROM " + DependencyDto.class.getSimpleName() + " WHERE projectSnapshotId in (:ids)"); } diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java index 3ce14d6d27b..5fb68a63e88 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java @@ -31,6 +31,15 @@ public class PurgeDependenciesTest extends AbstractDbUnitTestCase { assertPurge("purgeDependencies"); } + /** + * See https://jira.codehaus.org/browse/SONAR-2707 + * Do not remove dependencies which are computed at the same time in other parallel jobs. + */ + @Test + public void shouldNotPurgeUnprocessedSnapshots() throws SQLException { + assertPurge("shouldNotPurgeUnprocessedSnapshots"); + } + private void assertPurge(String testName) { setupData(testName); new PurgeDependencies(getSession()).purge(null); diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml new file mode 100644 index 00000000000..2d2599d8794 --- /dev/null +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml @@ -0,0 +1,73 @@ +<dataset> + + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="first:project" name="One" + root_id="[null]" + description="[null]" + enabled="true" language="java" copy_resource_id="[null]"/> + + <projects long_name="[null]" id="2" scope="PRJ" qualifier="TRK" kee="second:project" name="Two" + root_id="[null]" + description="[null]" + enabled="true" language="java" copy_resource_id="[null]"/> + + + <!-- old --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="1" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="2" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false" + path="[null]"/> + + + <!-- last --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="3" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="4" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true" + path="[null]"/> + + + <!-- in progress --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="5" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="6" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false" + path="[null]"/> + + + + <!-- old dependencies --> + <!--<dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2"--> + <!--parent_dependency_id="[null]" project_snapshot_id="1"--> + <!--dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/>--> + + + <!-- last dependencies --> + <dependencies id="2" from_resource_id="1" from_snapshot_id="3" to_resource_id="2" to_snapshot_id="4" + parent_dependency_id="[null]" project_snapshot_id="3" + dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/> + + <!-- in progress --> + <dependencies id="3" from_resource_id="1" from_snapshot_id="5" to_resource_id="2" to_snapshot_id="6" + parent_dependency_id="[null]" project_snapshot_id="5" + dep_usage="uses" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/> + +</dataset>
\ No newline at end of file diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml new file mode 100644 index 00000000000..6b143bea1ec --- /dev/null +++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml @@ -0,0 +1,73 @@ +<dataset> + + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="first:project" name="One" + root_id="[null]" + description="[null]" + enabled="true" language="java" copy_resource_id="[null]"/> + + <projects long_name="[null]" id="2" scope="PRJ" qualifier="TRK" kee="second:project" name="Two" + root_id="[null]" + description="[null]" + enabled="true" language="java" copy_resource_id="[null]"/> + + + <!-- old --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="1" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="2" scope="PRJ" qualifier="TRK" created_at="2008-12-01 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="false" + path="[null]"/> + + + <!-- last --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="3" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="4" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="P" islast="true" + path="[null]"/> + + + <!-- in progress --> + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="5" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]" + project_id="1" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false" + path="[null]"/> + + <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" + depth="[null]" id="6" scope="PRJ" qualifier="TRK" created_at="2008-12-03 13:58:00.00" version="[null]" + project_id="2" + parent_snapshot_id="[null]" root_project_id="[null]" root_snapshot_id="[null]" status="U" islast="false" + path="[null]"/> + + + + <!-- old dependencies --> + <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="2" to_snapshot_id="2" + parent_dependency_id="[null]" project_snapshot_id="1" + dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/> + + + <!-- last dependencies --> + <dependencies id="2" from_resource_id="1" from_snapshot_id="3" to_resource_id="2" to_snapshot_id="4" + parent_dependency_id="[null]" project_snapshot_id="3" + dep_usage="compile" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/> + + <!-- in progress --> + <dependencies id="3" from_resource_id="1" from_snapshot_id="5" to_resource_id="2" to_snapshot_id="6" + parent_dependency_id="[null]" project_snapshot_id="5" + dep_usage="uses" dep_weight="1" from_scope="PRJ" to_scope="PRJ"/> + +</dataset>
\ No newline at end of file |