UNPKG

snyk-mvn-plugin

Version:
43 lines • 2.1 kB
"use strict"; 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\]/m; const successLabel = /^\[INFO\] BUILD SUCCESS/m; // JVM unified logging (JDK 9+, e.g. -Xlog:gc), e.g. // "[4.326s][info][gc] GC(9) Pause Young (Normal) 24M->8M(64M) 3.1ms". // Decorators are optional; the level is always lowercase, which keeps // Maven's uppercase "[INFO]" labels out of the match. These lines reach // stdout when the JVM logs GC to stdout and must not reach the digraph parser. const jvmUnifiedLogLine = /^(?:\[[^\]\n]*\])*\[(?:trace|debug|info|warning|error)\s*\]\[[\w,+-]+\s*\].*(?:\r?\n|$)/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.'); } // Strip JVM log lines on both sides of the Maven label strip. Before: logLabel // also eats the level of an undecorated "[info][gc] ..." line, leaving // "[gc] ..." that no longer matches. After: catches lines Maven prefixed // with "[INFO] ". return stdout .replace(jvmUnifiedLogLine, '') .replace(logLabel, '') .replace(jvmUnifiedLogLine, ''); } // 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