@snyk/java-call-graph-builder
Version:
Tool for building a call graph for JVM ecosystem (Maven, Gradle...)
48 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getClassPathFromGradle = exports.getGradleCommandArgs = void 0;
const tslib_1 = require("tslib");
require("source-map-support/register");
const sub_process_1 = require("./sub-process");
const path = require("path");
const os_1 = require("os");
const errors_1 = require("./errors");
const fs = require("fs");
const tmp = require("tmp");
function getGradleCommandArgs(targetPath, initScript, confAttrs) {
// For binary releases, the original file would be in the binary build and inaccesible
const originalPath = path.join(__dirname, ...'../bin/init.gradle'.split('/'));
const tmpFilePath = tmp.fileSync().name;
fs.copyFileSync(originalPath, tmpFilePath);
const gradleArgs = ['printClasspath', '-I', tmpFilePath, '-q'];
if (targetPath) {
gradleArgs.push('-p', targetPath);
}
if (initScript) {
gradleArgs.push('--init-script', initScript);
}
if (confAttrs) {
const isWin = /^win/.test(os_1.platform());
const quot = isWin ? '"' : "'";
gradleArgs.push(`-PconfAttrs=${quot}${confAttrs}${quot}`);
}
return gradleArgs;
}
exports.getGradleCommandArgs = getGradleCommandArgs;
function getClassPathFromGradle(targetPath, gradlePath, initScript, confAttrs) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const args = getGradleCommandArgs(targetPath, initScript, confAttrs);
try {
const output = yield sub_process_1.execute(gradlePath, args, { cwd: targetPath });
const lines = output.trim().split(os_1.EOL);
const lastLine = lines[lines.length - 1];
return lastLine.trim();
}
catch (e) {
console.log(e);
throw new errors_1.ClassPathGenerationError(e);
}
});
}
exports.getClassPathFromGradle = getClassPathFromGradle;
//# sourceMappingURL=gradle-wrapper.js.map