aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src/main
diff options
context:
space:
mode:
authorSteve Marion <steve.marion@sonarsource.com>2024-11-21 10:36:22 +0100
committersonartech <sonartech@sonarsource.com>2024-11-28 20:02:59 +0000
commit84398329f3989d32830e7fd4f623c8b8fc47e5d5 (patch)
treebddb3ef6821fe5ca77f50728d0475b43a5e0fb45 /sonar-core/src/main
parent49e3469392c8a5d5d17a72a19b60583445993cee (diff)
downloadsonarqube-84398329f3989d32830e7fd4f623c8b8fc47e5d5.tar.gz
sonarqube-84398329f3989d32830e7fd4f623c8b8fc47e5d5.zip
SONAR-23755 Add core extension common to allow SQS specific behavior to happen. Add to DefaultLinkGenerator extension point to modify the default documentation base URL.
Diffstat (limited to 'sonar-core/src/main')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/documentation/DefaultDocumentationLinkGenerator.java26
-rw-r--r--sonar-core/src/main/java/org/sonar/core/documentation/DocumentationBaseLinkProvider.java33
-rw-r--r--sonar-core/src/main/java/org/sonar/core/documentation/DocumentationLinkGenerator.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/documentation/VersionedDocumentationBaseLinkProvider.java50
5 files changed, 93 insertions, 22 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
index 440c6d09ff4..c8c4b139611 100644
--- a/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
+++ b/sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
@@ -27,7 +27,6 @@ import org.sonar.api.PropertyType;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinition.ConfigScope;
-import org.sonar.core.documentation.DefaultDocumentationLinkGenerator;
import org.sonar.core.extension.PluginRiskConsent;
import static java.util.Arrays.asList;
@@ -136,8 +135,7 @@ public class CorePropertyDefinitions {
.build(),
PropertyDefinition.builder(DOCUMENTATION_BASE_URL)
.name("Base URL of the documentation")
- .description("Base URL to be used in SonarQube documentation links, such as <i>https://docs.sonarsource.com/sonarqube/</i>")
- .defaultValue(DefaultDocumentationLinkGenerator.DOCUMENTATION_PUBLIC_URL)
+ .description("Override the base URL to be used in SonarQube documentation links.")
.hidden()
.type(STRING)
.build(),
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 92c530ae8e1..b499c6406f4 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
@@ -22,31 +22,19 @@ package org.sonar.core.documentation;
import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.config.Configuration;
-import org.sonar.api.utils.Version;
import org.sonar.core.config.CorePropertyDefinitions;
-import org.sonar.core.platform.SonarQubeVersion;
public class DefaultDocumentationLinkGenerator implements DocumentationLinkGenerator {
- public static final String DOCUMENTATION_PUBLIC_URL = "https://docs.sonarsource.com/sonarqube/";
+ public static final String DOCUMENTATION_PUBLIC_URL = "https://docs.sonarsource.com/sonarqube-community-build";
private final String documentationBaseUrl;
- public DefaultDocumentationLinkGenerator(SonarQubeVersion sonarQubeVersion, Configuration configuration) {
- this.documentationBaseUrl = completeUrl(configuration.get(CorePropertyDefinitions.DOCUMENTATION_BASE_URL)
- .orElse(DOCUMENTATION_PUBLIC_URL), sonarQubeVersion.get());
- }
-
- private static String completeUrl(String baseUrl, Version version) {
- String url = baseUrl;
- if (!url.endsWith("/")) {
- url += "/";
- }
- if (version.qualifier().equals("SNAPSHOT")) {
- url += "latest";
- } else {
- url += version.major() + "." + version.minor();
- }
- return url;
+ public DefaultDocumentationLinkGenerator(Configuration configuration, @Nullable DocumentationBaseLinkProvider documentationBaseLinkProvider) {
+ this.documentationBaseUrl =
+ configuration.get(CorePropertyDefinitions.DOCUMENTATION_BASE_URL)
+ .or(() -> Optional.ofNullable(documentationBaseLinkProvider).map(DocumentationBaseLinkProvider::getDocumentationBaseUrl))
+ .map(url -> url.endsWith("/") ? url.substring(0, url.lastIndexOf("/")) : url)
+ .orElse(DOCUMENTATION_PUBLIC_URL);
}
@Override
diff --git a/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationBaseLinkProvider.java b/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationBaseLinkProvider.java
new file mode 100644
index 00000000000..e1f18289f84
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationBaseLinkProvider.java
@@ -0,0 +1,33 @@
+/*
+ * 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.core.documentation;
+
+import org.sonar.api.ce.ComputeEngineSide;
+import org.sonar.api.scanner.ScannerSide;
+import org.sonar.api.server.ServerSide;
+import org.sonar.core.extension.PlatformLevel;
+
+@ServerSide
+@ComputeEngineSide
+@ScannerSide
+@PlatformLevel(1)
+public interface DocumentationBaseLinkProvider {
+ String getDocumentationBaseUrl();
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationLinkGenerator.java b/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationLinkGenerator.java
index 2ccbf5dbd89..aad1593af15 100644
--- a/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationLinkGenerator.java
+++ b/sonar-core/src/main/java/org/sonar/core/documentation/DocumentationLinkGenerator.java
@@ -23,10 +23,12 @@ import javax.annotation.Nullable;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.server.ServerSide;
+import org.sonar.core.extension.PlatformLevel;
@ServerSide
@ComputeEngineSide
@ScannerSide
+@PlatformLevel(1)
public interface DocumentationLinkGenerator {
String getDocumentationLink(@Nullable String suffix);
diff --git a/sonar-core/src/main/java/org/sonar/core/documentation/VersionedDocumentationBaseLinkProvider.java b/sonar-core/src/main/java/org/sonar/core/documentation/VersionedDocumentationBaseLinkProvider.java
new file mode 100644
index 00000000000..4b6b3271c86
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/documentation/VersionedDocumentationBaseLinkProvider.java
@@ -0,0 +1,50 @@
+/*
+ * 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.core.documentation;
+
+import org.sonar.api.utils.Version;
+import org.sonar.core.platform.SonarQubeVersion;
+
+public class VersionedDocumentationBaseLinkProvider implements DocumentationBaseLinkProvider {
+
+ private final String documentationBaseUrl;
+
+ public VersionedDocumentationBaseLinkProvider(String baseUrl, SonarQubeVersion sonarQubeVersion) {
+ documentationBaseUrl = completeUrl(baseUrl, sonarQubeVersion.get());
+ }
+
+ @Override
+ public String getDocumentationBaseUrl() {
+ return documentationBaseUrl;
+ }
+
+ private static String completeUrl(String baseUrl, Version version) {
+ String url = baseUrl;
+ if (!url.endsWith("/")) {
+ url += "/";
+ }
+ if ("SNAPSHOT".equals(version.qualifier())) {
+ url += "latest";
+ } else {
+ url += version.major() + "." + version.minor();
+ }
+ return url;
+ }
+}