diff options
33 files changed, 400 insertions, 98 deletions
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 18c5d7785a2..55ce78fe4d6 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 @@ -101,7 +101,7 @@ from_date = first_date if !from_date || from_date > first_date end end - Event.find(:all, :conditions => ["resource_id=? AND event_date>=?", @resource.id, from_date], :order => 'event_date').each() do |event| + Event.find(:all, :conditions => ["resource_id=? AND event_date>=?", @resource.id, from_date.to_i*1000], :order => 'event_date').each() do |event| if events[event.event_date] events[event.event_date] << event else 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 dd8a452b74c..661fff4fcfb 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 @@ -90,6 +90,7 @@ public interface DatabaseMigrations { FeedFileSourcesBinaryData.class, FeedSemaphoresLongDates.class, FeedProjectMeasuresLongDates.class, - FeedManualMeasuresLongDates.class + FeedManualMeasuresLongDates.class, + FeedEventsLongDates.class ); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedEventsLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedEventsLongDates.java new file mode 100644 index 00000000000..239b16fe213 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedEventsLongDates.java @@ -0,0 +1,76 @@ +/* + * 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; +import java.util.Date; + +public class FeedEventsLongDates extends BaseDataChange { + + private final System2 system2; + + public FeedEventsLongDates(Database db, System2 system2) { + super(db); + this.system2 = system2; + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + massUpdate + .select("SELECT e.event_date, e.created_at, e.id FROM events e WHERE event_date_ms IS NULL"); + massUpdate + .update("UPDATE events SET event_date_ms=?, created_at_ms=? WHERE id=?"); + massUpdate.rowPluralName("events"); + massUpdate.execute(new EventDateHandler(system2.now())); + } + + private static class EventDateHandler implements MassUpdate.Handler { + + private final long now; + + public EventDateHandler(long now) { + this.now = now; + } + + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + Date eventDate = row.getDate(1); + long eventTime = eventDate == null ? now : Math.min(now, eventDate.getTime()); + update.setLong(1, eventTime); + Date createdAt = row.getDate(2); + update.setLong(2, createdAt == null ? eventTime : Math.min(now, createdAt.getTime())); + + Long id = row.getLong(3); + update.setLong(3, id); + + return true; + } + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDates.java index 78529fcfa6c..2244c603065 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDates.java @@ -47,7 +47,7 @@ public class FeedManualMeasuresLongDates extends BaseDataChange { .select("SELECT m.created_at, m.updated_at, m.id FROM manual_measures m WHERE created_at_ms IS NULL"); massUpdate .update("UPDATE manual_measures SET created_at_ms=?, updated_at_ms=? WHERE id=?"); - massUpdate.rowPluralName("manualMeasures"); + massUpdate.rowPluralName("manual measures"); massUpdate.execute(new MassUpdate.Handler() { @Override public boolean handle(Select.Row row, SqlStatement update) throws SQLException { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedProjectMeasuresLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedProjectMeasuresLongDates.java index 6cea58309dc..00e00feccbf 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedProjectMeasuresLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedProjectMeasuresLongDates.java @@ -47,7 +47,7 @@ public class FeedProjectMeasuresLongDates extends BaseDataChange { .select("SELECT m.measure_date, m.id FROM project_measures m WHERE measure_date_ms IS NULL"); massUpdate .update("UPDATE project_measures SET measure_date_ms=? WHERE id=?"); - massUpdate.rowPluralName("projectMeasures"); + massUpdate.rowPluralName("project measures"); massUpdate.execute(new MassUpdate.Handler() { @Override public boolean handle(Select.Row row, SqlStatement update) throws SQLException { diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java new file mode 100644 index 00000000000..4076ba2e382 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest.java @@ -0,0 +1,88 @@ +/* + * 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.Before; +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 FeedEventsLongDatesTest { + @ClassRule + public static DbTester db = new DbTester().schema(FeedEventsLongDatesTest.class, "schema.sql"); + + @Before + public void before() throws Exception { + db.prepareDbUnit(getClass(), "before.xml"); + } + + @Test + public void execute() throws Exception { + DatabaseMigration migration = newMigration(System2.INSTANCE); + + migration.execute(); + + int count = db + .countSql("select count(*) from events where " + + "created_at_ms is not null " + + "and event_date_ms is not null"); + assertThat(count).isEqualTo(3); + } + + @Test + public void take_now_if_date_in_the_future() throws Exception { + System2 system = mock(System2.class); + when(system.now()).thenReturn(1234L); + + DatabaseMigration migration = newMigration(system); + + migration.execute(); + + int count = db + .countSql("select count(*) from events where " + + "created_at_ms = 1234"); + assertThat(count).isEqualTo(2); + } + + @Test + public void take_date_if_in_the_past() throws Exception { + DatabaseMigration migration = newMigration(System2.INSTANCE); + + migration.execute(); + + long time = parseDate("2014-09-25").getTime(); + int count = db + .countSql("select count(*) from events where " + + "created_at_ms=" + time); + assertThat(count).isEqualTo(1); + } + + private DatabaseMigration newMigration(System2 system) { + return new FeedEventsLongDates(db.database(), system); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java index c3b2a47c45d..d91efe79024 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedManualMeasuresLongDatesTest.java @@ -70,7 +70,7 @@ public class FeedManualMeasuresLongDatesTest { } @Test - public void take_snapshot_date_if_in_the_past() throws Exception { + public void take_manual_measure_date_if_in_the_past() throws Exception { DatabaseMigration migration = newMigration(System2.INSTANCE); migration.execute(); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/before.xml new file mode 100644 index 00000000000..52ad14d35b2 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/before.xml @@ -0,0 +1,28 @@ +<dataset> + <!-- new migration --> + <events + id="1" + created_at="2014-09-25" + created_at_ms="[null]" + event_date="2014-09-25" + event_date_ms="[null]" + /> + + <!-- re-entrant migration - ignore the ones that are already fed with new dates --> + <events + id="2" + created_at="2014-09-25" + created_at_ms="1500000000" + event_date="2014-09-25" + event_date_ms="1500000000" + /> + + <!-- NULL dates --> + <events + id="3" + created_at="[null]" + created_at_ms="[null]" + event_date="[null]" + event_date_ms="[null]" + /> +</dataset> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/schema.sql new file mode 100644 index 00000000000..71ac42d40ef --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedEventsLongDatesTest/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE "EVENTS" ( + "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "CREATED_AT" TIMESTAMP, + "CREATED_AT_MS" BIGINT, + "EVENT_DATE" TIMESTAMP, + "EVENT_DATE_MS" BIGINT +); 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 ebf29970d09..e6d4696c397 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 @@ -51,7 +51,7 @@ class Api::EventsController < Api::ApiController end if from conditions<<'event_date>=:from' - values[:from]=from + values[:from]=from.to_i*1000 end to=nil @@ -62,7 +62,7 @@ class Api::EventsController < Api::ApiController end if to conditions<<'event_date<=:to' - values[:to]=to + values[:to]=to.to_i*1000 end events=Event.find(:all, :conditions => [conditions.join(' AND '), values], :order => 'event_date DESC') diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb index 97d5c277e7a..d5349ebaad3 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/event.rb @@ -27,6 +27,27 @@ class Event < ActiveRecord::Base belongs_to :snapshot before_save :populate_snapshot + + def created_at + long_to_date(:created_at) + end + + def created_at=(date) + write_attribute(:created_at, date.to_i*1000) + end + + def event_date + long_to_date(:event_date) + end + + def event_date=(date) + write_attribute(:event_date, date.to_i*1000) + end + + def long_to_date(attribute) + date_in_long = read_attribute(attribute) + Time.at(date_in_long/1000) if date_in_long + end def fullname if category @@ -59,10 +80,8 @@ class Event < ActiveRecord::Base return false end - # - # TODO: Remove this code when everything has been checked on the Event handling, both on the UI and the WS API - # def populate_snapshot + self.created_at=DateTime.now unless self.created_at self.snapshot=Snapshot.snapshot_by_date(resource_id, event_date) unless self.snapshot end end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/791_add_events_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/791_add_events_long_dates.rb new file mode 100644 index 00000000000..ae4f097c7f0 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/791_add_events_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 AddEventsLongDates < ActiveRecord::Migration + def self.up + add_column 'events', :event_date_ms, :big_integer, :null => true + add_column 'events', :created_at_ms, :big_integer, :null => true + end +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/792_feed_events_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/792_feed_events_long_dates.rb new file mode 100644 index 00000000000..b058d46e559 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/792_feed_events_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 FeedEventsLongDates < ActiveRecord::Migration + def self.up + execute_java_migration('org.sonar.server.db.migrations.v51.FeedEventsLongDates') + end +end + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/793_rename_events_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/793_rename_events_long_dates.rb new file mode 100644 index 00000000000..a46e2a5c488 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/793_rename_events_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 RenameEventsLongDates < ActiveRecord::Migration + def self.up + remove_column 'events', 'created_at' + remove_column 'events', 'event_date' + rename_column 'events', 'created_at_ms', 'created_at' + rename_column 'events', 'event_date_ms', 'event_date' + change_column 'events', 'created_at', :big_integer, :null => false + change_column 'events', 'event_date', :big_integer, :null => false + end +end + diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java index 2b309da1100..6c7146c6e61 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/DeprecatedSensorContext.java @@ -37,12 +37,7 @@ import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.Metric; -import org.sonar.api.resources.Directory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectLink; -import org.sonar.api.resources.Qualifiers; -import org.sonar.api.resources.Resource; +import org.sonar.api.resources.*; import org.sonar.api.rules.Violation; import org.sonar.api.utils.SonarException; import org.sonar.batch.duplication.DuplicationCache; @@ -50,6 +45,8 @@ import org.sonar.batch.index.ComponentDataCache; import org.sonar.batch.sensor.DefaultSensorContext; import org.sonar.batch.sensor.coverage.CoverageExclusions; +import javax.annotation.Nullable; + import java.io.Serializable; import java.util.Collection; import java.util.Date; @@ -255,7 +252,7 @@ public class DeprecatedSensorContext extends DefaultSensorContext implements Sen } @Override - public Event createEvent(Resource resource, String name, String description, String category, Date date) { + public Event createEvent(Resource resource, String name, String description, String category, @Nullable Date date) { return index.addEvent(resource, name, description, category, date); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 4cc275dc4aa..e551d462507 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -38,14 +38,7 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; import org.sonar.api.measures.MeasuresFilters; -import org.sonar.api.resources.Directory; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.ProjectLink; -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.rules.Rule; import org.sonar.api.rules.Violation; import org.sonar.api.scan.filesystem.PathResolver; @@ -59,16 +52,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public class DefaultIndex extends SonarIndex { @@ -103,7 +87,11 @@ public class DefaultIndex extends SonarIndex { private final ResourceCache resourceCache; private final MetricFinder metricFinder; - + private final MeasureCache measureCache; + private final ResourceKeyMigration migration; + private final DependencyPersister dependencyPersister; + private final LinkPersister linkPersister; + private final EventPersister eventPersister; // caches private Project currentProject; private Map<Resource, Bucket> buckets = Maps.newLinkedHashMap(); @@ -112,11 +100,6 @@ public class DefaultIndex extends SonarIndex { private Map<Resource, Map<Resource, Dependency>> incomingDependenciesByResource = Maps.newLinkedHashMap(); private ProjectTree projectTree; private ModuleIssues moduleIssues; - private final MeasureCache measureCache; - private final ResourceKeyMigration migration; - private final DependencyPersister dependencyPersister; - private final LinkPersister linkPersister; - private final EventPersister eventPersister; public DefaultIndex(ResourceCache resourceCache, DependencyPersister dependencyPersister, LinkPersister linkPersister, EventPersister eventPersister, ProjectTree projectTree, MetricFinder metricFinder, @@ -476,10 +459,11 @@ public class DefaultIndex extends SonarIndex { } @Override - public Event addEvent(Resource resource, String name, String description, String category, Date date) { + public Event addEvent(Resource resource, String name, String description, String category, @Nullable Date date) { Event event = new Event(name, description, category); - event.setDate(date); - event.setCreatedAt(new Date()); + if (date != null) { + event.setDate(date); + } if (eventPersister != null) { eventPersister.saveEvent(resource, event); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/EventPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/EventPersister.java index b01efa10063..8ee521c247e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/EventPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/EventPersister.java @@ -22,16 +22,22 @@ package org.sonar.batch.index; import org.sonar.api.batch.Event; import org.sonar.api.database.DatabaseSession; import org.sonar.api.resources.Resource; +import org.sonar.api.utils.System2; +import java.util.Date; import java.util.List; +import static com.google.common.base.Preconditions.checkState; + public class EventPersister { + private final System2 system2; private DatabaseSession session; private ResourceCache resourceCache; - public EventPersister(DatabaseSession session, ResourceCache resourceCache) { + public EventPersister(DatabaseSession session, ResourceCache resourceCache, System2 system2) { this.session = session; this.resourceCache = resourceCache; + this.system2 = system2; } public List<Event> getEvents(Resource resource) { @@ -45,16 +51,16 @@ public class EventPersister { public void saveEvent(Resource resource, Event event) { BatchResource batchResource = resourceCache.get(resource.getEffectiveKey()); - if (batchResource == null) { - throw new IllegalStateException("Unknow component: " + resource); - } + checkState(batchResource != null, "Unknown component: " + resource); + + event.setCreatedAt(new Date(system2.now())); if (event.getDate() == null) { event.setSnapshot(batchResource.snapshot()); } else { event.setResourceId(batchResource.resource().getId()); } + session.save(event); session.commit(); - } } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml index 2f01f86b989..480b91f147e 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/no-previous-version.xml @@ -30,13 +30,13 @@ scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path="" status="U" islast="true" depth="0" /> - <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="2008-11-03 13:58:00.00" created_at="2008-11-03 13:58:00.00" description="" + <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/> - <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="2008-11-05 13:58:00.00" created_at="2008-11-05 13:58:00.00" description="" + <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/> - <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="2008-11-07 13:58:00.00" created_at="2008-11-07 13:58:00.00" description="" + <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/> - <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="2008-11-09 13:58:00.00" created_at="2008-11-09 13:58:00.00" description="" + <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description="" event_data="[null]"/> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml index d990e648414..bc3a3c9c055 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version-deleted.xml @@ -30,17 +30,17 @@ scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path="" status="U" islast="true" depth="0" /> - <events id="1" name="1.0" resource_id="1" snapshot_id="1000" category="Version" event_date="2008-11-02 13:58:00.00" created_at="2008-11-02 13:58:00.00" description="" + <events id="1" name="1.0" resource_id="1" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/> - <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="2008-11-03 13:58:00.00" created_at="2008-11-03 13:58:00.00" description="" + <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/> <!-- The "1.1" version was deleted from the history : --> <!-- events id="3" name="1.1" resource_id="1" snapshot_id="1001" category="Version" event_date="2008-11-04 13:58:00.00" created_at="2008-11-04 13:58:00.00" description=""/--> - <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="2008-11-05 13:58:00.00" created_at="2008-11-05 13:58:00.00" description="" + <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/> - <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="2008-11-07 13:58:00.00" created_at="2008-11-07 13:58:00.00" description="" + <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/> - <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="2008-11-09 13:58:00.00" created_at="2008-11-09 13:58:00.00" description="" + <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description="" event_data="[null]"/> </dataset> diff --git a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml index 5ecbc2fa959..6efee1a0f51 100644 --- a/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml +++ b/sonar-batch/src/test/resources/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersionTest/with-previous-version.xml @@ -30,11 +30,11 @@ scope="PRJ" qualifier="TRK" created_at="1226235480000" build_date="1226235480000" version="1.2-SNAPSHOT" path="" status="U" islast="true" depth="0" /> - <events id="1" name="1.0" resource_id="1" snapshot_id="1000" category="Version" event_date="2008-11-02 13:58:00.00" created_at="2008-11-02 13:58:00.00" description="" event_data="[null]"/> - <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="2008-11-03 13:58:00.00" created_at="2008-11-03 13:58:00.00" description="" event_data="[null]"/> - <events id="3" name="1.1" resource_id="1" snapshot_id="1001" category="Version" event_date="2008-11-04 13:58:00.00" created_at="2008-11-04 13:58:00.00" description="" event_data="[null]"/> - <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="2008-11-05 13:58:00.00" created_at="2008-11-05 13:58:00.00" description="" event_data="[null]"/> - <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="2008-11-07 13:58:00.00" created_at="2008-11-07 13:58:00.00" description="" event_data="[null]"/> - <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="2008-11-09 13:58:00.00" created_at="2008-11-09 13:58:00.00" description="" event_data="[null]"/> + <events id="1" name="1.0" resource_id="1" snapshot_id="1000" category="Version" event_date="1225630680000" created_at="1225630680000" description="" event_data="[null]"/> + <events id="2" name="Foo" resource_id="1" snapshot_id="1000" category="Other" event_date="1225717080000" created_at="1225717080000" description="" event_data="[null]"/> + <events id="3" name="1.1" resource_id="1" snapshot_id="1001" category="Version" event_date="1225803480000" created_at="1225803480000" description="" event_data="[null]"/> + <events id="4" name="Bar" resource_id="1" snapshot_id="1001" category="Other" event_date="1225889880000" created_at="1225889880000" description="" event_data="[null]"/> + <events id="5" name="Uhh" resource_id="1" snapshot_id="1002" category="Other" event_date="1226062680000" created_at="1226062680000" description="" event_data="[null]"/> + <events id="6" name="1.2-SNAPSHOT" resource_id="1" snapshot_id="1003" category="Version" event_date="1226235480000" created_at="1226235480000" description="" event_data="[null]"/> </dataset> 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 048e602afe9..790209ba8b0 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 = 790; + public static final int LAST_VERSION = 793; /** * List of all the tables.n 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 af6b0b2df00..c44b9b31dd4 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 @@ -317,6 +317,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('787'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('788'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('789'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('790'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('791'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('792'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('793'); 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 484d9265b83..86d2134ef54 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 @@ -167,8 +167,8 @@ CREATE TABLE "EVENTS" ( "RESOURCE_ID" INTEGER, "SNAPSHOT_ID" INTEGER, "CATEGORY" VARCHAR(50), - "EVENT_DATE" TIMESTAMP, - "CREATED_AT" TIMESTAMP, + "EVENT_DATE" BIGINT NOT NULL, + "CREATED_AT" BIGINT NOT NULL, "DESCRIPTION" VARCHAR(4000), "EVENT_DATA" VARCHAR(4000) ); diff --git a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java index d7d285e42fa..693ea65a447 100644 --- a/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java @@ -115,12 +115,10 @@ public class PurgeCommandsTest extends AbstractDaoTestCase { @Test public void shouldDeleteResource() { setupData("shouldDeleteResource"); - SqlSession session = getMyBatis().openSession(); - try { + try (SqlSession session = getMyBatis().openSession()) { new PurgeCommands(session, profiler).deleteResources(newArrayList(new IdUuidPair(1L, "1"))); - } finally { - MyBatis.closeQuietly(session); } + assertEmptyTables("projects", "snapshots", "events", "issues", "issue_changes", "authors"); } 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 e7d8f49a2b4..2f30df757d0 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 @@ -16,7 +16,7 @@ version="[null]" path="[null]"/> <events id="1" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" - event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> + event_date="1228222680000" created_at="1228222680000" event_data="[null]"/> <issues id="1" kee="ABCDE" component_uuid="1" project_uuid="1" status="CLOSED" resolution="[null]" line="200" severity="BLOCKER" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml index 3bac29d413a..f7a0a3a81b3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot-result.xml @@ -26,7 +26,7 @@ parent_dependency_id="[null]" project_snapshot_id="1" dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/> <events id="1" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" - event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> + event_date="1228222680000" created_at="1228222680000" event_data="[null]"/> <duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0" end_line="0"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml index 8fd273d1c08..45eaee58163 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldDeleteSnapshot.xml @@ -25,7 +25,7 @@ parent_dependency_id="[null]" project_snapshot_id="1" dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/> <events id="1" name="Version 1.0" resource_id="1" snapshot_id="1" category="VERSION" description="[null]" - event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> + event_date="1228222680000" created_at="1228222680000" event_data="[null]"/> <duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0" end_line="0"/> @@ -58,7 +58,7 @@ parent_dependency_id="[null]" project_snapshot_id="5" dep_usage="USES" dep_weight="1" from_scope="PRJ" to_scope="LIB"/> <events id="2" name="Version 1.0" resource_id="5" snapshot_id="5" category="VERSION" description="[null]" - event_date="2008-12-02 13:58:00.00" created_at="[null]" event_data="[null]"/> + event_date="1228222680000" created_at="1228222680000" event_data="[null]"/> <duplications_index id="2" project_snapshot_id="5" snapshot_id="5" hash="bb" index_in_file="0" start_line="0" end_line="0"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml index bcd5544b9f6..4a45a7fc405 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot-result.xml @@ -42,8 +42,8 @@ Note that measures, events and reviews are not deleted. <!--dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/>--> <events id="1" resource_id="1" snapshot_id="1" - category="VERSION" description="[null]" name="Version 1.0" event_date="2008-12-02 13:58:00.00" - created_at="[null]" + category="VERSION" description="[null]" name="Version 1.0" event_date="1228222680000" + created_at="1228222680000" event_data="[null]"/> <!--<duplications_index id="1" project_snapshot_id="1" snapshot_id="1"--> @@ -81,8 +81,8 @@ Note that measures, events and reviews are not deleted. dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> <events id="2" resource_id="2" snapshot_id="2" - category="VERSION" description="[null]" name="Version 1.0" event_date="2008-12-02 13:58:00.00" - created_at="[null]" + category="VERSION" description="[null]" name="Version 1.0" event_date="1228222680000" + created_at="1228222680000" event_data="[null]"/> <duplications_index id="2" project_snapshot_id="2" snapshot_id="2" diff --git a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml index 5a576b3edf8..6c6e5bd44c2 100644 --- a/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml +++ b/sonar-core/src/test/resources/org/sonar/core/purge/PurgeCommandsTest/shouldPurgeSnapshot.xml @@ -27,8 +27,8 @@ dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> <events id="1" resource_id="1" snapshot_id="1" - category="VERSION" description="[null]" name="Version 1.0" event_date="2008-12-02 13:58:00.00" - created_at="[null]" + category="VERSION" description="[null]" name="Version 1.0" event_date="1228222680000" + created_at="1228222680000" event_data="[null]"/> <duplications_index id="1" project_snapshot_id="1" snapshot_id="1" @@ -65,8 +65,8 @@ dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> <events id="2" resource_id="2" snapshot_id="2" - category="VERSION" description="[null]" name="Version 1.0" event_date="2008-12-02 13:58:00.00" - created_at="[null]" + category="VERSION" description="[null]" name="Version 1.0" event_date="1228222680000" + created_at="1228222680000" event_data="[null]"/> <duplications_index id="2" project_snapshot_id="2" snapshot_id="2" 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 f3a3b9bd0b3..78e14ead2a7 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 @@ -56,7 +56,7 @@ depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> <events id="2" resource_id="1" snapshot_id="5" - category="Version" description="[null]" name="Version 1.0" event_date="2008-12-02 13:58:00.00" created_at="[null]" + category="Version" description="[null]" name="Version 1.0" event_date="1228222680000" created_at="1228222680000" event_data="[null]"/> </dataset> 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 8c802c2ca98..eb4db71fe41 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 @@ -26,6 +26,9 @@ import org.sonar.api.database.model.Snapshot; import javax.persistence.*; import java.util.Date; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.sonar.api.utils.DateUtils.longToDate; + /** * @since 1.10 */ @@ -46,10 +49,10 @@ public class Event extends BaseIdentifiable { private String category; @Column(name = "event_date", updatable = true, nullable = false) - private Date date; + private Long date; - @Column(name = "created_at", updatable = true, nullable = true) - private Date createdAt; + @Column(name = "created_at", updatable = true, nullable = false) + private Long createdAt; @Column(name = "event_data", updatable = true, nullable = true) private String data; @@ -103,11 +106,11 @@ public class Event extends BaseIdentifiable { } public Date getDate() { - return date; + return longToDate(date); } public void setDate(Date date) { - this.date = date; + this.date = date.getTime(); } public Snapshot getSnapshot() { @@ -115,19 +118,17 @@ public class Event extends BaseIdentifiable { } public Date getCreatedAt() { - return createdAt; + return new Date(createdAt); } public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; + this.createdAt = createdAt.getTime(); } public final void setSnapshot(Snapshot snapshot) { - this.snapshot = snapshot; - if (snapshot != null) { - this.date = (snapshot.getCreatedAtMs() == null ? null : new Date(snapshot.getCreatedAtMs())); - this.resourceId = snapshot.getResourceId(); - } + this.snapshot = checkNotNull(snapshot, "it is not possible to set a null snapshot linked to an event"); + this.date = snapshot.getCreatedAtMs(); + this.resourceId = snapshot.getResourceId(); } public Integer getResourceId() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index b75209e1538..00fd00d8314 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -30,6 +30,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Violation; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.io.Serializable; import java.util.Collection; @@ -242,7 +243,7 @@ public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext * @param date the event date * @return the created event */ - Event createEvent(Resource resource, String name, String description, String category, Date date); + Event createEvent(Resource resource, String name, @Nullable String description, String category, @Nullable Date date); /** * Deletes an event diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java index f21b83bab5f..6714ed9c1bb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java @@ -30,6 +30,7 @@ import org.sonar.api.rules.Violation; import org.sonar.graph.DirectedGraphAccessor; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.util.Collection; import java.util.Date; @@ -155,7 +156,7 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe public abstract void deleteEvent(Event event); - public abstract Event addEvent(Resource resource, String name, String description, String category, Date date); + public abstract Event addEvent(Resource resource, String name, String description, String category, @Nullable Date date); public final Collection<Dependency> getOutgoingDependencies(Resource from) { return getOutgoingEdges(from); |