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

Commit

Permalink
Merge pull request #68 from JustinMcNamara74/add-binary-cache
Browse files Browse the repository at this point in the history
Added env var for cached binary
  • Loading branch information
bellingard committed Mar 24, 2020
2 parents b435549 + d86e5fc commit 3e669d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dist/sonarqube-scanner-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var sonarQubeParams = require('./sonarqube-scanner-params')
module.exports.prepareExecEnvironment = prepareExecEnvironment
module.exports.getSonarQubeScannerExecutable = getSonarQubeScannerExecutable
module.exports.getLocalSonarQubeScannerExecutable = getLocalSonarQubeScannerExecutable
module.exports.getInstallFolderPath = getInstallFolderPath

const SONAR_SCANNER_MIRROR = 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/'
const SONAR_SCANNER_VERSION = '4.2.0.1873'
Expand Down Expand Up @@ -62,7 +63,7 @@ function getSonarQubeScannerExecutable(passExecutableCallback) {
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 installFolder = getInstallFolderPath()
var binaryExtension = ''
if (isWindows()) {
binaryExtension = '.bat'
Expand Down Expand Up @@ -158,6 +159,11 @@ function findTargetOS() {
throw Error(`Your platform '${process.platform}' is currently not supported.`)
}

function getInstallFolderPath() {
var basePath = process.env.SONAR_BINARY_CACHE ? process.env.SONAR_BINARY_CACHE : os.homedir()
return path.join(basePath, '.sonar', 'native-sonar-scanner')
}

/*
* Some util functions...
*/
Expand Down
7 changes: 7 additions & 0 deletions specs/sonarqube-scanner-executable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('sqScannerExecutable', function() {
})
})

describe('getSonarQubeScannerExecutable', function() {
it('should use SONAR_BINARY_CACHE env when exists', function() {
process.env.SONAR_BINARY_CACHE = './test-cache'
assert.equal(index.getInstallFolderPath(), 'test-cache/.sonar/native-sonar-scanner', 'congrats')
})
})

function pathForProject(projectFolder) {
return path.join(process.cwd(), 'specs', 'resources', projectFolder)
}

0 comments on commit 3e669d4

Please sign in to comment.