]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2707 Some dependencies might miss in the Libraries, Dependencies and Design...
authorSimon Brandhof <simon.brandhof@gmail.com>
Mon, 15 Aug 2011 13:47:40 +0000 (15:47 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Mon, 15 Aug 2011 13:47:40 +0000 (15:47 +0200)
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest.java
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots-result.xml [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDependenciesTest/shouldNotPurgeUnprocessedSnapshots.xml [new file with mode: 0644]

index a05bd16bb02ffcaea982136166befee907500e4e..65792f152aabfa59a2b08d9b1dbbcfd783b18814 100644 (file)
@@ -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)");
   }
index 3ce14d6d27b0b4b2e896d4a122d17e6785c5620e..5fb68a63e88a2f99784c6eacba0b693cbef400e8 100644 (file)
@@ -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 (file)
index 0000000..2d2599d
--- /dev/null
@@ -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 (file)
index 0000000..6b143be
--- /dev/null
@@ -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