aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2024-12-19 11:39:04 +0100
committersonartech <sonartech@sonarsource.com>2024-12-20 20:03:10 +0000
commit77a3f39cc788ea88e28e72caee5d36cf72bc2c95 (patch)
tree9270bd70dbe3496f60554ae47deae4fbc8ae4301
parentc9ad40cee05365b2539a7f03987a313f18d7fa1c (diff)
downloadsonarqube-77a3f39cc788ea88e28e72caee5d36cf72bc2c95.tar.gz
sonarqube-77a3f39cc788ea88e28e72caee5d36cf72bc2c95.zip
SONAR-23995 Fix broken documentation links from the new code period API description
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java3
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWs.java4
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWsUtils.java36
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java10
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ShowAction.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java10
10 files changed, 64 insertions, 24 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java
index 8e0dd56f64f..0cb584c57ca 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ListActionIT.java
@@ -59,6 +59,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.SnapshotTesting.newAnalysis;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.DOCUMENTATION_LINK;
public class ListActionIT {
@Rule
@@ -74,7 +75,7 @@ public class ListActionIT {
@Before
public void setup() {
- when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc");
+ when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc" + DOCUMENTATION_LINK);
ws = new WsActionTester(new ListAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator));
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java
index 2a89605770e..509631d91b2 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/SetActionIT.java
@@ -61,6 +61,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.DOCUMENTATION_LINK;
@RunWith(DataProviderRunner.class)
public class SetActionIT {
@@ -78,7 +79,7 @@ public class SetActionIT {
@Before
public void setup() {
- when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc");
+ when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc" + DOCUMENTATION_LINK);
ws = new WsActionTester(new SetAction(dbClient, userSession, componentFinder, editionProvider, dao, documentationLinkGenerator));
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java
index 6d82f5fa472..c26ce0fa647 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/ShowActionIT.java
@@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.DOCUMENTATION_LINK;
import static org.sonarqube.ws.NewCodePeriods.NewCodePeriodType.NUMBER_OF_DAYS;
import static org.sonarqube.ws.NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION;
@@ -65,7 +66,7 @@ public class ShowActionIT {
@Before
public void setup() {
- when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc");
+ when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc" + DOCUMENTATION_LINK);
ws = new WsActionTester(new ShowAction(dbClient, userSession, componentFinder, dao, documentationLinkGenerator));
}
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java
index bec4270a046..1541e95c16c 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/newcodeperiod/ws/UnsetActionIT.java
@@ -53,6 +53,7 @@ import static org.assertj.core.api.Assertions.entry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.DOCUMENTATION_LINK;
public class UnsetActionIT {
@Rule
@@ -69,7 +70,7 @@ public class UnsetActionIT {
@Before
public void setup() {
- when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc");
+ when(documentationLinkGenerator.getDocumentationLink(any())).thenReturn("https://docs.sonarsource.com/someddoc" + DOCUMENTATION_LINK);
ws = new WsActionTester(new UnsetAction(dbClient, userSession, componentFinder, editionProvider, dao, documentationLinkGenerator));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
index f67401985b1..fa382f8d6c6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ListAction.java
@@ -47,7 +47,7 @@ import org.sonar.server.user.UserSession;
import org.sonarqube.ws.NewCodePeriods;
import org.sonarqube.ws.NewCodePeriods.ListWSResponse;
-import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.createNewCodePeriodHtmlLink;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.NewCodePeriods.ShowWSResponse.newBuilder;
@@ -58,7 +58,7 @@ public class ListAction implements NewCodePeriodsWsAction {
private final UserSession userSession;
private final ComponentFinder componentFinder;
private final NewCodePeriodDao newCodePeriodDao;
- private final String newCodeDefinitionDocumentationUrl;
+ private final DocumentationLinkGenerator documentationLinkGenerator;
public ListAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder, NewCodePeriodDao newCodePeriodDao,
DocumentationLinkGenerator documentationLinkGenerator) {
@@ -66,13 +66,13 @@ public class ListAction implements NewCodePeriodsWsAction {
this.userSession = userSession;
this.componentFinder = componentFinder;
this.newCodePeriodDao = newCodePeriodDao;
- this.newCodeDefinitionDocumentationUrl = documentationLinkGenerator.getDocumentationLink("/project-administration/clean-as-you-code-settings/defining-new-code/");
+ this.documentationLinkGenerator = documentationLinkGenerator;
}
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("list")
- .setDescription("Lists the " + createHtmlExternalLink(newCodeDefinitionDocumentationUrl, "new code definition") +
+ .setDescription("Lists the " + createNewCodePeriodHtmlLink(documentationLinkGenerator) +
" for all branches in a project.<br>" +
"Requires the permission to browse the project")
.setSince("8.0")
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWs.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWs.java
index 7177add0739..e0246181bcf 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWs.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWs.java
@@ -22,7 +22,7 @@ package org.sonar.server.newcodeperiod.ws;
import org.sonar.api.server.ws.WebService;
import org.sonar.core.documentation.DocumentationLinkGenerator;
-import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.createNewCodePeriodHtmlLink;
public class NewCodePeriodsWs implements WebService {
@@ -37,7 +37,7 @@ public class NewCodePeriodsWs implements WebService {
@Override
public void define(Context context) {
NewController controller = context.createController("api/new_code_periods")
- .setDescription("Manage "+ createHtmlExternalLink(documentationLinkGenerator.getDocumentationLink("/project-administration/clean-as-you-code-settings/defining-new-code/"), "new code definition") +".")
+ .setDescription("Manage "+ createNewCodePeriodHtmlLink(documentationLinkGenerator) +".")
.setSince("8.0");
for (NewCodePeriodsWsAction action : actions) {
action.define(controller);
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWsUtils.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWsUtils.java
new file mode 100644
index 00000000000..47d051eface
--- /dev/null
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/NewCodePeriodsWsUtils.java
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.newcodeperiod.ws;
+
+import org.sonar.core.documentation.DocumentationLinkGenerator;
+
+import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
+
+public class NewCodePeriodsWsUtils {
+ public static final String DOCUMENTATION_LINK = "/project-administration/setting-up-clean-as-you-code/#setting-a-new-code-definition";
+
+ private NewCodePeriodsWsUtils() {
+ // do nothing
+ }
+
+ public static String createNewCodePeriodHtmlLink(DocumentationLinkGenerator documentationLinkGenerator){
+ return createHtmlExternalLink(documentationLinkGenerator.getDocumentationLink(DOCUMENTATION_LINK), "new code definition");
+ }
+}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
index 8049446577b..64dc5d8018e 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/SetAction.java
@@ -40,9 +40,9 @@ import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodParser;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.db.project.ProjectDto;
+import org.sonar.server.common.newcodeperiod.CaycUtils;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.common.newcodeperiod.CaycUtils;
import org.sonar.server.user.UserSession;
import static com.google.common.base.Preconditions.checkArgument;
@@ -51,7 +51,7 @@ import static org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.PREVIOUS_VERSION;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.SPECIFIC_ANALYSIS;
-import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.createNewCodePeriodHtmlLink;
public class SetAction implements NewCodePeriodsWsAction {
private static final String PARAM_BRANCH = "branch";
@@ -73,7 +73,7 @@ public class SetAction implements NewCodePeriodsWsAction {
private final ComponentFinder componentFinder;
private final PlatformEditionProvider editionProvider;
private final NewCodePeriodDao newCodePeriodDao;
- private final String newCodeDefinitionDocumentationUrl;
+ private final DocumentationLinkGenerator documentationLinkGenerator;
public SetAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder, PlatformEditionProvider editionProvider,
NewCodePeriodDao newCodePeriodDao, DocumentationLinkGenerator documentationLinkGenerator) {
@@ -82,14 +82,14 @@ public class SetAction implements NewCodePeriodsWsAction {
this.componentFinder = componentFinder;
this.editionProvider = editionProvider;
this.newCodePeriodDao = newCodePeriodDao;
- this.newCodeDefinitionDocumentationUrl = documentationLinkGenerator.getDocumentationLink("/project-administration/clean-as-you-code-settings/defining-new-code/");
+ this.documentationLinkGenerator = documentationLinkGenerator;
}
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("set")
.setPost(true)
- .setDescription("Updates the " + createHtmlExternalLink(newCodeDefinitionDocumentationUrl, "new code definition") +
+ .setDescription("Updates the " + createNewCodePeriodHtmlLink(documentationLinkGenerator) +
" on different levels:<br>" +
BEGIN_LIST +
BEGIN_ITEM_LIST + "Not providing a project key and a branch key will update the default value at global level. " +
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ShowAction.java
index f21c938194e..4cd39ee20a6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ShowAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/ShowAction.java
@@ -40,8 +40,8 @@ import org.sonarqube.ws.NewCodePeriods;
import static java.lang.String.format;
import static org.sonar.db.permission.GlobalPermission.SCAN;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.createNewCodePeriodHtmlLink;
import static org.sonar.server.user.AbstractUserSession.insufficientPrivilegesException;
-import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
import static org.sonarqube.ws.NewCodePeriods.ShowWSResponse;
@@ -53,7 +53,7 @@ public class ShowAction implements NewCodePeriodsWsAction {
private final UserSession userSession;
private final ComponentFinder componentFinder;
private final NewCodePeriodDao newCodePeriodDao;
- private final String newCodeDefinitionDocumentationUrl;
+ private final DocumentationLinkGenerator documentationLinkGenerator;
public ShowAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder, NewCodePeriodDao newCodePeriodDao,
DocumentationLinkGenerator documentationLinkGenerator) {
@@ -61,13 +61,13 @@ public class ShowAction implements NewCodePeriodsWsAction {
this.userSession = userSession;
this.componentFinder = componentFinder;
this.newCodePeriodDao = newCodePeriodDao;
- this.newCodeDefinitionDocumentationUrl = documentationLinkGenerator.getDocumentationLink("/project-administration/clean-as-you-code-settings/defining-new-code/");
+ this.documentationLinkGenerator = documentationLinkGenerator;
}
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("show")
- .setDescription("Shows the " + createHtmlExternalLink(newCodeDefinitionDocumentationUrl, "new code definition") + ".<br> " +
+ .setDescription("Shows the " + createNewCodePeriodHtmlLink(documentationLinkGenerator) + ".<br> " +
"If the component requested doesn't exist or if no new code definition is set for it, a value is inherited from the project or from the global setting." +
"Requires one of the following permissions if a component is specified: " +
"<ul>" +
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
index 73f1e82396d..e959327eb4b 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/newcodeperiod/ws/UnsetAction.java
@@ -32,13 +32,13 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.BranchDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDao;
import org.sonar.db.project.ProjectDto;
+import org.sonar.server.common.newcodeperiod.CaycUtils;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.NotFoundException;
-import org.sonar.server.common.newcodeperiod.CaycUtils;
import org.sonar.server.user.UserSession;
import static java.lang.String.format;
-import static org.sonar.server.ws.WsUtils.createHtmlExternalLink;
+import static org.sonar.server.newcodeperiod.ws.NewCodePeriodsWsUtils.createNewCodePeriodHtmlLink;
public class UnsetAction implements NewCodePeriodsWsAction {
private static final String BRANCH = "branch";
@@ -52,7 +52,7 @@ public class UnsetAction implements NewCodePeriodsWsAction {
private final ComponentFinder componentFinder;
private final PlatformEditionProvider editionProvider;
private final NewCodePeriodDao newCodePeriodDao;
- private final String newCodeDefinitionDocumentationUrl;
+ private final DocumentationLinkGenerator documentationLinkGenerator;
public UnsetAction(DbClient dbClient, UserSession userSession, ComponentFinder componentFinder,
PlatformEditionProvider editionProvider, NewCodePeriodDao newCodePeriodDao, DocumentationLinkGenerator documentationLinkGenerator) {
@@ -61,14 +61,14 @@ public class UnsetAction implements NewCodePeriodsWsAction {
this.componentFinder = componentFinder;
this.editionProvider = editionProvider;
this.newCodePeriodDao = newCodePeriodDao;
- this.newCodeDefinitionDocumentationUrl = documentationLinkGenerator.getDocumentationLink("/project-administration/clean-as-you-code-settings/defining-new-code/");
+ this.documentationLinkGenerator = documentationLinkGenerator;
}
@Override
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction("unset")
.setPost(true)
- .setDescription("Unsets the " + createHtmlExternalLink(newCodeDefinitionDocumentationUrl, "new code definition") +
+ .setDescription("Unsets the " + createNewCodePeriodHtmlLink(documentationLinkGenerator) +
" for a branch, project or global. It requires the inherited New Code Definition to be compatible with the Clean as You Code methodology, " +
"and one of the following permissions: " +
"<ul>" +