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

SONARGO-79 Update sonar-orchestrator dependency #47

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@
--info --stacktrace --console plain --no-daemon --build-cache
<<: *CLEANUP_GRADLE_CACHE_SCRIPT

qa_plugin_task:

Check warning on line 123 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L123

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 123 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L123

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 123 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L123

task "qa_plugin" depends on task "build", but their only_if conditions are different

Check warning on line 123 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L123

task "qa_plugin" depends on task "build", but their only_if conditions are different
<<: *QA_TASK_FILTER
env:
ITS_PROJECT: "plugin"
GRADLE_TASK: ":its:plugin:integrationTest"
KEEP_ORCHESTRATOR_RUNNING: "true"
matrix:
- SQ_VERSION: "DEV"
- SQ_VERSION: "LATEST_RELEASE"
Expand All @@ -133,12 +134,13 @@
<<: *ON_FAILURE


qa_ruling_task:

Check warning on line 137 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L137

task "qa_ruling" depends on task "build", but their only_if conditions are different

Check warning on line 137 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L137

task "qa_ruling" depends on task "build", but their only_if conditions are different
<<: *QA_TASK_FILTER
env:
SQ_VERSION: "LATEST_RELEASE"
GRADLE_TASK: ":its:ruling:integrationTest"
ITS_PROJECT: "ruling"
KEEP_ORCHESTRATOR_RUNNING: "true"
<<: *LINUX_4_CPU_8G
<<: *GRADLE_ITS_TEMPLATE
<<: *ON_FAILURE
Expand Down Expand Up @@ -173,7 +175,7 @@

### Promote tasks

promote_task:

Check warning on line 178 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L178

task "promote" depends on task "build", but their only_if conditions are different

Check warning on line 178 in .cirrus.yml

View check run for this annotation

Cirrus CI / Build Parsing Results

.cirrus.yml#L178

task "promote" depends on task "build", but their only_if conditions are different
depends_on:
- build
- qa_plugin
Expand Down
8 changes: 5 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ slang-dependencies = "1.17.0.6351"
analyzer-commons = "2.16.0.3141"
plugin-api = "10.10.0.2391"
sonarqube = "10.0.0.68432"
orchestrator = "3.42.0.312"
orchestrator = "5.1.0.2254"
sonarlint = "9.0.0.74282"
minimal-json = "0.9.5"
mockito-core = "5.13.0"
assertj-core = "3.26.3"
junit-jupiter = "5.11.0"
# slf4j is provided by SQ, SC or SL, should be aligned with sonar-plugin-api in integration tests
slf4j-api = "1.7.30"

[libraries]
sonar-plugin-api = { group = "org.sonarsource.api.plugin", name = "sonar-plugin-api", version.ref = "plugin-api" }
Expand All @@ -20,7 +22,7 @@ checkstyle-import = { group = "org.sonarsource.slang", name = "checkstyle-import
minimal-json = { group = "com.eclipsesource.minimal-json", name = "minimal-json", version.ref = "minimal-json" }
sonar-plugin-api-test-fixtures = { group = "org.sonarsource.api.plugin", name = "sonar-plugin-api-test-fixtures", version.ref = "plugin-api" }
sonar-plugin-api-impl = { group = "org.sonarsource.sonarqube", name = "sonar-plugin-api-impl", version.ref = "sonarqube" }
sonar-orchestrator = { group = "org.sonarsource.orchestrator", name = "sonar-orchestrator", version.ref = "orchestrator" }
sonar-orchestrator-junit5 = { group = "org.sonarsource.orchestrator", name = "sonar-orchestrator-junit5", version.ref = "orchestrator" }
sonarlint-core = { group = "org.sonarsource.sonarlint.core", name = "sonarlint-core", version.ref = "sonarlint" }
sonar-ws = { group = "org.sonarsource.sonarqube", name = "sonar-ws", version.ref = "sonarqube" }
slang-antlr = { group = "org.sonarsource.slang", name = "slang-antlr", version.ref = "slang-dependencies" }
Expand All @@ -29,4 +31,4 @@ mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mo
assertj-core = { group = "org.assertj", name = "assertj-core", version.ref = "assertj-core" }
junit-jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" }
junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" }
junit-vintage-engine = { group = "org.junit.vintage", name = "junit-vintage-engine", version.ref = "junit-jupiter" }
slf4j-api = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j-api" }
19 changes: 12 additions & 7 deletions its/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ plugins {
}

dependencies {
"integrationTestImplementation"(libs.slf4j.api)
"integrationTestImplementation"(project(":sonar-go-plugin", configuration = "shadow"))
"integrationTestImplementation"(libs.sonar.analyzer.commons)
"integrationTestImplementation"(libs.sonar.ws)
"integrationTestImplementation"(libs.assertj.core)
"integrationTestImplementation"(libs.sonarlint.core)
"integrationTestImplementation"(libs.sonar.orchestrator)
"integrationTestRuntimeOnly"(libs.junit.vintage.engine)
"integrationTestImplementation"(libs.sonar.orchestrator.junit5) {
exclude("ch.qos.logback", "logback-classic")
exclude("org.slf4j", "slf4j-api")
exclude("org.slf4j", "jcl-over-slf4j")
exclude("org.slf4j", "log4j-over-slf4j")
}
"integrationTestImplementation"(libs.junit.jupiter.api)

"integrationTestRuntimeOnly"(libs.junit.jupiter.engine)
}

sonarqube.isSkipProject = true
sonar.isSkipProject = true

integrationTest {
testSources.set(file("projects"))
}
tasks.named<Test>("integrationTest") {
filter {
includeTestsMatching("org.sonarsource.slang.Tests")
includeTestsMatching("org.sonarsource.slang.SonarLintTest")
}
systemProperty("java.awt.headless", "true")
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
import com.sonar.orchestrator.build.SonarScanner;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class CoverageTest extends TestBase {

private static final Path BASE_DIRECTORY = Paths.get("projects", "measures");

@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();

@Test
public void go_coverage() {
final String projectKey = "goCoverage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.sonarsource.slang;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,19 @@
package org.sonarsource.slang;

import com.sonar.orchestrator.build.SonarScanner;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.client.issues.SearchRequest;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

public class ExternalReportTest extends TestBase {

private static final String BASE_DIRECTORY = "projects/externalreport/";

@Rule
public TemporaryFolder tmpDir = new TemporaryFolder();

@Test
public void govet() {
final String projectKey = "govet";
Expand Down Expand Up @@ -119,14 +110,6 @@ private List<Issue> getExternalIssues(String componentKey) {
.collect(Collectors.toList());
}

private Path createTemporaryReportFromTemplate(Path sourceReportPath, String placeHolder, String newValue) throws IOException {
String reportContent = new String(Files.readAllBytes(sourceReportPath), UTF_8);
reportContent = reportContent.replace(placeHolder, newValue);
Path destReportPath = tmpDir.newFile(sourceReportPath.getFileName().toString()).toPath().toRealPath();
Files.write(destReportPath, reportContent.getBytes(UTF_8));
return destReportPath;
}

private static String formatIssues(List<Issue> issues) {
return issues.stream()
.map(issue -> filePath(issue) + "|" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.sonarsource.slang;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.sonarsource.slang;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.sonarsource.slang;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.OrchestratorBuilder;
import com.sonar.orchestrator.locator.Locators;
import java.io.File;
import java.io.IOException;
Expand All @@ -33,11 +32,10 @@
import org.apache.commons.io.FileUtils;
import org.assertj.core.groups.Tuple;
import org.jetbrains.annotations.NotNull;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl;
import org.sonarsource.sonarlint.core.analysis.api.ClientInputFile;
import org.sonarsource.sonarlint.core.client.api.common.analysis.Issue;
Expand All @@ -52,22 +50,14 @@

public class SonarLintTest {

@ClassRule
public static TemporaryFolder temp = new TemporaryFolder();
@TempDir
static Path baseDir;

private static StandaloneSonarLintEngine sonarlintEngine;

private static File baseDir;

@BeforeClass
public static void prepare() throws Exception {
// Orchestrator is used only to retrieve plugin artifacts from filesystem or maven
OrchestratorBuilder orchestratorBuilder = Orchestrator.builderEnv();
Tests.addGoPlugin(orchestratorBuilder);
Orchestrator orchestrator = orchestratorBuilder
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(System.getProperty(Tests.SQ_VERSION_PROPERTY, Tests.DEFAULT_SQ_VERSION))
.build();
@BeforeAll
public static void prepare() {
Orchestrator orchestrator = TestBase.ORCHESTRATOR;

Locators locators = orchestrator.getConfiguration().locators();
StandaloneGlobalConfiguration.Builder sonarLintConfigBuilder = StandaloneGlobalConfiguration.builder();
Expand All @@ -77,18 +67,17 @@ public static void prepare() throws Exception {
.forEach(sonarLintConfigBuilder::addPlugin);

sonarLintConfigBuilder
.setSonarLintUserHome(temp.newFolder().toPath())
.setSonarLintUserHome(baseDir)
.setLogOutput((formattedMessage, level) -> {
/* Don't pollute logs */
});
StandaloneGlobalConfiguration configuration = sonarLintConfigBuilder
.addEnabledLanguage(Language.GO)
.build();
sonarlintEngine = new StandaloneSonarLintEngineImpl(configuration);
baseDir = temp.newFolder();
}

@AfterClass
@AfterAll
public static void stop() {
sonarlintEngine.stop();
}
Expand Down Expand Up @@ -116,7 +105,7 @@ public void test_go_nosonar() throws Exception {
private List<Issue> analyzeWithSonarLint(ClientInputFile inputFile) {
List<Issue> issues = new ArrayList<>();
StandaloneAnalysisConfiguration analysisConfiguration = StandaloneAnalysisConfiguration.builder()
.setBaseDir(baseDir.toPath())
.setBaseDir(baseDir)
.addInputFiles(Collections.singletonList(inputFile))
.build();

Expand All @@ -132,7 +121,7 @@ private void assertIssues(List<Issue> issues, Tuple... expectedIssues) {
}

private ClientInputFile prepareInputFile(String content) throws IOException {
File file = new File(baseDir, "foo.go");
File file = new File(baseDir.toFile(), "foo.go");
FileUtils.write(file, content, StandardCharsets.UTF_8);
return createInputFile(file.toPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.build.SonarScannerInstaller;
import com.sonar.orchestrator.config.Configuration;
import com.sonar.orchestrator.junit5.OrchestratorExtension;
import com.sonar.orchestrator.junit5.OrchestratorExtensionBuilder;
import com.sonar.orchestrator.locator.FileLocation;
import com.sonar.orchestrator.version.Version;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.sonarqube.ws.Issues;
import org.sonarqube.ws.Measures.ComponentWsResponse;
import org.sonarqube.ws.Measures.Measure;
Expand All @@ -36,8 +45,49 @@

public abstract class TestBase {

@ClassRule
public static final Orchestrator ORCHESTRATOR = Tests.ORCHESTRATOR;
public static final String KEEP_ORCHESTRATOR_RUNNING_ENV = "KEEP_ORCHESTRATOR_RUNNING";
public static final boolean KEEP_ORCHESTRATOR_RUNNING = "true".equals(System.getenv(KEEP_ORCHESTRATOR_RUNNING_ENV));
public static final String SQ_VERSION_PROPERTY = "sonar.runtimeVersion";
public static final String DEFAULT_SQ_VERSION = "LATEST_RELEASE";
public static final FileLocation GO_PLUGIN_LOCATION = FileLocation.byWildcardFilename(new File("../../sonar-go-plugin/build/libs"), "sonar-go-plugin-*-all.jar");
public static final Configuration CONFIGURATION = Configuration.createEnv();

private static final AtomicInteger REQUESTED_ORCHESTRATORS_KEY = new AtomicInteger();
private static final CountDownLatch IS_ORCHESTRATOR_READY = new CountDownLatch(1);
private static final String SCANNER_VERSION = "5.0.1.3006";
Copy link
Contributor

Choose a reason for hiding this comment

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

Latest version is 6.2.1.4610, maybe we should already use it here?


private static final OrchestratorExtensionBuilder orchestratorBuilder = OrchestratorExtension.builder(CONFIGURATION);
public static final Orchestrator ORCHESTRATOR = orchestratorBuilder
.addPlugin(GO_PLUGIN_LOCATION)
.useDefaultAdminCredentialsForBuilds(true)
.setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION))
.restoreProfileAtStartup(FileLocation.of("src/integrationTest/resources/nosonar-go.xml"))
.build();

@BeforeAll
public static void startOrchestrator() {
// This is to avoid multiple starts when using nested tests
// See https://github.com/junit-team/junit5/issues/2421
if (REQUESTED_ORCHESTRATORS_KEY.getAndIncrement() == 0) {
ORCHESTRATOR.start();
// installed scanner will be shared by all tests
new SonarScannerInstaller(CONFIGURATION.locators()).install(Version.create(SCANNER_VERSION), CONFIGURATION.fileSystem().workspace());
IS_ORCHESTRATOR_READY.countDown();
} else {
try {
IS_ORCHESTRATOR_READY.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
}

@AfterAll
public static void stopOrchestrator() {
if (!KEEP_ORCHESTRATOR_RUNNING && REQUESTED_ORCHESTRATORS_KEY.decrementAndGet() == 0) {
ORCHESTRATOR.stop();
}
}

protected SonarScanner getSonarScanner(String projectKey, String directoryToScan, String languageKey) {
return getSonarScanner(projectKey, directoryToScan, languageKey, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
*/
package org.sonarsource.slang;

import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarScanner;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class TestReportTest extends TestBase {

private static final Path BASE_DIRECTORY = Paths.get("projects", "measures");

@ClassRule
public static Orchestrator orchestrator = Tests.ORCHESTRATOR;

@Test
public void go_test_report() {
final String projectKey = "goTestReport";
Expand Down
Loading
Loading