diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2023-05-08 10:09:52 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-05-09 20:10:37 +0000 |
commit | 2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae (patch) | |
tree | ccddf48d508826cf3615d3d2f32c1532ad184328 /sonar-core | |
parent | 9e906a6151503e38c17a30529407be8f820aa158 (diff) | |
download | sonarqube-2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae.tar.gz sonarqube-2c5ee5384d9f3e7bccee6260112f3cbd20d0f9ae.zip |
SONAR-19103 Open documentation links safely in new tabs
Diffstat (limited to 'sonar-core')
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); |