UNPKG

@atlassian/wrm-troubleshooting

Version:

A tool that can help you with troubleshooting the configuration of webpack and Atlassian P2 project.

94 lines 4.41 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEffectivePomConfig = void 0; const execa_1 = __importDefault(require("execa")); const fs_1 = __importStar(require("fs")); const lookpath_1 = require("lookpath"); const path = __importStar(require("path")); const MavenError_1 = require("../maven/MavenError"); const types_1 = require("./types"); const getEffectivePomConfig = async (options, payload) => { const { pomFile } = payload; console.log('👀 We will retrieve pom configuration now. This might take some time...'); const pomFileWd = path.dirname(pomFile); const xmlConfigOutput = path.resolve(pomFileWd, '.temp-pom-config.xml'); // We need to check if at least one of the following commands is available const mvnCommands = ['atlas-mvn', 'mvn']; let mvnCommand; for (const mvnCmd of mvnCommands) { mvnCommand = await (0, lookpath_1.lookpath)(mvnCmd); if (mvnCommand) { break; } } // When we run integration tests locally with Jest we need to use a different maven command than `mvn`. // For some reason, using `mvn` command will cause this error: // // Command failed with exit code 1: mvn help:effective-pom -Doutput=<<file-path>> --quiet // mkdir: /.mvnvm: Read-only file system // // So for the integration tests we are running locally we need to use "atlas-mvn" from the Atlassian SDK. if (process.env.NODE_ENV === 'test' && !process.env.CI) { mvnCommand = 'atlas-mvn'; } if (!mvnCommand) { return (0, types_1.getFailedResult)(new MavenError_1.MavenError(`We can't run the "atlas-mvn" or "mvn" commands. Please ensure you have installed Atlassian SDK and one of those command can be executed. Refer to the SDK Installation Guide: https://developer.atlassian.com/server/framework/atlassian-sdk/install-the-atlassian-sdk-on-a-linux-or-mac-system/`, '')); } try { await (0, execa_1.default)(mvnCommand, ['help:effective-pom', `-Doutput=${xmlConfigOutput}`, '--quiet'], { cwd: pomFileWd, timeout: options.timeout, }); } catch (err) { const error = err; if (error.timedOut) { return (0, types_1.getCommandTimeoutResult)('mvn', options.timeout); } const errorMessage = error.stdout || error.message || error.shortMessage; return (0, types_1.getFailedResult)(new MavenError_1.MavenError('Maven "help:effective-pom" command failed.', errorMessage)); } // Verify if the effective pom file was created try { await fs_1.promises.access(xmlConfigOutput); } catch (err) { const error = err; const errorMessage = error.message; const xmlFilename = path.basename(xmlConfigOutput); return (0, types_1.getFailedResult)(new MavenError_1.MavenError(`Maven "help:effective-pom" command failed. We couldn't create the "${xmlFilename}" file with effective pom configuration.`, errorMessage)); } const pomConfig = fs_1.default.readFileSync(xmlConfigOutput, { encoding: 'utf-8', }); // Remove the temporary file that we don't need anymore fs_1.default.unlinkSync(xmlConfigOutput); return (0, types_1.getPassedResult)({ pomConfig, }); }; exports.getEffectivePomConfig = getEffectivePomConfig; //# sourceMappingURL=getEffectivePomConfig.js.map