]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2061 add the flag Metric#deleteHistoricalData. Default value is false.
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 25 Jan 2012 18:26:18 +0000 (19:26 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 25 Jan 2012 18:26:52 +0000 (19:26 +0100)
* New column METRICS.DELETE_HISTORICAL_DATA (boolean, nullable)
* Hidden core metrics and some data metrics have this new field to true

41 files changed:
plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/sensors/ManualMeasureDecoratorTest/testCopyManualMeasures.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeletedResourcesTest/sharedFixture.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDeprecatedLastTest/sharedFixture.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeDisabledResourcesTest/sharedFixture.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeEntitiesTest/sharedFixture.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeRuleMeasuresTest/sharedFixture.xml
plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/purges/PurgeUnprocessedTest/sharedFixture.xml
sonar-batch/src/test/resources/org/sonar/batch/DefaultTimeMachineTest/loadMeasuresFromDate.xml
sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shared.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldDelaySaving-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldInsertMeasure-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldNotDelaySavingWithDatabaseOnlyMeasure-result.xml
sonar-batch/src/test/resources/org/sonar/batch/index/MeasurePersisterTest/shouldUpdateMeasure-result.xml
sonar-batch/src/test/resources/org/sonar/batch/phases/UpdateStatusJobTest/sharedFixture.xml
sonar-core/src/main/java/org/sonar/core/purge/PurgeDao.java
sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java
sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-derby.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-derby.ddl
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/test/java/org/sonar/core/purge/PurgeDaoTest.java
sonar-core/src/test/resources/org/sonar/core/metric/CacheMetricFinderTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/metric/DefaultMetricFinderTest/shared.xml
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml [new file with mode: 0644]
sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml [new file with mode: 0644]
sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java
sonar-server/src/main/webapp/WEB-INF/db/migrate/254_add_metrics_delete_historical_data.rb [new file with mode: 0644]
sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/measures.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/cleanAlerts-result.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/cleanAlerts.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/enableOnlyLoadedMetrics.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/shouldSaveIfNew-result.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/shouldSaveIfNew.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/shouldUpdateIfAlreadyExists-result.xml
sonar-server/src/test/resources/org/sonar/server/startup/RegisterMetricsTest/shouldUpdateIfAlreadyExists.xml

index a75e62fedc299dcd5b3dd5572ae80099424230b4..0307f16e6e30c32c07ca4d4d58d5ca4cdae7d00b 100644 (file)
@@ -1,7 +1,7 @@
 <dataset>
-  <metrics id="1" NAME="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" NAME="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-  <metrics id="2" NAME="review_note" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" NAME="review_note" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
 
index e0b28e724749644e04070351ee47af3cafac0373..160173688ec9f8f4d896fcd18439cae60e920da7 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index 9b0006441a3b1da03ec4da4d9cdaa2081ec00359..dc7938cdd531fc1ddaa0419ddbc563f350e7a518 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index d2031ec398fa79cd340077822f824df66f30badc..a1dca62ac81713851d1a3b06b9c74f6bf77ef2ee 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index d2031ec398fa79cd340077822f824df66f30badc..a1dca62ac81713851d1a3b06b9c74f6bf77ef2ee 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index 6ee23b4208315ade44861318c61a1320ddc8ebc1..289878079160fe7a6d6a30614a912e52dd84863c 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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"/>
 
 </dataset>
\ No newline at end of file
index d2031ec398fa79cd340077822f824df66f30badc..a1dca62ac81713851d1a3b06b9c74f6bf77ef2ee 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index 46b5a77133bf01291c43c87b926a6873d2e33323..3c151749b7984e53a702c5a060fa1daae43bd20c 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index d2031ec398fa79cd340077822f824df66f30badc..a1dca62ac81713851d1a3b06b9c74f6bf77ef2ee 100644 (file)
@@ -3,7 +3,7 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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 -->
index 1ffa6e4da22789caf9b55b207523f0e35c63364f..5d94c817fd01b49b09b188aa5e31114c2ed178e8 100644 (file)
@@ -1,7 +1,7 @@
 <dataset>
-  <metrics id="1" NAME="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" NAME="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-  <metrics id="2" NAME="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" NAME="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
   <projects long_name="[null]" id="1" scope="PRJ" kee="group:artifact" qualifier="TRK" name="my project"
index 6288eba680bafbceaa95886c3ede0fe2a207f5f9..77e98e8ffb6226a0b4c6a9b0266849576f64ebc4 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
 
index 7b71eafa78bd5759a882e12f305e6f335786368b..31ad2b24475d2384dcad4f2de9298677fa677c51 100644 (file)
@@ -1,8 +1,8 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
   <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
index 839631af64ca090838554f2eb326d5998b877ff1..68186ddd9182d9cb27cfe73bfb3bb5c51d552c18 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0"
            hidden="false"/>
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
   <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
index 72b30a69eedfcd9dfc5049a36e79683c99f1cfc9..c9ebfefebf6ecad588181157f17e871a7aa1e276 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
   <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
index 7b71a86ed0538b0dee4bd422a539e394ea07426e..0f12743ae7d39523490eedca8194ddf03a4d254b 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
   <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
index d4311e4484aff8e98d829f0354d0b6c50b22d66e..00a8539678dc25ed317ccc51d5e198c60ad1e818 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0" hidden="false"/>
 
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]"  domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
   
   <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
index 262433c5fc57371e976bc659fd27c1353b9d6aa0..9bb3df9ceed8bac4fa0ddfdabe4ffaffd5a96778 100644 (file)
@@ -3,13 +3,13 @@
   <rules id="1" name="foo" 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]"
+  <metrics delete_historical_data="[null]" 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"/>
-  <metrics id="2" name="foo" val_type="INT" description="[null]"  domain="[null]"
+  <metrics delete_historical_data="[null]" id="2" name="foo" 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"/>
-  <metrics id="3" name="bar" val_type="INT" description="[null]"  domain="[null]"
+  <metrics delete_historical_data="[null]" id="3" name="bar" 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"/>
-  <metrics id="4" name="baz" val_type="INT" description="[null]"  domain="[null]"
+  <metrics delete_historical_data="[null]" id="4" name="baz" 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"/>
 
   <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="mygroup:myartifact" name="[null]"
index fc8ff41e8163664f050b8a28844b19ff3e7d5dd6..8bbe33b44b8e94581125c86efcbe0f1ddcff7ef1 100644 (file)
@@ -67,6 +67,7 @@ public class PurgeDao {
           purgeSnapshot(snapshotId, purgeMapper);
         }
       });
+
       // must be executed at the end for reentrance
       purgeSnapshot(projectSnapshotId, purgeMapper);
     }
@@ -159,11 +160,9 @@ public class PurgeDao {
     mapper.deleteSnapshotDuplications(snapshotId);
     mapper.deleteSnapshotSource(snapshotId);
     mapper.deleteSnapshotViolations(snapshotId);
-    mapper.deleteSnapshotRuleMeasures(snapshotId);
-    mapper.deleteSnapshotCharacteristicMeasures(snapshotId);
-    // TODO SONAR-2061 delete wasted measures (!metric.keepHistory)
+    mapper.deleteSnapshotWastedMeasures(snapshotId);
     mapper.updatePurgeStatusToOne(snapshotId);
-    return 8; // nb of SQL requests
+    return 7; // nb of SQL requests
   }
 
   @VisibleForTesting
index 65536f6acc13f86549e4772f40a21d37524ae20d..38cccfe0e60650d95730cf5c23e2490018663e20 100644 (file)
@@ -41,9 +41,7 @@ public interface PurgeMapper {
 
   void deleteSnapshotViolations(long snapshotId);
 
-  void deleteSnapshotRuleMeasures(long snapshotId);
-
-  void deleteSnapshotCharacteristicMeasures(long snapshotId);
+  void deleteSnapshotWastedMeasures(long snapshotId);
 
   void updatePurgeStatusToOne(long snapshotId);
 
index a6e8c7653e09c021109759563fc79788ad5c5e7a..4481fef39a76fb5d326d1e61df5b26b2dd983ff2 100644 (file)
@@ -34,7 +34,7 @@ public class SchemaMigration {
 
   public final static int VERSION_UNKNOWN = -1;
 
-  public static final int LAST_VERSION = 253;
+  public static final int LAST_VERSION = 254;
   public static final int VERSION_2_13 = 241;
 
   public final static String TABLE_NAME = "schema_migrations";
index 6b842872b00e9135e25d534fa77c2a5d55f6e416..fd4626b92678138c3c88accb81f8f71d614ab950 100644 (file)
@@ -172,6 +172,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('250');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('251');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('252');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('253');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('254');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 81491225d86cab1e57489e071a3d7af6a9179cb7..1dcd74b9e03dac05adc17b9294adc7bafa1eeb1e 100644 (file)
@@ -450,7 +450,8 @@ CREATE TABLE "METRICS" (
   "WORST_VALUE" DECIMAL(30,20),
   "BEST_VALUE" DECIMAL(30,20),
   "OPTIMIZED_BEST_VALUE" BOOLEAN,
-  "HIDDEN" BOOLEAN
+  "HIDDEN" BOOLEAN,
+  "DELETE_HISTORICAL_DATA" BOOLEAN
 );
 
 CREATE TABLE "LOADED_TEMPLATES" (
index 44eaed90b4377b9f375b83bc710da35cd32879a2..3f942d66c6bbd79c8823b255ae3e4392e9f3cb55 100644 (file)
     delete from snapshots where id=#{id}
   </delete>
 
-  <delete id="deleteSnapshotRuleMeasures" parameterType="long">
-    delete from project_measures where snapshot_id=#{id} and rule_id is not null
-  </delete>
-
-  <delete id="deleteSnapshotCharacteristicMeasures" parameterType="long">
-    delete from project_measures where snapshot_id=#{id} and characteristic_id is not null
+  <delete id="deleteSnapshotWastedMeasures" parameterType="long">
+    delete from project_measures where snapshot_id=#{id} and
+    (characteristic_id is not null or rule_id is not null or metric_id in (select id from metrics where delete_historical_data=${_true}))
   </delete>
 
   <update id="updatePurgeStatusToOne" parameterType="long">
index 88f56b9e08373c6abf6c9672f8361f4c30af7158..b6644f9b275404dd6638c846a9fa9c26d7ca05d7 100644 (file)
@@ -58,7 +58,6 @@ public class PurgeDaoTest extends DaoTestCase {
   /**
    * Test that all related data is purged.
    */
-
   @Test
   public void shouldPurgeSnapshot() {
     setupData("shouldPurgeSnapshot");
@@ -76,6 +75,39 @@ public class PurgeDaoTest extends DaoTestCase {
       "snapshots", "project_measures", "measure_data", "rule_failures", "snapshot_sources", "duplications_index", "events", "dependencies", "reviews");
   }
 
+  @Test
+    public void shouldDeleteWastedMeasuresWhenPurgingSnapshot() {
+      setupData("shouldDeleteWastedMeasuresWhenPurgingSnapshot");
+
+      SqlSession session = getMyBatis().openSession();
+      try {
+        // this method does not commit and close the session
+        dao.purgeSnapshot(1L, session.getMapper(PurgeMapper.class));
+        session.commit();
+
+      } finally {
+        MyBatis.closeQuietly(session);
+      }
+      checkTables("shouldDeleteWastedMeasuresWhenPurgingSnapshot", "project_measures");
+    }
+
+  @Test
+  public void shouldCloseReviewWhenDisablingResource() {
+    setupData("shouldCloseReviewWhenDisablingResource");
+
+    SqlSession session = getMyBatis().openSession();
+    try {
+      // this method does not commit and close the session
+      dao.disableResource(1L, session.getMapper(PurgeMapper.class));
+      session.commit();
+
+    } finally {
+      MyBatis.closeQuietly(session);
+    }
+    checkTables("shouldCloseReviewWhenDisablingResource", /* excluded column */new String[]{"updated_at"}, "reviews");
+  }
+
+
   @Test
   public void shouldPurgeProject() {
     setupData("shouldPurgeProject");
index 85709bcbf9805bba22dba534d5fa3b37edbc960c..dd645d66ec1943279e775fb1254f165b8511e984 100644 (file)
@@ -1,12 +1,12 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0"
            hidden="false"/>
 
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
-  <metrics id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="false" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 </dataset>
\ No newline at end of file
index 85709bcbf9805bba22dba534d5fa3b37edbc960c..dd645d66ec1943279e775fb1254f165b8511e984 100644 (file)
@@ -1,12 +1,12 @@
 <dataset>
 
-  <metrics id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="1" name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="0"
            hidden="false"/>
 
-  <metrics id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="2" name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="true" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 
-  <metrics id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
+  <metrics delete_historical_data="[null]" id="3" name="disabled" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name=""
            enabled="false" worst_value="0" optimized_best_value="true" best_value="100" direction="1" hidden="false"/>
 </dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource-result.xml
new file mode 100644 (file)
index 0000000..562d194
--- /dev/null
@@ -0,0 +1,15 @@
+<!--
+
+Changes:
+* review.status=CLOSED
+
+Note that the column updated_at has been removed because it's excluded from DBUnit comparison.
+-->
+
+<dataset>
+
+  <reviews id="1" project_id="1" resource_id="1" status="CLOSED"
+        rule_failure_permanent_id="1" resolution="[null]" created_at="[null]" resource_line="200" severity="BLOCKER"
+        user_id="300" assignee_id="300" rule_id="500" manual_violation="[true]" manual_severity="[false]" title="[null]"/>
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldCloseReviewWhenDisablingResource.xml
new file mode 100644 (file)
index 0000000..6f6ca9c
--- /dev/null
@@ -0,0 +1,16 @@
+<dataset>
+
+  <snapshots id="1"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="true" purge_status="[null]"
+             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]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
+
+  <reviews id="1" project_id="1" resource_id="1" status="OPEN"
+        rule_failure_permanent_id="1" resolution="[null]" created_at="[null]" updated_at="[null]" resource_line="200" severity="BLOCKER"
+        user_id="300" assignee_id="300" rule_id="500" manual_violation="[true]" manual_severity="[false]" title="[null]"/>
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot-result.xml
new file mode 100644 (file)
index 0000000..fd36604
--- /dev/null
@@ -0,0 +1,44 @@
+<dataset>
+
+  <metrics id="1" delete_historical_data="[null]"
+           name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]"
+           direction="0" hidden="false"/>
+
+  <metrics id="2" delete_historical_data="true"
+           name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100"
+           direction="1" hidden="false"/>
+
+  <snapshots id="1"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="true" purge_status="[null]"
+             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]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
+
+  <!-- do not delete standard measure -->
+  <project_measures ID="1" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="1"
+                    url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
+                    variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>
+
+  <!-- delete measure on rule -->
+  <!--<project_measures ID="2" project_id="1" SNAPSHOT_ID="1" RULE_ID="33" characteristic_id="[null]" METRIC_ID="1" -->
+                    <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"-->
+                    <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"-->
+                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>-->
+
+  <!-- delete measure on quality model characteristic -->
+  <!--<project_measures ID="3" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="22" METRIC_ID="1" -->
+                    <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"-->
+                    <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"-->
+                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>-->
+
+  <!-- delete measure on metrics that are flagged with delete_historical_data=true -->
+  <!--<project_measures ID="4" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="2"-->
+                    <!--url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"-->
+                    <!--variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"-->
+                    <!--text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>-->
+</dataset>
\ No newline at end of file
diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteWastedMeasuresWhenPurgingSnapshot.xml
new file mode 100644 (file)
index 0000000..17db23c
--- /dev/null
@@ -0,0 +1,44 @@
+<dataset>
+
+  <metrics id="1" delete_historical_data="[null]"
+           name="ncloc" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="[null]" optimized_best_value="[null]" best_value="[null]"
+           direction="0" hidden="false"/>
+
+  <metrics id="2" delete_historical_data="true"
+           name="coverage" VAL_TYPE="INT" DESCRIPTION="[null]" domain="[null]" short_name="" enabled="true" worst_value="0" optimized_best_value="true" best_value="100"
+           direction="1" hidden="false"/>
+
+  <snapshots id="1"
+             project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+             status="P" islast="true" purge_status="[null]"
+             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]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" version="[null]" path="[null]"/>
+
+  <!-- do not delete standard measure -->
+  <project_measures ID="1" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="1"
+                    url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
+                    variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>
+
+  <!-- delete measure on rule -->
+  <project_measures ID="2" project_id="1" SNAPSHOT_ID="1" RULE_ID="33" characteristic_id="[null]" METRIC_ID="1"
+                    url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
+                    variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>
+
+  <!-- delete measure on quality model characteristic -->
+  <project_measures ID="3" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="22" METRIC_ID="1"
+                    url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
+                    variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>
+
+  <!-- delete measure on metrics that are flagged with delete_historical_data=true -->
+  <project_measures ID="4" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="2"
+                    url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]" variation_value_4="[null]"
+                    variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0" rules_category_id="[null]"
+                    text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]" description="[null]"/>
+</dataset>
\ No newline at end of file
index 0a16d6ac77762b89581f2d314c73658b41863de8..33f91b7db5fe2d76d6a8eabcde3acc999aab0c66 100644 (file)
@@ -443,6 +443,7 @@ public final class CoreMetrics {
       .setDomain(DOMAIN_TESTS)
       .setFormula(new SumChildValuesFormula(false))
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String NEW_LINES_TO_COVER_KEY = "new_lines_to_cover";
@@ -503,6 +504,7 @@ public final class CoreMetrics {
    */
   public static final Metric COVERAGE_LINE_HITS_DATA = new Metric.Builder(COVERAGE_LINE_HITS_DATA_KEY, "Coverage hits by line", Metric.ValueType.DATA)
       .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String CONDITIONS_TO_COVER_KEY = "conditions_to_cover";
@@ -515,6 +517,7 @@ public final class CoreMetrics {
       .setDomain(DOMAIN_TESTS)
       .setFormula(new SumChildValuesFormula(false))
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String NEW_CONDITIONS_TO_COVER_KEY = "new_conditions_to_cover";
@@ -578,6 +581,7 @@ public final class CoreMetrics {
   @Deprecated
   public static final Metric BRANCH_COVERAGE_HITS_DATA = new Metric.Builder(BRANCH_COVERAGE_HITS_DATA_KEY, "Branch coverage hits", Metric.ValueType.DATA)
       .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String CONDITIONS_BY_LINE_KEY = "conditions_by_line";
@@ -589,6 +593,7 @@ public final class CoreMetrics {
    */
   public static final Metric CONDITIONS_BY_LINE = new Metric.Builder(CONDITIONS_BY_LINE_KEY, "Conditions by line", Metric.ValueType.DATA)
       .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String COVERED_CONDITIONS_BY_LINE_KEY = "covered_conditions_by_line";
@@ -600,6 +605,7 @@ public final class CoreMetrics {
    */
   public static final Metric COVERED_CONDITIONS_BY_LINE = new Metric.Builder(COVERED_CONDITIONS_BY_LINE_KEY, "Covered conditions by line", Metric.ValueType.DATA)
       .setDomain(DOMAIN_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
 
@@ -658,6 +664,7 @@ public final class CoreMetrics {
       .setQualitative(false)
       .setFormula(new SumChildValuesFormula(false))
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   /**
@@ -753,6 +760,7 @@ public final class CoreMetrics {
       .setDirection(Metric.DIRECTION_NONE)
       .setQualitative(false)
       .setDomain(DOMAIN_INTEGRATION_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
   /**
@@ -770,6 +778,7 @@ public final class CoreMetrics {
       .setDomain(DOMAIN_INTEGRATION_TESTS)
       .setFormula(new SumChildValuesFormula(false))
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   /**
@@ -861,6 +870,7 @@ public final class CoreMetrics {
    */
   public static final Metric IT_CONDITIONS_BY_LINE = new Metric.Builder(IT_CONDITIONS_BY_LINE_KEY, "IT Branches by Line", Metric.ValueType.DATA)
       .setDomain(DOMAIN_INTEGRATION_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
   /**
@@ -873,6 +883,7 @@ public final class CoreMetrics {
    */
   public static final Metric IT_COVERED_CONDITIONS_BY_LINE = new Metric.Builder(IT_COVERED_CONDITIONS_BY_LINE_KEY, "IT Covered Branches by Line", Metric.ValueType.DATA)
       .setDomain(DOMAIN_INTEGRATION_TESTS)
+      .setDeleteHistoricalData(true)
       .create();
 
 
@@ -929,6 +940,7 @@ public final class CoreMetrics {
       .setDirection(Metric.DIRECTION_NONE)
       .setQualitative(false)
       .setDomain(DOMAIN_DUPLICATION)
+      .setDeleteHistoricalData(true)
       .create();
 
 
@@ -1226,6 +1238,7 @@ public final class CoreMetrics {
       .setQualitative(false)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String LCOM4_DISTRIBUTION_KEY = "lcom4_distribution";
@@ -1267,6 +1280,7 @@ public final class CoreMetrics {
       .setDirection(Metric.DIRECTION_NONE)
       .setQualitative(false)
       .setDomain(DOMAIN_DESIGN)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String PACKAGE_CYCLES_KEY = "package_cycles";
@@ -1312,6 +1326,7 @@ public final class CoreMetrics {
       .setDomain(DOMAIN_DESIGN)
       .setFormula(new SumChildValuesFormula(false))
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String FILE_CYCLES_KEY = "file_cycles";
@@ -1321,6 +1336,7 @@ public final class CoreMetrics {
       .setQualitative(true)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String FILE_TANGLE_INDEX_KEY = "file_tangle_index";
@@ -1330,6 +1346,7 @@ public final class CoreMetrics {
       .setQualitative(true)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String FILE_TANGLES_KEY = "file_tangles";
@@ -1339,6 +1356,7 @@ public final class CoreMetrics {
       .setQualitative(false)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String FILE_FEEDBACK_EDGES_KEY = "file_feedback_edges";
@@ -1348,6 +1366,7 @@ public final class CoreMetrics {
       .setQualitative(false)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
   public static final String FILE_EDGES_WEIGHT_KEY = "file_edges_weight";
@@ -1357,6 +1376,7 @@ public final class CoreMetrics {
       .setQualitative(false)
       .setDomain(DOMAIN_DESIGN)
       .setHidden(true)
+      .setDeleteHistoricalData(true)
       .create();
 
 
index cca4f784cc2e2d282de7580bdac2b9b0788fcaa6..5929aa25d8a4cc3d2d3e7de8014027c45e85950c 100644 (file)
@@ -121,6 +121,29 @@ public class Metric implements ServerExtension, BatchExtension {
   @Column(name = "hidden", updatable = true, nullable = true)
   private Boolean hidden = Boolean.FALSE;
 
+  @Column(name = "delete_historical_data", updatable = true, nullable = true)
+  private Boolean deleteHistoricalData;
+
+  private Metric(Builder builder) {
+    this.key = builder.key;
+    this.name = builder.name;
+    this.description = builder.description;
+    this.type = builder.type;
+    this.direction = builder.direction;
+    this.domain = builder.domain;
+    this.qualitative = builder.qualitative;
+    this.userManaged = Boolean.FALSE;
+    this.enabled = Boolean.TRUE;
+    this.worstValue = builder.worstValue;
+    this.optimizedBestValue = builder.optimizedBestValue;
+    this.bestValue = builder.bestValue;
+    this.hidden = builder.hidden;
+    this.formula = builder.formula;
+    this.userManaged = builder.userManaged;
+    this.deleteHistoricalData = builder.deleteHistoricalData;
+  }
+
+
   /**
    * Creates an empty metric
    *
@@ -230,25 +253,6 @@ public class Metric implements ServerExtension, BatchExtension {
     }
   }
 
-  private Metric(String key, String name, ValueType type, String description, Integer direction, String domain, Boolean qualitative, Double worstValue, Double bestValue,
-                 Boolean optimizedBestValue, Boolean hidden, Formula formula, boolean userManaged) {
-    this.key = key;
-    this.name = name;
-    this.description = description;
-    this.type = type;
-    this.direction = direction;
-    this.domain = domain;
-    this.qualitative = qualitative;
-    this.userManaged = Boolean.FALSE;
-    this.enabled = Boolean.TRUE;
-    this.worstValue = worstValue;
-    this.optimizedBestValue = optimizedBestValue;
-    this.bestValue = bestValue;
-    this.hidden = hidden;
-    this.formula = formula;
-    this.userManaged = userManaged;
-  }
-
   /**
    * For internal use only
    */
@@ -491,11 +495,11 @@ public class Metric implements ServerExtension, BatchExtension {
    */
   public boolean isNumericType() {
     return ValueType.INT.equals(type)
-        || ValueType.FLOAT.equals(type)
-        || ValueType.PERCENT.equals(type)
-        || ValueType.BOOL.equals(type)
-        || ValueType.MILLISEC.equals(type)
-        || ValueType.RATING.equals(type);
+      || ValueType.FLOAT.equals(type)
+      || ValueType.PERCENT.equals(type)
+      || ValueType.BOOL.equals(type)
+      || ValueType.MILLISEC.equals(type)
+      || ValueType.RATING.equals(type);
   }
 
   /**
@@ -530,6 +534,15 @@ public class Metric implements ServerExtension, BatchExtension {
     return this;
   }
 
+  public Boolean getDeleteHistoricalData() {
+    return deleteHistoricalData;
+  }
+
+  private Metric setDeleteHistoricalData(Boolean b) {
+    this.deleteHistoricalData = b;
+    return this;
+  }
+
   @Override
   public int hashCode() {
     return key.hashCode();
@@ -572,6 +585,7 @@ public class Metric implements ServerExtension, BatchExtension {
     this.userManaged = with.userManaged;
     this.origin = with.origin;
     this.hidden = with.hidden;
+    this.deleteHistoricalData = with.deleteHistoricalData;
     return this;
   }
 
@@ -592,6 +606,7 @@ public class Metric implements ServerExtension, BatchExtension {
     private boolean optimizedBestValue = false;
     private boolean hidden = false;
     private boolean userManaged = false;
+    private boolean deleteHistoricalData = false;
 
     /**
      * @param key  the metric key, should be unique among all metrics
@@ -702,12 +717,27 @@ public class Metric implements ServerExtension, BatchExtension {
       return this;
     }
 
+
+    public boolean isDeleteHistoricalData() {
+      return deleteHistoricalData;
+    }
+
+    /**
+     * By default, historical data are kept, but they can be automatically deleted to minimize database volume.
+     *
+     * @since 2.14
+     */
+    public Builder setDeleteHistoricalData(boolean b) {
+      this.deleteHistoricalData = b;
+      return this;
+    }
+
     public Metric create() {
       if (ValueType.PERCENT.equals(this.type)) {
         this.bestValue = (direction == DIRECTION_BETTER ? 100.0 : 0.0);
         this.worstValue = (direction == DIRECTION_BETTER ? 0.0 : 100.0);
       }
-      return new Metric(key, name, type, description, direction, domain, qualitative, worstValue, bestValue, optimizedBestValue, hidden, formula, userManaged);
+      return new Metric(this);
     }
   }
 }
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/254_add_metrics_delete_historical_data.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/254_add_metrics_delete_historical_data.rb
new file mode 100644 (file)
index 0000000..41d8f66
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# Sonar, entreprise quality control tool.
+# Copyright (C) 2008-2012 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
+#
+
+#
+# Sonar 2.14
+#
+class AddMetricsDeleteHistoricalData < ActiveRecord::Migration
+
+  def self.up
+    add_column 'metrics', 'delete_historical_data', :boolean, :null => true
+    Metric.reset_column_information
+  end
+
+end
index ec617317db1b95ed5d8dadffe653c6b89bece3e9..bdc9bb389b9752a28ed76d3495192f6960e26480 100644 (file)
@@ -1,13 +1,13 @@
 <dataset>
-  <metrics id="1" name="lines" val_type="FLOAT" description="Lines"  domain="Size"
+  <metrics delete_historical_data="[null]" id="1" name="lines" val_type="FLOAT" description="Lines"  domain="Size"
            short_name="Lines"   qualitative="false"  user_managed="false" enabled="true" origin="JAV" worst_value="[null]"
            optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
-  <metrics id="2" name="coverage" val_type="PERCENT" description="Coverage"  domain="Tests"
+  <metrics delete_historical_data="[null]" id="2" name="coverage" val_type="PERCENT" description="Coverage"  domain="Tests"
            short_name="Coverage"   qualitative="true"  user_managed="false" enabled="true" origin="JAV" worst_value="[null]"
            optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
-  <metrics id="3" name="duplicated_lines" val_type="INT" description="Duplicated lines"  domain="Duplications"
+  <metrics delete_historical_data="[null]" id="3" name="duplicated_lines" val_type="INT" description="Duplicated lines"  domain="Duplications"
            short_name="Duplications"   qualitative="false"  user_managed="false" enabled="true" origin="JAV" worst_value="[null]"
            optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
index a17525b594e7a168e2287c64374a75ab546b7b4f..abb38157dc4b6e1dd132dc0c565b7ac2efae6698 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="key1" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="1" name="key1" val_type="INT" description="description"  domain="domain"
            short_name="name1" qualitative="false" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false" />
 
-  <metrics id="2" name="disabledkey2" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="2" name="disabledkey2" val_type="INT" description="description"  domain="domain"
            short_name="name2" qualitative="false" user_managed="false" enabled="false" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
   <rules_profiles id="1" version="1" used_profile="true" name="profile1" default_profile="true" provided="true" language="JAV" enabled="true"/>
index 9dc524b15d30d03bdfe45adc177cafc756aaeead..aeeb3db7a57ce13aa93221d2392b953843d2bc35 100644 (file)
@@ -1,9 +1,9 @@
 <dataset>
 
-  <metrics id="1" name="key1" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="1" name="key1" val_type="INT" description="description"  domain="domain"
            short_name="name1" qualitative="false" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
-  <metrics id="2" name="disabledkey2" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="2" name="disabledkey2" val_type="INT" description="description"  domain="domain"
            short_name="name2" qualitative="false" user_managed="false" enabled="false" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
 
index 1e751efcc3f72711441bebdb794c0bf200fdf4d1..dc46fbcbd8697b187da7143b160c6b0ac039d29c 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <metrics id="1" name="deprecated" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="1" name="deprecated" val_type="INT" description="description"  domain="domain"
            short_name="short name"  qualitative="false" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
 </dataset>
\ No newline at end of file
index bbc756e9ec53563d3609dda4822d37af9976408b..a43601c64b601ce4e8db8147dddbfda06e8a9407 100644 (file)
@@ -1,12 +1,12 @@
 <dataset>
 
-  <metrics id="1" name="key1" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="1" name="key1" val_type="INT" description="description"  domain="domain"
            short_name="short name"  qualitative="false" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
   <!--New metrics -->
-  <metrics id="2" name="new1" val_type="FLOAT" description="desc1"  domain="domain1"
+  <metrics delete_historical_data="[null]" id="2" name="new1" val_type="FLOAT" description="desc1"  domain="domain1"
            short_name="short1"  qualitative="true"  user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
-  <metrics id="3" name="new2" val_type="FLOAT" description="desc2"  domain="domain2"
+  <metrics delete_historical_data="[null]" id="3" name="new2" val_type="FLOAT" description="desc2"  domain="domain2"
            short_name="short2"   qualitative="true"  user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
 
 </dataset>
\ No newline at end of file
index e0c019ba27ac6266b571e5628a296186d6c2267b..c56f073dafa30d3a136d864dbf68192f2efa2967 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <metrics id="1" name="key1" val_type="INT" description="description"  domain="domain"
+  <metrics delete_historical_data="[null]" id="1" name="key1" val_type="INT" description="description"  domain="domain"
            short_name="short name"  qualitative="false" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>
   
 </dataset>
\ No newline at end of file
index a995cfd7f9888873882d76629d944c92fe0d0451..cf7cb97fd80effbe53a1790b2467ac44622885d1 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <metrics id="1" name="key" val_type="FLOAT" description="new description" domain="new domain"
+  <metrics delete_historical_data="[null]" id="1" name="key" val_type="FLOAT" description="new description" domain="new domain"
            short_name="new short name"  qualitative="true" user_managed="false" enabled="true" origin="JAV" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="-1" hidden="false"/>
 
 </dataset>
\ No newline at end of file
index 6ab28c07b9c876ac3f387ed9f43ecd61c36c5a7b..b826ae71d7759ed6512dd468a9b1884e35728dde 100644 (file)
@@ -1,6 +1,6 @@
 <dataset>
 
-  <metrics id="1" name="key" val_type="INT" description="old description"  domain="old domain"
+  <metrics delete_historical_data="[null]" id="1" name="key" val_type="INT" description="old description"  domain="old domain"
            short_name="old short name"  qualitative="false" user_managed="false" enabled="true" origin="GUI" worst_value="[null]" optimized_best_value="[null]" best_value="[null]" direction="1" hidden="false"/>