Skip to content

MCP-318 Add SONARQUBE_IS_CLOUD env var to force SQC detection#239

Merged
nquinquenel merged 1 commit intomasterfrom
task/nq/MCP-318-is-cloud
Mar 4, 2026
Merged

MCP-318 Add SONARQUBE_IS_CLOUD env var to force SQC detection#239
nquinquenel merged 1 commit intomasterfrom
task/nq/MCP-318-is-cloud

Conversation

@nquinquenel
Copy link
Copy Markdown
Member

No description provided.

@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented Mar 3, 2026

MCP-318

@sonarqube-agent
Copy link
Copy Markdown

sonarqube-agent Bot commented Mar 3, 2026

Remediation Agent Summary 📊

🤖 To review: Fixes are ready for 1 of 1 issues found.
💪 Save time: Applying these fixes could save you an estimated 10 minutes.
Suggested fixes (1)

QualityIssueStatus
Maintainability
🔴 High
Define a constant instead of duplicating this literal "false" 4 times.

Why is this an issue?

🛠️ Suggested Fix [1]
Defines a private static final constant `DEFAULT_FALSE` with the value "false". This provides the single constant that replaces all four duplicated occurrences of the string literal "false" throughout the class, which is the root cause of the duplicated string literal code smell.
🛠️ Suggested Fix [2]
Replaces the first duplicated "false" string literal (used as the default value when resolving the SONARQUBE_IS_CLOUD configuration) with the newly defined `DEFAULT_FALSE` constant, eliminating one of the four duplications flagged by the code smell.
🛠️ Suggested Fix [3]
Replaces the second duplicated "false" string literal (used as the default value when resolving the TELEMETRY_DISABLED configuration) with the `DEFAULT_FALSE` constant, eliminating another of the four duplications flagged by the code smell.
🛠️ Suggested Fix [4]
Replaces the third duplicated "false" string literal (used as the default value when resolving the SONARQUBE_READ_ONLY configuration) with the `DEFAULT_FALSE` constant, eliminating another of the four duplications flagged by the code smell.
🛠️ Suggested Fix [5]
Replaces the fourth and final duplicated "false" string literal (used as the default value when resolving the SONARQUBE_ADVANCED_ANALYSIS_ENABLED configuration) with the `DEFAULT_FALSE` constant, completing the elimination of all duplicated "false" literals flagged by the code smell.

Fix 1

Note

Help us improve the Agent!
Have a suggestion or found an issue? Share your feedback here.

@sonarqube-agent
Copy link
Copy Markdown

sonarqube-agent Bot commented Mar 3, 2026

Agent Fix (Issue 1 of 1)

Quality Issue
Maintainability
🔴 High
Define a constant instead of duplicating this literal "false" 4 times.
Location 1: src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:83-84
--- a/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
+++ b/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
@@ -82,0 +83,2 @@ public class McpServerLaunchConfiguration {
+  private static final String DEFAULT_FALSE = "false";
+
View suggestion details Explanation 1:

Defines a private static final constant DEFAULT_FALSE with the value "false". This provides the single constant that replaces all four duplicated occurrences of the string literal "false" throughout the class, which is the root cause of the duplicated string literal code smell.


Show 4 other locations Location 2: src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:140-142
--- a/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
+++ b/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
@@ -140,1 +142,1 @@ public class McpServerLaunchConfiguration {
-    var forceSonarQubeCloud = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_IS_CLOUD, "false"));
+    var forceSonarQubeCloud = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_IS_CLOUD, DEFAULT_FALSE));
View suggestion details Explanation 2:

Replaces the first duplicated "false" string literal (used as the default value when resolving the SONARQUBE_IS_CLOUD configuration) with the newly defined DEFAULT_FALSE constant, eliminating one of the four duplications flagged by the code smell.


Location 3: src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:172-174

--- a/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
+++ b/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
@@ -172,1 +174,1 @@ public class McpServerLaunchConfiguration {
-    this.isTelemetryEnabled = !Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, TELEMETRY_DISABLED, "false"));
+    this.isTelemetryEnabled = !Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, TELEMETRY_DISABLED, DEFAULT_FALSE));
View suggestion details Explanation 3:

Replaces the second duplicated "false" string literal (used as the default value when resolving the TELEMETRY_DISABLED configuration) with the DEFAULT_FALSE constant, eliminating another of the four duplications flagged by the code smell.


Location 4: src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:193-195

--- a/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
+++ b/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
@@ -193,1 +195,1 @@ public class McpServerLaunchConfiguration {
-    this.isReadOnlyMode = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_READ_ONLY, "false"));
+    this.isReadOnlyMode = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_READ_ONLY, DEFAULT_FALSE));
View suggestion details Explanation 4:

Replaces the third duplicated "false" string literal (used as the default value when resolving the SONARQUBE_READ_ONLY configuration) with the DEFAULT_FALSE constant, eliminating another of the four duplications flagged by the code smell.


Location 5: src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:195-197

--- a/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
+++ b/src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java
@@ -195,1 +197,1 @@ public class McpServerLaunchConfiguration {
-    this.isAdvancedAnalysisEnabled = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_ADVANCED_ANALYSIS_ENABLED, "false"));
+    this.isAdvancedAnalysisEnabled = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_ADVANCED_ANALYSIS_ENABLED, DEFAULT_FALSE));
View suggestion details Explanation 5:

Replaces the fourth and final duplicated "false" string literal (used as the default value when resolving the SONARQUBE_ADVANCED_ANALYSIS_ENABLED configuration) with the DEFAULT_FALSE constant, completing the elimination of all duplicated "false" literals flagged by the code smell.


Review

  • Select fix
    Select this to add the fix to a queue. It may take a few seconds to update. You can commit all selected fixes at once.

🔒 Commit changes (0 of 1 selected)
Select one or more fixes above to enable this action.

Go back to Summary ⬆️


Did this fix help?
  • 👍
  • 👎

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for a SONARQUBE_IS_CLOUD flag to force SonarCloud (SQC) detection in McpServerLaunchConfiguration, with accompanying unit tests to validate forced cloud vs non-cloud behavior.

Changes:

  • Introduce SONARQUBE_IS_CLOUD configuration key to override SonarCloud detection logic.
  • Update SonarCloud detection branching to honor the forced flag.
  • Add tests covering forced SonarCloud detection in both HTTP and stdio modes, plus a “false” case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java Adds SONARQUBE_IS_CLOUD flag and updates SonarCloud detection logic to allow forced cloud mode.
src/test/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfigurationTest.java Adds unit tests validating forced SonarCloud detection behavior.
Comments suppressed due to low confidence (1)

src/main/java/org/sonarsource/sonarqube/mcp/configuration/McpServerLaunchConfiguration.java:147

  • When SONARQUBE_IS_CLOUD is set to true and SONARQUBE_URL is missing/blank, the configuration currently defaults to https://sonarcloud.io. Since the flag is intended for non-standard SonarCloud-like deployments, defaulting to the public SonarCloud URL can be surprising and may accidentally send credentials/traffic to the wrong endpoint. Consider requiring an explicit SONARQUBE_URL (throwing an IllegalArgumentException) when SONARQUBE_IS_CLOUD=true and no URL is provided.
    var forceSonarQubeCloud = Boolean.parseBoolean(getValueViaEnvOrPropertyOrDefault(environment, SONARQUBE_IS_CLOUD, "false"));
    if (forceSonarQubeCloud) {
      this.isSonarCloud = true;
    } else if (!isHttpEnabled) {
      this.isSonarCloud = this.sonarqubeOrg != null;
    } else {
      this.isSonarCloud = sonarqubeUrlFromEnv == null || isSonarCloudUrl(sonarqubeUrlFromEnv);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@nquinquenel nquinquenel force-pushed the task/nq/MCP-318-is-cloud branch from 4ef224a to e82e559 Compare March 3, 2026 21:51
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 3, 2026

@nquinquenel nquinquenel marked this pull request as ready for review March 4, 2026 12:08
@nquinquenel nquinquenel merged commit 2748388 into master Mar 4, 2026
9 checks passed
@nquinquenel nquinquenel deleted the task/nq/MCP-318-is-cloud branch March 4, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants