"use strict";
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 });
exports.GradleBuildService = void 0;
const helpers_1 = require("../../common/helpers");
const constants = require("../../constants");
const events_1 = require("events");
const yok_1 = require("../../common/yok");
class GradleBuildService extends events_1.EventEmitter {
    constructor($childProcess, $gradleBuildArgsService, $gradleCommandService) {
        super();
        this.$childProcess = $childProcess;
        this.$gradleBuildArgsService = $gradleBuildArgsService;
        this.$gradleCommandService = $gradleCommandService;
    }
    buildProject(projectRoot, buildData) {
        return __awaiter(this, void 0, void 0, function* () {
            const buildTaskArgs = yield this.$gradleBuildArgsService.getBuildTaskArgs(buildData);
            const spawnOptions = {
                emitOptions: { eventName: constants.BUILD_OUTPUT_EVENT_NAME },
                throwError: true,
            };
            const gradleCommandOptions = {
                cwd: projectRoot,
                message: "Gradle build...",
                stdio: buildData.buildOutputStdio,
                gradlePath: buildData.gradlePath,
                spawnOptions,
            };
            yield (0, helpers_1.attachAwaitDetach)(constants.BUILD_OUTPUT_EVENT_NAME, this.$childProcess, (data) => this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data), this.$gradleCommandService.executeCommand(buildTaskArgs, gradleCommandOptions));
        });
    }
    cleanProject(projectRoot, buildData) {
        return __awaiter(this, void 0, void 0, function* () {
            const cleanTaskArgs = this.$gradleBuildArgsService.getCleanTaskArgs(buildData);
            const gradleCommandOptions = {
                cwd: projectRoot,
                message: "Gradle clean...",
                gradlePath: buildData.gradlePath,
            };
            yield this.$gradleCommandService.executeCommand(cleanTaskArgs, gradleCommandOptions);
        });
    }
}
exports.GradleBuildService = GradleBuildService;
yok_1.injector.register("gradleBuildService", GradleBuildService);
//# sourceMappingURL=gradle-build-service.js.map