Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
#57 Sonar CLI mirror and version variables
Browse files Browse the repository at this point in the history
Contribued by @marapper
  • Loading branch information
bellingard committed Mar 24, 2020
1 parent 4e8e6a6 commit b435549
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@ Thanks to [Philipp Eschenbach](https://github.com/peh) for troubleshooting this
## Download From Mirrors

By default, SonarQube scanner binaries are downloaded from `https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/`.
To use a custom mirror, set `$SONAR_SCANNER_MIRROR`.
To use a custom mirror, set `$SONAR_SCANNER_MIRROR`. Or download precise version with `$SONAR_SCANNER_VERSION`

**Example:**
```shell
export SONAR_SCANNER_MIRROR=https://npm.taobao.org/mirrors/sonar-scanner/
export SONAR_SCANNER_VERSION=3.2.0.1227
```

or alternatively set variable in `.npmrc`

```
sonar_scanner_mirror=https://npm.taobao.org/mirrors/sonar-scanner/
sonar_scanner_version=3.2.0.1227
```

## License
Expand Down
14 changes: 10 additions & 4 deletions dist/sonarqube-scanner-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports.prepareExecEnvironment = prepareExecEnvironment
module.exports.getSonarQubeScannerExecutable = getSonarQubeScannerExecutable
module.exports.getLocalSonarQubeScannerExecutable = getLocalSonarQubeScannerExecutable

const SONAR_SCANNER_MIRROR = 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/'
const SONAR_SCANNER_VERSION = '4.2.0.1873'

const bar = new ProgressBar('[:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
Expand Down Expand Up @@ -56,7 +59,8 @@ function prepareExecEnvironment(params, process) {
* Returns the SQ Scanner executable for the current platform
*/
function getSonarQubeScannerExecutable(passExecutableCallback) {
const platformBinariesVersion = '4.2.0.1873'
const platformBinariesVersion =
process.env.SONAR_SCANNER_VERSION || process.env.npm_config_sonar_scanner_version || SONAR_SCANNER_VERSION
var targetOS = findTargetOS()
var installFolder = path.join(os.homedir(), '.sonar', 'native-sonar-scanner')
var binaryExtension = ''
Expand Down Expand Up @@ -91,7 +95,7 @@ function getSonarQubeScannerExecutable(passExecutableCallback) {
log('Proceed with download of the platform binaries for SonarQube Scanner...')
log('Creating ' + installFolder)
mkdirs(installFolder)
var baseUrl = process.env.SONAR_SCANNER_MIRROR || 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/'
var baseUrl = process.env.SONAR_SCANNER_MIRROR || process.env.npm_config_sonar_scanner_mirror || SONAR_SCANNER_MIRROR
var fileName = 'sonar-scanner-cli-' + platformBinariesVersion + '-' + targetOS + '.zip'
var downloadUrl = baseUrl + fileName
log(`Downloading from ${downloadUrl}`)
Expand All @@ -104,10 +108,12 @@ function getSonarQubeScannerExecutable(passExecutableCallback) {
.then(() => {
passExecutableCallback(platformExecutable)
})
.catch((err) => {
.catch(err => {
logError(`ERROR: impossible to download and extract binary: ${err.message}`)
logError(` SonarQube Scanner binaries probably don't exist for your OS (${targetOS}).`)
logError(' In such situation, the best solution is to install the standard SonarQube Scanner (requires a JVM).')
logError(
' In such situation, the best solution is to install the standard SonarQube Scanner (requires a JVM).'
)
logError(' Check it out at https://redirect.sonarsource.com/doc/install-configure-scanner.html')
})
}
Expand Down

0 comments on commit b435549

Please sign in to comment.