From 7485c34dead228336791067e3a6b03cbb3dcaaa2 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 13 Mar 2015 14:25:42 +0100 Subject: [PATCH] SONAR-6261 Persist events in compute stack --- .../plugins/core/widgets/events.html.erb | 4 +- .../plugins/core/widgets/timeline.html.erb | 2 +- .../computation/step/PersistEventsStep.java | 129 ++ .../java/org/sonar/server/db/DbClient.java | 7 + .../db/migrations/DatabaseMigrations.java | 4 +- .../v52/FeedEventsComponentUuid.java | 55 + .../org/sonar/server/event/db/EventDao.java | 45 + .../sonar/server/event/db/package-info.java | 24 + .../step/PersistEventsStepTest.java | 193 ++ .../v52/FeedEventsComponentUuidTest.java | 63 + .../sonar/server/event/db/EventDaoTest.java | 117 ++ .../add_events-result.xml | 10 + .../add_version_event-result.xml | 6 + .../step/PersistEventsStepTest/empty.xml | 3 + .../keep_one_event_by_version-result.xml | 14 + .../keep_one_event_by_version.xml | 10 + ...nothing_to_do_when_no_events_in_report.xml | 13 + .../migrate-result.xml | 5 + .../FeedEventsComponentUuidTest/migrate.xml | 11 + .../not_migrate_already_migrated_data.xml | 11 + .../FeedEventsComponentUuidTest/schema.sql | 35 + .../server/event/db/EventDaoTest/delete.xml | 6 + .../server/event/db/EventDaoTest/empty.xml | 3 + .../event/db/EventDaoTest/insert-result.xml | 6 + .../server/event/db/EventDaoTest/shared.xml | 13 + .../app/controllers/api/events_controller.rb | 32 +- .../app/controllers/project_controller.rb | 12 +- .../main/webapp/WEB-INF/app/models/event.rb | 2 +- .../main/webapp/WEB-INF/app/models/project.rb | 2 +- .../migrate/903_add_events_component_uuid.rb | 32 + .../migrate/904_feed_events_component_uuid.rb | 31 + .../migrate/905_remove_events_resource_id.rb | 32 + .../org/sonar/batch/protocol/Constants.java | 96 +- .../batch/protocol/output/BatchReport.java | 1679 ++++++++++++++++- .../src/main/protobuf/batch_report.proto | 14 +- .../src/main/protobuf/constants.proto | 6 + .../PastSnapshotFinderByPreviousVersion.java | 7 +- .../org/sonar/batch/index/EventPersister.java | 5 +- .../no-previous-version.xml | 10 +- .../with-previous-version-deleted.xml | 14 +- .../with-previous-version.xml | 14 +- .../java/org/sonar/core/event/EventDto.java | 132 ++ .../org/sonar/core/event/db/EventMapper.java | 35 + .../org/sonar/core/event/db/package-info.java | 24 + .../org/sonar/core/event/package-info.java | 24 + .../core/persistence/DatabaseVersion.java | 2 +- .../org/sonar/core/persistence/MyBatis.java | 5 +- .../org/sonar/core/purge/PurgeCommands.java | 6 +- .../org/sonar/core/purge/PurgeMapper.java | 2 +- .../org/sonar/core/event/db/EventMapper.xml | 35 + .../org/sonar/core/persistence/rows-h2.sql | 3 + .../org/sonar/core/persistence/schema-h2.ddl | 4 +- .../org/sonar/core/purge/PurgeMapper.xml | 8 +- .../should_create_database.xml | 6 +- .../shouldDeleteResource.xml | 2 +- .../shouldDeleteSnapshot-result.xml | 2 +- .../shouldDeleteSnapshot.xml | 4 +- .../shouldPurgeSnapshot-result.xml | 4 +- .../PurgeCommandsTest/shouldPurgeSnapshot.xml | 4 +- .../shouldSelectPurgeableSnapshots.xml | 2 +- .../main/java/org/sonar/api/batch/Event.java | 31 +- .../api/database/model/ResourceModel.java | 3 +- 62 files changed, 2964 insertions(+), 151 deletions(-) create mode 100644 server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuid.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java create mode 100644 server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java create mode 100644 server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_events-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/empty.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/not_migrate_already_migrated_data.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/schema.sql create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/903_add_events_component_uuid.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/904_feed_events_component_uuid.rb create mode 100644 server/sonar-web/src/main/webapp/WEB-INF/db/migrate/905_remove_events_resource_id.rb create mode 100644 sonar-core/src/main/java/org/sonar/core/event/EventDto.java create mode 100644 sonar-core/src/main/java/org/sonar/core/event/db/EventMapper.java create mode 100644 sonar-core/src/main/java/org/sonar/core/event/db/package-info.java create mode 100644 sonar-core/src/main/java/org/sonar/core/event/package-info.java create mode 100644 sonar-core/src/main/resources/org/sonar/core/event/db/EventMapper.xml diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb index 9f0381f48cb..d6be1d2e667 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb @@ -1,8 +1,8 @@ <% if @resource.scope=='PRJ' - conditions = "resource_id=:resource_id" - values = {:resource_id => @resource.id} + conditions = "component_uuid=:component_uuid" + values = {:component_uuid => @resource.uuid} # in order to not display events linked to deleted snapshot, we build the SQL request with 'NOT IN' as most of the time, there won't be unprocessed snapshots snapshots_to_be_deleted = Snapshot.find(:all, :conditions => ["status='U' AND project_id=?", @resource.id]) unless snapshots_to_be_deleted.empty? 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 55ce78fe4d6..7e7ad6ec44f 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.to_i*1000], :order => 'event_date').each() do |event| + Event.find(:all, :conditions => ["component_uuid=? AND event_date>=?", @resource.uuid, 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/computation/step/PersistEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java new file mode 100644 index 00000000000..97c678b4f08 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java @@ -0,0 +1,129 @@ +/* + * 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.computation.step; + +import org.sonar.api.resources.Qualifiers; +import org.sonar.api.utils.System2; +import org.sonar.batch.protocol.Constants; +import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.BatchReportReader; +import org.sonar.core.event.EventDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.MyBatis; +import org.sonar.server.computation.ComputationContext; +import org.sonar.server.db.DbClient; + +import java.util.List; + +public class PersistEventsStep implements ComputationStep { + + private final DbClient dbClient; + private final System2 system2; + + public PersistEventsStep(DbClient dbClient, System2 system2) { + this.dbClient = dbClient; + this.system2 = system2; + } + + @Override + public String[] supportedProjectQualifiers() { + return new String[] {Qualifiers.PROJECT}; + } + + @Override + public void execute(ComputationContext context) { + DbSession session = dbClient.openSession(false); + try { + int rootComponentRef = context.getReportMetadata().getRootComponentRef(); + recursivelyProcessComponent(session, context, rootComponentRef); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + private void recursivelyProcessComponent(DbSession session, ComputationContext context, int componentRef) { + BatchReportReader reportReader = context.getReportReader(); + BatchReport.Component component = reportReader.readComponent(componentRef); + processEvents(session, component, context.getReportMetadata().getAnalysisDate()); + createVersionEvent(session, component, context.getReportMetadata().getAnalysisDate()); + + for (Integer childRef : component.getChildRefsList()) { + recursivelyProcessComponent(session, context, childRef); + } + } + + private void processEvents(DbSession session, BatchReport.Component component, Long analysisDate) { + List events = component.getEventsList(); + if (!events.isEmpty()) { + for (BatchReport.Event event : component.getEventsList()) { + dbClient.eventDao().insert(session, createBaseEvent(component, analysisDate) + .setName(event.getName()) + .setCategory(convertCategory(event.getCategory())) + .setDescription(event.hasDescription() ? event.getDescription() : null) + .setData(event.hasEventData() ? event.getEventData() : null) + ); + } + } + } + + private void createVersionEvent(DbSession session, BatchReport.Component component, Long analysisDate) { + if (component.hasVersion()) { + deletePreviousEventsHavingSameVersion(session, component); + dbClient.eventDao().insert(session, createBaseEvent(component, analysisDate) + .setName(component.getVersion()) + .setCategory(EventDto.CATEGORY_VERSION) + ); + } + } + + private void deletePreviousEventsHavingSameVersion(DbSession session, BatchReport.Component component){ + for (EventDto dto : dbClient.eventDao().selectByComponentUuid(session, component.getUuid())) { + if (dto.getCategory().equals(EventDto.CATEGORY_VERSION) && dto.getName().equals(component.getVersion())) { + dbClient.eventDao().delete(session, dto.getId()); + } + } + } + + private EventDto createBaseEvent(BatchReport.Component component, Long analysisDate) { + return new EventDto() + .setComponentUuid(component.getUuid()) + .setSnapshotId(component.getSnapshotId()) + .setCreatedAt(system2.now()) + .setDate(analysisDate); + } + + private static String convertCategory(Constants.EventCategory category) { + switch (category) { + case ALERT: + return EventDto.CATEGORY_ALERT; + case PROFILE: + return EventDto.CATEGORY_PROFILE; + default: + throw new IllegalArgumentException(String.format("Unsupported category %s", category.name())); + } + } + + @Override + public String getDescription() { + return "Persist component links"; + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java index 77cc92e3c27..a0056e42064 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java @@ -43,6 +43,7 @@ import org.sonar.server.computation.db.AnalysisReportDao; import org.sonar.server.dashboard.db.DashboardDao; import org.sonar.server.dashboard.db.WidgetDao; import org.sonar.server.dashboard.db.WidgetPropertyDao; +import org.sonar.server.event.db.EventDao; import org.sonar.server.issue.db.IssueDao; import org.sonar.server.measure.persistence.MeasureDao; import org.sonar.server.measure.persistence.MetricDao; @@ -91,6 +92,7 @@ public class DbClient implements ServerComponent { private final AuthorDao authorDao; private final ComponentIndexDao componentIndexDao; private final ComponentLinkDao componentLinkDao; + private final EventDao eventDao; public DbClient(Database db, MyBatis myBatis, DaoComponent... daoComponents) { this.db = db; @@ -126,6 +128,7 @@ public class DbClient implements ServerComponent { authorDao = getDao(map, AuthorDao.class); componentIndexDao = getDao(map, ComponentIndexDao.class); componentLinkDao = getDao(map, ComponentLinkDao.class); + eventDao = getDao(map, EventDao.class); } public Database database() { @@ -240,6 +243,10 @@ public class DbClient implements ServerComponent { return componentLinkDao; } + public EventDao eventDao() { + return eventDao; + } + private K getDao(Map map, Class clazz) { return (K) map.get(clazz); } 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 86cffa68afd..dba501d891c 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 @@ -31,6 +31,7 @@ import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigrati import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities; import org.sonar.server.db.migrations.v50.*; import org.sonar.server.db.migrations.v51.*; +import org.sonar.server.db.migrations.v52.FeedEventsComponentUuid; import org.sonar.server.db.migrations.v52.FeedProjectLinksComponentUuid; import java.util.List; @@ -97,6 +98,7 @@ public interface DatabaseMigrations { RemovePermissionsOnModulesMigration.class, // 5.2 - FeedProjectLinksComponentUuid.class + FeedProjectLinksComponentUuid.class, + FeedEventsComponentUuid.class ); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuid.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuid.java new file mode 100644 index 00000000000..5e2c83ddd56 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuid.java @@ -0,0 +1,55 @@ +/* + * 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.v52; + +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 FeedEventsComponentUuid extends BaseDataChange { + + public FeedEventsComponentUuid(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + MassUpdate update = context.prepareMassUpdate().rowPluralName("events"); + update.select( + "SELECT p.uuid, event.id " + + "FROM events event " + + "INNER JOIN projects p ON p.id=event.resource_id " + + "WHERE event.component_uuid is null"); + update.update("UPDATE events SET component_uuid=? WHERE id=?"); + update.execute(new MassUpdate.Handler() { + @Override + public boolean handle(Select.Row row, SqlStatement update) throws SQLException { + update.setString(1, row.getString(1)); + update.setLong(2, row.getLong(2)); + return true; + } + }); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java b/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java new file mode 100644 index 00000000000..ef03a50cf68 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/event/db/EventDao.java @@ -0,0 +1,45 @@ +/* + * 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.event.db; + +import org.sonar.api.ServerComponent; +import org.sonar.core.event.EventDto; +import org.sonar.core.event.db.EventMapper; +import org.sonar.core.persistence.DaoComponent; +import org.sonar.core.persistence.DbSession; + +import java.util.List; + +public class EventDao implements ServerComponent, DaoComponent { + + public List selectByComponentUuid(DbSession session, String componentUuid) { + return session.getMapper(EventMapper.class).selectByComponentUuid(componentUuid); + } + + public void insert(DbSession session, EventDto dto) { + session.getMapper(EventMapper.class).insert(dto); + } + + public void delete(DbSession session, Long id) { + session.getMapper(EventMapper.class).delete(id); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java new file mode 100644 index 00000000000..b0e26025947 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/event/db/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.server.event.db; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java new file mode 100644 index 00000000000..422411269ef --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java @@ -0,0 +1,193 @@ +/* + * 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.computation.step; + +import org.junit.*; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.utils.System2; +import org.sonar.batch.protocol.Constants; +import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.BatchReportReader; +import org.sonar.batch.protocol.output.BatchReportWriter; +import org.sonar.core.component.ComponentDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.computation.ComputationContext; +import org.sonar.server.db.DbClient; +import org.sonar.server.event.db.EventDao; +import org.sonar.test.DbTests; + +import java.io.File; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@Category(DbTests.class) +public class PersistEventsStepTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @ClassRule + public static DbTester dbTester = new DbTester(); + + DbSession session; + + EventDao dao; + + System2 system2; + + PersistEventsStep step; + + @Before + public void setup() throws Exception { + session = dbTester.myBatis().openSession(false); + dao = new EventDao(); + DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), dao); + + system2 = mock(System2.class); + when(system2.now()).thenReturn(1225630680000L); + + step = new PersistEventsStep(dbClient, system2); + } + + @After + public void tearDown() throws Exception { + session.close(); + } + + @Test + public void execute_only_on_projects() throws Exception { + assertThat(step.supportedProjectQualifiers()).containsOnly("TRK"); + } + + @Test + public void nothing_to_do_when_no_events_in_report() throws Exception { + dbTester.prepareDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml"); + + File reportDir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(reportDir); + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("ABCD") + .build()); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + + dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", "events"); + } + + @Test + public void persist_report_events() throws Exception { + dbTester.prepareDbUnit(getClass(), "empty.xml"); + + File reportDir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(reportDir); + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("ABCD") + .setSnapshotId(1000L) + .addEvents(BatchReport.Event.newBuilder() + .setName("Red (was Orange)") + .setCategory(Constants.EventCategory.ALERT) + .setDescription("Open issues > 0") + .build() + ) + .addEvents(BatchReport.Event.newBuilder() + .setName("Changes in 'Default' (Java)") + .setCategory(Constants.EventCategory.PROFILE) + .setEventData("from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000") + .build() + ) + .build()); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + + dbTester.assertDbUnit(getClass(), "add_events-result.xml", "events"); + } + + @Test + public void create_version_event() throws Exception { + dbTester.prepareDbUnit(getClass(), "empty.xml"); + + File reportDir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(reportDir); + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("ABCD") + .setSnapshotId(1000L) + .setVersion("1.0") + .build()); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + + dbTester.assertDbUnit(getClass(), "add_version_event-result.xml", "events"); + } + + @Test + public void keep_one_event_by_version() throws Exception { + dbTester.prepareDbUnit(getClass(), "keep_one_event_by_version.xml"); + + File reportDir = temp.newFolder(); + BatchReportWriter writer = new BatchReportWriter(reportDir); + writer.writeMetadata(BatchReport.Metadata.newBuilder() + .setRootComponentRef(1) + .setProjectKey("PROJECT_KEY") + .setAnalysisDate(150000000L) + .build()); + + writer.writeComponent(BatchReport.Component.newBuilder() + .setRef(1) + .setType(Constants.ComponentType.PROJECT) + .setUuid("ABCD") + .setSnapshotId(1001L) + .setVersion("1.5-SNAPSHOT") + .build()); + + step.execute(new ComputationContext(new BatchReportReader(reportDir), mock(ComponentDto.class))); + + dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", "events"); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java new file mode 100644 index 00000000000..2e13dbbce8c --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest.java @@ -0,0 +1,63 @@ +/* + * 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.v52; + +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonar.core.persistence.DbTester; +import org.sonar.server.db.migrations.DatabaseMigration; + +public class FeedEventsComponentUuidTest { + + @ClassRule + public static DbTester db = new DbTester().schema(FeedEventsComponentUuidTest.class, "schema.sql"); + + DatabaseMigration migration; + + @Before + public void setUp() throws Exception { + db.executeUpdateSql("truncate table events"); + db.executeUpdateSql("truncate table projects"); + + migration = new FeedEventsComponentUuid(db.database()); + } + + @Test + public void migrate_empty_db() throws Exception { + migration.execute(); + } + + @Test + public void migrate() throws Exception { + db.prepareDbUnit(this.getClass(), "migrate.xml"); + migration.execute(); + db.assertDbUnit(this.getClass(), "migrate-result.xml", "events"); + } + + @Test + public void not_migrate_already_migrated_data() throws Exception { + db.prepareDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml"); + migration.execute(); + db.assertDbUnit(this.getClass(), "not_migrate_already_migrated_data.xml", "events"); + } + +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java new file mode 100644 index 00000000000..9dba34a33fc --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/event/db/EventDaoTest.java @@ -0,0 +1,117 @@ +/* + * 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.event.db; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.sonar.core.event.EventDto; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.DbTester; +import org.sonar.test.DbTests; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +@Category(DbTests.class) +public class EventDaoTest { + + @ClassRule + public static DbTester dbTester = new DbTester(); + + DbSession session; + + EventDao dao; + + @Before + public void setup() throws Exception { + session = dbTester.myBatis().openSession(false); + dao = new EventDao(); + } + + @After + public void tearDown() throws Exception { + session.close(); + } + + @Test + public void select_by_component_uuid() throws Exception { + dbTester.prepareDbUnit(getClass(), "shared.xml"); + + List dtos = dao.selectByComponentUuid(session, "ABCD"); + assertThat(dtos).hasSize(3); + + dtos = dao.selectByComponentUuid(session, "BCDE"); + assertThat(dtos).hasSize(1); + + EventDto dto = dtos.get(0); + assertThat(dto.getId()).isEqualTo(4L); + assertThat(dto.getComponentUuid()).isEqualTo("BCDE"); + assertThat(dto.getSnapshotId()).isEqualTo(1000L); + assertThat(dto.getName()).isEqualTo("1.0"); + assertThat(dto.getCategory()).isEqualTo("Version"); + assertThat(dto.getDescription()).isEqualTo("Version 1.0"); + assertThat(dto.getData()).isEqualTo("some data"); + assertThat(dto.getDate()).isEqualTo(1413407091086L); + assertThat(dto.getCreatedAt()).isEqualTo(1225630680000L); + } + + @Test + public void return_different_categories() throws Exception { + dbTester.prepareDbUnit(getClass(), "shared.xml"); + + List dtos = dao.selectByComponentUuid(session, "ABCD"); + assertThat(dtos).extracting("category").containsOnly(EventDto.CATEGORY_ALERT, EventDto.CATEGORY_PROFILE, EventDto.CATEGORY_VERSION); + } + + @Test + public void insert() throws Exception { + dbTester.prepareDbUnit(getClass(), "empty.xml"); + + dao.insert(session, new EventDto() + .setName("1.0") + .setCategory(EventDto.CATEGORY_VERSION) + .setDescription("Version 1.0") + .setData("some data") + .setDate(1413407091086L) + .setComponentUuid("ABCD") + .setSnapshotId(1000L) + .setCreatedAt(1225630680000L) + ); + session.commit(); + + dbTester.assertDbUnit(getClass(), "insert-result.xml", "events"); + } + + @Test + public void delete() throws Exception { + dbTester.prepareDbUnit(getClass(), "delete.xml"); + + dao.delete(session, 1L); + session.commit(); + + assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0); + } + +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_events-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_events-result.xml new file mode 100644 index 00000000000..a1ba2c07bd3 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_events-result.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml new file mode 100644 index 00000000000..458a0425586 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/add_version_event-result.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/empty.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml new file mode 100644 index 00000000000..2a56e0c7203 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version-result.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml new file mode 100644 index 00000000000..44c19d1b921 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/keep_one_event_by_version.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml new file mode 100644 index 00000000000..0002deec3c2 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/step/PersistEventsStepTest/nothing_to_do_when_no_events_in_report.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate-result.xml new file mode 100644 index 00000000000..ada195e5574 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate-result.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate.xml new file mode 100644 index 00000000000..476fad9a85f --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/migrate.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/not_migrate_already_migrated_data.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/not_migrate_already_migrated_data.xml new file mode 100644 index 00000000000..7c0d6df26d3 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/not_migrate_already_migrated_data.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/schema.sql new file mode 100644 index 00000000000..e4ca540f2f2 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v52/FeedEventsComponentUuidTest/schema.sql @@ -0,0 +1,35 @@ +CREATE TABLE "PROJECTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(400), + "ROOT_ID" INTEGER, + "UUID" VARCHAR(50), + "PROJECT_UUID" VARCHAR(50), + "MODULE_UUID" VARCHAR(50), + "MODULE_UUID_PATH" VARCHAR(4000), + "NAME" VARCHAR(256), + "DESCRIPTION" VARCHAR(2000), + "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE, + "SCOPE" VARCHAR(3), + "QUALIFIER" VARCHAR(10), + "DEPRECATED_KEE" VARCHAR(400), + "PATH" VARCHAR(2000), + "LANGUAGE" VARCHAR(20), + "COPY_RESOURCE_ID" INTEGER, + "LONG_NAME" VARCHAR(256), + "PERSON_ID" INTEGER, + "CREATED_AT" TIMESTAMP, + "AUTHORIZATION_UPDATED_AT" BIGINT +); + +CREATE TABLE "EVENTS" ( + "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "NAME" VARCHAR(400), + "RESOURCE_ID" INTEGER, + "COMPONENT_UUID" VARCHAR(50), + "SNAPSHOT_ID" INTEGER, + "CATEGORY" VARCHAR(50), + "EVENT_DATE" BIGINT NOT NULL, + "CREATED_AT" BIGINT NOT NULL, + "DESCRIPTION" VARCHAR(4000), + "EVENT_DATA" VARCHAR(4000) +); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml new file mode 100644 index 00000000000..c22a68ed8e0 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/delete.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/empty.xml @@ -0,0 +1,3 @@ + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml new file mode 100644 index 00000000000..27a2a24e080 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/insert-result.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml new file mode 100644 index 00000000000..0002deec3c2 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/event/db/EventDaoTest/shared.xml @@ -0,0 +1,13 @@ + + + + + + + + + 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 e6d4696c397..44277d0885b 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 @@ -37,10 +37,10 @@ class Api::EventsController < Api::ApiController end if @resource - conditions<<'resource_id=:rid' - values[:rid]=@resource.id + conditions<<'component_uuid=:component_uuid' + values[:component_uuid]=@resource.uuid else - conditions<<'resource_id IS NULL' + conditions<<'component_uuid IS NULL' end from=nil @@ -87,7 +87,7 @@ class Api::EventsController < Api::ApiController def show begin event=Event.find(params[:id]) - load_resource(:user, event.resource_id) + load_resource_by_uuid(:user, event.component_uuid) respond_to do |format| format.json { render :json => jsonp(events_to_json([event])) } @@ -144,7 +144,7 @@ class Api::EventsController < Api::ApiController name = params[:name] desc = params[:description] category = params[:category] - snapshots = Snapshot.find(:all, :include => 'events', :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", root_snapshot.id, root_snapshot.id]) + snapshots = Snapshot.find(:all, :include => ['events', 'project'], :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", root_snapshot.id, root_snapshot.id]) snapshots.each do |snapshot| # if this is a 'Version' event, must propagate the version number to the snapshot if category==EventCategory::KEY_VERSION @@ -157,7 +157,7 @@ class Api::EventsController < Api::ApiController :description => desc, :category => category, :snapshot => snapshot, - :resource_id => snapshot.project_id, + :component_uuid => snapshot.project.uuid, :event_date => snapshot.created_at ) event.save! @@ -185,7 +185,7 @@ class Api::EventsController < Api::ApiController def destroy begin event=Event.find(params[:id]) - load_resource(:admin, event.resource_id) + load_resource_by_uuid(:admin, event.component_uuid) events = [] name = event.name @@ -238,6 +238,24 @@ class Api::EventsController < Api::ApiController end end + def load_resource_by_uuid(required_resource_role, component_uuid=nil) + if component_uuid + @resource=Project.first(:conditions => {:uuid => component_uuid}) + if @resource.nil? + raise ApiException.new 404, "Component uuid not found: #{component_uuid}" + end + + unless has_role?(required_resource_role, @resource) + raise ApiException.new 401, "Unauthorized" + end + else + # global events + unless is_admin? + raise ApiException.new 401, "Unauthorized" + end + end + end + def events_to_json(events=[]) json=[] events.each do |event| 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 5bcc25b9c4e..8e3d9358012 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 @@ -283,7 +283,7 @@ class ProjectController < ApplicationController end def update_version - snapshot=Snapshot.find(params[:sid]) + snapshot=Snapshot.find(params[:sid], :include => 'project') not_found("Snapshot not found") unless snapshot access_denied unless is_admin?(snapshot) @@ -307,7 +307,7 @@ class ProjectController < ApplicationController # We create an event for every concerned snapshot snapshots.each do |snapshot| event = Event.create!(:name => params[:version_name], :snapshot => snapshot, - :resource_id => snapshot.project_id, :category => EventCategory::KEY_VERSION, + :component_uuid => snapshot.project.uuid, :category => EventCategory::KEY_VERSION, :event_date => snapshot.created_at) end flash[:notice] = message('project_history.version_created', :params => params[:version_name]) @@ -359,7 +359,7 @@ class ProjectController < ApplicationController e = Event.new({:name => params[:event_name], :category => EventCategory::KEY_OTHER, :snapshot => s, - :resource_id => s.project_id, + :component_uuid => s.project.uuid, :event_date => s.created_at}) e.save! end @@ -385,7 +385,7 @@ class ProjectController < ApplicationController flash[:notice] = message('project_history.event_updated') end - redirect_to :action => 'history', :id => event.resource_id + redirect_to :action => 'history', :id => event.resource.id end def delete_event @@ -394,7 +394,7 @@ class ProjectController < ApplicationController access_denied unless is_admin?(event.resource) name = event.name - resource_id = event.resource_id + resource_id = event.resource.id events = find_events(event) Event.transaction do events.map { |e| e.id }.each_slice(999) do |safe_for_oracle_ids| @@ -416,7 +416,7 @@ class ProjectController < ApplicationController end def find_project_snapshots(root_snapshot_id) - snapshots = Snapshot.find(:all, :include => 'events', :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", root_snapshot_id, root_snapshot_id]) + Snapshot.find(:all, :include => ['events', 'project'], :conditions => ["(root_snapshot_id = ? OR id = ?) AND scope = 'PRJ'", root_snapshot_id, root_snapshot_id]) end # Returns all an array that contains the given event + all the events that are the same, but which are attached on the submodules 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 d5349ebaad3..01e4c8ef7f1 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 @@ -23,7 +23,7 @@ class Event < ActiveRecord::Base validates_length_of :name, :within => 1..400 validates_length_of :category, :within => 1..50 - belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id' + belongs_to :resource, :class_name => 'Project', :foreign_key => 'component_uuid', :primary_key => 'uuid' belongs_to :snapshot before_save :populate_snapshot diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb index f8d83a5640b..2c6c8b9cbf7 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/project.rb @@ -23,7 +23,7 @@ class Project < ActiveRecord::Base has_many :snapshots has_many :processed_snapshots, :class_name => 'Snapshot', :conditions => "status='#{Snapshot::STATUS_PROCESSED}' AND qualifier<>'LIB'", :order => 'created_at asc' - has_many :events, :foreign_key => 'resource_id', :order => 'event_date DESC' + has_many :events, :foreign_key => 'component_uuid', :primary_key => 'uuid', :order => 'event_date DESC' has_many :project_links, :foreign_key => 'component_uuid', :primary_key => 'uuid', :dependent => :delete_all, :order => 'link_type' has_many :user_roles, :foreign_key => 'resource_id' has_many :group_roles, :foreign_key => 'resource_id' diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/903_add_events_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/903_add_events_component_uuid.rb new file mode 100644 index 00000000000..e721accdf1b --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/903_add_events_component_uuid.rb @@ -0,0 +1,32 @@ +# +# 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.2 +# SONAR-6261 +# +class AddEventsComponentUuid < ActiveRecord::Migration + + def self.up + add_column 'events', 'component_uuid', :string, :limit => 50 + add_index 'events', 'component_uuid', :name => 'events_component_uuid' + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/904_feed_events_component_uuid.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/904_feed_events_component_uuid.rb new file mode 100644 index 00000000000..fb840dfb750 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/904_feed_events_component_uuid.rb @@ -0,0 +1,31 @@ +# +# 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.2 +# SONAR-6261 +# +class FeedEventsComponentUuid < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v52.FeedEventsComponentUuid') + end + +end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/905_remove_events_resource_id.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/905_remove_events_resource_id.rb new file mode 100644 index 00000000000..ba3ff7f6b93 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/905_remove_events_resource_id.rb @@ -0,0 +1,32 @@ +# +# 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.2 +# SONAR-6261 +# +class RemoveEventsResourceId < ActiveRecord::Migration + + def self.up + remove_index 'events', :name => 'events_resource_id' + remove_column 'events', 'resource_id' + end + +end diff --git a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java index bb13257ef3e..0c5b8965216 100644 --- a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java +++ b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/Constants.java @@ -235,6 +235,92 @@ public final class Constants { // @@protoc_insertion_point(enum_scope:ComponentType) } + /** + * Protobuf enum {@code EventCategory} + * + *
+   * temporary enum during development of computation stack
+   * 
+ */ + public enum EventCategory + implements com.google.protobuf.ProtocolMessageEnum { + /** + * ALERT = 0; + */ + ALERT(0, 0), + /** + * PROFILE = 1; + */ + PROFILE(1, 1), + ; + + /** + * ALERT = 0; + */ + public static final int ALERT_VALUE = 0; + /** + * PROFILE = 1; + */ + public static final int PROFILE_VALUE = 1; + + + public final int getNumber() { return value; } + + public static EventCategory valueOf(int value) { + switch (value) { + case 0: return ALERT; + case 1: return PROFILE; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public EventCategory findValueByNumber(int number) { + return EventCategory.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return org.sonar.batch.protocol.Constants.getDescriptor().getEnumTypes().get(2); + } + + private static final EventCategory[] VALUES = values(); + + public static EventCategory valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private EventCategory(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:EventCategory) + } + /** * Protobuf enum {@code ComponentLinkType} */ @@ -319,7 +405,7 @@ public final class Constants { } public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { - return org.sonar.batch.protocol.Constants.getDescriptor().getEnumTypes().get(2); + return org.sonar.batch.protocol.Constants.getDescriptor().getEnumTypes().get(3); } private static final ComponentLinkType[] VALUES = values(); @@ -357,9 +443,11 @@ public final class Constants { "\t\n\005MINOR\020\001\022\t\n\005MAJOR\020\002\022\014\n\010CRITICAL\020\003\022\013\n\007B" + "LOCKER\020\004*X\n\rComponentType\022\013\n\007PROJECT\020\000\022\n" + "\n\006MODULE\020\001\022\r\n\tDIRECTORY\020\002\022\010\n\004FILE\020\003\022\010\n\004V" + - "IEW\020\004\022\013\n\007SUBVIEW\020\005*F\n\021ComponentLinkType\022" + - "\010\n\004HOME\020\000\022\007\n\003SCM\020\001\022\013\n\007SCM_DEV\020\002\022\t\n\005ISSUE" + - "\020\003\022\006\n\002CI\020\004B\034\n\030org.sonar.batch.protocolH\001" + "IEW\020\004\022\013\n\007SUBVIEW\020\005*\'\n\rEventCategory\022\t\n\005A" + + "LERT\020\000\022\013\n\007PROFILE\020\001*F\n\021ComponentLinkType" + + "\022\010\n\004HOME\020\000\022\007\n\003SCM\020\001\022\013\n\007SCM_DEV\020\002\022\t\n\005ISSU" + + "E\020\003\022\006\n\002CI\020\004B\034\n\030org.sonar.batch.protocolH" + + "\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { diff --git a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java index c544e6f356b..19f233b6ebb 100644 --- a/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java +++ b/sonar-batch-protocol/src/main/gen-java/org/sonar/batch/protocol/output/BatchReport.java @@ -1396,6 +1396,968 @@ public final class BatchReport { // @@protoc_insertion_point(class_scope:ComponentLink) } + public interface EventOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional int32 component_ref = 1; + /** + * optional int32 component_ref = 1; + */ + boolean hasComponentRef(); + /** + * optional int32 component_ref = 1; + */ + int getComponentRef(); + + // optional string name = 2; + /** + * optional string name = 2; + */ + boolean hasName(); + /** + * optional string name = 2; + */ + java.lang.String getName(); + /** + * optional string name = 2; + */ + com.google.protobuf.ByteString + getNameBytes(); + + // optional string description = 3; + /** + * optional string description = 3; + */ + boolean hasDescription(); + /** + * optional string description = 3; + */ + java.lang.String getDescription(); + /** + * optional string description = 3; + */ + com.google.protobuf.ByteString + getDescriptionBytes(); + + // optional .EventCategory category = 4; + /** + * optional .EventCategory category = 4; + */ + boolean hasCategory(); + /** + * optional .EventCategory category = 4; + */ + org.sonar.batch.protocol.Constants.EventCategory getCategory(); + + // optional string event_data = 5; + /** + * optional string event_data = 5; + */ + boolean hasEventData(); + /** + * optional string event_data = 5; + */ + java.lang.String getEventData(); + /** + * optional string event_data = 5; + */ + com.google.protobuf.ByteString + getEventDataBytes(); + } + /** + * Protobuf type {@code Event} + * + *
+   * temporary message during development of computation stack
+   * 
+ */ + public static final class Event extends + com.google.protobuf.GeneratedMessage + implements EventOrBuilder { + // Use Event.newBuilder() to construct. + private Event(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private Event(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final Event defaultInstance; + public static Event getDefaultInstance() { + return defaultInstance; + } + + public Event getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private Event( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + componentRef_ = input.readInt32(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + name_ = input.readBytes(); + break; + } + case 26: { + bitField0_ |= 0x00000004; + description_ = input.readBytes(); + break; + } + case 32: { + int rawValue = input.readEnum(); + org.sonar.batch.protocol.Constants.EventCategory value = org.sonar.batch.protocol.Constants.EventCategory.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(4, rawValue); + } else { + bitField0_ |= 0x00000008; + category_ = value; + } + break; + } + case 42: { + bitField0_ |= 0x00000010; + eventData_ = input.readBytes(); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_Event_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_Event_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.Event.class, org.sonar.batch.protocol.output.BatchReport.Event.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public Event parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new Event(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + // optional int32 component_ref = 1; + public static final int COMPONENT_REF_FIELD_NUMBER = 1; + private int componentRef_; + /** + * optional int32 component_ref = 1; + */ + public boolean hasComponentRef() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional int32 component_ref = 1; + */ + public int getComponentRef() { + return componentRef_; + } + + // optional string name = 2; + public static final int NAME_FIELD_NUMBER = 2; + private java.lang.Object name_; + /** + * optional string name = 2; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string name = 2; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } + } + /** + * optional string name = 2; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // optional string description = 3; + public static final int DESCRIPTION_FIELD_NUMBER = 3; + private java.lang.Object description_; + /** + * optional string description = 3; + */ + public boolean hasDescription() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string description = 3; + */ + public java.lang.String getDescription() { + java.lang.Object ref = description_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + description_ = s; + } + return s; + } + } + /** + * optional string description = 3; + */ + public com.google.protobuf.ByteString + getDescriptionBytes() { + java.lang.Object ref = description_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + description_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // optional .EventCategory category = 4; + public static final int CATEGORY_FIELD_NUMBER = 4; + private org.sonar.batch.protocol.Constants.EventCategory category_; + /** + * optional .EventCategory category = 4; + */ + public boolean hasCategory() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional .EventCategory category = 4; + */ + public org.sonar.batch.protocol.Constants.EventCategory getCategory() { + return category_; + } + + // optional string event_data = 5; + public static final int EVENT_DATA_FIELD_NUMBER = 5; + private java.lang.Object eventData_; + /** + * optional string event_data = 5; + */ + public boolean hasEventData() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional string event_data = 5; + */ + public java.lang.String getEventData() { + java.lang.Object ref = eventData_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + eventData_ = s; + } + return s; + } + } + /** + * optional string event_data = 5; + */ + public com.google.protobuf.ByteString + getEventDataBytes() { + java.lang.Object ref = eventData_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + eventData_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + componentRef_ = 0; + name_ = ""; + description_ = ""; + category_ = org.sonar.batch.protocol.Constants.EventCategory.ALERT; + eventData_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt32(1, componentRef_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getNameBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(3, getDescriptionBytes()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeEnum(4, category_.getNumber()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeBytes(5, getEventDataBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, componentRef_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getNameBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, getDescriptionBytes()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(4, category_.getNumber()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(5, getEventDataBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.sonar.batch.protocol.output.BatchReport.Event parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(org.sonar.batch.protocol.output.BatchReport.Event prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code Event} + * + *
+     * temporary message during development of computation stack
+     * 
+ */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements org.sonar.batch.protocol.output.BatchReport.EventOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_Event_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_Event_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.sonar.batch.protocol.output.BatchReport.Event.class, org.sonar.batch.protocol.output.BatchReport.Event.Builder.class); + } + + // Construct using org.sonar.batch.protocol.output.BatchReport.Event.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + componentRef_ = 0; + bitField0_ = (bitField0_ & ~0x00000001); + name_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + description_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + category_ = org.sonar.batch.protocol.Constants.EventCategory.ALERT; + bitField0_ = (bitField0_ & ~0x00000008); + eventData_ = ""; + bitField0_ = (bitField0_ & ~0x00000010); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.sonar.batch.protocol.output.BatchReport.internal_static_Event_descriptor; + } + + public org.sonar.batch.protocol.output.BatchReport.Event getDefaultInstanceForType() { + return org.sonar.batch.protocol.output.BatchReport.Event.getDefaultInstance(); + } + + public org.sonar.batch.protocol.output.BatchReport.Event build() { + org.sonar.batch.protocol.output.BatchReport.Event result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.sonar.batch.protocol.output.BatchReport.Event buildPartial() { + org.sonar.batch.protocol.output.BatchReport.Event result = new org.sonar.batch.protocol.output.BatchReport.Event(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.componentRef_ = componentRef_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.name_ = name_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.description_ = description_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.category_ = category_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.eventData_ = eventData_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.sonar.batch.protocol.output.BatchReport.Event) { + return mergeFrom((org.sonar.batch.protocol.output.BatchReport.Event)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.sonar.batch.protocol.output.BatchReport.Event other) { + if (other == org.sonar.batch.protocol.output.BatchReport.Event.getDefaultInstance()) return this; + if (other.hasComponentRef()) { + setComponentRef(other.getComponentRef()); + } + if (other.hasName()) { + bitField0_ |= 0x00000002; + name_ = other.name_; + onChanged(); + } + if (other.hasDescription()) { + bitField0_ |= 0x00000004; + description_ = other.description_; + onChanged(); + } + if (other.hasCategory()) { + setCategory(other.getCategory()); + } + if (other.hasEventData()) { + bitField0_ |= 0x00000010; + eventData_ = other.eventData_; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.sonar.batch.protocol.output.BatchReport.Event parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.sonar.batch.protocol.output.BatchReport.Event) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + // optional int32 component_ref = 1; + private int componentRef_ ; + /** + * optional int32 component_ref = 1; + */ + public boolean hasComponentRef() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional int32 component_ref = 1; + */ + public int getComponentRef() { + return componentRef_; + } + /** + * optional int32 component_ref = 1; + */ + public Builder setComponentRef(int value) { + bitField0_ |= 0x00000001; + componentRef_ = value; + onChanged(); + return this; + } + /** + * optional int32 component_ref = 1; + */ + public Builder clearComponentRef() { + bitField0_ = (bitField0_ & ~0x00000001); + componentRef_ = 0; + onChanged(); + return this; + } + + // optional string name = 2; + private java.lang.Object name_ = ""; + /** + * optional string name = 2; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string name = 2; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + name_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string name = 2; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string name = 2; + */ + public Builder setName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + name_ = value; + onChanged(); + return this; + } + /** + * optional string name = 2; + */ + public Builder clearName() { + bitField0_ = (bitField0_ & ~0x00000002); + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * optional string name = 2; + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + name_ = value; + onChanged(); + return this; + } + + // optional string description = 3; + private java.lang.Object description_ = ""; + /** + * optional string description = 3; + */ + public boolean hasDescription() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional string description = 3; + */ + public java.lang.String getDescription() { + java.lang.Object ref = description_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + description_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string description = 3; + */ + public com.google.protobuf.ByteString + getDescriptionBytes() { + java.lang.Object ref = description_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + description_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string description = 3; + */ + public Builder setDescription( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + description_ = value; + onChanged(); + return this; + } + /** + * optional string description = 3; + */ + public Builder clearDescription() { + bitField0_ = (bitField0_ & ~0x00000004); + description_ = getDefaultInstance().getDescription(); + onChanged(); + return this; + } + /** + * optional string description = 3; + */ + public Builder setDescriptionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + description_ = value; + onChanged(); + return this; + } + + // optional .EventCategory category = 4; + private org.sonar.batch.protocol.Constants.EventCategory category_ = org.sonar.batch.protocol.Constants.EventCategory.ALERT; + /** + * optional .EventCategory category = 4; + */ + public boolean hasCategory() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional .EventCategory category = 4; + */ + public org.sonar.batch.protocol.Constants.EventCategory getCategory() { + return category_; + } + /** + * optional .EventCategory category = 4; + */ + public Builder setCategory(org.sonar.batch.protocol.Constants.EventCategory value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + category_ = value; + onChanged(); + return this; + } + /** + * optional .EventCategory category = 4; + */ + public Builder clearCategory() { + bitField0_ = (bitField0_ & ~0x00000008); + category_ = org.sonar.batch.protocol.Constants.EventCategory.ALERT; + onChanged(); + return this; + } + + // optional string event_data = 5; + private java.lang.Object eventData_ = ""; + /** + * optional string event_data = 5; + */ + public boolean hasEventData() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional string event_data = 5; + */ + public java.lang.String getEventData() { + java.lang.Object ref = eventData_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + eventData_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string event_data = 5; + */ + public com.google.protobuf.ByteString + getEventDataBytes() { + java.lang.Object ref = eventData_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + eventData_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string event_data = 5; + */ + public Builder setEventData( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + eventData_ = value; + onChanged(); + return this; + } + /** + * optional string event_data = 5; + */ + public Builder clearEventData() { + bitField0_ = (bitField0_ & ~0x00000010); + eventData_ = getDefaultInstance().getEventData(); + onChanged(); + return this; + } + /** + * optional string event_data = 5; + */ + public Builder setEventDataBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + eventData_ = value; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:Event) + } + + static { + defaultInstance = new Event(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:Event) + } + public interface ComponentOrBuilder extends com.google.protobuf.MessageOrBuilder { @@ -1513,9 +2475,36 @@ public final class BatchReport { org.sonar.batch.protocol.output.BatchReport.ComponentLinkOrBuilder getLinkOrBuilder( int index); - // optional int32 snapshot_id = 8; + // optional string version = 12; + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + boolean hasVersion(); + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + java.lang.String getVersion(); + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + com.google.protobuf.ByteString + getVersionBytes(); + + // optional int64 snapshot_id = 8; /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
      * temporary fields during development of computation stack
@@ -1523,13 +2512,13 @@ public final class BatchReport {
      */
     boolean hasSnapshotId();
     /**
-     * optional int32 snapshot_id = 8;
+     * optional int64 snapshot_id = 8;
      *
      * 
      * temporary fields during development of computation stack
      * 
*/ - int getSnapshotId(); + long getSnapshotId(); // optional string uuid = 9; /** @@ -1545,6 +2534,31 @@ public final class BatchReport { */ com.google.protobuf.ByteString getUuidBytes(); + + // repeated .Event events = 11; + /** + * repeated .Event events = 11; + */ + java.util.List + getEventsList(); + /** + * repeated .Event events = 11; + */ + org.sonar.batch.protocol.output.BatchReport.Event getEvents(int index); + /** + * repeated .Event events = 11; + */ + int getEventsCount(); + /** + * repeated .Event events = 11; + */ + java.util.List + getEventsOrBuilderList(); + /** + * repeated .Event events = 11; + */ + org.sonar.batch.protocol.output.BatchReport.EventOrBuilder getEventsOrBuilder( + int index); } /** * Protobuf type {@code Component} @@ -1655,12 +2669,12 @@ public final class BatchReport { break; } case 64: { - bitField0_ |= 0x00000040; - snapshotId_ = input.readInt32(); + bitField0_ |= 0x00000080; + snapshotId_ = input.readInt64(); break; } case 74: { - bitField0_ |= 0x00000080; + bitField0_ |= 0x00000100; uuid_ = input.readBytes(); break; } @@ -1672,6 +2686,19 @@ public final class BatchReport { link_.add(input.readMessage(org.sonar.batch.protocol.output.BatchReport.ComponentLink.PARSER, extensionRegistry)); break; } + case 90: { + if (!((mutable_bitField0_ & 0x00000800) == 0x00000800)) { + events_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000800; + } + events_.add(input.readMessage(org.sonar.batch.protocol.output.BatchReport.Event.PARSER, extensionRegistry)); + break; + } + case 98: { + bitField0_ |= 0x00000040; + version_ = input.readBytes(); + break; + } } } } catch (com.google.protobuf.InvalidProtocolBufferException e) { @@ -1686,6 +2713,9 @@ public final class BatchReport { if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) { link_ = java.util.Collections.unmodifiableList(link_); } + if (((mutable_bitField0_ & 0x00000800) == 0x00000800)) { + events_ = java.util.Collections.unmodifiableList(events_); + } this.unknownFields = unknownFields.build(); makeExtensionsImmutable(); } @@ -1955,27 +2985,82 @@ public final class BatchReport { return link_.get(index); } - // optional int32 snapshot_id = 8; + // optional string version = 12; + public static final int VERSION_FIELD_NUMBER = 12; + private java.lang.Object version_; + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + public boolean hasVersion() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + public java.lang.String getVersion() { + java.lang.Object ref = version_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + version_ = s; + } + return s; + } + } + /** + * optional string version = 12; + * + *
+     * Only available on PROJECT and MODULE type
+     * 
+ */ + public com.google.protobuf.ByteString + getVersionBytes() { + java.lang.Object ref = version_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // optional int64 snapshot_id = 8; public static final int SNAPSHOT_ID_FIELD_NUMBER = 8; - private int snapshotId_; + private long snapshotId_; /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
      * temporary fields during development of computation stack
      * 
*/ public boolean hasSnapshotId() { - return ((bitField0_ & 0x00000040) == 0x00000040); + return ((bitField0_ & 0x00000080) == 0x00000080); } /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
      * temporary fields during development of computation stack
      * 
*/ - public int getSnapshotId() { + public long getSnapshotId() { return snapshotId_; } @@ -1986,7 +3071,7 @@ public final class BatchReport { * optional string uuid = 9; */ public boolean hasUuid() { - return ((bitField0_ & 0x00000080) == 0x00000080); + return ((bitField0_ & 0x00000100) == 0x00000100); } /** * optional string uuid = 9; @@ -2022,6 +3107,42 @@ public final class BatchReport { } } + // repeated .Event events = 11; + public static final int EVENTS_FIELD_NUMBER = 11; + private java.util.List events_; + /** + * repeated .Event events = 11; + */ + public java.util.List getEventsList() { + return events_; + } + /** + * repeated .Event events = 11; + */ + public java.util.List + getEventsOrBuilderList() { + return events_; + } + /** + * repeated .Event events = 11; + */ + public int getEventsCount() { + return events_.size(); + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.Event getEvents(int index) { + return events_.get(index); + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.EventOrBuilder getEventsOrBuilder( + int index) { + return events_.get(index); + } + private void initFields() { ref_ = 0; path_ = ""; @@ -2031,8 +3152,10 @@ public final class BatchReport { language_ = ""; childRef_ = java.util.Collections.emptyList(); link_ = java.util.Collections.emptyList(); - snapshotId_ = 0; + version_ = ""; + snapshotId_ = 0L; uuid_ = ""; + events_ = java.util.Collections.emptyList(); } private byte memoizedIsInitialized = -1; public final boolean isInitialized() { @@ -2071,15 +3194,21 @@ public final class BatchReport { for (int i = 0; i < childRef_.size(); i++) { output.writeInt32NoTag(childRef_.get(i)); } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - output.writeInt32(8, snapshotId_); - } if (((bitField0_ & 0x00000080) == 0x00000080)) { + output.writeInt64(8, snapshotId_); + } + if (((bitField0_ & 0x00000100) == 0x00000100)) { output.writeBytes(9, getUuidBytes()); } for (int i = 0; i < link_.size(); i++) { output.writeMessage(10, link_.get(i)); } + for (int i = 0; i < events_.size(); i++) { + output.writeMessage(11, events_.get(i)); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeBytes(12, getVersionBytes()); + } getUnknownFields().writeTo(output); } @@ -2127,11 +3256,11 @@ public final class BatchReport { } childRefMemoizedSerializedSize = dataSize; } - if (((bitField0_ & 0x00000040) == 0x00000040)) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(8, snapshotId_); - } if (((bitField0_ & 0x00000080) == 0x00000080)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(8, snapshotId_); + } + if (((bitField0_ & 0x00000100) == 0x00000100)) { size += com.google.protobuf.CodedOutputStream .computeBytesSize(9, getUuidBytes()); } @@ -2139,6 +3268,14 @@ public final class BatchReport { size += com.google.protobuf.CodedOutputStream .computeMessageSize(10, link_.get(i)); } + for (int i = 0; i < events_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(11, events_.get(i)); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(12, getVersionBytes()); + } size += getUnknownFields().getSerializedSize(); memoizedSerializedSize = size; return size; @@ -2248,6 +3385,7 @@ public final class BatchReport { private void maybeForceBuilderInitialization() { if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { getLinkFieldBuilder(); + getEventsFieldBuilder(); } } private static Builder create() { @@ -2276,10 +3414,18 @@ public final class BatchReport { } else { linkBuilder_.clear(); } - snapshotId_ = 0; + version_ = ""; bitField0_ = (bitField0_ & ~0x00000100); - uuid_ = ""; + snapshotId_ = 0L; bitField0_ = (bitField0_ & ~0x00000200); + uuid_ = ""; + bitField0_ = (bitField0_ & ~0x00000400); + if (eventsBuilder_ == null) { + events_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000800); + } else { + eventsBuilder_.clear(); + } return this; } @@ -2349,11 +3495,24 @@ public final class BatchReport { if (((from_bitField0_ & 0x00000100) == 0x00000100)) { to_bitField0_ |= 0x00000040; } - result.snapshotId_ = snapshotId_; + result.version_ = version_; if (((from_bitField0_ & 0x00000200) == 0x00000200)) { to_bitField0_ |= 0x00000080; } + result.snapshotId_ = snapshotId_; + if (((from_bitField0_ & 0x00000400) == 0x00000400)) { + to_bitField0_ |= 0x00000100; + } result.uuid_ = uuid_; + if (eventsBuilder_ == null) { + if (((bitField0_ & 0x00000800) == 0x00000800)) { + events_ = java.util.Collections.unmodifiableList(events_); + bitField0_ = (bitField0_ & ~0x00000800); + } + result.events_ = events_; + } else { + result.events_ = eventsBuilder_.build(); + } result.bitField0_ = to_bitField0_; onBuilt(); return result; @@ -2430,14 +3589,45 @@ public final class BatchReport { } } } + if (other.hasVersion()) { + bitField0_ |= 0x00000100; + version_ = other.version_; + onChanged(); + } if (other.hasSnapshotId()) { setSnapshotId(other.getSnapshotId()); } if (other.hasUuid()) { - bitField0_ |= 0x00000200; + bitField0_ |= 0x00000400; uuid_ = other.uuid_; onChanged(); } + if (eventsBuilder_ == null) { + if (!other.events_.isEmpty()) { + if (events_.isEmpty()) { + events_ = other.events_; + bitField0_ = (bitField0_ & ~0x00000800); + } else { + ensureEventsIsMutable(); + events_.addAll(other.events_); + } + onChanged(); + } + } else { + if (!other.events_.isEmpty()) { + if (eventsBuilder_.isEmpty()) { + eventsBuilder_.dispose(); + eventsBuilder_ = null; + events_ = other.events_; + bitField0_ = (bitField0_ & ~0x00000800); + eventsBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getEventsFieldBuilder() : null; + } else { + eventsBuilder_.addAllMessages(other.events_); + } + } + } this.mergeUnknownFields(other.getUnknownFields()); return this; } @@ -3095,51 +4285,149 @@ public final class BatchReport { return linkBuilder_; } - // optional int32 snapshot_id = 8; - private int snapshotId_ ; + // optional string version = 12; + private java.lang.Object version_ = ""; + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public boolean hasVersion() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public java.lang.String getVersion() { + java.lang.Object ref = version_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + version_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public com.google.protobuf.ByteString + getVersionBytes() { + java.lang.Object ref = version_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + version_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public Builder setVersion( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000100; + version_ = value; + onChanged(); + return this; + } + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public Builder clearVersion() { + bitField0_ = (bitField0_ & ~0x00000100); + version_ = getDefaultInstance().getVersion(); + onChanged(); + return this; + } + /** + * optional string version = 12; + * + *
+       * Only available on PROJECT and MODULE type
+       * 
+ */ + public Builder setVersionBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000100; + version_ = value; + onChanged(); + return this; + } + + // optional int64 snapshot_id = 8; + private long snapshotId_ ; /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
        * temporary fields during development of computation stack
        * 
*/ public boolean hasSnapshotId() { - return ((bitField0_ & 0x00000100) == 0x00000100); + return ((bitField0_ & 0x00000200) == 0x00000200); } /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
        * temporary fields during development of computation stack
        * 
*/ - public int getSnapshotId() { + public long getSnapshotId() { return snapshotId_; } /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
        * temporary fields during development of computation stack
        * 
*/ - public Builder setSnapshotId(int value) { - bitField0_ |= 0x00000100; + public Builder setSnapshotId(long value) { + bitField0_ |= 0x00000200; snapshotId_ = value; onChanged(); return this; } /** - * optional int32 snapshot_id = 8; + * optional int64 snapshot_id = 8; * *
        * temporary fields during development of computation stack
        * 
*/ public Builder clearSnapshotId() { - bitField0_ = (bitField0_ & ~0x00000100); - snapshotId_ = 0; + bitField0_ = (bitField0_ & ~0x00000200); + snapshotId_ = 0L; onChanged(); return this; } @@ -3150,7 +4438,7 @@ public final class BatchReport { * optional string uuid = 9; */ public boolean hasUuid() { - return ((bitField0_ & 0x00000200) == 0x00000200); + return ((bitField0_ & 0x00000400) == 0x00000400); } /** * optional string uuid = 9; @@ -3190,7 +4478,7 @@ public final class BatchReport { if (value == null) { throw new NullPointerException(); } - bitField0_ |= 0x00000200; + bitField0_ |= 0x00000400; uuid_ = value; onChanged(); return this; @@ -3199,7 +4487,7 @@ public final class BatchReport { * optional string uuid = 9; */ public Builder clearUuid() { - bitField0_ = (bitField0_ & ~0x00000200); + bitField0_ = (bitField0_ & ~0x00000400); uuid_ = getDefaultInstance().getUuid(); onChanged(); return this; @@ -3212,12 +4500,252 @@ public final class BatchReport { if (value == null) { throw new NullPointerException(); } - bitField0_ |= 0x00000200; + bitField0_ |= 0x00000400; uuid_ = value; onChanged(); return this; } + // repeated .Event events = 11; + private java.util.List events_ = + java.util.Collections.emptyList(); + private void ensureEventsIsMutable() { + if (!((bitField0_ & 0x00000800) == 0x00000800)) { + events_ = new java.util.ArrayList(events_); + bitField0_ |= 0x00000800; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Event, org.sonar.batch.protocol.output.BatchReport.Event.Builder, org.sonar.batch.protocol.output.BatchReport.EventOrBuilder> eventsBuilder_; + + /** + * repeated .Event events = 11; + */ + public java.util.List getEventsList() { + if (eventsBuilder_ == null) { + return java.util.Collections.unmodifiableList(events_); + } else { + return eventsBuilder_.getMessageList(); + } + } + /** + * repeated .Event events = 11; + */ + public int getEventsCount() { + if (eventsBuilder_ == null) { + return events_.size(); + } else { + return eventsBuilder_.getCount(); + } + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.Event getEvents(int index) { + if (eventsBuilder_ == null) { + return events_.get(index); + } else { + return eventsBuilder_.getMessage(index); + } + } + /** + * repeated .Event events = 11; + */ + public Builder setEvents( + int index, org.sonar.batch.protocol.output.BatchReport.Event value) { + if (eventsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureEventsIsMutable(); + events_.set(index, value); + onChanged(); + } else { + eventsBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder setEvents( + int index, org.sonar.batch.protocol.output.BatchReport.Event.Builder builderForValue) { + if (eventsBuilder_ == null) { + ensureEventsIsMutable(); + events_.set(index, builderForValue.build()); + onChanged(); + } else { + eventsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder addEvents(org.sonar.batch.protocol.output.BatchReport.Event value) { + if (eventsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureEventsIsMutable(); + events_.add(value); + onChanged(); + } else { + eventsBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder addEvents( + int index, org.sonar.batch.protocol.output.BatchReport.Event value) { + if (eventsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureEventsIsMutable(); + events_.add(index, value); + onChanged(); + } else { + eventsBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder addEvents( + org.sonar.batch.protocol.output.BatchReport.Event.Builder builderForValue) { + if (eventsBuilder_ == null) { + ensureEventsIsMutable(); + events_.add(builderForValue.build()); + onChanged(); + } else { + eventsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder addEvents( + int index, org.sonar.batch.protocol.output.BatchReport.Event.Builder builderForValue) { + if (eventsBuilder_ == null) { + ensureEventsIsMutable(); + events_.add(index, builderForValue.build()); + onChanged(); + } else { + eventsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder addAllEvents( + java.lang.Iterable values) { + if (eventsBuilder_ == null) { + ensureEventsIsMutable(); + super.addAll(values, events_); + onChanged(); + } else { + eventsBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder clearEvents() { + if (eventsBuilder_ == null) { + events_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000800); + onChanged(); + } else { + eventsBuilder_.clear(); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public Builder removeEvents(int index) { + if (eventsBuilder_ == null) { + ensureEventsIsMutable(); + events_.remove(index); + onChanged(); + } else { + eventsBuilder_.remove(index); + } + return this; + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.Event.Builder getEventsBuilder( + int index) { + return getEventsFieldBuilder().getBuilder(index); + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.EventOrBuilder getEventsOrBuilder( + int index) { + if (eventsBuilder_ == null) { + return events_.get(index); } else { + return eventsBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .Event events = 11; + */ + public java.util.List + getEventsOrBuilderList() { + if (eventsBuilder_ != null) { + return eventsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(events_); + } + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.Event.Builder addEventsBuilder() { + return getEventsFieldBuilder().addBuilder( + org.sonar.batch.protocol.output.BatchReport.Event.getDefaultInstance()); + } + /** + * repeated .Event events = 11; + */ + public org.sonar.batch.protocol.output.BatchReport.Event.Builder addEventsBuilder( + int index) { + return getEventsFieldBuilder().addBuilder( + index, org.sonar.batch.protocol.output.BatchReport.Event.getDefaultInstance()); + } + /** + * repeated .Event events = 11; + */ + public java.util.List + getEventsBuilderList() { + return getEventsFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Event, org.sonar.batch.protocol.output.BatchReport.Event.Builder, org.sonar.batch.protocol.output.BatchReport.EventOrBuilder> + getEventsFieldBuilder() { + if (eventsBuilder_ == null) { + eventsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + org.sonar.batch.protocol.output.BatchReport.Event, org.sonar.batch.protocol.output.BatchReport.Event.Builder, org.sonar.batch.protocol.output.BatchReport.EventOrBuilder>( + events_, + ((bitField0_ & 0x00000800) == 0x00000800), + getParentForChildren(), + isClean()); + events_ = null; + } + return eventsBuilder_; + } + // @@protoc_insertion_point(builder_scope:Component) } @@ -7742,6 +9270,11 @@ public final class BatchReport { private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_ComponentLink_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_Event_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_Event_fieldAccessorTable; private static com.google.protobuf.Descriptors.Descriptor internal_static_Component_descriptor; private static @@ -7772,28 +9305,32 @@ public final class BatchReport { "(\005\022\023\n\013snapshot_id\030\004 \001(\003\022 \n\030deleted_compo" + "nents_count\030\005 \001(\005\"?\n\rComponentLink\022 \n\004ty" + "pe\030\001 \001(\0162\022.ComponentLinkType\022\014\n\004href\030\002 \001" + - "(\t\"\315\001\n\tComponent\022\013\n\003ref\030\001 \001(\005\022\014\n\004path\030\002 " + - "\001(\t\022\014\n\004name\030\003 \001(\t\022\034\n\004type\030\004 \001(\0162\016.Compon" + - "entType\022\017\n\007is_test\030\005 \001(\010\022\020\n\010language\030\006 \001" + - "(\t\022\025\n\tchild_ref\030\007 \003(\005B\002\020\001\022\034\n\004link\030\n \003(\0132", - "\016.ComponentLink\022\023\n\013snapshot_id\030\010 \001(\005\022\014\n\004" + - "uuid\030\t \001(\t\"\231\004\n\005Issue\022\027\n\017rule_repository\030" + - "\001 \001(\t\022\020\n\010rule_key\030\002 \001(\t\022\014\n\004line\030\003 \001(\005\022\013\n" + - "\003msg\030\004 \001(\t\022\033\n\010severity\030\005 \001(\0162\t.Severity\022" + - "\013\n\003tag\030\006 \003(\t\022\025\n\reffort_to_fix\030\007 \001(\001\022\016\n\006i" + - "s_new\030\010 \001(\010\022\014\n\004uuid\030\t \001(\t\022\027\n\017debt_in_min" + - "utes\030\n \001(\003\022\022\n\nresolution\030\013 \001(\t\022\016\n\006status" + - "\030\014 \001(\t\022\020\n\010checksum\030\r \001(\t\022\027\n\017manual_sever" + - "ity\030\016 \001(\010\022\020\n\010reporter\030\017 \001(\t\022\020\n\010assignee\030" + - "\020 \001(\t\022\027\n\017action_plan_key\030\021 \001(\t\022\022\n\nattrib", - "utes\030\022 \001(\t\022\024\n\014author_login\030\023 \001(\t\022\025\n\rcrea" + - "tion_date\030\024 \001(\003\022\022\n\nclose_date\030\025 \001(\003\022\023\n\013u" + - "pdate_date\030\026 \001(\003\022\023\n\013selected_at\030\027 \001(\003\022\023\n" + - "\013diff_fields\030\030 \001(\t\022\022\n\nis_changed\030\031 \001(\010\022\036" + - "\n\026must_send_notification\030\032 \001(\010\"N\n\006Issues" + - "\022\025\n\rcomponent_ref\030\001 \001(\005\022\025\n\005issue\030\002 \003(\0132\006" + - ".Issue\022\026\n\016component_uuid\030\003 \001(\tB#\n\037org.so" + - "nar.batch.protocol.outputH\001" + "(\t\"w\n\005Event\022\025\n\rcomponent_ref\030\001 \001(\005\022\014\n\004na" + + "me\030\002 \001(\t\022\023\n\013description\030\003 \001(\t\022 \n\010categor" + + "y\030\004 \001(\0162\016.EventCategory\022\022\n\nevent_data\030\005 " + + "\001(\t\"\366\001\n\tComponent\022\013\n\003ref\030\001 \001(\005\022\014\n\004path\030\002", + " \001(\t\022\014\n\004name\030\003 \001(\t\022\034\n\004type\030\004 \001(\0162\016.Compo" + + "nentType\022\017\n\007is_test\030\005 \001(\010\022\020\n\010language\030\006 " + + "\001(\t\022\025\n\tchild_ref\030\007 \003(\005B\002\020\001\022\034\n\004link\030\n \003(\013" + + "2\016.ComponentLink\022\017\n\007version\030\014 \001(\t\022\023\n\013sna" + + "pshot_id\030\010 \001(\003\022\014\n\004uuid\030\t \001(\t\022\026\n\006events\030\013" + + " \003(\0132\006.Event\"\231\004\n\005Issue\022\027\n\017rule_repositor" + + "y\030\001 \001(\t\022\020\n\010rule_key\030\002 \001(\t\022\014\n\004line\030\003 \001(\005\022" + + "\013\n\003msg\030\004 \001(\t\022\033\n\010severity\030\005 \001(\0162\t.Severit" + + "y\022\013\n\003tag\030\006 \003(\t\022\025\n\reffort_to_fix\030\007 \001(\001\022\016\n" + + "\006is_new\030\010 \001(\010\022\014\n\004uuid\030\t \001(\t\022\027\n\017debt_in_m", + "inutes\030\n \001(\003\022\022\n\nresolution\030\013 \001(\t\022\016\n\006stat" + + "us\030\014 \001(\t\022\020\n\010checksum\030\r \001(\t\022\027\n\017manual_sev" + + "erity\030\016 \001(\010\022\020\n\010reporter\030\017 \001(\t\022\020\n\010assigne" + + "e\030\020 \001(\t\022\027\n\017action_plan_key\030\021 \001(\t\022\022\n\nattr" + + "ibutes\030\022 \001(\t\022\024\n\014author_login\030\023 \001(\t\022\025\n\rcr" + + "eation_date\030\024 \001(\003\022\022\n\nclose_date\030\025 \001(\003\022\023\n" + + "\013update_date\030\026 \001(\003\022\023\n\013selected_at\030\027 \001(\003\022" + + "\023\n\013diff_fields\030\030 \001(\t\022\022\n\nis_changed\030\031 \001(\010" + + "\022\036\n\026must_send_notification\030\032 \001(\010\"N\n\006Issu" + + "es\022\025\n\rcomponent_ref\030\001 \001(\005\022\025\n\005issue\030\002 \003(\013", + "2\006.Issue\022\026\n\016component_uuid\030\003 \001(\tB#\n\037org." + + "sonar.batch.protocol.outputH\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -7812,20 +9349,26 @@ public final class BatchReport { com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_ComponentLink_descriptor, new java.lang.String[] { "Type", "Href", }); - internal_static_Component_descriptor = + internal_static_Event_descriptor = getDescriptor().getMessageTypes().get(2); + internal_static_Event_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_Event_descriptor, + new java.lang.String[] { "ComponentRef", "Name", "Description", "Category", "EventData", }); + internal_static_Component_descriptor = + getDescriptor().getMessageTypes().get(3); internal_static_Component_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_Component_descriptor, - new java.lang.String[] { "Ref", "Path", "Name", "Type", "IsTest", "Language", "ChildRef", "Link", "SnapshotId", "Uuid", }); + new java.lang.String[] { "Ref", "Path", "Name", "Type", "IsTest", "Language", "ChildRef", "Link", "Version", "SnapshotId", "Uuid", "Events", }); internal_static_Issue_descriptor = - getDescriptor().getMessageTypes().get(3); + getDescriptor().getMessageTypes().get(4); internal_static_Issue_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_Issue_descriptor, new java.lang.String[] { "RuleRepository", "RuleKey", "Line", "Msg", "Severity", "Tag", "EffortToFix", "IsNew", "Uuid", "DebtInMinutes", "Resolution", "Status", "Checksum", "ManualSeverity", "Reporter", "Assignee", "ActionPlanKey", "Attributes", "AuthorLogin", "CreationDate", "CloseDate", "UpdateDate", "SelectedAt", "DiffFields", "IsChanged", "MustSendNotification", }); internal_static_Issues_descriptor = - getDescriptor().getMessageTypes().get(4); + getDescriptor().getMessageTypes().get(5); internal_static_Issues_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_Issues_descriptor, diff --git a/sonar-batch-protocol/src/main/protobuf/batch_report.proto b/sonar-batch-protocol/src/main/protobuf/batch_report.proto index e159bedf516..4f5145cb87b 100644 --- a/sonar-batch-protocol/src/main/protobuf/batch_report.proto +++ b/sonar-batch-protocol/src/main/protobuf/batch_report.proto @@ -53,6 +53,15 @@ message ComponentLink { optional string href = 2; } +// temporary message during development of computation stack +message Event { + optional int32 component_ref = 1; + optional string name = 2; + optional string description = 3; + optional EventCategory category = 4; + optional string event_data = 5; +} + message Component { optional int32 ref = 1; optional string path = 2; @@ -62,10 +71,13 @@ message Component { optional string language = 6; repeated int32 child_ref = 7 [packed=true]; repeated ComponentLink link = 10; + // Only available on PROJECT and MODULE type + optional string version = 12; // temporary fields during development of computation stack - optional int32 snapshot_id = 8; + optional int64 snapshot_id = 8; optional string uuid = 9; + repeated Event events = 11; } message Issue { diff --git a/sonar-batch-protocol/src/main/protobuf/constants.proto b/sonar-batch-protocol/src/main/protobuf/constants.proto index e4e06eb0570..07c8aaf3540 100644 --- a/sonar-batch-protocol/src/main/protobuf/constants.proto +++ b/sonar-batch-protocol/src/main/protobuf/constants.proto @@ -38,6 +38,12 @@ enum ComponentType { SUBVIEW = 5; } +// temporary enum during development of computation stack +enum EventCategory { + ALERT = 0; + PROFILE = 1; +} + enum ComponentLinkType { HOME = 0; SCM = 1; diff --git a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java index 0125fa7d4d7..fcb0fce8ffb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java +++ b/sonar-batch/src/main/java/org/sonar/batch/deprecated/components/PastSnapshotFinderByPreviousVersion.java @@ -19,13 +19,12 @@ */ package org.sonar.batch.deprecated.components; -import org.sonar.batch.components.PastSnapshot; - import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; import org.sonar.api.batch.Event; import org.sonar.api.database.DatabaseSession; import org.sonar.api.database.model.Snapshot; +import org.sonar.batch.components.PastSnapshot; import java.util.List; @@ -43,8 +42,8 @@ public class PastSnapshotFinderByPreviousVersion implements BatchExtension { String currentVersion = projectSnapshot.getVersion(); Integer resourceId = projectSnapshot.getResourceId(); - String hql = "from " + Event.class.getSimpleName() + - " where name<>:version AND category='Version' AND resourceId=:resourceId ORDER BY date DESC"; + String hql = "select e from " + Event.class.getSimpleName() + " e " + + " join e.resource component where e.name<>:version AND e.category='Version' AND component.id=:resourceId ORDER BY e.date DESC"; List events = session.createQuery(hql) .setParameter("version", currentVersion) 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 8ee521c247e..3b68e8cda48 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 @@ -41,7 +41,7 @@ public class EventPersister { } public List getEvents(Resource resource) { - return session.getResults(Event.class, "resourceId", resource.getId()); + return session.getResults(Event.class, "componentUuid", resource.getUuid()); } public void deleteEvent(Event event) { @@ -56,8 +56,9 @@ public class EventPersister { event.setCreatedAt(new Date(system2.now())); if (event.getDate() == null) { event.setSnapshot(batchResource.snapshot()); + event.setComponentUuid(batchResource.resource().getUuid()); } else { - event.setResourceId(batchResource.resource().getId()); + event.setComponentUuid(batchResource.resource().getUuid()); } session.save(event); 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 480b91f147e..eb6b6ba8ee3 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 @@ -1,7 +1,7 @@ @@ -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" /> - - - - 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 bc3a3c9c055..5c328032d44 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 @@ -1,7 +1,7 @@ @@ -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" /> - - - - + - - 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 6efee1a0f51..64ebe4d642e 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 @@ -1,7 +1,7 @@ @@ -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" /> - - - - - - + + + + + + diff --git a/sonar-core/src/main/java/org/sonar/core/event/EventDto.java b/sonar-core/src/main/java/org/sonar/core/event/EventDto.java new file mode 100644 index 00000000000..f505c3a569b --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/event/EventDto.java @@ -0,0 +1,132 @@ +/* + * 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.core.event; + +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; + +public class EventDto { + + public static final String CATEGORY_VERSION = "Version"; + public static final String CATEGORY_ALERT = "Alert"; + public static final String CATEGORY_PROFILE = "Profile"; + + private Long id; + + private String name; + + private String description; + + private String category; + + private Long date; + + private Long createdAt; + + private String data; + + private Long snapshotId; + + private String componentUuid; + + public Long getId() { + return id; + } + + public EventDto setId(Long id) { + this.id = id; + return this; + } + + public String getCategory() { + return category; + } + + public EventDto setCategory(String category) { + this.category = category; + return this; + } + + public String getComponentUuid() { + return componentUuid; + } + + public EventDto setComponentUuid(String componentUuid) { + this.componentUuid = componentUuid; + return this; + } + + public Long getCreatedAt() { + return createdAt; + } + + public EventDto setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + return this; + } + + @CheckForNull + public String getData() { + return data; + } + + public EventDto setData(@Nullable String data) { + this.data = data; + return this; + } + + public Long getDate() { + return date; + } + + public EventDto setDate(Long date) { + this.date = date; + return this; + } + + @CheckForNull + public String getDescription() { + return description; + } + + public EventDto setDescription(@Nullable String description) { + this.description = description; + return this; + } + + public String getName() { + return name; + } + + public EventDto setName(String name) { + this.name = name; + return this; + } + + public Long getSnapshotId() { + return snapshotId; + } + + public EventDto setSnapshotId(Long snapshotId) { + this.snapshotId = snapshotId; + return this; + } +} diff --git a/sonar-core/src/main/java/org/sonar/core/event/db/EventMapper.java b/sonar-core/src/main/java/org/sonar/core/event/db/EventMapper.java new file mode 100644 index 00000000000..7fa3734967f --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/event/db/EventMapper.java @@ -0,0 +1,35 @@ +/* + * 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.core.event.db; + +import org.sonar.core.event.EventDto; + +import java.util.List; + +public interface EventMapper { + + List selectByComponentUuid(String uuid); + + void insert(EventDto dto); + + void delete(long id); + +} diff --git a/sonar-core/src/main/java/org/sonar/core/event/db/package-info.java b/sonar-core/src/main/java/org/sonar/core/event/db/package-info.java new file mode 100644 index 00000000000..7651f0b3db9 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/event/db/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.core.event.db; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-core/src/main/java/org/sonar/core/event/package-info.java b/sonar-core/src/main/java/org/sonar/core/event/package-info.java new file mode 100644 index 00000000000..a11358f5f24 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/event/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +@ParametersAreNonnullByDefault +package org.sonar.core.event; + +import javax.annotation.ParametersAreNonnullByDefault; 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 1ebd681a27c..72d79512ceb 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 = 902; + public static final int LAST_VERSION = 905; /** * List of all the tables.n diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java index 721288c807e..85873f4fc45 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java @@ -50,6 +50,8 @@ import org.sonar.core.dependency.ResourceSnapshotDto; import org.sonar.core.dependency.ResourceSnapshotMapper; import org.sonar.core.duplication.DuplicationMapper; import org.sonar.core.duplication.DuplicationUnitDto; +import org.sonar.core.event.EventDto; +import org.sonar.core.event.db.EventMapper; import org.sonar.core.graph.jdbc.GraphDto; import org.sonar.core.graph.jdbc.GraphDtoMapper; import org.sonar.core.issue.db.*; @@ -184,6 +186,7 @@ public class MyBatis implements BatchComponent, ServerComponent { loadAlias(conf, "IdUuidPair", IdUuidPair.class); loadAlias(conf, "FilePathWithHash", FilePathWithHashDto.class); loadAlias(conf, "UuidWithProjectUuid", UuidWithProjectUuidDto.class); + loadAlias(conf, "Event", EventDto.class); // AuthorizationMapper has to be loaded before IssueMapper because this last one used it loadMapper(conf, "org.sonar.core.user.AuthorizationMapper"); @@ -202,7 +205,7 @@ public class MyBatis implements BatchComponent, ServerComponent { NotificationQueueMapper.class, CharacteristicMapper.class, GroupMembershipMapper.class, QualityProfileMapper.class, ActiveRuleMapper.class, MeasureMapper.class, MetricMapper.class, QualityGateMapper.class, QualityGateConditionMapper.class, ComponentMapper.class, SnapshotMapper.class, - ProjectQgateAssociationMapper.class, + ProjectQgateAssociationMapper.class, EventMapper.class, AnalysisReportMapper.class, ComponentIndexMapper.class, ComponentLinkMapper.class, Migration45Mapper.class, Migration50Mapper.class }; diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 6abf150e396..438f416177c 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -125,9 +125,9 @@ class PurgeCommands { session.commit(); profiler.stop(); - profiler.start("deleteResourceEvents (events)"); - for (List partResourceIds : componentIdPartitions) { - purgeMapper.deleteResourceEvents(partResourceIds); + profiler.start("deleteComponentEvents (events)"); + for (List componentUuidPartition : componentUuidsPartitions) { + purgeMapper.deleteComponentEvents(componentUuidPartition); } session.commit(); profiler.stop(); diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java index 730b6845f43..2dda5e52837 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeMapper.java @@ -79,7 +79,7 @@ public interface PurgeMapper { void deleteResourceManualMeasures(@Param("resourceIds") List resourceIds); - void deleteResourceEvents(@Param("resourceIds") List resourceIds); + void deleteComponentEvents(@Param("componentUuids") List componentUuids); void deleteResourceActionPlans(@Param("resourceIds") List resourceIds); diff --git a/sonar-core/src/main/resources/org/sonar/core/event/db/EventMapper.xml b/sonar-core/src/main/resources/org/sonar/core/event/db/EventMapper.xml new file mode 100644 index 00000000000..11cd9bb3036 --- /dev/null +++ b/sonar-core/src/main/resources/org/sonar/core/event/db/EventMapper.xml @@ -0,0 +1,35 @@ + + + + + + e.id, + e.name, + e.category, + e.description, + e.event_data as "data", + e.event_date as "date", + e.component_uuid as "componentUuid", + e.snapshot_id as "snapshotId", + e.created_at as "createdAt" + + + + + + INSERT INTO events (name, category, description, event_data, event_date, component_uuid, snapshot_id, created_at) + VALUES (#{name}, #{category}, #{description}, #{data}, #{date}, #{componentUuid}, #{snapshotId}, #{createdAt}) + + + + DELETE FROM events WHERE id=#{id} + + + + 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 f09dceaddea..33e1daf7412 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 @@ -326,6 +326,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('796'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('900'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('901'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('902'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('903'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('904'); +INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('905'); 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 91af4c31769..720e4fd0ee6 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 @@ -164,7 +164,7 @@ CREATE TABLE "WIDGET_PROPERTIES" ( CREATE TABLE "EVENTS" ( "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(400), - "RESOURCE_ID" INTEGER, + "COMPONENT_UUID" VARCHAR(50), "SNAPSHOT_ID" INTEGER, "CATEGORY" VARCHAR(50), "EVENT_DATE" BIGINT NOT NULL, @@ -599,7 +599,7 @@ CREATE UNIQUE INDEX "METRICS_UNIQUE_NAME" ON "METRICS" ("NAME"); CREATE INDEX "EVENTS_SNAPSHOT_ID" ON "EVENTS" ("SNAPSHOT_ID"); -CREATE INDEX "EVENTS_RESOURCE_ID" ON "EVENTS" ("RESOURCE_ID"); +CREATE INDEX "EVENTS_COMPONENT_UUID" ON "EVENTS" ("COMPONENT_UUID"); CREATE INDEX "WIDGETS_WIDGETKEY" ON "WIDGETS" ("WIDGET_KEY"); diff --git a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml index 04c718a1eca..6ba17308f50 100644 --- a/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml @@ -238,10 +238,10 @@ - - delete from events where resource_id in - - #{resourceId} + + delete from events where component_uuid in + + #{componentUuid} 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 060dbfb065b..374c0652a83 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 @@ -22,9 +22,9 @@ - - - + + + 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 2f30df757d0..00363eb0100 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 @@ -15,7 +15,7 @@ build_date="1228222680000" version="[null]" path="[null]"/> - - 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 45eaee58163..a4cabcfff0d 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 @@ -24,7 +24,7 @@ - @@ -57,7 +57,7 @@ - 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 4a45a7fc405..8ca10cdab74 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 @@ -41,7 +41,7 @@ Note that measures, events and reviews are not deleted. - @@ -80,7 +80,7 @@ Note that measures, events and reviews are not deleted. parent_dependency_id="[null]" project_snapshot_id="2" dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> - 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 6c6e5bd44c2..00253585b49 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 @@ -26,7 +26,7 @@ parent_dependency_id="[null]" project_snapshot_id="2" dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> - @@ -64,7 +64,7 @@ parent_dependency_id="[null]" project_snapshot_id="2" dep_usage="USES" dep_weight="1" from_scope="LIB" to_scope="PRJ"/> - 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 78e14ead2a7..6a924f7f98a 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 @@ -55,7 +55,7 @@ period5_mode="[null]" period5_param="[null]" period5_date="[null]" depth="[null]" scope="PRJ" qualifier="TRK" created_at="1228222680000" build_date="1228222680000" version="[null]" path="[null]"/> - 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 eb4db71fe41..1e756c3f6bd 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 @@ -21,9 +21,11 @@ package org.sonar.api.batch; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.BaseIdentifiable; +import org.sonar.api.database.model.ResourceModel; import org.sonar.api.database.model.Snapshot; import javax.persistence.*; + import java.util.Date; import static com.google.common.base.Preconditions.checkNotNull; @@ -61,8 +63,12 @@ public class Event extends BaseIdentifiable { @JoinColumn(name = "snapshot_id", updatable = true, nullable = true) private Snapshot snapshot; - @Column(name = "resource_id", updatable = true, nullable = true) - private Integer resourceId; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "component_uuid", referencedColumnName = "uuid", insertable = false, updatable = false, nullable = false) + private ResourceModel resource; + + @Column(name = "component_uuid", updatable = true, nullable = true) + private String componentUuid; public Event() { } @@ -128,16 +134,23 @@ public class Event extends BaseIdentifiable { public final void setSnapshot(Snapshot snapshot) { 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(); +// this.resourceId = snapshot.getResourceId(); + } + + public ResourceModel getResource() { + return resource; + } + + public void setResource(ResourceModel resource) { + this.resource = resource; } - public Integer getResourceId() { - return resourceId; + public String getComponentUuid() { + return componentUuid; } - public Event setResourceId(Integer resourceId) { - this.resourceId = resourceId; - return this; + public void setComponentUuid(String componentUuid) { + this.componentUuid = componentUuid; } public String getData() { @@ -155,7 +168,7 @@ public class Event extends BaseIdentifiable { .append("categ", category) .append("date", date) .append("snapshot", snapshot) - .append("resource", resourceId) + .append("resource", resource) .toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java index d8b080cdab4..832885dfc8a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java @@ -30,6 +30,7 @@ import org.sonar.api.resources.Resource; import javax.annotation.Nullable; import javax.persistence.*; +import java.io.Serializable; import java.util.Date; /** @@ -37,7 +38,7 @@ import java.util.Date; */ @Entity @Table(name = "projects") -public class ResourceModel extends BaseIdentifiable implements Cloneable { +public class ResourceModel extends BaseIdentifiable implements Cloneable, Serializable { public static final String SCOPE_PROJECT = "PRJ"; public static final String QUALIFIER_PROJECT_TRUNK = "TRK"; -- 2.39.5