sonarqube-scanner
Version:
SonarQube/SonarCloud Scanner for the JavaScript world
93 lines (92 loc) • 4.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scan = scan;
/*
* sonar-scanner-npm
* Copyright (C) SonarSource Sàrl
* mailto:info AT sonarsource DOT com
*
* You can redistribute and/or modify this program under the terms of
* the Sonar Source-Available License Version 1, as published by SonarSource Sàrl.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Sonar Source-Available License for more details.
*
* You should have received a copy of the Sonar Source-Available License
* along with this program; if not, see https://sonarsource.com/license/ssal/
*/
const constants_1 = require("./constants");
const deps_1 = require("./deps");
const logging_1 = require("./logging");
const properties_1 = require("./properties");
const request_1 = require("./request");
const types_1 = require("./types");
const version_1 = require("./version");
async function scan(scanOptions, cliArgs) {
try {
await runScan(scanOptions, cliArgs);
}
catch (error) {
(0, logging_1.log)(logging_1.LogLevel.ERROR, `An error occurred: ${error}`);
throw error;
}
}
async function runScan(scanOptions, cliArgs) {
// Get dependencies from the container
const { serverSupportsJREProvisioning, fetchJRE, downloadScannerCli, runScannerCli, fetchScannerEngine, runScannerEngine, locateExecutableFromPath, } = (0, deps_1.getDeps)().scan;
const startTimestampMs = Date.now();
const properties = (0, properties_1.getProperties)(scanOptions, startTimestampMs, cliArgs);
if (properties[types_1.ScannerProperty.SonarVerbose] === 'true') {
(0, logging_1.setLogLevel)(logging_1.LogLevel.DEBUG);
(0, logging_1.log)(logging_1.LogLevel.DEBUG, 'Setting the log level to DEBUG due to verbose mode');
}
if (properties[types_1.ScannerProperty.SonarLogLevel]) {
(0, logging_1.setLogLevel)(properties[types_1.ScannerProperty.SonarLogLevel]);
(0, logging_1.log)(logging_1.LogLevel.DEBUG, `Overriding the log level to ${properties[types_1.ScannerProperty.SonarLogLevel]}`);
}
(0, logging_1.log)(logging_1.LogLevel.DEBUG, 'Properties:', properties);
(0, logging_1.log)(logging_1.LogLevel.INFO, 'Platform:', properties[types_1.ScannerProperty.SonarScannerOs], properties[types_1.ScannerProperty.SonarScannerArch]);
await (0, request_1.initializeAxios)(properties);
(0, logging_1.log)(logging_1.LogLevel.INFO, `Server URL: ${properties[types_1.ScannerProperty.SonarHostUrl]}`);
(0, logging_1.log)(logging_1.LogLevel.INFO, `Version: ${version_1.version}`);
(0, logging_1.log)(logging_1.LogLevel.DEBUG, 'Check if Server supports JRE provisioning');
const supportsJREProvisioning = await serverSupportsJREProvisioning(properties);
(0, logging_1.log)(logging_1.LogLevel.INFO, `JRE provisioning ${supportsJREProvisioning ? 'is' : 'is NOT'} supported`);
if (!supportsJREProvisioning) {
(0, logging_1.log)(logging_1.LogLevel.INFO, 'Falling back on using sonar-scanner-cli');
if (scanOptions.localScannerCli) {
(0, logging_1.log)(logging_1.LogLevel.INFO, 'Local scanner is requested, will not download sonar-scanner-cli');
const scannerPath = await locateExecutableFromPath(constants_1.SCANNER_CLI_DEFAULT_BIN_NAME);
if (!scannerPath) {
throw new Error('SonarScanner CLI not found in PATH');
}
await runScannerCli(scanOptions, properties, scannerPath);
}
else {
const binPath = await downloadScannerCli(properties);
await runScannerCli(scanOptions, properties, binPath);
}
return;
}
// Detect what Java to use (in path, specified from properties or provisioned)
let javaPath;
if (properties[types_1.ScannerProperty.SonarScannerJavaExePath]) {
javaPath = properties[types_1.ScannerProperty.SonarScannerJavaExePath];
}
else if (properties[types_1.ScannerProperty.SonarScannerSkipJreProvisioning] === 'true') {
const absoluteJavaPath = await locateExecutableFromPath('java');
if (!absoluteJavaPath) {
throw new Error('Java not found in PATH');
}
javaPath = absoluteJavaPath;
}
else {
javaPath = await fetchJRE(properties);
}
// Fetch the Scanner Engine
const latestScannerEngine = await fetchScannerEngine(properties);
// Run the Scanner Engine
await runScannerEngine(javaPath, latestScannerEngine, scanOptions, properties);
}