From 0a3e5df5accf1c9a7f301e550acf3f6e61173a35 Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Wed, 15 Dec 2021 16:51:11 +0100 Subject: [PATCH] SONAR-15838 - Deprecate Application and Portfolio Metrics --- .../org/sonar/server/measure/ws/ComponentAction.java | 4 +++- .../sonar/server/measure/ws/ComponentTreeAction.java | 6 ++++-- .../sonar/server/measure/ws/MeasuresWsModule.java | 7 +++++++ .../org/sonar/server/measure/ws/SearchAction.java | 12 ++++++++---- .../sonar/server/measure/ws/SearchHistoryAction.java | 5 ++++- .../sonar/server/measure/ws/SearchActionTest.java | 1 - 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java index 284b417b54d..ba5267e86b9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java @@ -96,6 +96,8 @@ public class ComponentAction implements MeasuresWsAction { .setResponseExample(getClass().getResource("component-example.json")) .setSince("5.4") .setChangelog( + new Change("9.3", format("The use of the following metrics in 'metricKeys' parameter is deprecated: %s", + MeasuresWsModule.getDeprecatedMetrics())), new Change("8.8", "deprecated response field 'id' has been removed"), new Change("8.8", "deprecated response field 'refId' has been removed."), new Change("8.1", "the response field periods under measures field is deprecated. Use period instead."), @@ -239,7 +241,7 @@ public class ComponentAction implements MeasuresWsAction { } private static ComponentWsResponse buildResponse(ComponentRequest request, ComponentDto component, Optional refComponent, - Map measuresByMetric, Collection metrics, Optional period) { + Map measuresByMetric, Collection metrics, Optional period) { ComponentWsResponse.Builder response = ComponentWsResponse.newBuilder(); if (refComponent.isPresent()) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java index f0d68708697..caeee46a833 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java @@ -106,8 +106,8 @@ import static org.sonar.server.measure.ws.SnapshotDtoToWsPeriod.snapshotToWsPeri import static org.sonar.server.ws.KeyExamples.KEY_BRANCH_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001; import static org.sonar.server.ws.KeyExamples.KEY_PULL_REQUEST_EXAMPLE_001; -import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsParameterBuilder.QualifierParameterContext.newQualifierParameterContext; +import static org.sonar.server.ws.WsParameterBuilder.createQualifiersParameter; import static org.sonar.server.ws.WsUtils.writeProtobuf; /** @@ -179,6 +179,8 @@ public class ComponentTreeAction implements MeasuresWsAction { .setHandler(this) .addPagingParams(100, MAX_SIZE) .setChangelog( + new Change("9.3", format("The use of the following metrics in 'metricKeys' parameter is deprecated: %s", + MeasuresWsModule.getDeprecatedMetrics())), new Change("8.8", "parameter 'component' is now required"), new Change("8.8", "deprecated parameter 'baseComponentId' has been removed"), new Change("8.8", "deprecated parameter 'baseComponentKey' has been removed."), @@ -272,7 +274,7 @@ public class ComponentTreeAction implements MeasuresWsAction { request, data, Paging.forPageIndex( - request.getPage()) + request.getPage()) .withPageSize(request.getPageSize()) .andTotal(data.getComponentCount())); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java index e3906cae186..4ee6077ffed 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java @@ -31,4 +31,11 @@ public class MeasuresWsModule extends Module { SearchAction.class, SearchHistoryAction.class); } + + + public static String getDeprecatedMetrics() { + return String.join(", ", "releasability_effort", "security_rating_effort", "reliability_rating_effort", "security_review_rating_effort", + "maintainability_rating_effort", "last_change_on_maintainability_rating", "last_change_on_releasability_rating", "last_change_on_reliability_rating", + "last_change_on_security_rating", "last_change_on_security_review_rating"); + } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java index b5589b90d5a..821480cae71 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; +import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -41,6 +42,7 @@ import org.sonarqube.ws.Measures.Measure; import org.sonarqube.ws.Measures.SearchWsResponse; import static com.google.common.base.Preconditions.checkArgument; +import static java.lang.String.format; import static java.util.Comparator.comparing; import static java.util.function.Function.identity; import static java.util.stream.Collectors.toMap; @@ -76,12 +78,14 @@ public class SearchAction implements MeasuresWsAction { WebService.NewAction action = context.createAction("search") .setInternal(true) .setDescription("Search for project measures ordered by project names.
" + - "At most %d projects can be provided.
" + - "Returns the projects with the 'Browse' permission.", + "At most %d projects can be provided.
" + + "Returns the projects with the 'Browse' permission.", MAX_NB_PROJECTS) .setSince("6.2") .setResponseExample(getClass().getResource("search-example.json")) - .setHandler(this); + .setHandler(this) + .setChangelog(new Change("9.3", format("The use of the following metrics in 'metricKeys' parameter is deprecated: %s", + MeasuresWsModule.getDeprecatedMetrics()))); createMetricKeysParameter(action); @@ -244,7 +248,7 @@ public class SearchAction implements MeasuresWsAction { checkArgument(projectKeys != null && !projectKeys.isEmpty(), "Project keys must be provided"); int nbComponents = projectKeys.size(); checkArgument(nbComponents <= MAX_NB_PROJECTS, - "%s projects provided, more than maximum authorized (%s)", nbComponents, MAX_NB_PROJECTS); + "%s projects provided, more than maximum authorized (%s)", nbComponents, MAX_NB_PROJECTS); return new SearchAction.SearchRequest(this); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java index 192907c04f0..a8cd2b87319 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java @@ -92,7 +92,10 @@ public class SearchHistoryAction implements MeasuresWsAction { "For applications, it also requires 'Browse' permission on its child projects.") .setResponseExample(getClass().getResource("search_history-example.json")) .setSince("6.3") - .setChangelog(new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT))) + .setChangelog( + new Change("9.3", format("The use of the following metrics in 'metrics' parameter is deprecated: %s", + MeasuresWsModule.getDeprecatedMetrics())), + new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT))) .setHandler(this); action.createParam(PARAM_COMPONENT) diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java index 8d75949c664..319d5cde0e3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/SearchActionTest.java @@ -60,7 +60,6 @@ import static org.sonar.test.JsonAssert.assertJson; public class SearchActionTest { - @Rule public UserSessionRule userSession = UserSessionRule.standalone().logIn(); -- 2.39.5