]> source.dussan.org Git - sonarqube.git/commitdiff
move org.sonar.plugins.dbcleaner.util.PurgeUtils to org.sonar.plugins.dbcleaner.api
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 19 Nov 2010 14:51:14 +0000 (14:51 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 19 Nov 2010 14:51:14 +0000 (14:51 +0000)
25 files changed:
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/Periods.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResources.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDependencies.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLast.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResources.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEntities.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeEventOrphans.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeOrphanResources.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgePropertyOrphans.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeResourceRoles.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasures.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessed.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/purges/UnflagLastDoublons.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java [deleted file]
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java [deleted file]
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java [deleted file]
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml [new file with mode: 0644]
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml [deleted file]
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml [deleted file]

index 41fa4916cf6f4f6bb400eb95b93e8722a540134e..5e8a261d33697c272e2efed55be013138e205f00 100644 (file)
@@ -22,11 +22,11 @@ package org.sonar.plugins.dbcleaner;
 import org.sonar.api.Plugin;\r
 import org.sonar.api.Properties;\r
 import org.sonar.api.Property;\r
+import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;\r
 import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;\r
 import org.sonar.plugins.dbcleaner.period.PeriodPurge;\r
 import org.sonar.plugins.dbcleaner.purges.*;\r
 import org.sonar.plugins.dbcleaner.runner.PurgeRunner;\r
-import org.sonar.plugins.dbcleaner.util.DbCleanerConstants;\r
 \r
 import java.util.Arrays;\r
 import java.util.List;\r
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/DbCleanerConstants.java
new file mode 100644 (file)
index 0000000..d39e0ae
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2010 SonarSource
+ * 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
+ */
+package org.sonar.plugins.dbcleaner.api;
+
+public interface DbCleanerConstants {
+
+  String PLUGIN_KEY = "dbcleaner";
+  String PLUGIN_NAME = "DbCleaner";
+  String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByWeek";
+  String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByMonth";
+  String MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS = "sonar.dbcleaner.monthsBeforeDeletingAllSnapshots";
+  String ONE_MONTH = "1";
+  String ONE_YEAR = "12";
+  String THREE_YEARS = "36";
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
new file mode 100644 (file)
index 0000000..229bcce
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Sonar, open source software quality management 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
+ */
+package org.sonar.plugins.dbcleaner.api;
+
+import org.apache.commons.configuration.Configuration;
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.*;
+import org.sonar.api.design.DependencyDto;
+import org.sonar.api.utils.TimeProfiler;
+
+import javax.persistence.Query;
+import java.util.List;
+
+/**
+ * @since 2.5
+ */
+public final class PurgeUtils {
+
+  public static final int DEFAULT_MINIMUM_PERIOD_IN_HOURS = 12;
+  public static final String PROP_KEY_MINIMUM_PERIOD_IN_HOURS = "sonar.purge.minimumPeriodInHours";
+
+  /**
+   * Maximum elements in the SQL statement "IN" due to an Oracle limitation (see error ORA-01795)
+   */
+  public static final int MAX_IN_ELEMENTS = 950;
+
+  private PurgeUtils() {
+    // only static methods
+  }
+
+  public static int getMinimumPeriodInHours(Configuration conf) {
+    int hours = DEFAULT_MINIMUM_PERIOD_IN_HOURS;
+    if (conf != null) {
+      hours = conf.getInt(PROP_KEY_MINIMUM_PERIOD_IN_HOURS, DEFAULT_MINIMUM_PERIOD_IN_HOURS);
+    }
+    return hours;
+  }
+
+  public static void deleteSnapshotsData(DatabaseSession session, List<Integer> snapshotIds) {
+    deleteMeasuresBySnapshotId(session, snapshotIds);
+    deleteSources(session, snapshotIds);
+    deleteViolations(session, snapshotIds);
+    deleteDependencies(session, snapshotIds);
+    deleteSnapshots(session, snapshotIds);
+  }
+
+  public static  void deleteDependencies(DatabaseSession session, List<Integer> snapshotIds) {
+    executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.fromSnapshotId in (:ids)");
+    executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.toSnapshotId in (:ids)");
+  }
+
+  /**
+   * Delete all measures, including MEASURE_DATA
+   */
+  public static  void deleteMeasuresBySnapshotId(DatabaseSession session, List<Integer> snapshotIds) {
+    executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.snapshotId in (:ids)");
+    executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.snapshotId in (:ids)");
+  }
+
+  /**
+   * Delete all measures, including MEASURE_DATA
+   */
+  public static  void deleteMeasuresById(DatabaseSession session, List<Integer> measureIds) {
+    executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.measure.id in (:ids)");
+    executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.id in (:ids)");
+  }
+
+  /**
+   * Delete SNAPSHOT_SOURCES table
+   */
+  public static  void deleteSources(DatabaseSession session, List<Integer> snapshotIds) {
+    executeQuery(session, "delete sources", snapshotIds, "delete from " + SnapshotSource.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+  }
+
+  /**
+   * Delete violations (RULE_FAILURES table)
+   */
+  public static  void deleteViolations(DatabaseSession session, List<Integer> snapshotIds) {
+    executeQuery(session, "delete violations", snapshotIds, "delete from " + RuleFailureModel.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+  }
+
+  /**
+   * Delete SNAPSHOTS table
+   */
+  public static  void deleteSnapshots(DatabaseSession session, List<Integer> snapshotIds) {
+    executeQuery(session, "delete snapshots", snapshotIds, "delete from " + Snapshot.class.getSimpleName() + " s where s.id in (:ids)");
+  }
+
+  /**
+   * Paginate execution of SQL requests to avoid exceeding size of rollback segment
+   */
+  public static  void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) {
+    if (ids == null || ids.isEmpty()) {
+      return;
+    }
+
+    TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description);
+
+    int index = 0;
+    while (index < ids.size()) {
+      Query query = session.createQuery(hql);
+      List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS));
+      query.setParameter("ids", paginedSids);
+      query.executeUpdate();
+      index += MAX_IN_ELEMENTS;
+      session.commit();
+    }
+
+    profiler.stop();
+  }
+
+}
index cc02ae077e0c5ea4f06c7fe5b2bef5096fea7875..43b707bbd675fd2550883a5cf48613f58457015b 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.api.resources.Project;
 import org.sonar.plugins.dbcleaner.api.PeriodCleaner;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.text.DateFormat;
 import java.util.Date;
index 19b9ba349bf58a61a5a428f851f67970cd4ef808..19abce77db5a9fdbed64e656d3587f173fd79ed7 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.commons.configuration.Configuration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.resources.Project;
-import org.sonar.plugins.dbcleaner.util.DbCleanerConstants;
+import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
index b0e3c3991f965619d618aeb0f87db8c4325f2955..4e4708fa564567445af6d6c74821352141f8f12a 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index b3532177878dfb7ffff3cdba1c6e553d987307f3..07f9e81efe87a353de0f20b2269cffae5479a1c0 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.database.model.Snapshot;
 import org.sonar.api.design.DependencyDto;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import javax.persistence.Query;
 import java.util.List;
index a08ba28718c3cfe1d78936ddfd265d1a3bf8ce35..fb4d3782f03cb215fdd0ad4768ed75ff458e6d0f 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 273765095433992da603b0d0e619d099697c3b8b..5ce0448833e501222c2c5784e406323ebb51edd5 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.database.model.Snapshot;
 
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 98415599098250a3ae29bfeaa9d95e3292fad33e..cff889cc37a160d92bde2f8e76c10c72f39e25b7 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.utils.Logs;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import javax.persistence.Query;
 import java.util.Date;
index 28dbc28129391f9a93c4be67846baa47d230f75b..16b01253ae93d9594e71fcb95028c13db412cbd2 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.ResourceModel;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 24bfd0f446704383e5c2c5d09e72a790706bccaa..680faa6633bc50c47eef702f34fee4644e5a4342 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.ResourceModel;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 251e94a2b6b4a31044594dece1d60ff9879f0912..485a036bedd0d5ba6b50771bd0e70c649606a3d8 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.database.model.ResourceModel;
 import org.sonar.api.database.model.User;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 87b3aa123a37a03bfcc950dbeab9c849066fc69b..80f16aadb9bc149501381eec1a1557fe47fb5c20 100644 (file)
@@ -25,7 +25,7 @@ import org.sonar.api.security.GroupRole;
 import org.sonar.api.security.UserRole;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index a67a0903f0785eabeea0fd828908fb51f7b484ed..d61ad8124991854aeaff14e0cd532bcedf7fc4f6 100644 (file)
@@ -24,7 +24,7 @@ import org.sonar.api.database.model.MeasureModel;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
index 4911b3fe45df09fa0bcb8989ae08d80de3deae25..579cadf275dfc80a55019ed19df9a13e000dc129 100644 (file)
@@ -26,7 +26,7 @@ import org.sonar.api.database.model.Snapshot;
 import org.sonar.api.utils.Logs;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import javax.persistence.Query;
 import java.util.Date;
index 0a1f030e466e2411914d3184b8d4b41693093ea6..bb309655a587244f72296b5d06c9333bf6bd6846 100644 (file)
@@ -23,7 +23,7 @@ import org.sonar.api.database.DatabaseSession;
 import org.sonar.api.database.model.Snapshot;
 import org.sonar.plugins.dbcleaner.api.Purge;
 import org.sonar.plugins.dbcleaner.api.PurgeContext;
-import org.sonar.plugins.dbcleaner.util.PurgeUtils;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
 
 import java.util.List;
 
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/DbCleanerConstants.java
deleted file mode 100644 (file)
index 03a2947..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2010 SonarSource
- * 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
- */
-package org.sonar.plugins.dbcleaner.util;
-
-public interface DbCleanerConstants {
-
-  String PLUGIN_KEY = "dbcleaner";
-  String PLUGIN_NAME = "DbCleaner";
-  String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_WEEK = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByWeek";
-  String MONTHS_BEFORE_KEEPING_ONLY_ONE_SNAPSHOT_BY_MONTH = "sonar.dbcleaner.monthsBeforeKeepingOnlyOneSnapshotByMonth";
-  String MONTHS_BEFORE_DELETING_ALL_SNAPSHOTS = "sonar.dbcleaner.monthsBeforeDeletingAllSnapshots";
-  String ONE_MONTH = "1";
-  String ONE_YEAR = "12";
-  String THREE_YEARS = "36";
-}
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/util/PurgeUtils.java
deleted file mode 100644 (file)
index 1fc28b3..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Sonar, open source software quality management 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
- */
-package org.sonar.plugins.dbcleaner.util;
-
-import org.apache.commons.configuration.Configuration;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.*;
-import org.sonar.api.design.DependencyDto;
-import org.sonar.api.utils.TimeProfiler;
-
-import javax.persistence.Query;
-import java.util.List;
-
-/**
- * @since 2.5
- */
-public final class PurgeUtils {
-
-  public static final int DEFAULT_MINIMUM_PERIOD_IN_HOURS = 12;
-  public static final String PROP_KEY_MINIMUM_PERIOD_IN_HOURS = "sonar.purge.minimumPeriodInHours";
-
-  /**
-   * Maximum elements in the SQL statement "IN" due to an Oracle limitation (see error ORA-01795)
-   */
-  public static final int MAX_IN_ELEMENTS = 950;
-
-  private PurgeUtils() {
-    // only static methods
-  }
-
-  public static int getMinimumPeriodInHours(Configuration conf) {
-    int hours = DEFAULT_MINIMUM_PERIOD_IN_HOURS;
-    if (conf != null) {
-      hours = conf.getInt(PROP_KEY_MINIMUM_PERIOD_IN_HOURS, DEFAULT_MINIMUM_PERIOD_IN_HOURS);
-    }
-    return hours;
-  }
-
-  public static void deleteSnapshotsData(DatabaseSession session, List<Integer> snapshotIds) {
-    deleteMeasuresBySnapshotId(session, snapshotIds);
-    deleteSources(session, snapshotIds);
-    deleteViolations(session, snapshotIds);
-    deleteDependencies(session, snapshotIds);
-    deleteSnapshots(session, snapshotIds);
-  }
-
-  public static  void deleteDependencies(DatabaseSession session, List<Integer> snapshotIds) {
-    executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.fromSnapshotId in (:ids)");
-    executeQuery(session, "delete dependencies", snapshotIds, "delete from " + DependencyDto.class.getSimpleName() + " d where d.toSnapshotId in (:ids)");
-  }
-
-  /**
-   * Delete all measures, including MEASURE_DATA
-   */
-  public static  void deleteMeasuresBySnapshotId(DatabaseSession session, List<Integer> snapshotIds) {
-    executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.snapshotId in (:ids)");
-    executeQuery(session, "delete measures by snapshot id", snapshotIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.snapshotId in (:ids)");
-  }
-
-  /**
-   * Delete all measures, including MEASURE_DATA
-   */
-  public static  void deleteMeasuresById(DatabaseSession session, List<Integer> measureIds) {
-    executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureData.class.getSimpleName() + " m where m.measure.id in (:ids)");
-    executeQuery(session, "delete measures by id", measureIds, "delete from " + MeasureModel.class.getSimpleName() + " m where m.id in (:ids)");
-  }
-
-  /**
-   * Delete SNAPSHOT_SOURCES table
-   */
-  public static  void deleteSources(DatabaseSession session, List<Integer> snapshotIds) {
-    executeQuery(session, "delete sources", snapshotIds, "delete from " + SnapshotSource.class.getSimpleName() + " e where e.snapshotId in (:ids)");
-  }
-
-  /**
-   * Delete violations (RULE_FAILURES table)
-   */
-  public static  void deleteViolations(DatabaseSession session, List<Integer> snapshotIds) {
-    executeQuery(session, "delete violations", snapshotIds, "delete from " + RuleFailureModel.class.getSimpleName() + " e where e.snapshotId in (:ids)");
-  }
-
-  /**
-   * Delete SNAPSHOTS table
-   */
-  public static  void deleteSnapshots(DatabaseSession session, List<Integer> snapshotIds) {
-    executeQuery(session, "delete snapshots", snapshotIds, "delete from " + Snapshot.class.getSimpleName() + " s where s.id in (:ids)");
-  }
-
-  /**
-   * Paginate execution of SQL requests to avoid exceeding size of rollback segment
-   */
-  public static  void executeQuery(DatabaseSession session, String description, List<Integer> ids, String hql) {
-    if (ids == null || ids.isEmpty()) {
-      return;
-    }
-
-    TimeProfiler profiler = new TimeProfiler().setLevelToDebug().start("Execute " + description);
-
-    int index = 0;
-    while (index < ids.size()) {
-      Query query = session.createQuery(hql);
-      List<Integer> paginedSids = ids.subList(index, Math.min(ids.size(), index + MAX_IN_ELEMENTS));
-      query.setParameter("ids", paginedSids);
-      query.executeUpdate();
-      index += MAX_IN_ELEMENTS;
-      session.commit();
-    }
-
-    profiler.stop();
-  }
-
-}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java
new file mode 100644 (file)
index 0000000..08bb860
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Sonar, open source software quality management 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
+ */
+package org.sonar.plugins.dbcleaner.api;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+import org.sonar.plugins.dbcleaner.api.PurgeUtils;
+
+import java.sql.SQLException;
+import java.util.Arrays;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PurgeUtilsTest extends AbstractDbUnitTestCase {
+
+  @Test
+  public void shouldReturnDefaultMinimumPeriod() {
+    assertThat(PurgeUtils.getMinimumPeriodInHours(new PropertiesConfiguration()), is(PurgeUtils.DEFAULT_MINIMUM_PERIOD_IN_HOURS));
+  }
+
+  @Test
+  public void shouldReturnMinimumPeriod() {
+    PropertiesConfiguration conf = new PropertiesConfiguration();
+    conf.setProperty(PurgeUtils.PROP_KEY_MINIMUM_PERIOD_IN_HOURS, "9");
+    assertThat(PurgeUtils.getMinimumPeriodInHours(conf), is(9));
+  }
+
+  @Test
+  public void purgeSnapshots() throws SQLException {
+    setupData("purgeSnapshots");
+
+    PurgeUtils.deleteSnapshotsData(getSession(), Arrays.asList(3, 4));
+
+    checkTables("purgeSnapshots", "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "dependencies");
+  }
+}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest.java
deleted file mode 100644 (file)
index 31de15a..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Sonar, open source software quality management 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
- */
-package org.sonar.plugins.dbcleaner.util;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.junit.Test;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import java.sql.SQLException;
-import java.util.Arrays;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-public class PurgeUtilsTest extends AbstractDbUnitTestCase {
-
-  @Test
-  public void shouldReturnDefaultMinimumPeriod() {
-    assertThat(PurgeUtils.getMinimumPeriodInHours(new PropertiesConfiguration()), is(PurgeUtils.DEFAULT_MINIMUM_PERIOD_IN_HOURS));
-  }
-
-  @Test
-  public void shouldReturnMinimumPeriod() {
-    PropertiesConfiguration conf = new PropertiesConfiguration();
-    conf.setProperty(PurgeUtils.PROP_KEY_MINIMUM_PERIOD_IN_HOURS, "9");
-    assertThat(PurgeUtils.getMinimumPeriodInHours(conf), is(9));
-  }
-
-  @Test
-  public void purgeSnapshots() throws SQLException {
-    setupData("purgeSnapshots");
-
-    PurgeUtils.deleteSnapshotsData(getSession(), Arrays.asList(3, 4));
-
-    checkTables("purgeSnapshots", "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "dependencies");
-  }
-}
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
new file mode 100644 (file)
index 0000000..f5039b0
--- /dev/null
@@ -0,0 +1,111 @@
+<dataset>
+  <rules_categories id="1" name="category one" description="[null]"/>
+  <rules id="1" name="foo" rules_category_id="1" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1"
+         plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]" />
+
+  <metrics id="1" name="ncloc" val_type="INT" description="[null]"  domain="[null]"
+           short_name="" qualitative="false" user_managed="false" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="project"
+            root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <!-- package -->
+  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:my.package" name="package"
+            root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <!-- files -->
+  <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class1"
+            name="class" root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <projects long_name="[null]" id="4" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class2"
+            name="class" root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+  <snapshots depth="[null]" id="1" 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="false"
+             path="[null]"/>
+
+  <snapshots depth="[null]" id="2" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="2"
+             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
+             path="[null]"/>
+
+
+  <!--<snapshots depth="[null]" id="3" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"-->
+             <!--project_id="3"-->
+             <!--parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"-->
+             <!--path="[null]"/>-->
+
+  <!--<snapshots depth="[null]" id="4" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"-->
+             <!--project_id="4"-->
+             <!--parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"-->
+             <!--path="[null]"/>-->
+
+
+  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="30" DATA="some sources"/>
+  <!--<SNAPSHOT_SOURCES ID="2" SNAPSHOT_ID="4" DATA="some sources"/>-->
+
+
+  <RULE_FAILURES ID="1" SNAPSHOT_ID="1" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg1" LINE="[null]" COST="[null]"/>
+  <RULE_FAILURES ID="2" SNAPSHOT_ID="2" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg2" LINE="[null]" COST="[null]"/>
+  <!--<RULE_FAILURES ID="3" SNAPSHOT_ID="3" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg3" LINE="[null]" COST="[null]"/>-->
+  <!--<RULE_FAILURES ID="4" SNAPSHOT_ID="4" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg4" LINE="[null]" COST="[null]"/>-->
+
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="1" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="1" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+  <!--<project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"-->
+                    <!--rule_priority="[null]"-->
+                    <!--alert_text="[null]" ID="3" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" RULES_CATEGORY_ID="1"-->
+                    <!--RULE_ID="1"-->
+                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"-->
+                    <!--alert_status="[null]" description="[null]"/>-->
+
+  <!--<project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"-->
+                    <!--rule_priority="[null]"-->
+                    <!--alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"-->
+                    <!--RULE_ID="1"-->
+                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"-->
+                    <!--alert_status="[null]" description="[null]"/>-->
+
+
+  <measure_data id="1" measure_id="1" snapshot_id="1" data="[null]"/>
+  <measure_data id="2" measure_id="2" snapshot_id="2" data="[null]"/>
+  <!--<measure_data id="3" measure_id="3" snapshot_id="3" data="[null]"/>-->
+  <!--<measure_data id="4" measure_id="4" snapshot_id="4" data="[null]"/>-->
+
+  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
+
+  <!--<dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="40" to_snapshot_id="40"-->
+                <!--parent_dependency_id="[null]" project_snapshot_id="1"-->
+                <!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
+
+  <!--<dependencies id="3" from_resource_id="50" from_snapshot_id="50" to_resource_id="3" to_snapshot_id="3"-->
+                <!--parent_dependency_id="[null]" project_snapshot_id="1"-->
+                <!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
+
+</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
new file mode 100644 (file)
index 0000000..93ef910
--- /dev/null
@@ -0,0 +1,111 @@
+<dataset>
+  <rules_categories id="1" name="category one" description="[null]"/>
+  <rules id="1" name="foo" rules_category_id="1" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1"
+         plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/>
+
+  <metrics id="1" name="ncloc" val_type="INT" description="[null]"  domain="[null]"
+           short_name="" qualitative="false" user_managed="false" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
+
+  <!-- project -->
+  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="project"
+            root_id="[null]"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <!-- package -->
+  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:my.package" name="package"
+            root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <!-- files -->
+  <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class1"
+            name="class" root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+  <projects long_name="[null]" id="4" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class2"
+            name="class" root_id="1"
+            description="[null]"
+            enabled="true" language="java" copy_resource_id="[null]"/>
+
+
+  <snapshots depth="[null]" id="1" 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="false"
+             path="[null]"/>
+
+  <snapshots depth="[null]" id="2" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="2"
+             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
+             path="[null]"/>
+
+
+  <snapshots depth="[null]" id="3" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="3"
+             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
+             path="[null]"/>
+
+  <snapshots depth="[null]" id="4" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"
+             project_id="4"
+             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
+             path="[null]"/>
+
+
+  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="30" DATA="some sources"/>
+  <SNAPSHOT_SOURCES ID="2" SNAPSHOT_ID="4" DATA="some sources"/>
+
+
+  <RULE_FAILURES ID="1" SNAPSHOT_ID="1" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg1" LINE="[null]" COST="[null]"/>
+  <RULE_FAILURES ID="2" SNAPSHOT_ID="2" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg2" LINE="[null]" COST="[null]"/>
+  <RULE_FAILURES ID="3" SNAPSHOT_ID="3" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg3" LINE="[null]" COST="[null]"/>
+  <RULE_FAILURES ID="4" SNAPSHOT_ID="4" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg4" LINE="[null]" COST="[null]"/>
+
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="1" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="1" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="3" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
+                    rule_priority="[null]"
+                    alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"
+                    RULE_ID="1"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
+                    alert_status="[null]" description="[null]"/>
+
+
+  <measure_data id="1" measure_id="1" snapshot_id="1" data="[null]"/>
+  <measure_data id="2" measure_id="2" snapshot_id="2" data="[null]"/>
+  <measure_data id="3" measure_id="3" snapshot_id="3" data="[null]"/>
+  <measure_data id="4" measure_id="4" snapshot_id="4" data="[null]"/>
+
+  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
+
+  <dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="40" to_snapshot_id="40"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>
+
+  <dependencies id="3" from_resource_id="50" from_snapshot_id="50" to_resource_id="3" to_snapshot_id="3"
+                parent_dependency_id="[null]" project_snapshot_id="1"
+                dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL" />
+
+</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots-result.xml
deleted file mode 100644 (file)
index f5039b0..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<dataset>
-  <rules_categories id="1" name="category one" description="[null]"/>
-  <rules id="1" name="foo" rules_category_id="1" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1"
-         plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]" />
-
-  <metrics id="1" name="ncloc" val_type="INT" description="[null]"  domain="[null]"
-           short_name="" qualitative="false" user_managed="false" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="project"
-            root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <!-- package -->
-  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:my.package" name="package"
-            root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <!-- files -->
-  <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class1"
-            name="class" root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <projects long_name="[null]" id="4" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class2"
-            name="class" root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-
-  <snapshots depth="[null]" id="1" 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="false"
-             path="[null]"/>
-
-  <snapshots depth="[null]" id="2" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="2"
-             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
-             path="[null]"/>
-
-
-  <!--<snapshots depth="[null]" id="3" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"-->
-             <!--project_id="3"-->
-             <!--parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"-->
-             <!--path="[null]"/>-->
-
-  <!--<snapshots depth="[null]" id="4" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"-->
-             <!--project_id="4"-->
-             <!--parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"-->
-             <!--path="[null]"/>-->
-
-
-  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="30" DATA="some sources"/>
-  <!--<SNAPSHOT_SOURCES ID="2" SNAPSHOT_ID="4" DATA="some sources"/>-->
-
-
-  <RULE_FAILURES ID="1" SNAPSHOT_ID="1" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg1" LINE="[null]" COST="[null]"/>
-  <RULE_FAILURES ID="2" SNAPSHOT_ID="2" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg2" LINE="[null]" COST="[null]"/>
-  <!--<RULE_FAILURES ID="3" SNAPSHOT_ID="3" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg3" LINE="[null]" COST="[null]"/>-->
-  <!--<RULE_FAILURES ID="4" SNAPSHOT_ID="4" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg4" LINE="[null]" COST="[null]"/>-->
-
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="1" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="1" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-  <!--<project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"-->
-                    <!--rule_priority="[null]"-->
-                    <!--alert_text="[null]" ID="3" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" RULES_CATEGORY_ID="1"-->
-                    <!--RULE_ID="1"-->
-                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"-->
-                    <!--alert_status="[null]" description="[null]"/>-->
-
-  <!--<project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"-->
-                    <!--rule_priority="[null]"-->
-                    <!--alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"-->
-                    <!--RULE_ID="1"-->
-                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"-->
-                    <!--alert_status="[null]" description="[null]"/>-->
-
-
-  <measure_data id="1" measure_id="1" snapshot_id="1" data="[null]"/>
-  <measure_data id="2" measure_id="2" snapshot_id="2" data="[null]"/>
-  <!--<measure_data id="3" measure_id="3" snapshot_id="3" data="[null]"/>-->
-  <!--<measure_data id="4" measure_id="4" snapshot_id="4" data="[null]"/>-->
-
-  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
-                parent_dependency_id="[null]" project_snapshot_id="1"
-                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
-
-  <!--<dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="40" to_snapshot_id="40"-->
-                <!--parent_dependency_id="[null]" project_snapshot_id="1"-->
-                <!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
-
-  <!--<dependencies id="3" from_resource_id="50" from_snapshot_id="50" to_resource_id="3" to_snapshot_id="3"-->
-                <!--parent_dependency_id="[null]" project_snapshot_id="1"-->
-                <!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
-
-</dataset>
\ No newline at end of file
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/util/PurgeUtilsTest/purgeSnapshots.xml
deleted file mode 100644 (file)
index 93ef910..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<dataset>
-  <rules_categories id="1" name="category one" description="[null]"/>
-  <rules id="1" name="foo" rules_category_id="1" plugin_config_key="checker/foo" plugin_rule_key="checkstyle.rule1"
-         plugin_name="maven-checkstyle-plugin" description="description" cardinality="SINGLE" parent_id="[null]"/>
-
-  <metrics id="1" name="ncloc" val_type="INT" description="[null]"  domain="[null]"
-           short_name="" qualitative="false" user_managed="false" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-
-  <!-- project -->
-  <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="project"
-            root_id="[null]"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <!-- package -->
-  <projects long_name="[null]" id="2" scope="DIR" qualifier="PAC" kee="mygroup:myartifact:my.package" name="package"
-            root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <!-- files -->
-  <projects long_name="[null]" id="3" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class1"
-            name="class" root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-  <projects long_name="[null]" id="4" scope="FIL" qualifier="CLA" kee="mygroup:myartifact:my.package.Class2"
-            name="class" root_id="1"
-            description="[null]"
-            enabled="true" language="java" copy_resource_id="[null]"/>
-
-
-  <snapshots depth="[null]" id="1" 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="false"
-             path="[null]"/>
-
-  <snapshots depth="[null]" id="2" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="2"
-             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
-             path="[null]"/>
-
-
-  <snapshots depth="[null]" id="3" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="3"
-             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
-             path="[null]"/>
-
-  <snapshots depth="[null]" id="4" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" version="[null]"
-             project_id="4"
-             parent_snapshot_id="2" root_project_id="[null]" root_snapshot_id="1" status="P" islast="false"
-             path="[null]"/>
-
-
-  <SNAPSHOT_SOURCES ID="1" SNAPSHOT_ID="30" DATA="some sources"/>
-  <SNAPSHOT_SOURCES ID="2" SNAPSHOT_ID="4" DATA="some sources"/>
-
-
-  <RULE_FAILURES ID="1" SNAPSHOT_ID="1" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg1" LINE="[null]" COST="[null]"/>
-  <RULE_FAILURES ID="2" SNAPSHOT_ID="2" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg2" LINE="[null]" COST="[null]"/>
-  <RULE_FAILURES ID="3" SNAPSHOT_ID="3" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg3" LINE="[null]" COST="[null]"/>
-  <RULE_FAILURES ID="4" SNAPSHOT_ID="4" RULE_ID="1" FAILURE_LEVEL="2" MESSAGE="msg4" LINE="[null]" COST="[null]"/>
-
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="1" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="1" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="2" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="2" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="3" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="3" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-  <project_measures characteristic_id="[null]" url="[null]" diff_value_1="[null]" diff_value_2="[null]" diff_value_3="[null]"
-                    rule_priority="[null]"
-                    alert_text="[null]" ID="4" VALUE="10.0" METRIC_ID="1" SNAPSHOT_ID="4" RULES_CATEGORY_ID="1"
-                    RULE_ID="1"
-                    text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]"
-                    alert_status="[null]" description="[null]"/>
-
-
-  <measure_data id="1" measure_id="1" snapshot_id="1" data="[null]"/>
-  <measure_data id="2" measure_id="2" snapshot_id="2" data="[null]"/>
-  <measure_data id="3" measure_id="3" snapshot_id="3" data="[null]"/>
-  <measure_data id="4" measure_id="4" snapshot_id="4" data="[null]"/>
-
-  <dependencies id="1" from_resource_id="1" from_snapshot_id="1" to_resource_id="30" to_snapshot_id="30"
-                parent_dependency_id="[null]" project_snapshot_id="1"
-                dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/>
-
-  <dependencies id="2" from_resource_id="3" from_snapshot_id="3" to_resource_id="40" to_snapshot_id="40"
-                parent_dependency_id="[null]" project_snapshot_id="1"
-                dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>
-
-  <dependencies id="3" from_resource_id="50" from_snapshot_id="50" to_resource_id="3" to_snapshot_id="3"
-                parent_dependency_id="[null]" project_snapshot_id="1"
-                dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL" />
-
-</dataset>
\ No newline at end of file