aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2023-05-08 10:09:52 +0200
committersonartech <sonartech@sonarsource.com>2023-05-09 20:10:37 +0000
commit2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae (patch)
treeccddf48d508826cf3615d3d2f32c1532ad184328 /sonar-core
parent9e906a6151503e38c17a30529407be8f820aa158 (diff)
downloadsonarqube-2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae.tar.gz
sonarqube-2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae.zip
SONAR-19103 Open documentation links safely in new tabs
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java6
-rw-r--r--sonar-core/src/test/java/org/sonar/core/documentation/DefaultDocumentationLinkGeneratorTest.java11
2 files changed, 16 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java b/sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java
index 6b447820b0d..dbfa0740328 100644
--- a/sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java
+++ b/sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java
@@ -41,7 +41,11 @@ public class DefaultDocumentationLinkGenerator implements DocumentationLinkGener
if (!url.endsWith("/")) {
url += "/";
}
- url += version.major() + "." + version.minor();
+ if (version.qualifier().equals("SNAPSHOT")) {
+ url += "latest";
+ } else {
+ url += version.major() + "." + version.minor();
+ }
return url;
}
diff --git a/sonar-core/src/test/java/org/sonar/core/documentation/DefaultDocumentationLinkGeneratorTest.java b/sonar-core/src/test/java/org/sonar/core/documentation/DefaultDocumentationLinkGeneratorTest.java
index 5d6cc77e5c2..5c20ea45ab4 100644
--- a/sonar-core/src/test/java/org/sonar/core/documentation/DefaultDocumentationLinkGeneratorTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/documentation/DefaultDocumentationLinkGeneratorTest.java
@@ -49,6 +49,7 @@ public class DefaultDocumentationLinkGeneratorTest {
public void setUp() {
when(sonarQubeVersion.get().major()).thenReturn(100);
when(sonarQubeVersion.get().minor()).thenReturn(1000);
+ when(sonarQubeVersion.get().qualifier()).thenReturn("");
when(configuration.get(DOCUMENTATION_BASE_URL)).thenReturn(Optional.empty());
documentationLinkGenerator = new DefaultDocumentationLinkGenerator(sonarQubeVersion, configuration);
}
@@ -61,6 +62,16 @@ public class DefaultDocumentationLinkGeneratorTest {
}
@Test
+ public void getDocumentationLink_whenSnapshot_returnLatest() {
+ when(sonarQubeVersion.get().qualifier()).thenReturn("SNAPSHOT");
+ documentationLinkGenerator = new DefaultDocumentationLinkGenerator(sonarQubeVersion, configuration);
+
+ String generatedLink = documentationLinkGenerator.getDocumentationLink(TEST_SUFFIX);
+
+ assertThat(generatedLink).isEqualTo(DOCUMENTATION_PUBLIC_URL + "latest/documentation/analyzing-source-code/scm-integration/");
+ }
+
+ @Test
public void getDocumentationLink_whenSuffixNotProvided_returnsBaseUrl() {
String generatedLink = documentationLinkGenerator.getDocumentationLink(null);