UNPKG

@atomist/sdm-pack-spring

Version:

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

154 lines (153 loc) 6.6 kB
"use strict"; /* * Copyright © 2019 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) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const sdm_1 = require("@atomist/sdm"); const gradleCommand_1 = require("../gradleCommand"); function getProjectVersion(p) { return __awaiter(this, void 0, void 0, function* () { let version; const versionRegex = /^version\s?=\s?["']?([0-9a-zA-Z.-]*)['"]?/m; if (yield p.hasFile("gradle.properties")) { const gradleProperties = yield (yield p.getFile("gradle.properties")).getContent(); const match = gradleProperties.match(versionRegex); if (!!match) { version = gradleProperties.match(versionRegex)[1]; } } else if (yield p.hasFile("build.gradle")) { const gradleBuild = yield (yield p.getFile("build.gradle")).getContent(); const match = gradleBuild.match(versionRegex); if (!!match) { version = gradleBuild.match(versionRegex)[1]; } } else if (yield p.hasFile("build.gradle.kts")) { const gradleBuild = yield (yield p.getFile("build.gradle.kts")).getContent(); const match = gradleBuild.match(versionRegex); if (!!match) { version = gradleBuild.match(versionRegex)[1]; } } return version || "0.0.1-SNAPSHOT"; }); } exports.getProjectVersion = getProjectVersion; function getProjectGroup(p) { return __awaiter(this, void 0, void 0, function* () { let group; const groupRegex = /^group\s?=\s?["']?([0-9a-zA-Z.-]*)['"]?/m; if (yield p.hasFile("gradle.properties")) { const gradleProperties = yield (yield p.getFile("gradle.properties")).getContent(); const match = gradleProperties.match(groupRegex); if (!!match) { group = gradleProperties.match(groupRegex)[1]; } } else if (yield p.hasFile("build.gradle")) { const gradleBuild = yield (yield p.getFile("build.gradle")).getContent(); const match = gradleBuild.match(groupRegex); if (!!match) { group = gradleBuild.match(groupRegex)[1]; } } else if (yield p.hasFile("build.gradle.kts")) { const gradleBuild = yield (yield p.getFile("build.gradle.kts")).getContent(); const match = gradleBuild.match(groupRegex); if (!!match) { group = gradleBuild.match(groupRegex)[1]; } } return group; }); } exports.getProjectGroup = getProjectGroup; function getGradleModules(p) { return __awaiter(this, void 0, void 0, function* () { const initScript = ` rootProject { task getModules { def builder = []; subprojects.each { builder << it.project.projectPath.toString() } new File(rootDir, ".atomist-modules.txt").text = builder.join(";") } }`; const log = new sdm_1.StringCapturingProgressLog(); p.addFileSync(".atomist.gradle", initScript); yield sdm_1.spawnLog(yield gradleCommand_1.determineGradleCommand(p), ["--init-script", ".atomist.gradle", "-q", `:getModules`], { log, cwd: p.baseDir }); p.deleteFileSync(".atomist.gradle"); const output = yield (yield p.getFile(".atomist-modules.txt")).getContent(); p.deleteFileSync(".atomist-modules.txt"); return output.split(";"); }); } exports.getGradleModules = getGradleModules; function getClasspathForConfiguration(p, configuration, module) { return __awaiter(this, void 0, void 0, function* () { const initScript = ` allprojects { task generateConfigurationClasspath { def output = new File(rootDir, ".atomist-dependencies.txt"); doLast { output.text = configurations.${configuration}.resolve() } } }`; const log = new sdm_1.StringCapturingProgressLog(); p.addFileSync(".atomist.gradle", initScript); if (module) { yield sdm_1.spawnLog(yield gradleCommand_1.determineGradleCommand(p), ["--init-script", ".atomist.gradle", "-q", `${module}:generateConfigurationClasspath`], { log, cwd: p.baseDir }); } else { yield sdm_1.spawnLog(yield gradleCommand_1.determineGradleCommand(p), ["--init-script", ".atomist.gradle", "-q", `:generateConfigurationClasspath`], { log, cwd: p.baseDir }); } p.deleteFileSync(".atomist.gradle"); const output = yield (yield p.getFile(".atomist-dependencies.txt")).getContent(); p.deleteFileSync(".atomist-dependencies.txt"); const dependencies = output.substring(1, output.length - 1); return dependencies.split(", "); }); } exports.getClasspathForConfiguration = getClasspathForConfiguration; /** * Return the identification of a project: name and version * @param {Project} p * @return {Promise<any>} * @constructor */ exports.GradleProjectIdentifier = (p) => __awaiter(void 0, void 0, void 0, function* () { const appName = p.name; const version = yield getProjectVersion(p); const group = yield getProjectGroup(p); return { name: appName, artifact: appName, version, group, }; }); //# sourceMappingURL=buildGradleParser.js.map