Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ITs: Deduplicate orchestrator initialization #7017

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions its/src/test/java/com/sonar/it/csharp/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.locator.FileLocation;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -75,17 +74,13 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE[9.9]")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-csharp-plugin")) // Do not add VB.NET here, use shared project instead
.setEdition(Edition.DEVELOPER)
.restoreProfileAtStartup(FileLocation.of("profiles/no_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/class_name.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/template_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/custom_parameters.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/custom_complexity.xml"))
.activateLicense()
.build();

public static Path projectDir(TemporaryFolder temp, String projectName) throws IOException {
Expand Down
30 changes: 14 additions & 16 deletions its/src/test/java/com/sonar/it/shared/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
package com.sonar.it.shared;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.build.Build;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.http.HttpMethod;
import com.sonar.orchestrator.locator.FileLocation;
import com.sonar.orchestrator.locator.Location;
Expand All @@ -49,6 +51,7 @@
import org.slf4j.LoggerFactory;
import org.sonarqube.ws.Ce;
import org.sonarqube.ws.Components;
import org.sonarqube.ws.Duplications.ShowResponse;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Measures;
import org.sonarqube.ws.Measures.Measure;
Expand All @@ -58,7 +61,6 @@
import org.sonarqube.ws.client.ce.TaskRequest;
import org.sonarqube.ws.client.components.ShowRequest;
import org.sonarqube.ws.client.measures.ComponentRequest;
import org.sonarqube.ws.Duplications.ShowResponse;

import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -70,6 +72,15 @@ public class TestUtils {
private static final String MSBUILD_PATH = "MSBUILD_PATH";
private static final String MSBUILD_PATH_DEFAULT = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\msbuild.exe";

public static OrchestratorBuilder prepareOrchestrator() {
return Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
// See https://github.com/SonarSource/orchestrator#version-aliases
.setSonarVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE[9.9]"))
.setEdition(Edition.DEVELOPER)
.activateLicense();
}

// Ensure no AnalysisWarning is raised inside the SQ GUI
public static void verifyNoGuiWarnings(Orchestrator orchestrator, BuildResult buildResult) {
Ce.Task task = TestUtils.getAnalysisWarningsTask(orchestrator, buildResult);
Expand Down Expand Up @@ -215,27 +226,14 @@ public static List<Issues.Issue> getIssues(Orchestrator orch, String componentKe
}

public static List<Issues.Issue> getIssues(Orchestrator orch, String componentKey, String pullRequestKey) {
return newWsClient(orch).issues().search(new org.sonarqube.ws.client.issues.SearchRequest().setComponentKeys(Collections.singletonList(componentKey)).setPullRequest(pullRequestKey)).getIssuesList();
return newWsClient(orch).issues()
.search(new org.sonarqube.ws.client.issues.SearchRequest().setComponentKeys(Collections.singletonList(componentKey)).setPullRequest(pullRequestKey)).getIssuesList();
}

public static List<Hotspot> getHotspots(Orchestrator orch, String projectKey) {
return newWsClient(orch).hotspots().search(new org.sonarqube.ws.client.hotspots.SearchRequest().setProjectKey(projectKey)).getHotspotsList();
}

// Versions of SonarQube and plugins support aliases:
// - "DEV" for the latest build of master that passed QA
// - "DEV[1.0]" for the latest build that passed QA of series 1.0.x
// - "LATEST_RELEASE" for the latest release
// - "LATEST_RELEASE[1.0]" for latest release of series 1.0.x
// The SonarQube alias "LTS" has been dropped. An alternative is "LATEST_RELEASE[6.7]".
// The term "latest" refers to the highest version number, not the most recently published version.
public static String replaceLtsVersion(String version) {
if (version != null && version.equals("LTS")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use the old "LTS" value anywhere. And we don't need to => we don't need this functionality.

return "LATEST_RELEASE[8.9]";
}
return version;
}

public static void reset(Orchestrator orchestrator) {
// Only for local debugging:
if (orchestrator.getServer() == null) {
Expand Down
7 changes: 1 addition & 6 deletions its/src/test/java/com/sonar/it/shared/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.ScannerForMSBuild;
import com.sonar.orchestrator.container.Edition;
import com.sonar.orchestrator.locator.MavenLocation;
import java.io.File;
import java.io.IOException;
Expand All @@ -48,15 +47,11 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE[9.9]")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-csharp-plugin"))
.addPlugin(TestUtils.getPluginLocation("sonar-vbnet-plugin"))
// ScannerCliTest: Fixed version for the HTML plugin as we don't want to have failures in case of changes there.
.addPlugin(MavenLocation.of("org.sonarsource.html", "sonar-html-plugin", "3.2.0.2082"))
.setEdition(Edition.DEVELOPER)
.activateLicense()
.build();

public static Path projectDir(TemporaryFolder temp, String projectName) throws IOException {
Expand Down
4 changes: 1 addition & 3 deletions its/src/test/java/com/sonar/it/vbnet/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
public class Tests {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(TestUtils.replaceLtsVersion(System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE[9.9]")))
public static final Orchestrator ORCHESTRATOR = TestUtils.prepareOrchestrator()
.addPlugin(TestUtils.getPluginLocation("sonar-vbnet-plugin")) // Do not add C# here, use shared project instead
.restoreProfileAtStartup(FileLocation.of("profiles/vbnet_no_rule.xml"))
.restoreProfileAtStartup(FileLocation.of("profiles/vbnet_class_name.xml"))
Expand Down