aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2021-12-09 11:25:15 -0600
committerLukasz Jarocki <lukasz.jarocki@sonarsource.com>2021-12-13 15:22:58 +0100
commit059288e778d3169c74b7c34b5c68edd0b356eec2 (patch)
tree61c42d70adc453d6b758ba7d69a64370a91a223b /sonar-plugin-api/src
parent6e0a3cf998145f8305c38a2a58f5af64dcb195a6 (diff)
downloadsonarqube-059288e778d3169c74b7c34b5c68edd0b356eec2.tar.gz
sonarqube-059288e778d3169c74b7c34b5c68edd0b356eec2.zip
SONAR-15824 WebService changelog not shown
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java19
2 files changed, 24 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
index 6e4e59b84a7..f3ff6b3208f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -328,14 +329,15 @@ public interface WebService extends Definable<WebService.Context> {
/**
* List of changes made to the contract or valuable insight. Example: changes to the response format.
+ * Calling this method multiple times will not override previously set changes - all changes will be added.
*
* @since 6.4
*/
public NewAction setChangelog(Change... changes) {
- this.changelog = stream(requireNonNull(changes))
+ requireNonNull(changes);
+ Arrays.stream(changes)
.filter(Objects::nonNull)
- .collect(Collectors.toList());
-
+ .forEach(this.changelog::add);
return this;
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
index 5c2573e7a12..3ecb95f38b3 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/ws/WebServiceTest.java
@@ -93,6 +93,25 @@ public class WebServiceTest {
}
@Test
+ public void add_changelog_if_called_twice() {
+ WebService webService = context -> {
+ NewController newController = context.createController("api/rule");
+ newDefaultAction(newController, "list")
+ .setDescription("desc")
+ .setChangelog(new Change("1.0", "change1"))
+ .setChangelog(new Change("2.0", "change2"));
+ newController.done();
+ };
+
+ webService.define(context);
+ assertThat(context.controller("api/rule").action("list").changelog())
+ .extracting(Change::getVersion, Change::getDescription)
+ .containsOnly(
+ tuple("1.0", "change1"),
+ tuple("2.0", "change2"));
+ }
+
+ @Test
public void fail_if_duplicated_ws_keys() {
MetricWs metricWs = new MetricWs();
metricWs.define(context);