insertActivity("T1", project1, SUCCESS);
insertActivity("T2", project2, FAILED);
insertQueue("T3", project1, IN_PROGRESS);
- List<String> messagesT1 = insertMessages("T1", 2);
- List<String> messagesT2 = insertMessages("T2", 1);
- insertMessages("T3", 5);
+ List<String> messagesT1 = insertMessages(MessageType.GENERIC,"T1", 2);
+ List<String> messagesT2 = insertMessages(MessageType.GENERIC,"T2", 1);
+ insertMessages(MessageType.GENERIC,"T3", 5);
ActivityResponse activityResponse = call(ws.newRequest()
.setParam(Param.PAGE_SIZE, Integer.toString(10))
.containsOnly(tuple("T1", messagesT1.size(), messagesT1), tuple("T2", messagesT2.size(), messagesT2), tuple("T3", 0, emptyList()));
}
- private List<String> insertMessages(String taskUuid, int messageCount) {
+ @Test
+ public void return_infoMessages() {
+ logInAsSystemAdministrator();
+ ProjectData project1 = db.components().insertPrivateProject();
+ ProjectData project2 = db.components().insertPrivateProject();
+ insertActivity("T1", project1, SUCCESS);
+ insertActivity("T2", project2, FAILED);
+ insertQueue("T3", project1, IN_PROGRESS);
+ List<String> messagesT1 = insertMessages(MessageType.INFO,"T1", 2);
+ List<String> messagesT2 = insertMessages(MessageType.INFO,"T2", 1);
+ insertMessages(MessageType.INFO,"T3", 5);
+
+ ActivityResponse activityResponse = call(ws.newRequest()
+ .setParam(Param.PAGE_SIZE, Integer.toString(10))
+ .setParam(PARAM_STATUS, "SUCCESS,FAILED,CANCELED,IN_PROGRESS,PENDING"));
+ assertThat(activityResponse.getTasksList())
+ .extracting(Task::getId, Task::getInfoMessagesList)
+ .containsOnly(tuple("T1", messagesT1), tuple("T2", messagesT2), tuple("T3", emptyList()));
+ }
+
+ private List<String> insertMessages(MessageType messageType, String taskUuid, int messageCount) {
List<CeTaskMessageDto> ceTaskMessageDtos = IntStream.range(0, messageCount)
.mapToObj(i -> new CeTaskMessageDto()
.setUuid("uuid_" + taskUuid + "_" + i)
.setTaskUuid(taskUuid)
.setMessage("m_" + taskUuid + "_" + i)
- .setType(MessageType.GENERIC)
+ .setType(messageType)
.setCreatedAt(taskUuid.hashCode() + i))
.toList();
new Change("8.8", "field \"logs\" is dropped"),
new Change("10.0", "Remove deprecated field 'componentId'"),
new Change("10.1", String.format("The use of module keys in parameter '%s' is removed", PARAM_COMPONENT)),
- new Change("10.1", "Warnings field will be now be filled (it was always empty in the past).")
+ new Change("10.1", "Warnings field will be now be filled (it was always empty in the past)."),
+ new Change("10.4", "field \"infoMessages\" added to response")
)
.setSince("5.2");
import com.google.common.collect.Multimap;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.sonar.db.ce.CeTaskCharacteristicDto;
import org.sonar.db.ce.CeTaskMessageDto;
import org.sonar.db.component.ComponentDto;
+import org.sonar.db.dismissmessage.MessageType;
import org.sonar.db.user.UserDto;
import org.sonarqube.ws.Ce;
import org.sonarqube.ws.Common;
builder.setWarningCount(warnings.size());
warnings.forEach(builder::addWarnings);
+ List<String> infoMessages = extractInfoMessages(activityDto);
+ builder.addAllInfoMessages(infoMessages);
+
return builder.build();
}
.toList();
}
+ private static List<String> extractInfoMessages(CeActivityDto activityDto) {
+ return activityDto.getCeTaskMessageDtos().stream()
+ .filter(ceTaskMessageDto -> MessageType.INFO.equals(ceTaskMessageDto.getType()))
+ .sorted(Comparator.comparing(CeTaskMessageDto::getCreatedAt))
+ .map(CeTaskMessageDto::getMessage)
+ .toList();
+ }
+
private static class DtoCache {
private final Map<String, ComponentDto> componentsByUuid;
private final Multimap<String, CeTaskCharacteristicDto> characteristicsByTaskUuid;
"warnings": [
"The properties \u0027sonar.login\u0027 and \u0027sonar.password\u0027 are deprecated and will be removed in the future. Please pass a token with the \u0027sonar.token\u0027 property instead.",
"Missing blame information for 2 files. This may lead to some features not working correctly. Please check the analysis logs and refer to \u003ca href\u003d\"https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scm-integration/\" rel\u003d\"noopener noreferrer\" target\u003d\"_blank\"\u003ethe documentation\u003c/a\u003e."
+ ] ,
+ "infoMessages": [
+ "Successfully synchronized 5 users.",
+ "Other information message"
]
},
{
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.Set;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
import org.junit.Rule;
import static org.mockito.Mockito.when;
import static org.sonar.db.ce.CeQueueTesting.makeInProgress;
import static org.sonar.db.dismissmessage.MessageType.INFO;
+import static org.sonar.db.dismissmessage.MessageType.PROJECT_NCD_PAGE_90;
public class TaskFormatterTest {
assertThat(wsTask.hasScannerContext()).isFalse();
assertThat(wsTask.getWarningCount()).isZero();
assertThat(wsTask.getWarningsList()).isEmpty();
+ assertThat(wsTask.getInfoMessagesList()).isEmpty();
}
@Test
}
@Test
- public void formatActivity_filterNonWarnings_andSetMessagesAndCount() {
+ public void formatActivity_filterWarnings_andSetWarningsAndCount() {
TestActivityDto dto = newActivity("UUID", "COMPONENT_UUID", CeActivityDto.Status.FAILED, null);
CeTaskMessageDto warning1 = createCeTaskMessageDto(1998, MessageType.GENERIC);
CeTaskMessageDto warning2 = createCeTaskMessageDto(1999, MessageType.GENERIC);
assertThat(wsTask.getWarningsList()).hasSameElementsAs(getMessagesText(List.of(warning1, warning2)));
}
+ @Test
+ public void formatActivity_filterInformation_andSetInformationMessages() {
+ TestActivityDto dto = newActivity("UUID", "COMPONENT_UUID", CeActivityDto.Status.FAILED, null);
+ CeTaskMessageDto nonInfo1 = createCeTaskMessageDto(1998, MessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
+ CeTaskMessageDto nonInfo2 = createCeTaskMessageDto(1999, MessageType.GENERIC);
+ CeTaskMessageDto nonInfo3 = createCeTaskMessageDto(2000, MessageType.BRANCH_NCD_90);
+ CeTaskMessageDto info2 = createCeTaskMessageDto(2002, INFO);
+ CeTaskMessageDto info1 = createCeTaskMessageDto(2001, INFO);
+
+ List<CeTaskMessageDto> ceTaskMessageDtos = new ArrayList<>(dto.getCeTaskMessageDtos());
+ ceTaskMessageDtos.addAll(Set.of(nonInfo1, nonInfo2, nonInfo3, info1, info2));
+ dto.setCeTaskMessageDtos(ceTaskMessageDtos);
+
+ Ce.Task wsTask = underTest.formatActivity(db.getSession(), dto, null);
+
+ assertThat(wsTask.getInfoMessagesList()).hasSameElementsAs(getMessagesText(List.of(info1, info2)));
+ }
+
private static List<String> getMessagesText(List<CeTaskMessageDto> ceTaskMessageDtos) {
return ceTaskMessageDtos.stream().map(CeTaskMessageDto::getMessage).toList();
}
TestActivityDto testActivityDto = new TestActivityDto(queueDto);
List<CeTaskMessageDto> ceTaskMessageDtos = IntStream.range(0, WARNING_COUNT)
- .mapToObj(i -> createCeTaskMessageDto(i, INFO))
+ .mapToObj(i -> createCeTaskMessageDto(i, PROJECT_NCD_PAGE_90))
.toList();
testActivityDto.setCeTaskMessageDtos(ceTaskMessageDtos);
return (TestActivityDto) testActivityDto
optional int32 warningCount = 26;
repeated string warnings = 27;
optional string nodeName = 28;
+ repeated string infoMessages = 29;
}
enum TaskStatus {