- Notifications
You must be signed in to change notification settings - Fork6
Java library for running SonarQube in tests
License
SonarSource/orchestrator
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Orchestrator is a Java library to install and run SonarQube from tests.
An instance of classcom.sonar.orchestrator.junit4.OrchestratorRule
can be used asRule
orClassRule
. It will represent a SonarQube server that will be started before tests, and stopped after:
public class MyTest { @ClassRule public static OrchestratorRule ORCHESTRATOR = OrchestratorRule.builderEnv() .setSonarVersion("7.0") .addPlugin(FileLocation.of("/path/to/plugin.jar")) .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "5.2.0.13398") .setServerProperty("sonar.web.javaOpts", "-Xmx1G") .build(); @Test public void myTest() { // run SonarQube Scanner ORCHESTRATOR.executeBuild(SonarScanner.create(new File("/path/to/project"))); // requests web services String baseUrl = ORCHESTRATOR.getServer().getUrl(); // ... }}
An instance of classcom.sonar.orchestrator.junit5.OrchestratorExtension
can be used asExtension
. It will represent a SonarQube server that will be started before tests, and stopped after:
class MyTests { @RegisterExtension static OrchestratorExtension ORCHESTRATOR = OrchestratorExtension.builderEnv() .setSonarVersion("7.0") .addPlugin(FileLocation.of("/path/to/plugin.jar")) .addPlugin(MavenLocation.of("org.sonarsource.java", "sonar-java-plugin", "5.2.0.13398") .setServerProperty("sonar.web.javaOpts", "-Xmx1G") .build(); @Test void myTest() { // run SonarQube Scanner ORCHESTRATOR.executeBuild(SonarScanner.create(new File("/path/to/project"))); // requests web services String baseUrl = ORCHESTRATOR.getServer().getUrl(); // ... }}
Aliases can be used to define the versions of SonarQube and plugins to be installed. Supported values are:
DEV
for the latest official build (in terms of version number, not date)DEV[x.y]
for the latest official build of a series. For exampleDEV[5.2]
may install version5.2.0.1234
.LATEST_RELEASE
for the latest release (in terms of version number, not date)LATEST_RELEASE[x.y]
for the latest release of a series, for exampleLATEST_RELEASE[5.2]
The aliasLTS
is no more supported for SonarQube since Orchestrator 3.17. It should be replaced byLATEST_RELEASE[6.7]
.
Please note that since Orchestrator 4.7, if the default value oforchestrator.artifactory.url
(https://repox.jfrog.io/repox) isnot used,theDEV
alias will not work.
The artifacts downloaded from Artifactory (SonarQube, plugins) are copied to the local directory~/.sonar/orchestrator/cache
.This directory isnot automatically purged and may grow significantly when using the version aliasDEV
.
The test environment is configured in the file~/.sonar/orchestrator/orchestrator.properties
:
# Token used to download SonarSource private artifacts from https://repox.jfrog.io/repox# Generate your identity token at https://repox.jfrog.io/ui/user_profile# This property can be replaced by the environment variable ARTIFACTORY_ACCESS_TOKEN.#orchestrator.artifactory.accessToken=xxx# Personal access token used to request SonarSource development licenses at https://github.com/sonarsource/licenses.# Generate a token from https://github.com/settings/tokens# This property can be replaced by the environment variable GITHUB_TOKEN.#github.token=xxx# Port of SonarQube server. Default value is 0 (random).#orchestrator.container.port=10000# Maven installation, used when running Scanner for Maven.# By default Maven binary is searched in $PATH#maven.home=/usr/local/Cellar/maven/3.5.0/libexec# Maven local repository (optional), used to search artifacts of plugins before# downloading from Artifactory.# Default is ~/.m2/repository#maven.localRepository=/path/to/maven/repository# Instance of Artifactory. Default is SonarSource's instance (https://repox.jfrog.io/repox).# This property can be replaced by the environment variable ARTIFACTORY_URL.# To use maven central instead, use https://repo1.maven.org/maven2# To use a custom instance, use your own URL that points to a Maven repository.#orchestrator.artifactory.url=https://repo1.maven.org/maven2
The path to configuration file can be overridden with the system propertyorchestrator.configUrl
or the environment variableORCHESTRATOR_CONFIG_URL
.Example:-Dorchestrator.configUrl=file:///path/to/orchestrator.properties
For running Orchestrator behind a corporate proxy, add Java properties :
-Dhttp.proxyHost=proxy.company.com-Dhttp.proxyPort=80-Dhttps.proxyHost=proxy.company.com-Dhttps.proxyPort=80-Dhttp.nonProxyHosts="localhost|127.0.0.1|*.company.com"-Dhttp.proxyUser=foo-Dhttp.proxyPassword=bar
Copyright 2011-2024 SonarSource.
Licensed under theGNU Lesser General Public License, Version 3.0
About
Java library for running SonarQube in tests