UNPKG

@atomist/sdm-pack-spring

Version:

Atomist software delivery machine extension pack for Spring and Spring Boot applications

142 lines 5.99 kB
"use strict"; /* * Copyright © 2018 Atomist, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const automation_client_1 = require("@atomist/automation-client"); const sdm_1 = require("@atomist/sdm"); const sdm_core_1 = require("@atomist/sdm-core"); const df = require("dateformat"); const mavenCommand_1 = require("../mavenCommand"); const MavenProgressReporter_1 = require("../MavenProgressReporter"); const pomParser_1 = require("../parse/pomParser"); const pushTests_1 = require("../pushtest/pushTests"); const MavenBuilder_1 = require("./MavenBuilder"); function newVersion(sdmGoal, p) { return __awaiter(this, void 0, void 0, function* () { const pi = yield pomParser_1.MavenProjectIdentifier(p); const branch = sdmGoal.branch.split("/").join("."); return `${pi.version}-${branch}.${df(new Date(), "yyyymmddHHMMss")}`; }); } /** * ProjectVersioner to be used with Maven projects * @param sdmGoal * @param p * @param log * @constructor */ exports.MavenProjectVersioner = (sdmGoal, p, log) => __awaiter(this, void 0, void 0, function* () { const version = yield newVersion(sdmGoal, p); yield changeMavenVersion(version, p, log); return version; }); /** * PrepareForGoalExecution for updating the Maven version in project * @param p * @param goalInvocation * @constructor */ exports.MavenVersionPreparation = (p, goalInvocation) => __awaiter(this, void 0, void 0, function* () { const version = yield newVersion(goalInvocation.sdmGoal, p); return changeMavenVersion(version, p, goalInvocation.progressLog); }); function changeMavenVersion(version, p, progressLog) { return __awaiter(this, void 0, void 0, function* () { const command = yield mavenCommand_1.determineMavenCommand(p); const args = ["build-helper:parse-version", "versions:set", `-DnewVersion=${version}`, "versions:commit"]; return automation_client_1.spawnAndWatch({ command, args }, { cwd: p.baseDir }, progressLog); }); } /** * PrepareForGoalExecution for running Maven package * @param p * @param goalInvocation * @constructor */ exports.MavenCompilePreparation = mavenPackagePreparation([{ name: "skipTests", value: "true", }]); /** * Constructs a PrepareForGoalExecution taking additional command line args * @param args */ function mavenPackagePreparation(args = []) { return (p, goalInvocation) => __awaiter(this, void 0, void 0, function* () { return MavenBuilder_1.mavenPackage(p, goalInvocation.progressLog, args); }); } exports.mavenPackagePreparation = mavenPackagePreparation; function mavenIncrementPatchVersionCommand(p, progressLog) { return __awaiter(this, void 0, void 0, function* () { const command = yield mavenCommand_1.determineMavenCommand(p); const args = [ "build-helper:parse-version", "versions:set", "\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-\${parsedVersion.qualifier}", "versions:commit", ]; return automation_client_1.spawnAndWatch({ command, args }, { cwd: p.baseDir }, progressLog); }); } exports.mavenIncrementPatchVersionCommand = mavenIncrementPatchVersionCommand; function mvnVersionProjectListener(p, gi, event) { return __awaiter(this, void 0, void 0, function* () { if (event === sdm_1.GoalProjectListenerEvent.before) { const v = yield sdm_core_1.readSdmVersion(gi.sdmGoal.repo.owner, gi.sdmGoal.repo.name, gi.sdmGoal.repo.providerId, gi.sdmGoal.sha, gi.sdmGoal.branch, gi.context); return automation_client_1.spawnAndWatch({ command: "mvn", args: ["versions:set", `-DnewVersion=${v}`, "versions:commit"], }, { cwd: p.baseDir }, gi.progressLog); } }); } exports.mvnVersionProjectListener = mvnVersionProjectListener; exports.MvnVersion = { name: "mvn-version", listener: mvnVersionProjectListener, pushTest: pushTests_1.IsMaven, }; function mvnPackageProjectListener(p, gi, event) { return __awaiter(this, void 0, void 0, function* () { if (event === sdm_1.GoalProjectListenerEvent.before) { return automation_client_1.spawnAndWatch({ command: "mvn", args: ["package", "-DskipTests=true", `-Dartifact.name=${p.id.repo}`], }, { cwd: p.baseDir, }, gi.progressLog); } }); } exports.MvnPackage = { name: "mvn-package", listener: mvnPackageProjectListener, pushTest: pushTests_1.IsMaven, }; exports.MavenDefaultOptions = { pushTest: pushTests_1.IsMaven, logInterpreter: sdm_1.LogSuppressor, progressReporter: MavenProgressReporter_1.MavenProgressReporter, }; //# sourceMappingURL=helpers.js.map