).build();
new SeleneseTest(selenese).runOn(orchestrator);
- assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(14);
+ assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(2);
selenese = Selenese.builder()
.setHtmlTestsInClasspath("delete_version_of_multimodule_project",
).build();
new SeleneseTest(selenese).runOn(orchestrator);
- assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(7);
+ assertThat(count("events where category='Version'")).as("Different number of events").isEqualTo(1);
}
/**
<tr>
<td>waitForText</td>
<td>infomsg</td>
- <td>glob:*Version "RELEASE" was removed from current project and all its sub-projects*</td>
+ <td>glob:*Version "RELEASE" was removed from current project*</td>
</tr>
<tr>
<td>assertNotText</td>
<tr>
<td>waitForText</td>
<td>infomsg</td>
- <td>Version "RELEASE" was created for current project and all its sub-projects.</td>
+ <td>Version "RELEASE" was created for current project.</td>
</tr>
<tr>
<td>waitForText</td>
import org.sonar.server.computation.component.Component;
+import static org.sonar.server.computation.component.Component.Type;
+
public interface EventRepository {
+ /**
+ * @throws NullPointerException if {@code component} or {@code event} is {@code null}
+ * @throws IllegalArgumentException if type of {@code component} is not {@link Type#PROJECT}
+ */
void add(Component component, Event event);
+ /**
+ * @throws NullPointerException if {@code component} is {@code null}
+ */
Iterable<Event> getEvents(Component component);
}
import com.google.common.collect.Multimap;
import org.sonar.server.computation.component.Component;
+import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
public class EventRepositoryImpl implements EventRepository {
@Override
public void add(Component component, Event event) {
+ checkArgument(component.getType() == Component.Type.PROJECT, "Component must be of type PROJECT");
events.put(component.getReportAttributes().getRef(), requireNonNull(event));
}
}
}
- private void processComponent(Component component, DbSession session, long analysisDate) {
- processEvents(session, component, analysisDate);
- saveVersionEvent(session, component, analysisDate);
- }
-
private void processEvents(DbSession session, Component component, Long analysisDate) {
Function<Event, EventDto> eventToEventDto = event -> newBaseEvent(component, analysisDate)
.setName(event.getName())
private final long analysisDate;
public PersistEventComponentVisitor(DbSession session, long analysisDate) {
- super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.PRE_ORDER);
+ super(CrawlerDepthLimit.PROJECT, ComponentVisitor.Order.PRE_ORDER);
this.session = session;
this.analysisDate = analysisDate;
}
@Override
public void visitProject(Component project) {
- processComponent(project, session, analysisDate);
- }
-
- @Override
- public void visitModule(Component module) {
- processComponent(module, session, analysisDate);
+ processEvents(session, project, analysisDate);
+ saveVersionEvent(session, project, analysisDate);
}
- @Override
- public void visitDirectory(Component directory) {
- processComponent(directory, session, analysisDate);
- }
-
- @Override
- public void visitFile(Component file) {
- processComponent(file, session, analysisDate);
- }
}
}
*/
package org.sonar.server.computation.event;
+import java.util.Arrays;
import org.junit.Test;
import org.sonar.server.computation.component.Component;
import org.sonar.server.computation.component.ReportComponent;
+import org.sonar.server.computation.component.ViewsComponent;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
public class EventRepositoryImplTest {
private static final Component COMPONENT_1 = newComponent(1);
underTest.add(COMPONENT_1, null);
}
+ @Test
+ public void add_throws_IAE_for_any_component_type_but_PROJECT() {
+ Arrays.stream(Component.Type.values())
+ .filter(type -> type != Component.Type.PROJECT)
+ .map(type -> {
+ if (type.isReportType()) {
+ return ReportComponent.builder(type, 1).build();
+ } else {
+ return ViewsComponent.builder(type, 1).build();
+ }
+ })
+ .forEach(component -> {
+ try {
+ underTest.add(component, EVENT_1);
+ fail("should have raised an IAE");
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Component must be of type PROJECT");
+ }
+ });
+ }
+
@Test
public void can_add_and_retrieve_many_events_per_component() {
underTest.add(COMPONENT_1, EVENT_1);
}
private static Component newComponent(int i) {
- return ReportComponent.builder(Component.Type.FILE, i).build();
+ return ReportComponent.builder(Component.Type.PROJECT, i).build();
}
}
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-
+import static org.sonar.server.computation.component.Component.Type.DIRECTORY;
+import static org.sonar.server.computation.component.Component.Type.FILE;
+import static org.sonar.server.computation.component.Component.Type.MODULE;
+import static org.sonar.server.computation.component.Component.Type.PROJECT;
+import static org.sonar.server.computation.component.ReportComponent.builder;
public class PersistEventsStepTest extends BaseStepTest {
+ private static final ReportComponent ROOT = builder(PROJECT, 1)
+ .setUuid("ABCD")
+ .addChildren(
+ builder(MODULE, 2)
+ .setUuid("BCDE")
+ .addChildren(
+ builder(DIRECTORY, 3)
+ .setUuid("Q")
+ .addChildren(
+ builder(FILE, 4)
+ .setUuid("Z")
+ .build())
+ .build())
+ .build())
+ .build();
+
System2 system2 = mock(System2.class);
@Rule
public DbTester dbTester = DbTester.create(system2);
-
@Rule
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
-
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
public void nothing_to_do_when_no_events_in_report() {
dbTester.prepareDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml");
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build());
+ treeRootHolder.setRoot(ROOT);
step.execute();
public void persist_report_events_with_component_children() {
dbTester.prepareDbUnit(getClass(), "empty.xml");
- ReportComponent module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").build();
- ReportComponent root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").addChildren(module).build();
- treeRootHolder.setRoot(root);
-
- dbIdsRepository.setSnapshotId(root, 1000L);
- dbIdsRepository.setSnapshotId(module, 1001L);
+ treeRootHolder.setRoot(ROOT);
- Component child = root.getChildren().get(0);
+ dbIdsRepository.setSnapshotId(ROOT, 1000L);
- when(eventRepository.getEvents(root)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0")));
- when(eventRepository.getEvents(child)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0")));
+ when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(Event.createAlert("Red (was Orange)", null, "Open issues > 0")));
- treeRootHolder.setRoot(root);
+ treeRootHolder.setRoot(ROOT);
step.execute();
dbTester.assertDbUnit(getClass(), "persist_report_events_with_component_children-result.xml", "events");
public void create_version_event() {
dbTester.prepareDbUnit(getClass(), "empty.xml");
- Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setVersion("1.0").build();
+ Component project = builder(PROJECT, 1)
+ .setUuid("ABCD")
+ .setVersion("1.0")
+ .addChildren(
+ builder(MODULE, 2)
+ .setUuid("BCDE")
+ .addChildren(
+ builder(DIRECTORY, 3)
+ .setUuid("Q")
+ .addChildren(
+ builder(FILE, 4)
+ .setUuid("Z")
+ .build())
+ .build())
+ .build())
+ .build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setSnapshotId(project, 1000L);
+ dbIdsRepository.setSnapshotId(ROOT, 1000L);
step.execute();
public void keep_one_event_by_version() {
dbTester.prepareDbUnit(getClass(), "keep_one_event_by_version.xml");
- Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setVersion("1.5-SNAPSHOT").build();
+ Component project = builder(PROJECT, 1)
+ .setUuid("ABCD")
+ .setVersion("1.5-SNAPSHOT")
+ .addChildren(
+ builder(MODULE, 2)
+ .setUuid("BCDE")
+ .addChildren(
+ builder(DIRECTORY, 3)
+ .setUuid("Q")
+ .addChildren(
+ builder(FILE, 4)
+ .setUuid("Z")
+ .build())
+ .build())
+ .build())
+ .build();
treeRootHolder.setRoot(project);
- dbIdsRepository.setSnapshotId(project, 1001L);
+ dbIdsRepository.setSnapshotId(ROOT, 1001L);
step.execute();
<dataset>
- <events id="1" name="1.0" category="Version" description="[null]" event_data="[null]" event_date="150000000"
- component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+ <events id="1"
+ name="1.0"
+ category="Version"
+ description="[null]"
+ event_data="[null]"
+ event_date="150000000"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
</dataset>
<dataset>
- <events id="1" name="1.3-SNAPSHOT" category="Version" description="[null]" event_data="[null]" event_date="120000000"
- component_uuid="ABCD" snapshot_id="1000" created_at="120000000" />
- <events id="2" name="1.4" category="Version" description="[null]" event_data="[null]" event_date="130000000"
- component_uuid="ABCD" snapshot_id="1000" created_at="130000000" />
- <events id="3" name="1.5-SNAPSHOT" category="Version" description="[null]" event_data="[null]" event_date="140000000"
- component_uuid="ABCD" snapshot_id="1000" created_at="140000000" />
+ <events id="1"
+ name="1.3-SNAPSHOT"
+ category="Version"
+ description="[null]"
+ event_data="[null]"
+ event_date="120000000"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="120000000"/>
+ <events id="2"
+ name="1.4"
+ category="Version"
+ description="[null]"
+ event_data="[null]"
+ event_date="130000000"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="130000000"/>
+ <events id="3"
+ name="1.5-SNAPSHOT"
+ category="Version"
+ description="[null]"
+ event_data="[null]"
+ event_date="140000000"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="140000000"/>
</dataset>
<dataset>
- <events id="1" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
- component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
- <events id="2" name="Red (was Orange)" category="Alert" description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
- event_data="[null]" event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
- <events id="3" name="Changes in 'Default' (Java)" category="Profile" description="Version 1.0" event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
- event_date="1413407091086" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
+ <events id="1"
+ name="1.0"
+ category="Version"
+ description="Version 1.0"
+ event_data="some data"
+ event_date="1413407091086"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
+ <events id="2"
+ name="Red (was Orange)"
+ category="Alert"
+ description="Critical issues variation > 0 since previous version (1.0 - 2015 Feb 09), Open issues > 0"
+ event_data="[null]"
+ event_date="1413407091086"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
+ <events id="3"
+ name="Changes in 'Default' (Java)"
+ category="Profile"
+ description="Version 1.0"
+ event_data="from=2014-10-12T08:36:25+0000;key=java-default;to=2014-10-12T10:36:25+0000"
+ event_date="1413407091086"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
- <events id="4" name="1.0" category="Version" description="Version 1.0" event_data="some data" event_date="1413407091086"
- component_uuid="BCDE" snapshot_id="1000" created_at="1225630680000" />
+ <events id="4"
+ name="1.0"
+ category="Version"
+ description="Version 1.0"
+ event_data="some data"
+ event_date="1413407091086"
+ component_uuid="BCDE"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
</dataset>
<dataset>
- <events id="1" name="Red (was Orange)" category="Alert" description="Open issues > 0"
+ <events id="1"
+ name="Red (was Orange)"
+ category="Alert"
+ description="Open issues > 0"
event_data="[null]"
- event_date="150000000" component_uuid="ABCD" snapshot_id="1000" created_at="1225630680000" />
- <events id="2" name="Red (was Orange)" category="Alert" description="Open issues > 0"
- event_data="[null]"
- event_date="150000000" component_uuid="BCDE" snapshot_id="1001" created_at="1225630680000" />
+ event_date="150000000"
+ component_uuid="ABCD"
+ snapshot_id="1000"
+ created_at="1225630680000"/>
</dataset>
if Event.already_exists(snapshot.id, params[:version_name], EventCategory::KEY_VERSION)
flash[:error] = message('project_history.version_already_exists', :params => h(params[:version_name]))
else
- snapshots = find_project_snapshots(snapshot.id)
- # We update all the related snapshots to have a version attribute in sync with the new name
- snapshots.each do |snapshot|
- snapshot.version = params[:version_name]
- snapshot.save!
- end
- # And then we update/create the event on each snapshot
+ # We update the snapshot to have a version attribute in sync with the new name
+ snapshot.version = params[:version_name]
+ snapshot.save!
+ # And then we update/create the event on the snapshot
if snapshot.event(EventCategory::KEY_VERSION)
- # This is an update: we update all the related events
+ # This is an update: we update the event
Event.update_all({:name => params[:version_name]},
- ["category = ? AND snapshot_id IN (?)", EventCategory::KEY_VERSION, snapshots.map { |s| s.id }])
+ ["category = ? AND snapshot_id = ?", EventCategory::KEY_VERSION, snapshot.id])
flash[:notice] = message('project_history.version_updated', :params => h(params[:version_name]))
else
- # We create an event for every concerned snapshot
- snapshots.each do |snapshot|
- event = Event.create!(:name => params[:version_name], :snapshot => snapshot,
- :component_uuid => snapshot.project.uuid, :category => EventCategory::KEY_VERSION,
- :event_date => snapshot.created_at)
- end
+ # We create an event on the snapshot
+ event = Event.create!(:name => params[:version_name], :snapshot => snapshot,
+ :component_uuid => snapshot.project.uuid, :category => EventCategory::KEY_VERSION,
+ :event_date => snapshot.created_at)
flash[:notice] = message('project_history.version_created', :params => h(params[:version_name]))
end
end
project_history.create_version=Create
project_history.remove_version=Remove
project_history.do_you_want_to_remove_version=Are you sure you want to remove "{0}" from this snapshot?
-project_history.version_updated=Version was updated to "{0}" for current project and all its sub-projects.
-project_history.version_created=Version "{0}" was created for current project and all its sub-projects.
-project_history.version_removed=Version "{0}" was removed from current project and all its sub-projects.
+project_history.version_updated=Version was updated to "{0}" for current project.
+project_history.version_created=Version "{0}" was created for current project.
+project_history.version_removed=Version "{0}" was removed from current project.
project_history.version_already_exists=Version "{0}" already exists.
project_history.rename_event=Rename
project_history.create_event=Create