snyk-mvn-plugin
Advanced tools
Comparing version
@@ -9,2 +9,28 @@ "use strict"; | ||
const jar_1 = require("./jar"); | ||
const os = require("os"); | ||
function getCommand(root, targetFile) { | ||
if (!targetFile) { | ||
return 'mvn'; | ||
} | ||
const isWinLocal = /^win/.test(os.platform()); // local check, can be stubbed in tests | ||
const wrapperScript = isWinLocal ? 'mvnw.cmd' : './mvnw'; | ||
// try to find a sibling wrapper script first | ||
let pathToWrapper = path.resolve(root, path.dirname(targetFile), wrapperScript); | ||
if (fs.existsSync(pathToWrapper)) { | ||
return wrapperScript; | ||
} | ||
// now try to find a wrapper in the root | ||
pathToWrapper = path.resolve(root, wrapperScript); | ||
if (fs.existsSync(pathToWrapper)) { | ||
return wrapperScript; | ||
} | ||
return 'mvn'; | ||
} | ||
exports.getCommand = getCommand; | ||
// When we have `mvn`, we can run the subProcess from anywhere. | ||
// However due to https://github.com/takari/maven-wrapper/issues/133, `mvnw` can only be run | ||
// within the directory where `mvnw` exists | ||
function calculateTargetFilePath(mavenCommand, root, targetPath) { | ||
return mavenCommand === 'mvn' ? root : path.dirname(targetPath); | ||
} | ||
function inspect(root, targetFile, options) { | ||
@@ -33,7 +59,11 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const mvnArgs = buildArgs(targetFile, options.args); | ||
const mavenCommand = getCommand(root, targetFile); | ||
const targetFilePath = calculateTargetFilePath(mavenCommand, root, targetPath); | ||
try { | ||
const result = yield subProcess.execute('mvn', mvnArgs, { cwd: root }); | ||
const versionResult = yield subProcess.execute('mvn --version', [], { | ||
cwd: root, | ||
const result = yield subProcess.execute(mavenCommand, mvnArgs, { | ||
cwd: targetFilePath, | ||
}); | ||
const versionResult = yield subProcess.execute(`${mavenCommand} --version`, [], { | ||
cwd: targetFilePath, | ||
}); | ||
const parseResult = parse_mvn_1.parseTree(result, options.dev); | ||
@@ -58,15 +88,3 @@ const { javaVersion, mavenVersion } = parse_mvn_1.parseVersions(versionResult); | ||
catch (error) { | ||
error.message = | ||
error.message + | ||
'\n\n' + | ||
'Please make sure that Apache Maven Dependency Plugin ' + | ||
'version 2.2 or above is installed, and that ' + | ||
'`mvn ' + | ||
mvnArgs.join(' ') + | ||
'` executes successfully ' + | ||
'on this project.\n\n' + | ||
'If the problem persists, collect the output of ' + | ||
'`mvn ' + | ||
mvnArgs.join(' ') + | ||
'` and contact support@snyk.io\n'; | ||
error.message = buildErrorMessage(error, mvnArgs, mavenCommand); | ||
throw error; | ||
@@ -89,2 +107,18 @@ } | ||
exports.buildArgs = buildArgs; | ||
function buildErrorMessage(error, mvnArgs, mavenCommand) { | ||
const mavenArguments = mvnArgs.join(' '); | ||
const fullCommand = `${mavenCommand} ${mavenArguments}`; | ||
const mvnwCommandTipMessage = 'Currently, you cannot run `mvnw` outside your current directory, you will have to go inside the directory of your project (see: https://github.com/takari/maven-wrapper/issues/133)\n\n'; | ||
return (error.message + | ||
'\n\n' + | ||
'Please make sure that Apache Maven Dependency Plugin ' + | ||
'version 2.2 or above is installed, and that `' + | ||
fullCommand + | ||
'` executes successfully ' + | ||
'on this project.\n\n' + | ||
(mavenCommand.indexOf('mvnw') >= 0 ? mvnwCommandTipMessage : '') + | ||
'If the problem persists, collect the output of `' + | ||
fullCommand + | ||
'` and contact support@snyk.io\n'); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -35,3 +35,5 @@ { | ||
"prettier": "^1.19.1", | ||
"@types/sinon": "^7.0.10", | ||
"semantic-release": "^15", | ||
"sinon": "^2.4.1", | ||
"tap": "^12.0.1", | ||
@@ -48,3 +50,3 @@ "tap-only": "0.0.5" | ||
}, | ||
"version": "2.8.0" | ||
"version": "2.9.0" | ||
} |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
33236
9.56%458
8.02%11
22.22%