From 070c3e240aec5697ef7e715fc18bacdb14fce9ef Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Wed, 4 Feb 2015 17:18:05 +0100 Subject: [PATCH] SONAR-5183 - analysis unsensitive to timezones - snapshots table --- .../TimeMachineConfigurationPersister.java | 4 +- .../plugins/core/widgets/timeline.html.erb | 8 +- .../shared.xml | 8 +- ...veConfigurationInSnapshotsTable-result.xml | 12 +- .../shared.xml | 2 +- ...rmanentIdFromReferenceViolation-result.xml | 2 +- .../shouldSaveViolations-result.xml | 2 +- .../server/component/db/SnapshotDao.java | 34 +++- .../server/computation/AnalysisReportLog.java | 8 +- .../server/computation/ws/QueueWsAction.java | 8 +- .../db/migrations/DatabaseMigrations.java | 1 + .../v51/FeedSnapshotsLongDates.java | 65 +++++++ .../server/measure/MeasureFilterRow.java | 8 +- .../server/measure/MeasureFilterSort.java | 33 ++-- .../server/measure/MeasureFilterSql.java | 40 +++- .../ProjectRepositoryLoaderMediumTest.java | 4 +- .../server/component/SnapshotTesting.java | 6 +- .../server/component/db/SnapshotDaoTest.java | 40 ++-- .../step/PurgeDatastoresStepMediumTest.java | 6 +- .../v51/FeedSnapshotsLongDatesTest.java | 84 ++++++++ .../measure/MeasureFilterExecutorTest.java | 27 ++- .../org/sonar/server/rule/RuleTesting.java | 4 +- .../db/ComponentDaoTest/delete-result.xml | 10 +- .../db/ComponentDaoTest/multi-modules.xml | 12 +- .../component/db/ComponentDaoTest/shared.xml | 10 +- .../db/ComponentDaoTest/shared_views.xml | 18 +- .../db/SnapshotDaoTest/insert-result.xml | 12 +- .../component/db/SnapshotDaoTest/modules.xml | 12 +- .../component/db/SnapshotDaoTest/shared.xml | 12 +- .../db/SnapshotDaoTest/snapshots.xml | 72 +++---- .../report-folder/snapshots.xml | 180 +++++++++--------- .../snapshots-result.xml | 180 +++++++++--------- .../step/SwitchSnapshotStepTest/snapshots.xml | 180 +++++++++--------- .../v51/FeedSnapshotsLongDatesTest/before.xml | 61 ++++++ .../v51/FeedSnapshotsLongDatesTest/schema.sql | 18 ++ .../filters/FilterExecutorTest/views.xml | 10 +- ...e_when_filter_by_component_name_or_key.xml | 8 +- .../ignore_person_measures.xml | 2 +- .../ignore_quality_model_measures.xml | 2 +- .../MeasureFilterExecutorTest/shared.xml | 10 +- .../sort_by_alert.xml | 6 +- .../view/index/ViewIndexerTest/index.xml | 18 +- .../app/controllers/api/events_controller.rb | 2 +- .../app/controllers/project_controller.rb | 2 +- .../webapp/WEB-INF/app/models/snapshot.rb | 35 +++- .../migrate/775_add_snapshots_long_dates.rb | 34 ++++ .../migrate/776_feed_snapshots_long_dates.rb | 29 +++ .../777_rename_snapshots_long_dates.rb | 42 ++++ .../org/sonar/batch/DefaultTimeMachine.java | 18 +- .../org/sonar/batch/ProjectConfigurator.java | 12 +- .../sonar/batch/components/PastSnapshot.java | 7 +- .../components/PastSnapshotFinderByDate.java | 14 +- .../components/PastSnapshotFinderByDays.java | 16 +- .../PastSnapshotFinderByPreviousAnalysis.java | 4 +- .../PastSnapshotFinderByPreviousVersion.java | 4 +- .../PastSnapshotFinderByVersion.java | 4 +- .../batch/components/PeriodsDefinition.java | 7 +- .../components/TimeMachineConfiguration.java | 7 +- .../sonar/batch/index/ResourcePersister.java | 21 +- .../DefaultProjectRepositoriesLoader.java | 5 +- .../sonar/batch/ProjectConfiguratorTest.java | 3 +- .../PastSnapshotFinderByDaysTest.java | 2 +- .../components/PastSnapshotFinderTest.java | 8 +- .../batch/components/PastSnapshotTest.java | 10 +- .../loadMeasuresFromDate.xml | 10 +- .../fail_if_not_latest_analysis.xml | 4 +- .../set_analysis_date_on_latest_analysis.xml | 4 +- ...e_on_latest_analysis_if_never_analysed.xml | 2 +- .../PastMeasuresLoaderTest/shared.xml | 6 +- .../PastSnapshotFinderByDateTest/shared.xml | 12 +- .../PastSnapshotFinderByDaysTest/shared.xml | 26 +-- .../shouldNotFindSelf.xml | 6 +- .../shouldFindPreviousAnalysis.xml | 6 +- .../shouldNotFindPreviousAnalysis.xml | 4 +- .../no-previous-version.xml | 8 +- .../with-previous-version-deleted.xml | 8 +- .../with-previous-version.xml | 8 +- .../shared.xml | 12 +- .../TimeMachineConfigurationTest/shared.xml | 4 +- ...oveRootIndexIfResourceIsProject-result.xml | 4 +- ...ouldRemoveRootIndexIfResourceIsProject.xml | 2 +- .../shouldSaveCopyProject-result.xml | 4 +- .../shouldSaveNewDirectory-result.xml | 6 +- .../shouldSaveNewLibrary-result.xml | 8 +- ...houldSaveNewMultiModulesProject-result.xml | 14 +- ...ewMultiModulesProjectAndLibrary-result.xml | 16 +- .../shouldSaveNewProject-result.xml | 4 +- .../shouldUpdateExistingResource-result.xml | 4 +- .../shouldUpdateExistingResource.xml | 2 +- .../org/sonar/core/component/SnapshotDto.java | 49 ++--- .../core/component/db/SnapshotMapper.java | 6 +- .../core/persistence/DatabaseVersion.java | 2 +- .../core/purge/PurgeableSnapshotDto.java | 5 +- .../org/sonar/core/timemachine/Periods.java | 10 +- .../core/component/db/SnapshotMapper.xml | 2 +- .../org/sonar/core/persistence/rows-h2.sql | 3 + .../org/sonar/core/persistence/schema-h2.ddl | 14 +- .../sonar/core/component/SnapshotDtoTest.java | 26 +-- .../dbcleaner/DbCleanerTestUtils.java | 4 +- .../period/DefaultPeriodCleanerTest.java | 9 +- .../sonar/core/resource/ResourceDaoTest.java | 4 +- .../sonar/core/timemachine/PeriodsTest.java | 18 +- .../should_create_database.xml | 2 +- .../shouldDeleteResource.xml | 4 +- .../shouldDeleteSnapshot-result.xml | 2 +- .../shouldDeleteSnapshot.xml | 8 +- ...stedMeasuresWhenPurgingSnapshot-result.xml | 4 +- ...eleteWastedMeasuresWhenPurgingSnapshot.xml | 4 +- .../shouldPurgeSnapshot-result.xml | 8 +- .../PurgeCommandsTest/shouldPurgeSnapshot.xml | 8 +- ...ete_file_sources_of_disabled_resources.xml | 16 +- ...resources_without_last_snapshot-result.xml | 12 +- ...isable_resources_without_last_snapshot.xml | 6 +- .../select_purgeable_file_uuids.xml | 16 +- .../shouldDeleteAbortedBuilds-result.xml | 6 +- .../shouldDeleteAbortedBuilds.xml | 6 +- ...oricalDataOfDirectoriesAndFiles-result.xml | 12 +- ...eteHistoricalDataOfDirectoriesAndFiles.xml | 12 +- .../PurgeDaoTest/shouldDeleteProject.xml | 16 +- .../shouldDeleteSnapshots-result.xml | 6 +- .../PurgeDaoTest/shouldDeleteSnapshots.xml | 8 +- .../shouldPurgeProject-result.xml | 6 +- .../purge/PurgeDaoTest/shouldPurgeProject.xml | 6 +- .../shouldSelectPurgeableSnapshots.xml | 10 +- ...should_delete_all_closed_issues-result.xml | 4 +- .../should_delete_all_closed_issues.xml | 4 +- ...should_delete_old_closed_issues-result.xml | 2 +- .../should_delete_old_closed_issues.xml | 4 +- ...g-ghost-projects-and-technical-project.xml | 16 +- .../core/resource/ResourceDaoTest/fixture.xml | 10 +- .../get_last_snapshot_by_component_uuid.xml | 14 +- .../main/java/org/sonar/api/batch/Event.java | 10 +- .../sonar/api/database/model/Snapshot.java | 69 ++++--- .../java/org/sonar/api/utils/DateUtils.java | 10 +- .../api/database/model/SnapshotTest.java | 9 +- .../org/sonar/api/utils/DateUtilsTest.java | 4 +- 136 files changed, 1291 insertions(+), 904 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/before.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/schema.sql create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 17cee708dd0..13f1a85efbf 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -34,6 +34,8 @@ import org.sonar.batch.index.ResourceCache; import java.util.List; +import static org.sonar.api.utils.DateUtils.dateToLong; + @DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE) public final class TimeMachineConfigurationPersister implements Decorator { @@ -75,6 +77,6 @@ public final class TimeMachineConfigurationPersister implements Decorator { int periodIndex = pastSnapshot.getIndex(); snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode()); snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter()); - snapshot.setPeriodDate(periodIndex, pastSnapshot.getDate()); + snapshot.setPeriodDate(periodIndex, dateToLong(pastSnapshot.getDate())); } } diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb index 6e5c662f104..200a48fd8a7 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb @@ -53,9 +53,7 @@ metric_data_map[metric_id].each() do |metric_data| # for every metric value, we need to check that the corresponding snapshot has values for each metric if metric_count_per_snapshot_id[metric_data[:sid]]==total_number_of_metrics - m_date = metric_data[:date] - # Only Oracle returns a Time object, so let's parse this string if it's not a Time instance - m_date = Time.parse(metric_data[:date]) unless m_date.is_a? Time + m_date = Time.at(metric_data[:date]/1000) m_value = sprintf("%0.02f", metric_data[:value]) m_value_localized = ProjectMeasure.new(:metric => metric_map[metric_id]).format_numeric_value(metric_data[:value], {}) js_data += "{x:d(" @@ -99,9 +97,7 @@ unless from_date # find the oldest date metric_data_map.values.each() do |metric_data_array| - first_date = metric_data_array[0][:date] - # Only Oracle returns a Time object, so let's parse this string if it's not a Time instance - first_date = Time.parse(metric_data_array[0][:date]) unless first_date.is_a? Time + first_date = Time.at(metric_data_array[0][:date]/1000) from_date = first_date if !from_date || from_date > first_date end end diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml index a4286611e65..70c8178d4e8 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml @@ -6,7 +6,7 @@ period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="100" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" - scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" + scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path="" status="P" islast="false" depth="0" /> @@ -27,7 +27,7 @@ period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="300" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" - scope="PRJ" qualifier="TRK" created_at="2008-12-13 13:58:00.00" build_date="2008-12-13 13:58:00.00" version="1.2.3" path="" + scope="PRJ" qualifier="TRK" created_at="1229173080000" build_date="1229173080000" version="1.2.3" path="" status="P" islast="false" depth="0" /> diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml index 63545d72ec0..34fdf2d4d32 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml @@ -6,7 +6,7 @@ period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="100" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" - scope="PRJ" qualifier="TRK" created_at="2008-11-01 13:58:00.00" build_date="2008-11-01 13:58:00.00" version="[null]" path="" + scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path="" status="P" islast="false" depth="0" /> @@ -27,16 +27,16 @@ period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="300" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]" - scope="PRJ" qualifier="TRK" created_at="2008-12-13 13:58:00.00" build_date="2008-12-13 13:58:00.00" version="1.2.3" path="" + scope="PRJ" qualifier="TRK" created_at="1229173080000" build_date="1229173080000" version="1.2.3" path="" status="P" islast="false" depth="0" /> diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml index 5800859154c..519ce8d5157 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shared.xml @@ -15,7 +15,7 @@ diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml index f0d25f8474a..061041849aa 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldCopyPermanentIdFromReferenceViolation-result.xml @@ -15,7 +15,7 @@ diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml index 9f3c7d89b52..f1bbc0bda6f 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/ViolationPersisterDecoratorTest/shouldSaveViolations-result.xml @@ -14,7 +14,7 @@ diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java b/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java index 5379396bcae..3acc948b70e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/db/SnapshotDao.java @@ -20,34 +20,44 @@ package org.sonar.server.component.db; -import org.sonar.api.ServerComponent; import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; import org.sonar.core.component.SnapshotDto; import org.sonar.core.component.db.SnapshotMapper; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DbSession; -import org.sonar.server.db.BaseDao; +import org.sonar.server.exceptions.NotFoundException; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.List; -public class SnapshotDao extends BaseDao implements ServerComponent, DaoComponent { +public class SnapshotDao implements DaoComponent { + + private final System2 system2; public SnapshotDao(System2 system) { - super(SnapshotMapper.class, system); + this.system2 = system; } - @Override @CheckForNull - protected SnapshotDto doGetNullableByKey(DbSession session, Long id) { + public SnapshotDto getNullableByKey(DbSession session, Long id) { return mapper(session).selectByKey(id); } - @Override - protected SnapshotDto doInsert(DbSession session, SnapshotDto item) { + public SnapshotDto getByKey(DbSession session, Long key) { + SnapshotDto value = getNullableByKey(session, key); + if (value == null) { + throw new NotFoundException(String.format("Key '%s' not found", key)); + } + + return value; + } + + public SnapshotDto insert(DbSession session, SnapshotDto item) { + if (item.getCreatedAt() == null) { + item.setCreatedAt(system2.now()); + } mapper(session).insert(item); return item; } @@ -83,6 +93,10 @@ public class SnapshotDao extends BaseDao impl } public boolean isLast(SnapshotDto snapshotTested, @Nullable SnapshotDto previousLastSnapshot) { - return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(snapshotTested.getCreatedAt()); + return previousLastSnapshot == null || previousLastSnapshot.getCreatedAt() < snapshotTested.getCreatedAt(); + } + + private SnapshotMapper mapper(DbSession session) { + return session.getMapper(SnapshotMapper.class); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportLog.java b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportLog.java index bf61b9b38df..1b307d69171 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportLog.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportLog.java @@ -28,7 +28,7 @@ import org.sonar.core.computation.db.AnalysisReportDto; import java.util.Map; import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe; -import static org.sonar.api.utils.DateUtils.timeToDate; +import static org.sonar.api.utils.DateUtils.longToDate; public class AnalysisReportLog implements ActivityLog { @@ -50,9 +50,9 @@ public class AnalysisReportLog implements ActivityLog { .put("projectName", project.name()) .put("projectUuid", project.uuid()) .put("status", String.valueOf(report.getStatus())) - .put("submittedAt", formatDateTimeNullSafe(timeToDate(report.getCreatedAt()))) - .put("startedAt", formatDateTimeNullSafe(timeToDate(report.getStartedAt()))) - .put("finishedAt", formatDateTimeNullSafe(timeToDate(report.getFinishedAt()))) + .put("submittedAt", formatDateTimeNullSafe(longToDate(report.getCreatedAt()))) + .put("startedAt", formatDateTimeNullSafe(longToDate(report.getStartedAt()))) + .put("finishedAt", formatDateTimeNullSafe(longToDate(report.getFinishedAt()))) .build(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueWsAction.java index 29175569e69..cf9f54029cc 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueWsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueWsAction.java @@ -30,7 +30,7 @@ import org.sonar.server.computation.AnalysisReportQueue; import java.util.List; -import static org.sonar.api.utils.DateUtils.timeToDate; +import static org.sonar.api.utils.DateUtils.longToDate; /** * @since 5.0 @@ -69,9 +69,9 @@ public class QueueWsAction implements ComputationWsAction, RequestHandler { json.prop("key", report.getId()); json.prop("projectKey", report.getProjectKey()); json.prop("projectName", report.getProjectKey()); - json.propDateTime("startedAt", timeToDate(report.getStartedAt())); - json.propDateTime("finishedAt", timeToDate(report.getFinishedAt())); - json.propDateTime("submittedAt", timeToDate(report.getCreatedAt())); + json.propDateTime("startedAt", longToDate(report.getStartedAt())); + json.propDateTime("finishedAt", longToDate(report.getFinishedAt())); + json.propDateTime("submittedAt", longToDate(report.getCreatedAt())); json.prop("status", report.getStatus().toString()); json.endObject(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java index 03703c13776..4f0a00b3f38 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java @@ -84,6 +84,7 @@ public interface DatabaseMigrations { FeedIssueChangesLongDates.class, FeedAnalysisReportsLongDates.class, UpdateProjectsModuleUuidPath.class, + FeedSnapshotsLongDates.class, FeedIssueComponentUuids.class, RemoveRuleMeasuresOnIssues.class ); diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java new file mode 100644 index 00000000000..09998ea93eb --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java @@ -0,0 +1,65 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.db.migrations.v51; + +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.Database; +import org.sonar.server.db.migrations.BaseDataChange; +import org.sonar.server.db.migrations.MassUpdate; +import org.sonar.server.db.migrations.Select; +import org.sonar.server.db.migrations.SqlStatement; + +import java.sql.SQLException; + +public class FeedSnapshotsLongDates extends BaseDataChange { + + private final System2 system2; + + public FeedSnapshotsLongDates(Database db, System2 system2) { + super(db); + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + final long now = system2.now(); + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate + .select("SELECT s.created_at, s.build_date, s.period1_date, s.period2_date, s.period3_date, s.period4_date, s.period5_date, s.id FROM snapshots s WHERE created_at_ms IS NULL"); + massUpdate + .update("UPDATE snapshots SET created_at_ms=?, build_date_ms=?, period1_date_ms=?, period2_date_ms=?, period3_date_ms=?, period4_date_ms=?, period5_date_ms=? WHERE id=?"); + massUpdate.rowPluralName("snapshots"); + massUpdate.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + for (int i = 1; i <= 7; i++) { + update.setLong(i, row.getDate(i) == null ? null : Math.min(now, row.getDate(i).getTime())); + } + + Long id = row.getLong(8); + update.setLong(8, id); + + return true; + } + }); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterRow.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterRow.java index bff50112501..990f6344512 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterRow.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterRow.java @@ -21,14 +21,12 @@ package org.sonar.server.measure; import org.apache.commons.lang.StringUtils; -import java.sql.Timestamp; - public class MeasureFilterRow { private final long snapshotId; private final long resourceId; private final long resourceRootId; private String sortText = null; - private Timestamp sortDate = null; + private Long sortDate = null; private Double sortDouble = null; MeasureFilterRow(long snapshotId, long resourceId, long resourceRootId) { @@ -57,11 +55,11 @@ public class MeasureFilterRow { this.sortText = StringUtils.defaultString(s); } - Timestamp getSortDate() { + Long getSortDate() { return sortDate; } - void setSortDate(Timestamp sortDate) { + void setSortDate(Long sortDate) { this.sortDate = sortDate; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSort.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSort.java index 0cbc114f775..584234f1e3a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSort.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSort.java @@ -23,19 +23,10 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Metric; class MeasureFilterSort { - public static enum Field { - KEY, NAME, VERSION, METRIC, SHORT_NAME, DESCRIPTION, - // Sort by last analysis date - DATE, - // Sort by project creation date - PROJECT_CREATION_DATE - } - private Field field = Field.NAME; private Metric metric = null; private Integer period = null; private boolean asc = true; - MeasureFilterSort() { } @@ -56,10 +47,6 @@ class MeasureFilterSort { this.period = period; } - void setAsc(boolean asc) { - this.asc = asc; - } - public Field field() { return field; } @@ -81,7 +68,11 @@ class MeasureFilterSort { } boolean isOnDate() { - return Field.DATE.equals(field) || Field.PROJECT_CREATION_DATE.equals(field); + return Field.PROJECT_CREATION_DATE.equals(field); + } + + boolean isOnTime() { + return Field.DATE.equals(field); } boolean isOnAlert() { @@ -92,6 +83,10 @@ class MeasureFilterSort { return asc; } + void setAsc(boolean asc) { + this.asc = asc; + } + String column() { // only numeric metrics can be sorted by database, else results are sorted programmatically. String column; @@ -126,11 +121,19 @@ class MeasureFilterSort { return column; } - private String getMetricColumn(){ + private String getMetricColumn() { if (metric.isNumericType()) { return period != null ? "pmsort.variation_value_" + period : "pmsort.value"; } else { return "pmsort.text_value"; } } + + public static enum Field { + KEY, NAME, VERSION, METRIC, SHORT_NAME, DESCRIPTION, + // Sort by last analysis date + DATE, + // Sort by project creation date + PROJECT_CREATION_DATE + } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java index 26f1b337f53..28bdc861d91 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilterSql.java @@ -37,6 +37,8 @@ import java.sql.*; import java.util.Comparator; import java.util.List; +import static org.sonar.api.utils.DateUtils.dateToLong; + class MeasureFilterSql { private final Database database; @@ -57,7 +59,7 @@ class MeasureFilterSql { ResultSet rs = null; try { for (int index = 0; index < dateParameters.size(); index++) { - statement.setDate(index + 1, dateParameters.get(index)); + statement.setLong(index + 1, dateToLong(dateParameters.get(index))); } rs = statement.executeQuery(); return process(rs); @@ -191,6 +193,8 @@ class MeasureFilterSql { rowProcessor = new NumericSortRowProcessor(); } else if (filter.sort().isOnDate()) { rowProcessor = new DateSortRowProcessor(); + } else if (filter.sort().isOnTime()) { + rowProcessor = new LongSortRowProcessor(); } else if (filter.sort().isOnAlert()) { rowProcessor = new AlertSortRowProcessor(); } else { @@ -220,11 +224,11 @@ class MeasureFilterSql { /** * Replace escape percent and underscore by adding a slash just before */ - private String escapePercentAndUnderscrore(String value){ + private String escapePercentAndUnderscrore(String value) { return value.replaceAll("%", "\\\\%").replaceAll("_", "\\\\_"); } - private void appendEscapeForSomeDb(StringBuilder sb){ + private void appendEscapeForSomeDb(StringBuilder sb) { if (database.getDialect().getId().equals(Oracle.ID) || database.getDialect().getId().equals(MsSql.ID)) { sb.append(" ESCAPE '\\'"); } @@ -323,15 +327,39 @@ class MeasureFilterSql { @Override MeasureFilterRow fetch(ResultSet rs) throws SQLException { MeasureFilterRow row = new MeasureFilterRow(rs.getLong(1), rs.getLong(2), rs.getLong(3)); - row.setSortDate(rs.getTimestamp(4)); + row.setSortDate(rs.getTimestamp(4).getTime()); + return row; + } + + @Override + Function sortFieldFunction() { + return new Function() { + @Override + public Long apply(MeasureFilterRow row) { + return row.getSortDate(); + } + }; + } + + @Override + Ordering sortFieldOrdering(boolean ascending) { + return newObjectOrdering(ascending); + } + } + + static class LongSortRowProcessor extends RowProcessor { + @Override + MeasureFilterRow fetch(ResultSet rs) throws SQLException { + MeasureFilterRow row = new MeasureFilterRow(rs.getLong(1), rs.getLong(2), rs.getLong(3)); + row.setSortDate(rs.getLong(4)); return row; } @Override Function sortFieldFunction() { - return new Function() { + return new Function() { @Override - public Timestamp apply(MeasureFilterRow row) { + public Long apply(MeasureFilterRow row) { return row.getSortDate(); } }; diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java index aa7a7c4d208..17fa759880e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectRepositoryLoaderMediumTest.java @@ -755,8 +755,8 @@ public class ProjectRepositoryLoaderMediumTest { .setData(",,,,,,,,,,,,,,,unchanged ,,,,,,,,,,,,,,,content ") .setDataHash("0263047cd758c68c27683625f072f010") .setLineHashes("8d7b3d6b83c0a517eac07e1aac94b773") - .setCreatedAt(new Date().getTime()) - .setUpdatedAt(new Date().getTime()) + .setCreatedAt(System.currentTimeMillis()) + .setUpdatedAt(System.currentTimeMillis()) .setSrcHash("123456"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java b/server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java index 57db17ac178..d5785121522 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java @@ -23,8 +23,6 @@ package org.sonar.server.component; import org.sonar.core.component.ComponentDto; import org.sonar.core.component.SnapshotDto; -import java.util.Date; - public class SnapshotTesting { /** @@ -42,7 +40,7 @@ public class SnapshotTesting { .setParentId(parentSnapshot.getId()) .setPath(parentSnapshot.getPath() == null ? Long.toString(parentSnapshot.getId()) + "." : parentSnapshot.getPath() + Long.toString(parentSnapshot.getId()) + ".") .setLast(true) - .setBuildDate(new Date()); + .setBuildDate(System.currentTimeMillis()); } public static SnapshotDto createForProject(ComponentDto project) { @@ -54,7 +52,7 @@ public class SnapshotTesting { .setScope(project.scope()) .setPath("") .setLast(true) - .setBuildDate(new Date()); + .setBuildDate(System.currentTimeMillis()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java index 4b175bf8f44..443ad6d6a79 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java @@ -78,22 +78,22 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { assertThat(result.getPeriodMode(1)).isEqualTo("days1"); assertThat(result.getPeriodModeParameter(1)).isEqualTo("30"); - assertThat(result.getPeriodDate(1)).isEqualTo(DateUtils.parseDate("2011-09-24")); + assertThat(result.getPeriodDate(1)).isEqualTo(1316815200000L); assertThat(result.getPeriodMode(2)).isEqualTo("days2"); assertThat(result.getPeriodModeParameter(2)).isEqualTo("31"); - assertThat(result.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2011-09-25")); + assertThat(result.getPeriodDate(2)).isEqualTo(1316901600000L); assertThat(result.getPeriodMode(3)).isEqualTo("days3"); assertThat(result.getPeriodModeParameter(3)).isEqualTo("32"); - assertThat(result.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2011-09-26")); + assertThat(result.getPeriodDate(3)).isEqualTo(1316988000000L); assertThat(result.getPeriodMode(4)).isEqualTo("days4"); assertThat(result.getPeriodModeParameter(4)).isEqualTo("33"); - assertThat(result.getPeriodDate(4)).isEqualTo(DateUtils.parseDate("2011-09-27")); + assertThat(result.getPeriodDate(4)).isEqualTo(1317074400000L); assertThat(result.getPeriodMode(5)).isEqualTo("days5"); assertThat(result.getPeriodModeParameter(5)).isEqualTo("34"); - assertThat(result.getPeriodDate(5)).isEqualTo(DateUtils.parseDate("2011-09-28")); + assertThat(result.getPeriodDate(5)).isEqualTo(1317160800000L); - assertThat(result.getCreatedAt()).isEqualTo(DateUtils.parseDate("2008-12-02")); - assertThat(result.getBuildDate()).isEqualTo(DateUtils.parseDate("2011-09-29")); + assertThat(result.getCreatedAt()).isEqualTo(1228172400000L); + assertThat(result.getBuildDate()).isEqualTo(1317247200000L); assertThat(sut.getNullableByKey(session, 999L)).isNull(); } @@ -102,7 +102,7 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { public void insert() { setupData("empty"); - when(system2.now()).thenReturn(DateUtils.parseDate("2014-06-18").getTime()); + when(system2.now()).thenReturn(1403042400000L); SnapshotDto dto = defaultSnapshot(); @@ -155,7 +155,7 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { setupData("snapshots"); SnapshotDto referenceSnapshot = defaultSnapshot().setResourceId(1L); - referenceSnapshot.setCreatedAt(DateUtils.parseDate("2008-12-03")); + referenceSnapshot.setCreatedAt(DateUtils.parseDate("2008-12-03").getTime()); SnapshotDto snapshot = sut.getLastSnapshotOlderThan(session, referenceSnapshot); assertThat(snapshot).isNotNull(); @@ -167,7 +167,7 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { setupData("snapshots"); SnapshotDto referenceSnapshot = defaultSnapshot().setResourceId(1L); - referenceSnapshot.setCreatedAt(DateUtils.parseDate("2008-12-01")); + referenceSnapshot.setCreatedAt(DateUtils.parseDate("2008-12-01").getTime()); SnapshotDto snapshot = sut.getLastSnapshotOlderThan(session, referenceSnapshot); assertThat(snapshot).isNull(); @@ -226,8 +226,8 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { Date today = new Date(); Date yesterday = DateUtils.addDays(today, -1); - SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today); - SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday); + SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today.getTime()); + SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday.getTime()); boolean isLast = sut.isLast(snapshot, previousLastSnapshot); @@ -239,8 +239,8 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { Date today = new Date(); Date yesterday = DateUtils.addDays(today, -1); - SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday); - SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today); + SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday.getTime()); + SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today.getTime()); boolean isLast = sut.isLast(snapshot, previousLastSnapshot); @@ -271,11 +271,11 @@ public class SnapshotDaoTest extends AbstractDaoTestCase { .setPeriodParam(3, "32") .setPeriodParam(4, "33") .setPeriodParam(5, "34") - .setPeriodDate(1, DateUtils.parseDate("2011-09-24")) - .setPeriodDate(2, DateUtils.parseDate("2011-09-25")) - .setPeriodDate(3, DateUtils.parseDate("2011-09-26")) - .setPeriodDate(4, DateUtils.parseDate("2011-09-27")) - .setPeriodDate(5, DateUtils.parseDate("2011-09-28")) - .setBuildDate(DateUtils.parseDate("2011-09-29")); + .setPeriodDate(1, DateUtils.parseDate("2011-09-24").getTime()) + .setPeriodDate(2, DateUtils.parseDate("2011-09-25").getTime()) + .setPeriodDate(3, DateUtils.parseDate("2011-09-26").getTime()) + .setPeriodDate(4, DateUtils.parseDate("2011-09-27").getTime()) + .setPeriodDate(5, DateUtils.parseDate("2011-09-28").getTime()) + .setBuildDate(DateUtils.parseDate("2011-09-29").getTime()); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java index a21e9b2955f..004265d841c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepMediumTest.java @@ -83,8 +83,7 @@ public class PurgeDatastoresStepMediumTest { dbClient.componentDao().insert(dbSession, project); SnapshotDto snapshot = SnapshotTesting.createForProject(project) - .setCreatedAt(aWeekAgo) - .setUpdatedAt(aWeekAgo); + .setCreatedAt(aWeekAgo.getTime()); dbClient.snapshotDao().insert(dbSession, snapshot); AnalysisReportDto report = AnalysisReportDto.newForTests(1L) @@ -118,8 +117,7 @@ public class PurgeDatastoresStepMediumTest { dbClient.componentDao().insert(dbSession, project); SnapshotDto snapshot = SnapshotTesting.createForProject(project) - .setCreatedAt(twoWeeksAgo) - .setUpdatedAt(twoWeeksAgo) + .setCreatedAt(twoWeeksAgo.getTime()) .setStatus("P") .setLast(true); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java new file mode 100644 index 00000000000..24f2e73500f --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest.java @@ -0,0 +1,84 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.sonar.server.db.migrations.v51; + +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.api.utils.System2; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.db.migrations.DatabaseMigration; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.api.utils.DateUtils.parseDate; + +public class FeedSnapshotsLongDatesTest { + @ClassRule + public static DbTester db = new DbTester().schema(FeedSnapshotsLongDatesTest.class, "schema.sql"); + + @Test + public void execute() throws Exception { + db.prepareDbUnit(getClass(), "before.xml"); + + DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); + migration.execute(); + + int count = db + .countSql("select count(*) from snapshots where created_at_ms is not null " + + "and build_date_ms is not null " + + "and period1_date_ms is not null " + + "and period2_date_ms is not null " + + "and period3_date_ms is not null " + + "and period4_date_ms is not null " + + "and period5_date_ms is not null"); + assertThat(count).isEqualTo(2); + } + + @Test + public void take_now_if_date_in_the_future() throws Exception { + db.prepareDbUnit(getClass(), "before.xml"); + System2 system2 = mock(System2.class); + when(system2.now()).thenReturn(0L); + + DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), mock(System2.class)); + migration.execute(); + + int count = db + .countSql("select count(*) from snapshots where " + + "created_at_ms = 0"); + assertThat(count).isEqualTo(1); + } + + @Test + public void take_snapshot_date_if_in_the_past() throws Exception { + db.prepareDbUnit(getClass(), "before.xml"); + long snapshotTime = parseDate("2014-09-25").getTime(); + + DatabaseMigration migration = new FeedSnapshotsLongDates(db.database(), System2.INSTANCE); + migration.execute(); + + int count = db + .countSql("select count(*) from snapshots where " + + "created_at_ms=" + snapshotTime); + assertThat(count).isEqualTo(1); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java index 860bf9ef7d1..3b868800768 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/measure/MeasureFilterExecutorTest.java @@ -34,6 +34,7 @@ import org.sonar.test.DbTests; import java.sql.SQLException; import java.util.Arrays; +import java.util.Date; import java.util.List; import static com.google.common.collect.Lists.newArrayList; @@ -55,11 +56,9 @@ public class MeasureFilterExecutorTest { private static final Metric METRIC_PROFILE = new Metric.Builder("profile", "Profile", Metric.ValueType.STRING).create().setId(2); private static final Metric METRIC_COVERAGE = new Metric.Builder("coverage", "Coverage", Metric.ValueType.FLOAT).create().setId(3); private static final Metric METRIC_UNKNOWN = new Metric.Builder("unknown", "Unknown", Metric.ValueType.FLOAT).create().setId(4); - - private MeasureFilterExecutor executor; - @ClassRule public static DbTester db = new DbTester(); + private MeasureFilterExecutor executor; @Before public void before() { @@ -212,7 +211,7 @@ public class MeasureFilterExecutorTest { List rows = executor.execute(filter, new MeasureFilterContext()); assertThat(rows).hasSize(2); - verifyPhpProject(rows.get(0));//php way + verifyPhpProject(rows.get(0));// php way verifyJavaProject(rows.get(1));// Sonar way } @@ -224,7 +223,7 @@ public class MeasureFilterExecutorTest { assertThat(rows).hasSize(2); verifyJavaProject(rows.get(0));// Sonar way - verifyPhpProject(rows.get(1));//php way + verifyPhpProject(rows.get(1));// php way } @Test @@ -234,7 +233,7 @@ public class MeasureFilterExecutorTest { MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("CLA")).setSortOnMetric(METRIC_PROFILE); List rows = executor.execute(filter, new MeasureFilterContext()); - assertThat(rows).hasSize(2);//2 files randomly sorted + assertThat(rows).hasSize(2);// 2 files randomly sorted } @Test @@ -348,9 +347,9 @@ public class MeasureFilterExecutorTest { List rows = executor.execute(filter, new MeasureFilterContext()); verifyJavaProject(rows.get(0));// 2008 - assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2008-12-19"); + assertThat(DateUtils.formatDate(new Date(rows.get(0).getSortDate()))).isEqualTo("2008-12-19"); verifyPhpProject(rows.get(1));// 2012 - assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2012-12-12"); + assertThat(DateUtils.formatDate(new Date(rows.get(1).getSortDate()))).isEqualTo("2012-12-12"); } @Test @@ -360,9 +359,9 @@ public class MeasureFilterExecutorTest { List rows = executor.execute(filter, new MeasureFilterContext()); verifyPhpProject(rows.get(0));// 2012 - assertThat(DateUtils.formatDate(rows.get(0).getSortDate())).isEqualTo("2012-12-12"); + assertThat(DateUtils.formatDate(new Date(rows.get(0).getSortDate()))).isEqualTo("2012-12-12"); verifyJavaProject(rows.get(1));// 2008 - assertThat(DateUtils.formatDate(rows.get(1).getSortDate())).isEqualTo("2008-12-19"); + assertThat(DateUtils.formatDate(new Date(rows.get(1).getSortDate()))).isEqualTo("2008-12-19"); } @Test @@ -530,7 +529,8 @@ public class MeasureFilterExecutorTest { @Test public void filter_by_parent_without_children() throws Exception { db.prepareDbUnit(getClass(), "shared.xml"); - MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK", "PAC", "CLA")).setBaseResourceKey("java_project:org.sonar.foo.Big").setOnBaseResourceChildren(true); + MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK", "PAC", "CLA")).setBaseResourceKey("java_project:org.sonar.foo.Big") + .setOnBaseResourceChildren(true); List rows = executor.execute(filter, new MeasureFilterContext()); assertThat(rows).isEmpty(); @@ -552,7 +552,7 @@ public class MeasureFilterExecutorTest { db.prepareDbUnit(getClass(), "ignore_person_measures.xml"); MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).addCondition( new MeasureFilterCondition(new Metric("ncloc").setId(1), MeasureFilterCondition.Operator.GREATER, 0.0) - ); + ); List rows = executor.execute(filter, new MeasureFilterContext().setUserId(50L)); assertThat(rows).hasSize(1); @@ -574,7 +574,7 @@ public class MeasureFilterExecutorTest { db.prepareDbUnit(getClass(), "ignore_quality_model_measures.xml"); MeasureFilter filter = new MeasureFilter().setResourceQualifiers(Arrays.asList("TRK")).addCondition( new MeasureFilterCondition(new Metric("ncloc").setId(1), MeasureFilterCondition.Operator.GREATER, 0.0) - ); + ); List rows = executor.execute(filter, new MeasureFilterContext().setUserId(50L)); assertThat(rows).hasSize(1); @@ -591,7 +591,6 @@ public class MeasureFilterExecutorTest { assertThat(rows.get(0).getSnapshotId()).isEqualTo(101L); } - private void verifyJavaProject(MeasureFilterRow row) { verifyProject(row, JAVA_PROJECT_SNAPSHOT_ID, JAVA_PROJECT_ID, JAVA_PROJECT_ID); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java index 0cba9544e0b..c25b9b8dc98 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/RuleTesting.java @@ -27,8 +27,6 @@ import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleDto.Format; -import java.util.Date; - /** * Utility class for tests involving rules */ @@ -91,7 +89,7 @@ public class RuleTesting { } public static RuleDto newCustomRule(RuleDto templateRule){ - return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + new Date().getTime())) + return newDto(RuleKey.of(templateRule.getRepositoryKey(), templateRule.getRuleKey() + "_" + System.currentTimeMillis())) .setTemplateId(templateRule.getId()); } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/delete-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/delete-result.xml index 1f5a52ba71d..3794b036623 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/delete-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/delete-result.xml @@ -16,7 +16,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> @@ -40,7 +40,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -56,7 +56,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -73,7 +73,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> @@ -36,7 +36,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -51,7 +51,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -67,7 +67,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> @@ -84,7 +84,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3.4."/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared.xml index d29c981b67d..4474f2ebdea 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared.xml @@ -16,7 +16,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> @@ -40,7 +40,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -56,7 +56,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -73,7 +73,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared_views.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared_views.xml index eaa1b6de4c0..be3bfa4e5ea 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared_views.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/ComponentDaoTest/shared_views.xml @@ -5,14 +5,14 @@ kee="MASTER_PROJECT" scope="PRJ" qualifier="VW" name="All projects" path="[null]"/> @@ -20,13 +20,13 @@ kee="LANGUAGE_VIEW" scope="PRJ" qualifier="VW" name="By Language" path="[null]"/> @@ -34,14 +34,14 @@ kee="JAVA_PROJECTS" scope="PRJ" qualifier="SVW" name="Java projects" path="[null]"/> @@ -49,7 +49,7 @@ kee="OTHER" scope="PRJ" qualifier="VW" name="Other projects" path="[null]"/> @@ -59,7 +59,7 @@ enabled="[true]" copy_resource_id="[null]" path="[null]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml index 2dfd09d5b68..094c6be6cb4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/insert-result.xml @@ -2,12 +2,12 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml index 12f2f9cd493..9ba70bee6f4 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/modules.xml @@ -12,7 +12,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> @@ -36,7 +36,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -51,7 +51,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -67,7 +67,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> @@ -84,7 +84,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3.4."/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml index b651e75ffc2..a52b271da32 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/shared.xml @@ -2,12 +2,12 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml index 7cfc057296d..4c18e257396 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml @@ -3,63 +3,63 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/AnalysisReportServiceTest/report-folder/snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/AnalysisReportServiceTest/report-folder/snapshots.xml index 965eb1081aa..6bc85fcec05 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/AnalysisReportServiceTest/report-folder/snapshots.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/AnalysisReportServiceTest/report-folder/snapshots.xml @@ -3,147 +3,147 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml index 86714d163a0..f92f776ff1a 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml @@ -3,147 +3,147 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots.xml index 965eb1081aa..6bc85fcec05 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots.xml @@ -3,147 +3,147 @@ diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/before.xml new file mode 100644 index 00000000000..73c4e0e8473 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/before.xml @@ -0,0 +1,61 @@ + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/schema.sql new file mode 100644 index 00000000000..318169c0787 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDatesTest/schema.sql @@ -0,0 +1,18 @@ +CREATE TABLE "SNAPSHOTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "CREATED_AT" TIMESTAMP, + "CREATED_AT_MS" BIGINT, + "BUILD_DATE" TIMESTAMP, + "BUILD_DATE_MS" BIGINT, + "PROJECT_ID" INTEGER NOT NULL, + "PERIOD1_DATE" TIMESTAMP, + "PERIOD1_DATE_MS" BIGINT, + "PERIOD2_DATE" TIMESTAMP, + "PERIOD2_DATE_MS" BIGINT, + "PERIOD3_DATE" TIMESTAMP, + "PERIOD3_DATE_MS" BIGINT, + "PERIOD4_DATE" TIMESTAMP, + "PERIOD4_DATE_MS" BIGINT, + "PERIOD5_DATE" TIMESTAMP, + "PERIOD5_DATE_MS" BIGINT +); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/views.xml b/server/sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/views.xml index 2b6a2036717..8c199a80d8b 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/views.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/filters/FilterExecutorTest/views.xml @@ -20,25 +20,25 @@ - - - - - \ No newline at end of file + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/escape_percent_and_underscore_when_filter_by_component_name_or_key.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/escape_percent_and_underscore_when_filter_by_component_name_or_key.xml index c2e8480b194..81112762aab 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/escape_percent_and_underscore_when_filter_by_component_name_or_key.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/escape_percent_and_underscore_when_filter_by_component_name_or_key.xml @@ -28,7 +28,7 @@ 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]" - created_at="2008-12-20 00:00:00.00" build_date="2008-12-20 00:00:00.00" + created_at="1229727600000" build_date="1229727600000" version="1.0" status="P" islast="[true]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml index fdecec73505..06a16b28952 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_person_measures.xml @@ -14,7 +14,7 @@ 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]" - created_at="2008-12-20 00:00:00.00" build_date="2008-12-20 00:00:00.00" + created_at="1229727600000" build_date="1229727600000" version="1.0" status="P" islast="[true]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml index 005439eeaff..53d8b4876e2 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/ignore_quality_model_measures.xml @@ -14,7 +14,7 @@ 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]" - created_at="2008-12-20 00:00:00.00" build_date="2008-12-20 00:00:00.00" + created_at="1229727600000" build_date="1229727600000" version="1.0" status="P" islast="[true]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml index 346ef1ae1fd..430e1de1a7c 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/shared.xml @@ -50,7 +50,7 @@ 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]" - created_at="2008-12-20 00:00:00.00" build_date="2008-12-20 00:00:00.00" + created_at="1229727600000" build_date="1229727600000" version="1.0" status="P" islast="[true]"/> @@ -139,7 +139,7 @@ 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]" - created_at="2012-12-13 04:06:00.00" build_date="2012-12-13 04:06:00.00" + created_at="1355367960000" build_date="1355367960000" version="3.0" status="P" islast="[true]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml index afcc9f3a1ea..98ef01efcb5 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/measure/MeasureFilterExecutorTest/sort_by_alert.xml @@ -17,7 +17,7 @@ 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]" - created_at="2008-12-20 00:00:00.00" build_date="2008-12-20 00:00:00.00" + created_at="1229727600000" build_date="1229727600000" version="1.0" status="P" islast="[true]"/> @@ -42,7 +42,7 @@ 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]" - created_at="2012-12-13 04:06:00.00" build_date="2012-12-13 04:06:00.00" + created_at="1355367960000" build_date="1355367960000" version="3.0" status="P" islast="[true]"/> @@ -66,7 +66,7 @@ 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]" - created_at="2012-12-13 04:06:00.00" build_date="2012-12-13 04:06:00.00" + created_at="1355367960000" build_date="1355367960000" version="3.0" status="P" islast="[true]"/> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml b/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml index eaa1b6de4c0..be3bfa4e5ea 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/view/index/ViewIndexerTest/index.xml @@ -5,14 +5,14 @@ kee="MASTER_PROJECT" scope="PRJ" qualifier="VW" name="All projects" path="[null]"/> @@ -20,13 +20,13 @@ kee="LANGUAGE_VIEW" scope="PRJ" qualifier="VW" name="By Language" path="[null]"/> @@ -34,14 +34,14 @@ kee="JAVA_PROJECTS" scope="PRJ" qualifier="SVW" name="Java projects" path="[null]"/> @@ -49,7 +49,7 @@ kee="OTHER" scope="PRJ" qualifier="VW" name="Other projects" path="[null]"/> @@ -59,7 +59,7 @@ enabled="[true]" copy_resource_id="[null]" path="[null]"/> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb index bb6189a6fad..ebf29970d09 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb @@ -130,7 +130,7 @@ class Api::EventsController < Api::ApiController if (params[:dateTime]) # try to find a snapshot on that day date = parse_datetime(params[:dateTime], true) - root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ? AND created_at >= ? AND created_at <= ?", @resource.id, date, date + 1.day], :order => :created_at) + root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ? AND created_at >= ? AND created_at <= ?", @resource.id, date.to_i*1000, (date + 1.day).to_i*1000], :order => :created_at) raise "No snapshot exists for given date" unless root_snapshot else root_snapshot = Snapshot.find(:last, :conditions => ["project_id = ?", @resource.id], :order => :created_at) diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb index ec55ef12904..5bcc25b9c4e 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/project_controller.rb @@ -324,7 +324,7 @@ class ProjectController < ApplicationController access_denied unless is_admin?(parent_snapshot) # We update all the related snapshots to have the same version as the next snapshot - next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', parent_snapshot.created_at, parent_snapshot.project_id], :order => 'created_at asc') + next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', parent_snapshot.created_at.to_i*1000, parent_snapshot.project_id], :order => 'created_at asc') snapshots = find_project_snapshots(parent_snapshot.id) snapshots.each do |snapshot| snapshot.version = next_snapshot.version diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb index 52192c35289..3e43cf885f2 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/snapshot.rb @@ -36,6 +36,39 @@ class Snapshot < ActiveRecord::Base STATUS_UNPROCESSED = 'U' STATUS_PROCESSED = 'P' + + def created_at + long_to_date(:created_at) + end + + def build_date + long_to_date(:build_date) + end + + def period1_date + long_to_date(:period1_date) + end + + def period2_date + long_to_date(:period2_date) + end + + def period3_date + long_to_date(:period3_date) + end + + def period4_date + long_to_date(:period4_date) + end + + def period5_date + long_to_date(:period5_date) + end + + def long_to_date(attribute) + date_in_long = read_attribute(attribute) + Time.at(date_in_long/1000) if date_in_long + end def self.for_timemachine_matrix(resource) # http://jira.codehaus.org/browse/SONAR-1850 @@ -185,7 +218,7 @@ class Snapshot < ActiveRecord::Base def self.snapshot_by_date(resource_id, date) if resource_id && date - Snapshot.find(:first, :conditions => ['created_at>=? and created_at 'created_at desc') + Snapshot.find(:first, :conditions => ['created_at>=? and created_at 'created_at desc') else nil end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb new file mode 100644 index 00000000000..389046ff1a8 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/775_add_snapshots_long_dates.rb @@ -0,0 +1,34 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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 this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 5.1 +# +class AddSnapshotsLongDates < ActiveRecord::Migration + def self.up + add_column 'snapshots', :created_at_ms, :big_integer, :null => true + add_column 'snapshots', :build_date_ms, :big_integer, :null => true + add_column 'snapshots', :period1_date_ms, :big_integer, :null => true + add_column 'snapshots', :period2_date_ms, :big_integer, :null => true + add_column 'snapshots', :period3_date_ms, :big_integer, :null => true + add_column 'snapshots', :period4_date_ms, :big_integer, :null => true + add_column 'snapshots', :period5_date_ms, :big_integer, :null => true + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb new file mode 100644 index 00000000000..42e272f7e42 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/776_feed_snapshots_long_dates.rb @@ -0,0 +1,29 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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 this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 5.1 +# +class FeedSnapshotsLongDates < ActiveRecord::Migration + def self.up + execute_java_migration('org.sonar.server.db.migrations.v51.FeedSnapshotsLongDates') + end +end + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb new file mode 100644 index 00000000000..9f35dd50c42 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/777_rename_snapshots_long_dates.rb @@ -0,0 +1,42 @@ +# +# SonarQube, open source software quality management tool. +# Copyright (C) 2008-2014 SonarSource +# mailto:contact AT sonarsource DOT com +# +# SonarQube 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. +# +# SonarQube 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 this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +# +# SonarQube 5.1 +# +class RenameSnapshotsLongDates < ActiveRecord::Migration + def self.up + remove_column 'snapshots', 'created_at' + remove_column 'snapshots', 'build_date' + remove_column 'snapshots', 'period1_date' + remove_column 'snapshots', 'period2_date' + remove_column 'snapshots', 'period3_date' + remove_column 'snapshots', 'period4_date' + remove_column 'snapshots', 'period5_date' + rename_column 'snapshots', 'created_at_ms', 'created_at' + rename_column 'snapshots', 'build_date_ms', 'build_date' + rename_column 'snapshots', 'period1_date_ms', 'period1_date' + rename_column 'snapshots', 'period2_date_ms', 'period2_date' + rename_column 'snapshots', 'period3_date_ms', 'period3_date' + rename_column 'snapshots', 'period4_date_ms', 'period4_date' + rename_column 'snapshots', 'period5_date_ms', 'period5_date' + end +end + diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java index 648b624bfa4..d026bfbb596 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java @@ -38,12 +38,10 @@ import org.sonar.batch.index.DefaultIndex; import javax.annotation.Nullable; import javax.persistence.Query; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; + +import static org.sonar.api.utils.DateUtils.dateToLong; +import static org.sonar.api.utils.DateUtils.longToDate; public class DefaultTimeMachine implements TimeMachine { @@ -71,7 +69,7 @@ public class DefaultTimeMachine implements TimeMachine { Integer characteristicId = model.getCharacteristicId(); Characteristic characteristic = techDebtModel.characteristicById(characteristicId); Measure measure = toMeasure(model, metricById.get(model.getMetricId()), characteristic); - measure.setDate((Date) object[1]); + measure.setDate(longToDate((Long) object[1])); result.add(measure); } return result; @@ -126,15 +124,15 @@ public class DefaultTimeMachine implements TimeMachine { } else if (query.getFrom() != null) { sb.append(" AND s.createdAt>=:from "); - params.put("from", query.getFrom()); + params.put("from", dateToLong(query.getFrom())); } if (query.isToCurrentAnalysis()) { sb.append(" AND s.createdAt<=:to "); - params.put("to", index.getProject().getAnalysisDate()); + params.put("to", dateToLong(index.getProject().getAnalysisDate())); } else if (query.getTo() != null) { sb.append(" AND s.createdAt<=:to "); - params.put("to", query.getTo()); + params.put("to", dateToLong(query.getTo())); } if (query.isOnlyLastAnalysis()) { sb.append(" AND s.last=:last "); diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java index 75b4ce1722c..4447bf9e4b4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectConfigurator.java @@ -31,7 +31,6 @@ import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Project; -import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.System2; @@ -39,13 +38,15 @@ import javax.annotation.Nullable; import java.util.Date; +import static org.sonar.api.utils.DateUtils.formatDateTime; +import static org.sonar.api.utils.DateUtils.longToDate; + public class ProjectConfigurator implements BatchComponent { private static final Logger LOG = LoggerFactory.getLogger(ProjectConfigurator.class); - + private final System2 system2; private DatabaseSession databaseSession; private Settings settings; - private final System2 system2; public ProjectConfigurator(@Nullable DatabaseSession databaseSession, Settings settings, System2 system2) { this.databaseSession = databaseSession; @@ -94,11 +95,12 @@ public class ProjectConfigurator implements BatchComponent { ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true); if (persistedProject != null) { Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true); - if (lastSnapshot != null && !lastSnapshot.getCreatedAt().before(analysisDate)) { + boolean analysisBeforeLastSnapshot = lastSnapshot != null && analysisDate.getTime() <= lastSnapshot.getCreatedAt(); + if (analysisBeforeLastSnapshot) { throw new IllegalArgumentException( "'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" + settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " + - "Latest quality snapshot: '" + DateUtils.formatDateTime(lastSnapshot.getCreatedAt()) + "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAt())) + "'. This property may only be used to rebuild the past in a chronological order."); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java index 378dffff16f..aaaca928970 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java @@ -26,10 +26,11 @@ import org.sonar.api.database.model.Snapshot; import org.sonar.api.utils.DateUtils; import javax.annotation.Nullable; - import java.util.Calendar; import java.util.Date; +import static org.sonar.api.utils.DateUtils.longToDate; + public class PastSnapshot { private int index; @@ -74,7 +75,7 @@ public class PastSnapshot { } public Date getDate() { - return projectSnapshot != null ? projectSnapshot.getCreatedAt() : null; + return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAt()) : null; } public PastSnapshot setMode(String mode) { @@ -111,7 +112,7 @@ public class PastSnapshot { return targetDate; } - public PastSnapshot clonePastSnapshot(){ + public PastSnapshot clonePastSnapshot() { PastSnapshot clone = new PastSnapshot(mode, targetDate, projectSnapshot); clone.setIndex(index); clone.setModeParameter(modeParameter); diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java index 057122d76d6..fbae4382e43 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDate.java @@ -31,6 +31,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import static org.sonar.api.utils.DateUtils.dateToLong; + public class PastSnapshotFinderByDate implements BatchExtension { private DatabaseSession session; @@ -57,12 +59,12 @@ public class PastSnapshotFinderByDate implements BatchExtension { private Snapshot findSnapshot(Integer projectId, Date date) { String hql = "from " + Snapshot.class.getSimpleName() + " where createdAt>=:date AND resourceId=:resourceId AND status=:status AND qualifier<>:lib order by createdAt asc"; List snapshots = session.createQuery(hql) - .setParameter("date", date) - .setParameter("resourceId", projectId) - .setParameter("status", Snapshot.STATUS_PROCESSED) - .setParameter("lib", Qualifiers.LIBRARY) - .setMaxResults(1) - .getResultList(); + .setParameter("date", dateToLong(date)) + .setParameter("resourceId", projectId) + .setParameter("status", Snapshot.STATUS_PROCESSED) + .setParameter("lib", Qualifiers.LIBRARY) + .setMaxResults(1) + .getResultList(); return snapshots.isEmpty() ? null : snapshots.get(0); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java index 07bc1e86342..a3aa8b8387f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByDays.java @@ -30,6 +30,8 @@ import javax.annotation.CheckForNull; import java.util.Date; import java.util.List; +import static org.sonar.api.utils.DateUtils.longToDate; + public class PastSnapshotFinderByDays implements BatchExtension { private DatabaseSession session; @@ -39,14 +41,14 @@ public class PastSnapshotFinderByDays implements BatchExtension { } PastSnapshot findFromDays(Snapshot projectSnapshot, int days) { - Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -days); + Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAt()), -days); String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc"; List snapshots = session.createQuery(hql) - .setParameter("date", projectSnapshot.getCreatedAt()) - .setParameter("resourceId", projectSnapshot.getResourceId()) - .setParameter("status", Snapshot.STATUS_PROCESSED) - .setParameter("lib", Qualifiers.LIBRARY) - .getResultList(); + .setParameter("date", projectSnapshot.getCreatedAt()) + .setParameter("resourceId", projectSnapshot.getResourceId()) + .setParameter("status", Snapshot.STATUS_PROCESSED) + .setParameter("lib", Qualifiers.LIBRARY) + .getResultList(); Snapshot snapshot = getNearestToTarget(snapshots, targetDate); return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, targetDate, snapshot).setModeParameter(String.valueOf(days)); @@ -63,7 +65,7 @@ public class PastSnapshotFinderByDays implements BatchExtension { long bestDistance = Long.MAX_VALUE; Snapshot nearest = null; for (Snapshot snapshot : snapshots) { - long distance = distance(snapshot.getCreatedAt(), targetDate); + long distance = distance(longToDate(snapshot.getCreatedAt()), targetDate); if (distance <= bestDistance) { bestDistance = distance; nearest = snapshot; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java index 750146974af..627e1943b0c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java @@ -30,6 +30,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import static org.sonar.api.utils.DateUtils.longToDate; + public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { private DatabaseSession session; @@ -54,7 +56,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); } Snapshot snapshot = snapshots.get(0); - Date targetDate = snapshot.getCreatedAt(); + Date targetDate = longToDate(snapshot.getCreatedAt()); SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT); return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, targetDate, snapshot).setModeParameter(format.format(targetDate)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java index ca7f9c5ea89..85fc0f855da 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousVersion.java @@ -27,6 +27,8 @@ import org.sonar.api.database.model.Snapshot; import java.util.List; +import static org.sonar.api.utils.DateUtils.longToDate; + public class PastSnapshotFinderByPreviousVersion implements BatchExtension { private final DatabaseSession session; @@ -55,7 +57,7 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension { Event previousVersionEvent = events.get(0); Snapshot snapshot = session.getSingleResult(Snapshot.class, "id", previousVersionEvent.getSnapshot().getId()); - return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshot.getCreatedAt(), snapshot).setModeParameter(snapshot.getVersion()); + return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAt()), snapshot).setModeParameter(snapshot.getVersion()); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java index 050ab1a4b78..3995c2cb69d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByVersion.java @@ -28,6 +28,8 @@ import org.sonar.api.resources.Qualifiers; import java.util.Date; import java.util.List; +import static org.sonar.api.utils.DateUtils.longToDate; + public class PastSnapshotFinderByVersion implements BatchExtension { private final DatabaseSession session; @@ -51,7 +53,7 @@ public class PastSnapshotFinderByVersion implements BatchExtension { result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION); } else { Snapshot snapshot = snapshots.get(0); - Date targetDate = snapshot.getCreatedAt(); + Date targetDate = longToDate(snapshot.getCreatedAt()); result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version); } return result; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java b/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java index 392180d4fb4..9f75d86fcb6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PeriodsDefinition.java @@ -28,11 +28,10 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.batch.ProjectTree; import javax.persistence.Query; - -import java.util.Date; import java.util.List; import static com.google.common.collect.Lists.newLinkedList; +import static org.sonar.api.utils.DateUtils.dateToLong; public class PeriodsDefinition implements BatchComponent { @@ -80,8 +79,8 @@ public class PeriodsDefinition implements BatchComponent { if (projectId != null) { snapshot = new Snapshot(); snapshot.setResourceId(projectId.intValue()); - snapshot.setCreatedAt(projectTree.getRootProject().getAnalysisDate()); - snapshot.setBuildDate(new Date()); + snapshot.setCreatedAt(dateToLong(projectTree.getRootProject().getAnalysisDate())); + snapshot.setBuildDate(System.currentTimeMillis()); snapshot.setVersion(projectTree.getRootProject().getAnalysisVersion()); } return snapshot; diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java index f5685852497..28c4957d89f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/TimeMachineConfiguration.java @@ -19,21 +19,20 @@ */ package org.sonar.batch.components; -import org.sonar.api.batch.RequiresDB; - import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.BatchComponent; +import org.sonar.api.batch.RequiresDB; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; import org.sonar.api.resources.Qualifiers; import javax.annotation.CheckForNull; - import java.util.List; import static com.google.common.collect.Lists.newLinkedList; +import static org.sonar.api.utils.DateUtils.longToDate; @RequiresDB public class TimeMachineConfiguration implements BatchComponent { @@ -61,7 +60,7 @@ public class TimeMachineConfiguration implements BatchComponent { PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot(); modulePastSnapshots.add(pastSnapshot); // When no snapshot is found, date of the period is null - periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? snapshot.getCreatedAt() : null)); + periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAt()) : null)); log(pastSnapshot); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java index d4a56676b58..7373053e2c0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java @@ -24,13 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Language; -import org.sonar.api.resources.Library; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.api.resources.Scopes; +import org.sonar.api.resources.*; import org.sonar.api.security.ResourcePermissions; import org.sonar.api.utils.SonarException; import org.sonar.api.utils.internal.Uuids; @@ -40,10 +34,11 @@ import org.sonar.core.component.ScanGraph; import javax.annotation.Nullable; import javax.persistence.NonUniqueResultException; import javax.persistence.Query; - import java.util.Date; import java.util.List; +import static org.sonar.api.utils.DateUtils.dateToLong; + public class ResourcePersister implements ScanPersister { private static final String RESOURCE_ID = "resourceId"; @@ -140,8 +135,8 @@ public class ResourcePersister implements ScanPersister { Snapshot snapshot = new Snapshot(model, parentSnapshot); snapshot.setVersion(project.getAnalysisVersion()); - snapshot.setCreatedAt(project.getAnalysisDate()); - snapshot.setBuildDate(new Date()); + snapshot.setCreatedAt(dateToLong(project.getAnalysisDate())); + snapshot.setBuildDate(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); @@ -175,8 +170,8 @@ public class ResourcePersister implements ScanPersister { Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion()); if (snapshot == null) { snapshot = new Snapshot(model, null); - snapshot.setCreatedAt(analysisDate); - snapshot.setBuildDate(new Date()); + snapshot.setCreatedAt(dateToLong(analysisDate)); + snapshot.setBuildDate(System.currentTimeMillis()); snapshot.setVersion(library.getVersion()); snapshot.setStatus(Snapshot.STATUS_PROCESSED); @@ -224,7 +219,7 @@ public class ResourcePersister implements ScanPersister { } Snapshot snapshot = new Snapshot(model, parentSnapshot); - snapshot.setBuildDate(new Date()); + snapshot.setBuildDate(System.currentTimeMillis()); snapshot = session.save(snapshot); session.commit(); return snapshot; diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java index 87cc1f19954..a4c455178f9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java @@ -41,13 +41,14 @@ import org.sonar.batch.rule.ModuleQProfiles; import javax.annotation.CheckForNull; import javax.persistence.NoResultException; import javax.persistence.Query; - import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import static org.sonar.api.utils.DateUtils.longToDate; + public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoader { private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectRepositoriesLoader.class); @@ -169,7 +170,7 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad jpaQuery.setParameter(entry.getKey(), entry.getValue()); } try { - return (Date) jpaQuery.getSingleResult(); + return longToDate((Long) jpaQuery.getSingleResult()); } catch (NoResultException e) { return null; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java index d07a94a44d8..c13593a9bba 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectConfiguratorTest.java @@ -28,7 +28,6 @@ import org.sonar.api.utils.System2; import org.sonar.jpa.test.AbstractDbUnitTestCase; import java.text.SimpleDateFormat; -import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -46,7 +45,7 @@ public class ProjectConfiguratorTest extends AbstractDbUnitTestCase { @Test public void analysis_is_today_by_default() { - Long now = new Date().getTime(); + Long now = System.currentTimeMillis(); when(system2.now()).thenReturn(now); Project project = new Project("key"); diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java index 096a3d6180b..44b69304b45 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java @@ -107,7 +107,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase { private Snapshot newSnapshot(int id, String date) throws ParseException { Snapshot snapshot = new Snapshot(); snapshot.setId(id); - snapshot.setCreatedAt(dateFormat.parse(date)); + snapshot.setCreatedAt(dateFormat.parse(date).getTime()); return snapshot; } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java index 7f914256695..f821e63057f 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java @@ -27,6 +27,7 @@ import org.mockito.MockitoAnnotations; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; +import org.sonar.api.utils.DateUtils; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -145,10 +146,9 @@ public class PastSnapshotFinderTest { @Test public void should_find_by_previous_analysis() throws ParseException { - final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - final Date date = format.parse("2010-05-18"); + final Date date = DateUtils.parseDate("2010-05-18"); Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAt(date); + snapshot.setCreatedAt(date.getTime()); when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot)); PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); @@ -175,7 +175,7 @@ public class PastSnapshotFinderTest { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); final Date date = format.parse("2010-05-18"); Snapshot snapshot = new Snapshot(); - snapshot.setCreatedAt(date); + snapshot.setCreatedAt(date.getTime()); when(finderByPreviousVersion.findByPreviousVersion(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, date, snapshot)); PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java index 26fcd948d18..4113cfc069c 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java @@ -32,7 +32,7 @@ public class PastSnapshotTest { @Test public void test_some_setters_and_getters() { - Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAt(new Date()); + Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAt(System.currentTimeMillis()); snapshot.setId(10); PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), snapshot) @@ -57,7 +57,7 @@ public class PastSnapshotTest { @Test public void testToStringForVersion() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAt(new Date())).setModeParameter("2.3"); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("2.3"); assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3"); } @@ -75,7 +75,7 @@ public class PastSnapshotTest { @Test public void testToStringForNumberOfDaysWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAt(new Date())).setModeParameter("30"); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("30"); assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days ("); } @@ -87,13 +87,13 @@ public class PastSnapshotTest { @Test public void testToStringForDateWithSnapshot() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAt(new Date())); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())); assertThat(pastSnapshot.toString()).startsWith("Compare to date "); } @Test public void testToStringForPreviousAnalysis() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAt(new Date())); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())); assertThat(pastSnapshot.toString()).startsWith("Compare to previous analysis "); } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/DefaultTimeMachineTest/loadMeasuresFromDate.xml b/sonar-batch/src/test/resources/org/sonar/batch/DefaultTimeMachineTest/loadMeasuresFromDate.xml index fef06b0f60d..a66341b5366 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/DefaultTimeMachineTest/loadMeasuresFromDate.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/DefaultTimeMachineTest/loadMeasuresFromDate.xml @@ -13,20 +13,20 @@ - - - - @@ -62,4 +62,4 @@ RULE_ID="[null]" text_value="[null]" tendency="[null]" measure_date="[null]" project_id="[null]" alert_status="[null]" description="[null]"/> - \ No newline at end of file + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/fail_if_not_latest_analysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/fail_if_not_latest_analysis.xml index 6658daa1b47..27d0ef4bac0 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/fail_if_not_latest_analysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/fail_if_not_latest_analysis.xml @@ -5,11 +5,11 @@ description="[null]" enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/> - - \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis.xml index de187166907..06e7901251a 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis.xml @@ -5,11 +5,11 @@ description="[null]" enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/> - - \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis_if_never_analysed.xml b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis_if_never_analysed.xml index a26c76aa43a..4879a225eec 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis_if_never_analysed.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/ProjectConfiguratorTest/set_analysis_date_on_latest_analysis_if_never_analysed.xml @@ -6,7 +6,7 @@ description="[null]" enabled="true" language="java" copy_resource_id="[null]" person_id="[null]"/> - \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml index 04dff250c1f..eb661e9f02b 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastMeasuresLoaderTest/shared.xml @@ -35,15 +35,15 @@ diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml index 2d07a1dda77..d794c3a2422 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDateTest/shared.xml @@ -9,34 +9,34 @@ - \ No newline at end of file + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml index 4a2fc84eb3c..119f7399b4d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shared.xml @@ -21,56 +21,56 @@ - \ No newline at end of file + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml index a62a55c49dd..166f7c18ea8 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByDaysTest/shouldNotFindSelf.xml @@ -21,14 +21,14 @@ \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml index f6e905101a6..eb5136dc808 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldFindPreviousAnalysis.xml @@ -7,20 +7,20 @@ \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml index 3c1bad25f37..5809598e5d7 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest/shouldNotFindPreviousAnalysis.xml @@ -9,13 +9,13 @@ \ No newline at end of file diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml index eca7da3d444..2f01f86b989 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml @@ -9,25 +9,25 @@ diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml index 98c40a5fc53..289a362f781 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/PastSnapshotFinderByVersionTest/shared.xml @@ -9,34 +9,34 @@ - \ No newline at end of file + diff --git a/sonar-batch/src/test/resources/org/sonar/batch/components/TimeMachineConfigurationTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/components/TimeMachineConfigurationTest/shared.xml index 2d267fb2963..c7713445479 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/components/TimeMachineConfigurationTest/shared.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/components/TimeMachineConfigurationTest/shared.xml @@ -3,13 +3,13 @@ diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml index 9b7ee4aad2e..32f00a7d0d8 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml @@ -6,12 +6,12 @@ diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml index 81d3d953079..fb8b855c622 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" created_at="[null]" path="[null]" deprecated_kee="foo"/> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveCopyProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveCopyProject-result.xml index 833ebcd5438..3142a88d3f3 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveCopyProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveCopyProject-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> @@ -16,7 +16,7 @@ enabled="true" language="[null]" copy_resource_id="10" person_id="[null]" path="[null]" deprecated_kee="foo" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml index 4ac03aed376..509c84c797e 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewDirectory-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> @@ -20,11 +20,11 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/foo" deprecated_kee="[null]" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml index 1f2478a3fc3..1fa430d877b 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewLibrary-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> @@ -20,15 +20,15 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" deprecated_kee="[null]" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml index f25ce3cbece..bed6ddbad3d 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProject-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> @@ -35,27 +35,27 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml index c16c139570f..86b94e27622 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewMultiModulesProjectAndLibrary-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key" /> @@ -35,31 +35,31 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="src/main/java/org/Foo.java" deprecated_kee="[null]" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml index 7b0e006507a..2f047d09640 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldSaveNewProject-result.xml @@ -6,7 +6,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="my:key"/> @@ -16,7 +16,7 @@ enabled="true" language="[null]" copy_resource_id="[null]" person_id="[null]" path="[null]" deprecated_kee="foo" /> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml index 14edf7cb5fa..b38cce164ff 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource-result.xml @@ -6,12 +6,12 @@ diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml index 674397123dd..859be16f7fd 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ResourcePersisterTest/shouldUpdateExistingResource.xml @@ -5,7 +5,7 @@ enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]" /> diff --git a/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java index a9b5aaa5a56..c575cc58f0d 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java +++ b/sonar-core/src/main/java/org/sonar/core/component/SnapshotDto.java @@ -19,11 +19,7 @@ */ package org.sonar.core.component; -import org.sonar.core.persistence.Dto; - -import java.util.Date; - -public final class SnapshotDto extends Dto { +public final class SnapshotDto { /** * This status is set on the snapshot at the beginning of the batch @@ -38,7 +34,8 @@ public final class SnapshotDto extends Dto { private Long rootId; private Long rootProjectId; - private Date buildDate; + private Long createdAt; + private Long buildDate; private Long resourceId; private String status = STATUS_UNPROCESSED; private Integer purgeStatus; @@ -61,11 +58,11 @@ public final class SnapshotDto extends Dto { private String period4Param; private String period5Param; - private Date period1Date; - private Date period2Date; - private Date period3Date; - private Date period4Date; - private Date period5Date; + private Long period1Date; + private Long period2Date; + private Long period3Date; + private Long period4Date; + private Long period5Date; public Long getId() { return id; @@ -94,11 +91,11 @@ public final class SnapshotDto extends Dto { return this; } - public Date getBuildDate() { + public Long getBuildDate() { return buildDate; } - public SnapshotDto setBuildDate(Date buildDate) { + public SnapshotDto setBuildDate(Long buildDate) { this.buildDate = buildDate; return this; } @@ -273,22 +270,22 @@ public final class SnapshotDto extends Dto { } } - public SnapshotDto setPeriodDate(int index, Date d) { + public SnapshotDto setPeriodDate(int index, Long date) { switch (index) { case 1: - period1Date = d; + period1Date = date; break; case 2: - period2Date = d; + period2Date = date; break; case 3: - period3Date = d; + period3Date = date; break; case 4: - period4Date = d; + period4Date = date; break; case 5: - period5Date = d; + period5Date = date; break; default: throw new IndexOutOfBoundsException(INDEX_SHOULD_BE_IN_RANGE_FROM_1_TO_5); @@ -296,7 +293,7 @@ public final class SnapshotDto extends Dto { return this; } - public Date getPeriodDate(int periodIndex) { + public Long getPeriodDate(int periodIndex) { switch (periodIndex) { case 1: return period1Date; @@ -313,21 +310,17 @@ public final class SnapshotDto extends Dto { } } - @Override public Long getKey() { return id; } - @Override - public SnapshotDto setCreatedAt(Date datetime) { - super.setCreatedAt(datetime); + public SnapshotDto setCreatedAt(Long createdAt) { + this.createdAt = createdAt; return this; } - @Override - public SnapshotDto setUpdatedAt(Date datetime) { - super.setUpdatedAt(datetime); - return this; + public Long getCreatedAt() { + return createdAt; } public Long getRootIdOrSelf() { diff --git a/sonar-core/src/main/java/org/sonar/core/component/db/SnapshotMapper.java b/sonar-core/src/main/java/org/sonar/core/component/db/SnapshotMapper.java index 31e36878ec9..865f3bc66bf 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/db/SnapshotMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/component/db/SnapshotMapper.java @@ -24,8 +24,6 @@ import org.apache.ibatis.annotations.Param; import org.sonar.core.component.SnapshotDto; import javax.annotation.CheckForNull; - -import java.util.Date; import java.util.List; public interface SnapshotMapper { @@ -33,13 +31,13 @@ public interface SnapshotMapper { @CheckForNull SnapshotDto selectByKey(long id); - void insert(SnapshotDto rule); + void insert(SnapshotDto snapshot); @CheckForNull SnapshotDto selectLastSnapshot(Long resourceId); @CheckForNull - SnapshotDto selectLastSnapshotOlderThan(@Param(value = "resource") Long resourceId, @Param(value = "createdAt") Date createdAtBefore); + SnapshotDto selectLastSnapshotOlderThan(@Param(value = "resource") Long resourceId, @Param(value = "createdAt") Long createdAtBefore); List selectSnapshotAndChildrenOfScope(@Param(value = "snapshot") Long resourceId, @Param(value = "scope") String scope); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index e4ae4e1364d..6b07dd2255e 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 774; + public static final int LAST_VERSION = 777; /** * List of all the tables.n diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java index f86b2e983b5..23acb6fa52a 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeableSnapshotDto.java @@ -46,7 +46,8 @@ public class PurgeableSnapshotDto implements Comparable { return isLast; } - public PurgeableSnapshotDto setDate(Date date) { + public PurgeableSnapshotDto setDate(Long aLong) { + Date date = aLong == null ? null : new Date(aLong); this.date = date; return this; } @@ -85,7 +86,7 @@ public class PurgeableSnapshotDto implements Comparable { @Override public int hashCode() { - return (int)snapshotId; + return (int) snapshotId; } @Override diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index 5c7b90def56..e37ceea8732 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -19,24 +19,24 @@ */ package org.sonar.core.timemachine; -import org.sonar.api.batch.RequiresDB; - import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchComponent; import org.sonar.api.CoreProperties; import org.sonar.api.ServerComponent; +import org.sonar.api.batch.RequiresDB; import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import static org.sonar.api.utils.DateUtils.longToDate; + @RequiresDB public class Periods implements BatchComponent, ServerComponent { @@ -50,12 +50,12 @@ public class Periods implements BatchComponent, ServerComponent { @CheckForNull public String label(Snapshot snapshot, int periodIndex) { - return label(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), snapshot.getPeriodDate(periodIndex)); + return label(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDate(periodIndex))); } @CheckForNull public String abbreviation(Snapshot snapshot, int periodIndex) { - return abbreviation(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), snapshot.getPeriodDate(periodIndex)); + return abbreviation(snapshot.getPeriodMode(periodIndex), snapshot.getPeriodModeParameter(periodIndex), longToDate(snapshot.getPeriodDate(periodIndex))); } @CheckForNull diff --git a/sonar-core/src/main/resources/org/sonar/core/component/db/SnapshotMapper.xml b/sonar-core/src/main/resources/org/sonar/core/component/db/SnapshotMapper.xml index c0112194bcf..87b79d2b104 100644 --- a/sonar-core/src/main/resources/org/sonar/core/component/db/SnapshotMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/component/db/SnapshotMapper.xml @@ -88,7 +88,7 @@ where root_snapshot_id=#{root} or id=#{root} or (path like #{path} and root_snapshot_id=#{pathRootId}) - + insert into snapshots values (#{parentId}, #{rootId}, #{rootProjectId}, #{resourceId}, #{createdAt}, #{buildDate}, #{status}, diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 0c3b77d2bcf..4a9a586cb1c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -303,6 +303,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('771'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('772'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('773'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('774'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('775'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('776'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('777'); 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', '1418215735482', '1418215735482', null, null); ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index d30b14e1a78..06133faa160 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -79,8 +79,8 @@ CREATE TABLE "GROUPS" ( CREATE TABLE "SNAPSHOTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), - "CREATED_AT" TIMESTAMP, - "BUILD_DATE" TIMESTAMP, + "CREATED_AT" BIGINT, + "BUILD_DATE" BIGINT, "PROJECT_ID" INTEGER NOT NULL, "PARENT_SNAPSHOT_ID" INTEGER, "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U', @@ -95,19 +95,19 @@ CREATE TABLE "SNAPSHOTS" ( "ROOT_PROJECT_ID" INTEGER, "PERIOD1_MODE" VARCHAR(100), "PERIOD1_PARAM" VARCHAR(100), - "PERIOD1_DATE" TIMESTAMP, + "PERIOD1_DATE" BIGINT, "PERIOD2_MODE" VARCHAR(100), "PERIOD2_PARAM" VARCHAR(100), - "PERIOD2_DATE" TIMESTAMP, + "PERIOD2_DATE" BIGINT, "PERIOD3_MODE" VARCHAR(100), "PERIOD3_PARAM" VARCHAR(100), - "PERIOD3_DATE" TIMESTAMP, + "PERIOD3_DATE" BIGINT, "PERIOD4_MODE" VARCHAR(100), "PERIOD4_PARAM" VARCHAR(100), - "PERIOD4_DATE" TIMESTAMP, + "PERIOD4_DATE" BIGINT, "PERIOD5_MODE" VARCHAR(100), "PERIOD5_PARAM" VARCHAR(100), - "PERIOD5_DATE" TIMESTAMP + "PERIOD5_DATE" BIGINT ); CREATE TABLE "SCHEMA_MIGRATIONS" ( diff --git a/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java b/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java index 13ed081c220..4004701d103 100644 --- a/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/component/SnapshotDtoTest.java @@ -21,9 +21,9 @@ package org.sonar.core.component; import org.junit.Test; -import org.sonar.api.utils.DateUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.utils.DateUtils.parseDate; public class SnapshotDtoTest { @@ -34,7 +34,7 @@ public class SnapshotDtoTest { .setParentId(2L) .setRootId(3L) .setRootProjectId(20L) - .setBuildDate(DateUtils.parseDate("2014-07-02")) + .setBuildDate(parseDate("2014-07-02").getTime()) .setResourceId(21L) .setLast(true) .setScope("FIL") @@ -52,18 +52,18 @@ public class SnapshotDtoTest { .setPeriodParam(3, "param3") .setPeriodParam(4, "param4") .setPeriodParam(5, "param5") - .setPeriodDate(1, DateUtils.parseDate("2014-06-01")) - .setPeriodDate(2, DateUtils.parseDate("2014-06-02")) - .setPeriodDate(3, DateUtils.parseDate("2014-06-03")) - .setPeriodDate(4, DateUtils.parseDate("2014-06-04")) - .setPeriodDate(5, DateUtils.parseDate("2014-06-05")); + .setPeriodDate(1, parseDate("2014-06-01").getTime()) + .setPeriodDate(2, parseDate("2014-06-02").getTime()) + .setPeriodDate(3, parseDate("2014-06-03").getTime()) + .setPeriodDate(4, parseDate("2014-06-04").getTime()) + .setPeriodDate(5, parseDate("2014-06-05").getTime()); assertThat(snapshotDto.getId()).isEqualTo(10L); assertThat(snapshotDto.getKey()).isEqualTo(10L); assertThat(snapshotDto.getParentId()).isEqualTo(2L); assertThat(snapshotDto.getRootId()).isEqualTo(3L); assertThat(snapshotDto.getRootProjectId()).isEqualTo(20L); - assertThat(snapshotDto.getBuildDate()).isEqualTo(DateUtils.parseDate("2014-07-02")); + assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime()); assertThat(snapshotDto.getResourceId()).isEqualTo(21L); assertThat(snapshotDto.getLast()).isTrue(); assertThat(snapshotDto.getScope()).isEqualTo("FIL"); @@ -81,11 +81,11 @@ public class SnapshotDtoTest { assertThat(snapshotDto.getPeriodModeParameter(3)).isEqualTo("param3"); assertThat(snapshotDto.getPeriodModeParameter(4)).isEqualTo("param4"); assertThat(snapshotDto.getPeriodModeParameter(5)).isEqualTo("param5"); - assertThat(snapshotDto.getPeriodDate(1)).isEqualTo(DateUtils.parseDate("2014-06-01")); - assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2014-06-02")); - assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2014-06-03")); - assertThat(snapshotDto.getPeriodDate(4)).isEqualTo(DateUtils.parseDate("2014-06-04")); - assertThat(snapshotDto.getPeriodDate(5)).isEqualTo(DateUtils.parseDate("2014-06-05")); + assertThat(snapshotDto.getPeriodDate(1)).isEqualTo(parseDate("2014-06-01").getTime()); + assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(parseDate("2014-06-02").getTime()); + assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(parseDate("2014-06-03").getTime()); + assertThat(snapshotDto.getPeriodDate(4)).isEqualTo(parseDate("2014-06-04").getTime()); + assertThat(snapshotDto.getPeriodDate(5)).isEqualTo(parseDate("2014-06-05").getTime()); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DbCleanerTestUtils.java b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DbCleanerTestUtils.java index 392e58c0f0b..0097b01a98c 100644 --- a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DbCleanerTestUtils.java +++ b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/DbCleanerTestUtils.java @@ -31,14 +31,14 @@ public final class DbCleanerTestUtils { public static PurgeableSnapshotDto createSnapshotWithDate(long snapshotId, String date) { PurgeableSnapshotDto snapshot = new PurgeableSnapshotDto(); snapshot.setSnapshotId(snapshotId); - snapshot.setDate(DateUtils.parseDate(date)); + snapshot.setDate(DateUtils.parseDate(date).getTime()); return snapshot; } public static PurgeableSnapshotDto createSnapshotWithDateTime(long snapshotId, String datetime) { PurgeableSnapshotDto snapshot = new PurgeableSnapshotDto(); snapshot.setSnapshotId(snapshotId); - snapshot.setDate(DateUtils.parseDateTime(datetime)); + snapshot.setDate(DateUtils.parseDateTime(datetime).getTime()); return snapshot; } diff --git a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleanerTest.java b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleanerTest.java index 759dac500af..3ca99a4b668 100644 --- a/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleanerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/computation/dbcleaner/period/DefaultPeriodCleanerTest.java @@ -27,6 +27,7 @@ import org.mockito.ArgumentMatcher; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.sonar.api.config.Settings; +import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import org.sonar.core.purge.PurgeDao; @@ -34,15 +35,11 @@ import org.sonar.core.purge.PurgeSnapshotQuery; import org.sonar.core.purge.PurgeableSnapshotDto; import java.util.Arrays; -import java.util.Date; import static org.mockito.Matchers.anyListOf; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class DefaultPeriodCleanerTest { @@ -51,7 +48,7 @@ public class DefaultPeriodCleanerTest { PurgeDao dao = mock(PurgeDao.class); DbSession session = mock(DbSession.class); when(dao.selectPurgeableSnapshots(123L, session)).thenReturn(Arrays.asList( - new PurgeableSnapshotDto().setSnapshotId(999L).setDate(new Date()))); + new PurgeableSnapshotDto().setSnapshotId(999L).setDate(System2.INSTANCE.now()))); Filter filter1 = newLazyFilter(); Filter filter2 = newLazyFilter(); diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index e97cfa1d868..ef6948a8c21 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -430,11 +430,11 @@ public class ResourceDaoTest extends AbstractDaoTestCase { assertThat(snapshotDto.getPeriodMode(2)).isEqualTo("days"); assertThat(snapshotDto.getPeriodModeParameter(2)).isEqualTo("30"); - assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2011-09-24")); + assertThat(snapshotDto.getPeriodDate(2)).isEqualTo(DateUtils.parseDate("2011-09-24").getTime()); assertThat(snapshotDto.getPeriodMode(3)).isEqualTo("days"); assertThat(snapshotDto.getPeriodModeParameter(3)).isEqualTo("90"); - assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2011-07-26")); + assertThat(snapshotDto.getPeriodDate(3)).isEqualTo(DateUtils.parseDate("2011-07-26").getTime()); assertThat(snapshotDto.getPeriodMode(4)).isEqualTo("previous_analysis"); assertThat(snapshotDto.getPeriodModeParameter(4)).isNull(); diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index b7fd67c71df..527f4bbacdd 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -25,8 +25,8 @@ import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; +import org.sonar.api.utils.System2; -import java.util.Date; import java.util.Locale; import static org.mockito.Matchers.any; @@ -63,7 +63,7 @@ public class PeriodsTest { @Test public void label_of_duration_in_days() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System2.INSTANCE.now()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); @@ -73,7 +73,7 @@ public class PeriodsTest { @Test public void abbreviation_of_duration_in_days() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); @@ -83,7 +83,7 @@ public class PeriodsTest { @Test public void label_of_snapshot_version() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); @@ -93,7 +93,7 @@ public class PeriodsTest { @Test public void abbreviation_of_snapshot_version() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); @@ -103,7 +103,7 @@ public class PeriodsTest { @Test public void label_of_previous_analysis_with_date() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); periods.label(snapshot, periodIndex); verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed"), isNull(String.class), anyString()); @@ -122,7 +122,7 @@ public class PeriodsTest { @Test public void abbreviation_of_previous_analysis_with_date() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); periods.abbreviation(snapshot, periodIndex); verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed.short"), isNull(String.class), anyString()); @@ -151,7 +151,7 @@ public class PeriodsTest { public void label_of_previous_version_with_param_and_date() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); periods.label(snapshot, periodIndex); verify(i18n).message(any(Locale.class), eq("since_previous_version_detailed"), isNull(String.class), eq(param), anyString()); @@ -169,7 +169,7 @@ public class PeriodsTest { @Test public void shouldReturnSnapshotLabelInModeDate() { when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DATE); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(System.currentTimeMillis()); periods.label(snapshot, periodIndex); diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/should_create_database.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/should_create_database.xml index 13aee7d5de4..060dbfb065b 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/should_create_database.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/PreviewDatabaseFactoryTest/should_create_database.xml @@ -17,7 +17,7 @@ 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]" - created_at="2013-01-25 02:04:06.00" build_date="2013-01-25 02:04:06.00" + created_at="1359075846000" build_date="1359075846000" version="1.0" status="P" islast="[true]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml index e7d92671489..8912afe10d4 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteResource.xml @@ -11,8 +11,8 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> @@ -59,8 +59,8 @@ Note that measures, events and reviews are not deleted. 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/disable_resources_without_last_snapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/disable_resources_without_last_snapshot-result.xml index d086991945a..b996557dd58 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/disable_resources_without_last_snapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/disable_resources_without_last_snapshot-result.xml @@ -37,8 +37,8 @@ What has been changed : 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml index 62cff84cd84..346e3d61b94 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml @@ -19,7 +19,7 @@ Snapshot 2 has been deleted 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> @@ -30,7 +30,7 @@ Snapshot 2 has been deleted - + + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml index 5c9aeaa6580..ef09ea6795d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml @@ -14,7 +14,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml index 2eb2c7033bc..3ae58b4fe94 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml @@ -30,7 +30,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> @@ -72,7 +72,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 - + @@ -83,6 +83,6 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 - + diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml index 87fcbb6f98a..b3449c545fe 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml @@ -24,7 +24,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="DIR" qualifier="DIR" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="FIL" qualifier="FIL" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml index a356e56fcf4..3d6f4e67009 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteProject.xml @@ -14,8 +14,8 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> @@ -82,8 +82,8 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" - build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> @@ -100,8 +100,8 @@ 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="FIL" qualifier="FIL" created_at="2008-12-02 13:58:00.00" - build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="FIL" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml index 60a2a3878a8..50d28695d3f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots-result.xml @@ -9,7 +9,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/>--> \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots.xml index cc7f1c6319a..d5ff7433484 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldDeleteSnapshots.xml @@ -9,7 +9,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> - \ No newline at end of file + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml index f79043727a5..aca3885c1db 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject-result.xml @@ -16,7 +16,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> @@ -28,7 +28,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml index c6f3169fec1..bbc7fb8b041 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldPurgeProject.xml @@ -16,7 +16,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> @@ -28,7 +28,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml index bd873bcdc57..f3a3b9bd0b3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml @@ -9,7 +9,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_all_closed_issues.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_all_closed_issues.xml index 7a35c7132e9..38c9c3ec360 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_all_closed_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_all_closed_issues.xml @@ -13,8 +13,8 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" + build_date="1228222680000" version="[null]" path="[null]"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml index 86284fe0b2a..1095715f65f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeDaoTest/should_delete_old_closed_issues-result.xml @@ -12,7 +12,7 @@ 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]"/> + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> @@ -36,7 +36,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -52,7 +52,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -69,7 +69,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> @@ -90,7 +90,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> @@ -121,7 +121,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml index f54bf533dcd..a28333eaa91 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml @@ -17,7 +17,7 @@ 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" + depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path=""/> @@ -42,7 +42,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -59,7 +59,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -77,7 +77,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/get_last_snapshot_by_component_uuid.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/get_last_snapshot_by_component_uuid.xml index f62fdee69b5..5ffea4fe62e 100644 --- a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/get_last_snapshot_by_component_uuid.xml +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/get_last_snapshot_by_component_uuid.xml @@ -12,11 +12,11 @@ @@ -40,7 +40,7 @@ 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="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="PRJ" qualifier="BRC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1."/> @@ -56,7 +56,7 @@ 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="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="DIR" qualifier="PAC" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2."/> @@ -73,7 +73,7 @@ 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="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00" + depth="[null]" scope="FIL" qualifier="CLA" created_at="1228222680000" build_date="1228222680000" version="[null]" path="1.2.3."/> diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java index edafda1b3c8..406161ed758 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java @@ -23,13 +23,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.BaseIdentifiable; import org.sonar.api.database.model.Snapshot; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - +import javax.persistence.*; import java.util.Date; /** @@ -131,7 +125,7 @@ public class Event extends BaseIdentifiable { public final void setSnapshot(Snapshot snapshot) { this.snapshot = snapshot; if (snapshot != null) { - this.date = snapshot.getCreatedAt(); + this.date = (snapshot.getCreatedAt() == null ? null : new Date(snapshot.getCreatedAt())); this.resourceId = snapshot.getResourceId(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java index 0912b7d6675..347690a8a21 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java @@ -29,9 +29,6 @@ import org.sonar.api.database.DatabaseSession; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - import java.io.Serializable; import java.util.Date; @@ -55,13 +52,11 @@ public class Snapshot extends BaseIdentifiable implements Serializable @Column(name = "project_id", updatable = true, nullable = true) private Integer resourceId; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "build_date", updatable = true, nullable = true) - private Date buildDate; + private Long buildDate; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at", updatable = true, nullable = true) - private Date createdAt; + private Long createdAt; @Column(name = "version", updatable = true, nullable = true, length = 500) private String version; @@ -127,19 +122,19 @@ public class Snapshot extends BaseIdentifiable implements Serializable private String period5Param; @Column(name = "period1_date", updatable = true, nullable = true) - private Date period1Date; + private Long period1Date; @Column(name = "period2_date", updatable = true, nullable = true) - private Date period2Date; + private Long period2Date; @Column(name = "period3_date", updatable = true, nullable = true) - private Date period3Date; + private Long period3Date; @Column(name = "period4_date", updatable = true, nullable = true) - private Date period4Date; + private Long period4Date; @Column(name = "period5_date", updatable = true, nullable = true) - private Date period5Date; + private Long period5Date; public Snapshot() { @@ -153,7 +148,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable if (parent == null) { path = ""; depth = 0; - this.createdAt = new Date(); + this.createdAt = System.currentTimeMillis(); } else { this.parentId = parent.getId(); @@ -188,7 +183,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable setResource(resource); this.status = status; this.last = last; - this.createdAt = date; + this.createdAt = date.getTime(); } /** @@ -196,7 +191,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.14 */ - public Date getBuildDate() { + public Long getBuildDate() { return buildDate; } @@ -205,16 +200,16 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.14 */ - public Snapshot setBuildDate(Date d) { + public Snapshot setBuildDate(Long d) { this.buildDate = d; return this; } - public Date getCreatedAt() { + public Long getCreatedAt() { return createdAt; } - public Snapshot setCreatedAt(Date createdAt) { + public Snapshot setCreatedAt(Long createdAt) { this.createdAt = createdAt; return this; } @@ -279,8 +274,8 @@ public class Snapshot extends BaseIdentifiable implements Serializable } /** - * @since 2.14 - */ + * @since 2.14 + */ public Snapshot setPurgeStatus(Integer i) { this.purgeStatus = i; return this; @@ -487,7 +482,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable return this; } - public Date getPeriod1Date() { + public Long getPeriod1Date() { return period1Date; } @@ -496,12 +491,12 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod1Date(Date period1Date) { + public Snapshot setPeriod1Date(Long period1Date) { this.period1Date = period1Date; return this; } - public Date getPeriod2Date() { + public Long getPeriod2Date() { return period2Date; } @@ -510,12 +505,12 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod2Date(Date period2Date) { + public Snapshot setPeriod2Date(Long period2Date) { this.period2Date = period2Date; return this; } - public Date getPeriod3Date() { + public Long getPeriod3Date() { return period3Date; } @@ -524,12 +519,12 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod3Date(Date period3Date) { + public Snapshot setPeriod3Date(Long period3Date) { this.period3Date = period3Date; return this; } - public Date getPeriod4Date() { + public Long getPeriod4Date() { return period4Date; } @@ -538,12 +533,12 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod4Date(Date period4Date) { + public Snapshot setPeriod4Date(Long period4Date) { this.period4Date = period4Date; return this; } - public Date getPeriod5Date() { + public Long getPeriod5Date() { return period5Date; } @@ -552,7 +547,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriod5Date(Date period5Date) { + public Snapshot setPeriod5Date(Long period5Date) { this.period5Date = period5Date; return this; } @@ -652,22 +647,22 @@ public class Snapshot extends BaseIdentifiable implements Serializable * * @since 2.5 */ - public Snapshot setPeriodDate(int periodIndex, Date d) { + public Snapshot setPeriodDate(int periodIndex, Long date) { switch (periodIndex) { case 1: - period1Date = d; + period1Date = date; break; case 2: - period2Date = d; + period2Date = date; break; case 3: - period3Date = d; + period3Date = date; break; case 4: - period4Date = d; + period4Date = date; break; case 5: - period5Date = d; + period5Date = date; break; default: throw new IndexOutOfBoundsException("Index of Snapshot.periodDate is between 1 and 5"); @@ -675,7 +670,7 @@ public class Snapshot extends BaseIdentifiable implements Serializable return this; } - public Date getPeriodDate(int periodIndex) { + public Long getPeriodDate(int periodIndex) { switch (periodIndex) { case 1: return period1Date; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index 1ff7bc4ac4a..6be43c827ea 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -19,8 +19,8 @@ */ package org.sonar.api.utils; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -60,10 +60,16 @@ public final class DateUtils { return date == null ? "" : THREAD_SAFE_DATETIME_FORMAT.format(date); } - public static Date timeToDate(@Nullable Long time) { + @CheckForNull + public static Date longToDate(@Nullable Long time) { return time == null ? null : new Date(time); } + @CheckForNull + public static Long dateToLong(@Nullable Date date) { + return date == null ? null : date.getTime(); + } + /** * @param s string in format {@link #DATE_FORMAT} * @throws SonarException when string cannot be parsed diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java index 5a0c8427a51..c102f844234 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java @@ -21,13 +21,8 @@ package org.sonar.api.database.model; import org.junit.Test; -import java.util.Date; - import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; public class SnapshotTest { @@ -36,7 +31,7 @@ public class SnapshotTest { Snapshot snapshot = new Snapshot(); assertNull(snapshot.getCreatedAt()); - Date now = new Date(); + Long now = System.currentTimeMillis(); snapshot.setCreatedAt(now); assertEquals(now, snapshot.getCreatedAt()); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java index 888ceeb4c69..7aa32f3cb20 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java @@ -109,8 +109,8 @@ public class DateUtilsTest { @Test public void time_to_date() throws Exception { Date date = new Date(); - Assertions.assertThat(DateUtils.timeToDate(date.getTime())).isEqualTo(date); - Assertions.assertThat(DateUtils.timeToDate(null)).isNull(); + Assertions.assertThat(DateUtils.longToDate(date.getTime())).isEqualTo(date); + Assertions.assertThat(DateUtils.longToDate(null)).isNull(); } /** -- 2.39.5