snyk-mvn-plugin
Version:
Snyk CLI Maven plugin
30 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDigraphsFromStdout = parseDigraphsFromStdout;
exports.parsePluginVersionFromStdout = parsePluginVersionFromStdout;
const parse_digraph_1 = require("../parse-digraph");
const logLabel = /^\[\w+\]\s*/gm;
const errorLabel = /^\[ERROR\]/gm;
const successLabel = /^\[INFO\] BUILD SUCCESS/gm;
const mavenDependencyPluginRegex = /(?:maven-dependency-plugin|dependency):(\d+\.\d+)(\.\d+)?:tree/m;
function cleanStdout(stdout) {
if (errorLabel.test(stdout) && !successLabel.test(stdout)) {
throw new Error('Maven output contains errors.');
}
return stdout.replace(logLabel, '');
}
// Parse the output from 'mvn dependency:tree -DoutputType=dot'
function parseDigraphsFromStdout(stdout) {
const cleanedStdout = cleanStdout(stdout);
const digraphs = (0, parse_digraph_1.parseDigraph)(cleanedStdout);
if (!digraphs) {
throw new Error('Cannot find any digraphs.');
}
return digraphs;
}
function parsePluginVersionFromStdout(stdout) {
const cleanedStdout = cleanStdout(stdout);
const versionRes = mavenDependencyPluginRegex.exec(cleanedStdout);
return versionRes ? `${versionRes[1]}${versionRes[2] || ''}` : '';
}
//# sourceMappingURL=stdout.js.map